-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_by_user.go
57 lines (47 loc) · 1.52 KB
/
list_by_user.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
/* Copyright (C) Fedir Petryk */
package user_properties
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/serajam/realestate-sample-app/internal/adapters/handlers/common"
)
// ListByUser
//
// @Summary List properties by auth user id.
// @Description List properties auth user id.
// @Tags properties
// @Accept json
// @Produce json
// @Param Search body propertyListRequest true "property list body"
// @Success 200 {object} common.DefaultResponse{data=[]propertyResponse}
// @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 [GET]
func (t Handler) ListByUser(ctx echo.Context) error {
userID, err := common.UserID(ctx)
if err != nil {
return err
}
req := common.BaseSearchRequest{}
if err := ctx.Bind(&req); err != nil {
return ctx.JSON(common.ErrBind.Code, common.ErrorResponse{Message: err.Error()})
}
ok, err := t.ValidateRequest(ctx, req)
if err != nil || !ok {
return err
}
reqDom := listUserPropertiesToListRequest(req)
properties, err := t.userPropService.ListByUser(ctx.Request().Context(), userID, reqDom)
if err != nil {
return common.ProcessDomainError(ctx, err)
}
if len(properties) == 0 {
return ctx.JSON(http.StatusNoContent, common.EmptyResponse{})
}
return ctx.JSON(
http.StatusOK, common.DefaultResponse{Data: propertiesToListResponse(properties), Count: len(properties)},
)
}