@@ -6,13 +6,13 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/models"
|
||||
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"go.unistack.org/micro/v4/logger"
|
||||
)
|
||||
|
||||
func (h *Handler) CommentsCreate(ctx context.Context, req *pb.CommentsCreateReq, rsp *pb.CommentsCreateRsp) error {
|
||||
logger := h.svc.Logger()
|
||||
logger.Debug(ctx, "Start AddComment")
|
||||
|
||||
err := req.Validate()
|
||||
|
@@ -6,12 +6,12 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"go.unistack.org/micro/v4/logger"
|
||||
)
|
||||
|
||||
func (h *Handler) CommentsDelete(ctx context.Context, req *pb.CommentsDeleteReq, rsp *pb.CommentsDeleteRsp) error {
|
||||
logger := h.svc.Logger()
|
||||
logger.Debug(ctx, "Start AddComment")
|
||||
|
||||
err := req.Validate()
|
||||
|
@@ -4,13 +4,13 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/models"
|
||||
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"go.unistack.org/micro/v4/logger"
|
||||
)
|
||||
|
||||
func (h *Handler) CommentsList(ctx context.Context, req *pb.CommentsListReq, rsp *pb.CommentsListRsp) error {
|
||||
logger := h.svc.Logger()
|
||||
logger.Debug(ctx, "Start GetModule")
|
||||
|
||||
err := req.Validate()
|
||||
|
@@ -1,27 +1,19 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"go.unistack.org/micro/v4"
|
||||
cligit "git.unistack.org/unistack-org/pkgdash/internal/service/client_git"
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/storage"
|
||||
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"github.com/google/uuid"
|
||||
jsonpbcodec "go.unistack.org/micro-codec-jsonpb/v4"
|
||||
"go.unistack.org/micro/v4/codec"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
svc micro.Service
|
||||
store storage.Storage
|
||||
|
||||
protojson.MarshalOptions
|
||||
protojson.UnmarshalOptions
|
||||
|
||||
git cligit.Client
|
||||
store storage.Storage
|
||||
codec codec.Codec
|
||||
chanUrl chan *pb.PackagesCreateReq
|
||||
}
|
||||
|
||||
@@ -52,25 +44,11 @@ func NewValidationError(err error) *pb.ErrorRsp {
|
||||
}
|
||||
}
|
||||
|
||||
func NewHandler(svc micro.Service, client cligit.Client) *Handler {
|
||||
func NewHandler(store storage.Storage) (*Handler, error) {
|
||||
h := &Handler{
|
||||
svc: svc,
|
||||
git: client,
|
||||
}
|
||||
h.EmitUnpopulated = true
|
||||
h.UseProtoNames = false
|
||||
return h
|
||||
}
|
||||
|
||||
func (h *Handler) Init(ctx context.Context) error {
|
||||
store, err := storage.FromContext(h.svc.Options().Context)
|
||||
if err != nil {
|
||||
return errors.New("missing storage")
|
||||
codec: jsonpbcodec.NewCodec(),
|
||||
store: store,
|
||||
}
|
||||
|
||||
h.chanUrl = h.git.Run(ctx, store)
|
||||
|
||||
h.store = store
|
||||
|
||||
return nil
|
||||
return h, nil
|
||||
}
|
||||
|
@@ -4,13 +4,13 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/models"
|
||||
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"go.unistack.org/micro/v4/logger"
|
||||
)
|
||||
|
||||
func (h *Handler) ModulesList(ctx context.Context, req *pb.ModulesListReq, rsp *pb.ModulesListRsp) error {
|
||||
logger := h.svc.Logger()
|
||||
logger.Debug(ctx, "Start GetModule")
|
||||
|
||||
err := req.Validate()
|
||||
|
@@ -4,29 +4,30 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/models"
|
||||
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"go.unistack.org/micro/v4/logger"
|
||||
)
|
||||
|
||||
func (h *Handler) PackagesCreate(ctx context.Context, req *pb.PackagesCreateReq, rsp *pb.PackagesCreateRsp) error {
|
||||
logger := h.svc.Logger()
|
||||
logger.Debug(ctx, "Start AddPackage")
|
||||
logger.Debug(ctx, "PackagesCreate handler start")
|
||||
|
||||
err := req.Validate()
|
||||
if err := req.Validate(); err != nil {
|
||||
logger.Error(ctx, err)
|
||||
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
|
||||
return httpsrv.SetError(NewValidationError(err))
|
||||
}
|
||||
|
||||
pkg, err := h.store.PackagesCreate(ctx, req)
|
||||
if err != nil {
|
||||
logger.Error(ctx, err)
|
||||
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
|
||||
return httpsrv.SetError(NewValidationError(err))
|
||||
}
|
||||
|
||||
if h.git.IsClose() {
|
||||
logger.Error(ctx, "chan is closed")
|
||||
} else {
|
||||
h.chanUrl <- req
|
||||
}
|
||||
rsp.Package = models.NewPackage(pkg)
|
||||
|
||||
rsp.Status = "Sent"
|
||||
|
||||
logger.Debug(ctx, "Success finish addPackage")
|
||||
logger.Debug(ctx, "PackagesCreate handler stop")
|
||||
return nil
|
||||
}
|
||||
|
@@ -4,12 +4,12 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"go.unistack.org/micro/v4/logger"
|
||||
)
|
||||
|
||||
func (h *Handler) PackagesDelete(ctx context.Context, req *pb.PackagesDeleteReq, rsp *pb.PackagesDeleteRsp) error {
|
||||
logger := h.svc.Logger()
|
||||
logger.Debug(ctx, "Start UpdatePackage")
|
||||
|
||||
if err := req.Validate(); err != nil {
|
||||
|
@@ -4,14 +4,14 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/models"
|
||||
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"go.unistack.org/micro/v4/logger"
|
||||
)
|
||||
|
||||
func (h *Handler) PackagesList(ctx context.Context, req *pb.PackagesListReq, rsp *pb.PackagesListRsp) error {
|
||||
logger := h.svc.Logger()
|
||||
logger.Debug(ctx, "Start getListPackage")
|
||||
logger.Debug(ctx, "PackagesList handler start")
|
||||
|
||||
packages, err := h.store.PackagesList(ctx, req)
|
||||
if err != nil {
|
||||
@@ -23,6 +23,6 @@ func (h *Handler) PackagesList(ctx context.Context, req *pb.PackagesListReq, rsp
|
||||
for _, pkg := range packages {
|
||||
rsp.Packages = append(rsp.Packages, models.NewPackage(pkg))
|
||||
}
|
||||
logger.Debug(ctx, "Success finish getListPackage")
|
||||
logger.Debug(ctx, "PackagesList handler stop")
|
||||
return nil
|
||||
}
|
||||
|
33
internal/handler/packages_lookup.go
Normal file
33
internal/handler/packages_lookup.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/models"
|
||||
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"go.unistack.org/micro/v4/logger"
|
||||
)
|
||||
|
||||
func (h *Handler) PackagesLookup(ctx context.Context, req *pb.PackagesLookupReq, rsp *pb.PackagesLookupRsp) error {
|
||||
logger.Debug(ctx, "Start PackagesLookup")
|
||||
|
||||
if err := req.Validate(); err != nil {
|
||||
logger.Error(ctx, err)
|
||||
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
|
||||
return httpsrv.SetError(NewValidationError(err))
|
||||
}
|
||||
|
||||
pkg, err := h.store.PackagesLookup(ctx, req)
|
||||
if err != nil {
|
||||
logger.Error(ctx, err)
|
||||
httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
|
||||
return httpsrv.SetError(NewInternalError(err))
|
||||
}
|
||||
|
||||
rsp.Package = models.NewPackage(pkg)
|
||||
|
||||
logger.Debug(ctx, "Success finish PackagesLookup")
|
||||
return nil
|
||||
}
|
@@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/models"
|
||||
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
"go.unistack.org/micro/v4/logger"
|
||||
)
|
||||
|
||||
func (h *Handler) PackagesUpdate(ctx context.Context, req *pb.PackagesUpdateReq, rsp *pb.PackagesUpdateRsp) error {
|
||||
logger := h.svc.Logger()
|
||||
logger.Debug(ctx, "Start UpdatePackage")
|
||||
|
||||
if err := req.Validate(); err != nil {
|
||||
@@ -18,13 +19,14 @@ func (h *Handler) PackagesUpdate(ctx context.Context, req *pb.PackagesUpdateReq,
|
||||
return httpsrv.SetError(NewValidationError(err))
|
||||
}
|
||||
|
||||
if err := h.store.PackagesUpdate(ctx, req); err != nil {
|
||||
pkg, err := h.store.PackagesUpdate(ctx, req)
|
||||
if err != nil {
|
||||
logger.Error(ctx, err)
|
||||
httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
|
||||
return httpsrv.SetError(NewInternalError(err))
|
||||
}
|
||||
|
||||
// rsp.Id = req.Id
|
||||
rsp.Package = models.NewPackage(pkg)
|
||||
|
||||
logger.Debug(ctx, "Success finish UpdatePackage")
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user