-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_forum.go
73 lines (59 loc) · 2.16 KB
/
show_forum.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
65
66
67
68
69
70
71
72
73
package endpoints
import (
"fantlab/core/converters"
"fantlab/core/helpers"
"fantlab/pb"
"net/http"
"strconv"
"google.golang.org/protobuf/proto"
)
func (api *API) ShowForumTopics(r *http.Request) (int, proto.Message) {
params := struct {
// id форума
ForumId uint64 `http:"id,path"`
// номер страницы (по умолчанию - 1)
Page uint64 `http:"page,query"`
// кол-во записей на странице (по умолчанию - 20)
Limit uint64 `http:"limit,query"`
}{
Page: 1,
Limit: api.services.AppConfig().ForumTopicsInPage,
}
api.bindParams(¶ms, r)
if params.ForumId == 0 {
return api.badParam("id")
}
if params.Page == 0 {
return api.badParam("page")
}
if !helpers.IsValidLimit(params.Limit) {
return api.badParam("limit")
}
availableForums := api.getAvailableForums(r)
isForumExists, err := api.services.DB().FetchForumExists(r.Context(), params.ForumId, availableForums)
if err != nil {
return http.StatusInternalServerError, &pb.Error_Response{
Status: pb.Error_SOMETHING_WENT_WRONG,
}
}
if !isForumExists {
return http.StatusNotFound, &pb.Error_Response{
Status: pb.Error_NOT_FOUND,
Context: strconv.FormatUint(params.ForumId, 10),
}
}
userId := api.getUserId(r)
dbResponse, err := api.services.DB().FetchForumTopics(r.Context(), userId, params.ForumId, params.Limit, params.Limit*(params.Page-1))
if err != nil {
return http.StatusInternalServerError, &pb.Error_Response{
Status: pb.Error_SOMETHING_WENT_WRONG,
}
}
// NOTE Пропущена следующая логика Perl-бэка:
// 1. workgroup_referee - модераторы (поскольку задается хардкодом в Auth.pm)
// 2. хардкод конкретных юзеров как модераторов
// 3. списки тем, посвященных отдельным фильмам, режиссерам, авторам и тд.
// 4. список пользователей, находящихся сейчас на этом форуме
forumTopics := converters.GetForumTopics(dbResponse, params.Page, params.Limit, api.services.AppConfig())
return http.StatusOK, forumTopics
}