all repos

onasty @ 0c026f2

a one-time notes service

onasty/internal/transport/http/apiv1/apiv1.go (view raw)

Smirnov Oleksandr Smirnov Oleksandr
ss2316544@gmail.com
feat: send emails on sign-up (#6)..., 1 year ago
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
	auth := r.Group("/auth")
26
	{
27
		auth.POST("/signup", a.signUpHandler)
28
		auth.POST("/signin", a.signInHandler)
29
		auth.POST("/refresh-tokens", a.refreshTokensHandler)
30
		auth.GET("/verify/:token", a.verifyHandler)
31
		auth.POST("/resend-verification-email", a.resendVerificationEmailHandler)
32
33
		authorized := auth.Group("/", a.authorizedMiddleware)
34
		{
35
			authorized.POST("/logout", a.logOutHandler)
36
			authorized.POST("/change-password", a.changePasswordHandler)
37
		}
38
	}
39
40
	note := r.Group("/note", a.couldBeAuthorizedMiddleware)
41
	{
42
		note.GET("/:slug", a.getNoteBySlugHandler)
43
		note.POST("", a.createNoteHandler)
44
	}
45
}