-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_default_bookcases.go
More file actions
40 lines (30 loc) · 1.04 KB
/
create_default_bookcases.go
File metadata and controls
40 lines (30 loc) · 1.04 KB
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
package endpoints
import (
"fantlab/core/converters"
"fantlab/pb"
"net/http"
"google.golang.org/protobuf/proto"
)
func (api *API) CreateDefaultBookcases(r *http.Request) (int, proto.Message) {
user := api.getUser(r)
dbBookcases, err := api.services.DB().FetchAllUserBookcases(r.Context(), user.UserId, true)
if err != nil {
return http.StatusInternalServerError, &pb.Error_Response{
Status: pb.Error_SOMETHING_WENT_WRONG,
}
}
if len(dbBookcases) > 0 {
return http.StatusForbidden, &pb.Error_Response{
Status: pb.Error_ACTION_FORBIDDEN,
Context: "Создать первичные книжные полки можно только в том случае, если не создано еще ни одной",
}
}
dbBookcases, err = api.services.DB().InsertDefaultBookcases(r.Context(), user.UserId)
if err != nil {
return http.StatusInternalServerError, &pb.Error_Response{
Status: pb.Error_SOMETHING_WENT_WRONG,
}
}
bookcasesResponse := converters.GetBookcases(dbBookcases)
return http.StatusOK, bookcasesResponse
}