/
link.go
41 lines (34 loc) · 972 Bytes
/
link.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
package v1
import (
"github.com/gin-gonic/gin"
"github.com/lc-tut/club-portal/consts"
"github.com/lc-tut/club-portal/models/clubs"
"net/http"
)
func (h *Handler) GetClubLinks() gin.HandlerFunc {
return func(ctx *gin.Context) {
clubUUID := ctx.GetString(consts.ClubUUIDKeyName)
links, err := h.repo.GetLinksByClubUUID(clubUUID)
if err != nil {
ctx.Status(http.StatusInternalServerError)
} else {
ctx.JSON(http.StatusOK, clubs.Links(links).ToLinkResponse())
}
}
}
func (h *Handler) UpdateClubLinks() gin.HandlerFunc {
return func(ctx *gin.Context) {
var pd []clubs.LinkRequest
if err := ctx.ShouldBindJSON(&pd); err != nil {
h.logger.Error(err.Error())
ctx.Status(http.StatusBadRequest)
return
}
clubUUID := ctx.GetString(consts.ClubUUIDKeyName)
if err := h.repo.UpdateLink(clubUUID, validateToLinksArgs(pd)); err != nil {
ctx.Status(http.StatusInternalServerError)
} else {
ctx.JSON(http.StatusCreated, pd)
}
}
}