-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
64 lines (53 loc) · 1.77 KB
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* Copyright (C) Fedir Petryk */
package user_properties
import (
"net/http"
"strconv"
"github.com/go-playground/validator/v10"
"github.com/labstack/echo/v4"
"github.com/serajam/realestate-sample-app/internal/adapters/handlers/common"
)
// GetUserProp user prop
//
// @Summary GetUserProp user propertyGetRequest by ID
// @Description GetUserProp user propertyGetRequest by ID
// @Tags properties
// @Accept json
// @Produce json
// @Param id path int true "propertyGetRequest ID"
// @Success 200 {object} common.DefaultResponse{data=propertyResponse}
// @Success 404 {object} common.EmptyResponse
// @Failure 400 {object} common.ErrorResponse
// @Failure 401 {object} common.ErrorResponse
// @Failure 403 {object} common.ErrorResponse
// @Failure 404 {object} common.ErrorResponse
// @Failure 500 {object} common.ErrorResponse
// @Router /v1/user/properties/{id} [GET]
func (t Handler) GetUserProp(ctx echo.Context) error {
userID, err := common.UserID(ctx)
if err != nil {
return err
}
id, err := strconv.Atoi(ctx.Param("id"))
if err != nil {
return ctx.JSON(common.ErrValidate.Code, common.ErrorResponse{Message: err.Error()})
}
req := propertyGetRequest{ID: id}
if err := ctx.Validate(req); err != nil {
errors, ok := err.(validator.ValidationErrors)
if !ok {
return ctx.JSON(common.ErrValidate.Code, common.ErrValidate)
}
return ctx.JSON(
common.ErrValidate.Code, common.NewErrorValidateResponse(common.ErrValidate.Err, errors),
)
}
prop, err := t.userPropService.GetUserProperty(ctx.Request().Context(), req.ID, userID)
if err != nil {
return common.ProcessDomainError(ctx, err)
}
if prop == nil {
return ctx.JSON(http.StatusNoContent, common.EmptyResponse{})
}
return ctx.JSON(http.StatusOK, common.DefaultResponse{Data: propertyToResponse(prop)})
}