This commit is contained in:
parent
a098baa253
commit
950fa9fd96
4 changed files with 60 additions and 0 deletions
|
|
@ -85,3 +85,38 @@ func (co *controller) delete(c *gin.Context) {
|
|||
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// me godoc
|
||||
//
|
||||
// @Summary Returns user data
|
||||
// @Description Returns user data
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Success 200 {object} MeDTO
|
||||
// @Failure 400 {object} responses.BadRequest
|
||||
// @Failure 401 {object} responses.Unauthorized
|
||||
// @Failure 404 {object} responses.NotFound
|
||||
// @Failure 500 {object} responses.InternalServerError
|
||||
// @Router /user [DELETE]
|
||||
func (co *controller) me(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.getUser(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)
|
||||
}
|
||||
|
|
|
|||
5
internal/user/dto.go
Normal file
5
internal/user/dto.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package user
|
||||
|
||||
type MeDTO struct {
|
||||
UserUuid string `json:"userUuid"`
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ type Repository interface {
|
|||
getUserId(ctx context.Context, userUuid string) (int64, error)
|
||||
addUser(ctx context.Context, u *userModel) error
|
||||
deleteUser(ctx context.Context, userUuid string, deletedAt sql.NullTime) error
|
||||
getUser(ctx context.Context, userUuid string) (*MeDTO, error)
|
||||
}
|
||||
|
||||
type repo struct {
|
||||
|
|
@ -47,3 +48,14 @@ func (r *repo) deleteUser(ctx context.Context, userUuid string, deletedAt sql.Nu
|
|||
_, err := r.db.Exec(ctx, q, deletedAt, userUuid)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *repo) getUser(ctx context.Context, userUuid string) (*MeDTO, error) {
|
||||
q := `SELECT uuid FROM users WHERE uuid = $1 AND deleted_at IS NULL LIMIT 1`
|
||||
row := r.db.QueryRow(ctx, q, userUuid)
|
||||
u := &MeDTO{}
|
||||
|
||||
if err := row.Scan(&u.UserUuid); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return u, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,3 +40,11 @@ func (s *service) createUser(ctx context.Context, userUuid string) error {
|
|||
func (s *service) deleteUser(ctx context.Context, userUuid string) error {
|
||||
return s.repo.deleteUser(ctx, userUuid, s.utils.NullTimeNowUTC())
|
||||
}
|
||||
|
||||
func (s *service) getUser(ctx context.Context, userUuid string) (*MeDTO, error) {
|
||||
if userUuid == "" {
|
||||
return nil, errors.New("user uuid is empty")
|
||||
}
|
||||
|
||||
return s.repo.getUser(ctx, userUuid)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue