onasty/internal/transport/http/apiv1/apiv1.go(view raw)
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 |
package apiv1
import (
"github.com/gin-gonic/gin"
"github.com/olexsmir/onasty/internal/service/notesrv"
"github.com/olexsmir/onasty/internal/service/usersrv"
)
type APIV1 struct {
usersrv usersrv.UserServicer
notesrv notesrv.NoteServicer
}
func NewAPIV1(
us usersrv.UserServicer,
ns notesrv.NoteServicer,
) *APIV1 {
return &APIV1{
usersrv: us,
notesrv: ns,
}
}
func (a *APIV1) Routes(r *gin.RouterGroup) {
auth := r.Group("/auth")
{
auth.POST("/signup", a.signUpHandler)
auth.POST("/signin", a.signInHandler)
auth.POST("/refresh-tokens", a.refreshTokensHandler)
authorized := auth.Group("/", a.authorizedMiddleware)
{
authorized.POST("/logout", a.logOutHandler)
}
}
note := r.Group("/note", a.couldBeAuthorizedMiddleware)
{
note.GET("/:slug", a.getNoteBySlugHandler)
note.POST("", a.createNoteHandler)
}
}
|