This commit is contained in:
parent
c7c67a641e
commit
081267a662
3 changed files with 57 additions and 8 deletions
|
|
@ -29,6 +29,7 @@ func (h *Handler) RegisterRoutes(r *gin.RouterGroup, mw *router.Middlewares) {
|
||||||
userGroup.POST("", mw.RegMW, h.controller.create)
|
userGroup.POST("", mw.RegMW, h.controller.create)
|
||||||
userGroup.DELETE("", mw.AuthMW, h.controller.delete)
|
userGroup.DELETE("", mw.AuthMW, h.controller.delete)
|
||||||
userGroup.GET("/me", mw.AuthMW, h.controller.me)
|
userGroup.GET("/me", mw.AuthMW, h.controller.me)
|
||||||
|
userGroup.GET("/personal", mw.AuthMW, h.controller.getPersonalData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create godoc
|
// create godoc
|
||||||
|
|
@ -121,3 +122,38 @@ func (co *controller) me(c *gin.Context) {
|
||||||
|
|
||||||
c.JSON(http.StatusOK, response)
|
c.JSON(http.StatusOK, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getPersonalData godoc
|
||||||
|
//
|
||||||
|
// @Summary Получить персональные данные.
|
||||||
|
// @Description Получить персональные данные. Запрос данных по gRPC у сервиса авторизации.
|
||||||
|
// @Tags User
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} common.PersonalDTO
|
||||||
|
// @Success 204 {object}
|
||||||
|
// @Failure 400 {object} responses.BadRequest
|
||||||
|
// @Failure 401 {object} responses.Unauthorized
|
||||||
|
// @Failure 500 {object} responses.InternalServerError
|
||||||
|
// @Router /merch/labels/{uuid} [get]
|
||||||
|
func (co *controller) getPersonalData(c *gin.Context) {
|
||||||
|
u, err := co.utils.GetUserUuidFromContext(c)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, responses.BadRequest{Error: err.Error()})
|
||||||
|
appLog.LogErr(pkgLogHeader, controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := co.service.getPersonalData(c, u)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||||
|
appLog.LogErr(pkgLogHeader, controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if response == nil {
|
||||||
|
c.Status(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, response)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
|
"merch-api/internal/common"
|
||||||
"merch-api/pkg/utils"
|
"merch-api/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -15,11 +16,12 @@ type Handler struct {
|
||||||
type Deps struct {
|
type Deps struct {
|
||||||
DB *pgxpool.Pool
|
DB *pgxpool.Pool
|
||||||
Utils utils.Utils
|
Utils utils.Utils
|
||||||
|
AuthDP common.AuthDataProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(deps Deps) *Handler {
|
func New(deps Deps) *Handler {
|
||||||
r := newRepository(deps.DB)
|
r := newRepository(deps.DB)
|
||||||
s := newService(r, deps.Utils)
|
s := newService(r, deps.Utils, deps.AuthDP)
|
||||||
c := newController(s, deps.Utils)
|
c := newController(s, deps.Utils)
|
||||||
|
|
||||||
return &Handler{
|
return &Handler{
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,21 @@ package user
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"merch-api/internal/common"
|
||||||
"merch-api/pkg/utils"
|
"merch-api/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
repo Repository
|
repo Repository
|
||||||
utils utils.Utils
|
utils utils.Utils
|
||||||
|
authDP common.AuthDataProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
func newService(repo Repository, utils utils.Utils) *service {
|
func newService(repo Repository, utils utils.Utils, adp common.AuthDataProvider) *service {
|
||||||
return &service{
|
return &service{
|
||||||
repo: repo,
|
repo: repo,
|
||||||
utils: utils,
|
utils: utils,
|
||||||
|
authDP: adp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,3 +51,11 @@ func (s *service) getUser(ctx context.Context, userUuid string) (*MeDTO, error)
|
||||||
|
|
||||||
return s.repo.getUser(ctx, userUuid)
|
return s.repo.getUser(ctx, userUuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *service) getPersonalData(ctx context.Context, userUuid string) (*common.PersonalDTO, error) {
|
||||||
|
if userUuid == "" {
|
||||||
|
return nil, errors.New("user uuid is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.authDP.GetPersonalData(ctx, userUuid)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue