onasty/internal/transport/http/apiv1/apiv1.go (view raw)
| 1 | package apiv1 |
| 2 | |
| 3 | import ( |
| 4 | "github.com/gin-gonic/gin" |
| 5 | "github.com/olexsmir/onasty/internal/service/notesrv" |
| 6 | "github.com/olexsmir/onasty/internal/service/usersrv" |
| 7 | ) |
| 8 | |
| 9 | type APIV1 struct { |
| 10 | usersrv usersrv.UserServicer |
| 11 | notesrv notesrv.NoteServicer |
| 12 | } |
| 13 | |
| 14 | func NewAPIV1( |
| 15 | us usersrv.UserServicer, |
| 16 | ns notesrv.NoteServicer, |
| 17 | ) *APIV1 { |
| 18 | return &APIV1{ |
| 19 | usersrv: us, |
| 20 | notesrv: ns, |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | func (a *APIV1) Routes(r *gin.RouterGroup) { |
| 25 | r.Use(a.metricsMiddleware) |
| 26 | auth := r.Group("/auth") |
| 27 | { |
| 28 | auth.POST("/signup", a.signUpHandler) |
| 29 | auth.POST("/signin", a.signInHandler) |
| 30 | auth.POST("/refresh-tokens", a.refreshTokensHandler) |
| 31 | auth.GET("/verify/:token", a.verifyHandler) |
| 32 | auth.POST("/resend-verification-email", a.resendVerificationEmailHandler) |
| 33 | |
| 34 | authorized := auth.Group("/", a.authorizedMiddleware) |
| 35 | { |
| 36 | authorized.POST("/logout", a.logOutHandler) |
| 37 | authorized.POST("/change-password", a.changePasswordHandler) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | note := r.Group("/note", a.couldBeAuthorizedMiddleware) |
| 42 | { |
| 43 | note.GET("/:slug", a.getNoteBySlugHandler) |
| 44 | note.POST("", a.createNoteHandler) |
| 45 | } |
| 46 | } |