2023-08-16 13:17:42 +03:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
2023-08-18 23:59:15 +03:00
|
|
|
"git.unistack.org/unistack-org/pkgdash/internal/models"
|
2023-08-16 13:17:42 +03:00
|
|
|
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
2023-08-18 23:59:15 +03:00
|
|
|
httpsrv "go.unistack.org/micro-server-http/v4"
|
|
|
|
"go.unistack.org/micro/v4/logger"
|
2023-08-16 13:17:42 +03:00
|
|
|
)
|
|
|
|
|
2023-08-20 14:19:57 +03:00
|
|
|
func (h *Handler) PackageUpdate(ctx context.Context, req *pb.PackageUpdateReq, rsp *pb.PackageUpdateRsp) error {
|
2023-08-16 13:17:42 +03:00
|
|
|
logger.Debug(ctx, "Start UpdatePackage")
|
|
|
|
|
|
|
|
if err := req.Validate(); err != nil {
|
|
|
|
logger.Error(ctx, err)
|
|
|
|
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
|
|
|
|
return httpsrv.SetError(NewValidationError(err))
|
|
|
|
}
|
|
|
|
|
2023-08-20 14:19:57 +03:00
|
|
|
pkg, err := h.store.PackageUpdate(ctx, req)
|
2023-08-18 23:59:15 +03:00
|
|
|
if err != nil {
|
2023-08-16 13:17:42 +03:00
|
|
|
logger.Error(ctx, err)
|
|
|
|
httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
|
|
|
|
return httpsrv.SetError(NewInternalError(err))
|
|
|
|
}
|
|
|
|
|
2023-08-18 23:59:15 +03:00
|
|
|
rsp.Package = models.NewPackage(pkg)
|
2023-08-16 13:17:42 +03:00
|
|
|
|
|
|
|
logger.Debug(ctx, "Success finish UpdatePackage")
|
|
|
|
return nil
|
|
|
|
}
|