/
schedule.go
40 lines (33 loc) · 978 Bytes
/
schedule.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
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) GetClubSchedule() gin.HandlerFunc {
return func(ctx *gin.Context) {
clubUUID := ctx.GetString(consts.ClubUUIDKeyName)
schedules, err := h.repo.GetSchedulesByClubUUID(clubUUID)
if err != nil {
ctx.Status(http.StatusInternalServerError)
} else {
ctx.JSON(http.StatusOK, clubs.Schedules(schedules).ToScheduleResponse())
}
}
}
func (h *Handler) UpdateClubSchedule() gin.HandlerFunc {
return func(ctx *gin.Context) {
var pd []clubs.ScheduleRequest
if err := ctx.ShouldBindJSON(&pd); err != nil {
ctx.Status(http.StatusBadRequest)
return
}
clubUUID := ctx.GetString(consts.ClubUUIDKeyName)
if err := h.repo.UpdateSchedule(clubUUID, validateToScheduleArgs(pd)); err != nil {
ctx.Status(http.StatusInternalServerError)
} else {
ctx.JSON(http.StatusCreated, pd)
}
}
}