/
handler.go
92 lines (67 loc) · 1.69 KB
/
handler.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package handler
import (
"github.com/4from5/TimeHack-webapi/pkg/service"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
type Handler struct {
services *service.Service
}
func NewHandler(services *service.Service) *Handler {
return &Handler{services: services}
}
func (h *Handler) InitRoutes() *gin.Engine {
router := gin.New()
router.Use(cors.Default())
auth := router.Group("/auth")
{
auth.POST("/sign-up", h.signUp)
auth.POST("/sign-in", h.signIn)
}
api := router.Group("/api", h.userIdentity)
{
user := api.Group("/user")
{
user.GET("/", h.getUsername)
}
categories := api.Group("/categories")
{
categories.GET("/", h.getCategories)
categories.GET("/:id", h.getCategoryById)
categories.POST("/", h.createCategory)
categories.DELETE("/:id", h.deleteCategory)
categories.PUT("/:id", h.updateCategory)
}
events := api.Group("/events")
{
events.GET("/", h.getEvents)
events.GET("/:id", h.getEventById)
events.POST("/:id", h.createEvent)
events.POST("/schedule", h.getSchedule)
events.DELETE("/:id", h.deleteEvent)
events.GET("/download", h.Download)
events.PUT("/:id", h.updateEvent)
}
notions := api.Group("/notions")
{
notions.GET("/", h.getNotions)
notions.GET("/:id", h.getNotionById)
notions.POST("/", h.createNotion)
notions.DELETE("/:id", h.deleteNotion)
notions.PUT("/:id", h.updateNotion)
}
tasks := api.Group("/tasks")
{
tasks.GET("/", h.getTasks)
tasks.GET("/:id", h.getTaskById)
tasks.POST("/", h.createTask)
tasks.DELETE("/:id", h.deleteTask)
tasks.PUT("/:id", h.updateTask)
}
week := api.Group("/week")
{
week.POST("/", h.getWeek)
}
}
return router
}