move init route
This commit is contained in:
parent
28353a910c
commit
54afe3ebcf
@ -85,3 +85,10 @@ func (s *Service) Logout(c *gin.Context) {
|
|||||||
"status": "success",
|
"status": "success",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) AccountInit() {
|
||||||
|
ac := s.Gin.Group("/account")
|
||||||
|
ac.POST("/signup", s.Signup)
|
||||||
|
ac.POST("/login", s.Login)
|
||||||
|
ac.GET("/logout", s.RequireAuthToken, s.Logout)
|
||||||
|
}
|
||||||
|
@ -260,3 +260,14 @@ func (s *Service) FileAnalyze(c *gin.Context) {
|
|||||||
"exif": entries,
|
"exif": entries,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) FileInit() {
|
||||||
|
file := s.Gin.Group("/file")
|
||||||
|
file.Use(s.RequireSession)
|
||||||
|
file.POST("", s.FileCreate)
|
||||||
|
file.HEAD("/:checksum", s.FileExists)
|
||||||
|
file.GET("/:checksum", s.FileGet)
|
||||||
|
file.POST("/chunk", s.FileCreateChunk)
|
||||||
|
file.HEAD("/chunk/:checksum", s.FileChunkExists)
|
||||||
|
file.GET("/analyze/:checksum", s.FileAnalyze)
|
||||||
|
}
|
||||||
|
@ -40,32 +40,15 @@ func New(config *ServiceConfig) *Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) SetupRoutes() {
|
func (s *Service) SetupRoutes() {
|
||||||
s.Gin.Use(gin.Logger())
|
s.Gin.Use(
|
||||||
s.Gin.Use(s.Recovery)
|
gin.Logger(),
|
||||||
s.Gin.Use(s.RequireBody)
|
s.Recovery,
|
||||||
|
s.RequireBody,
|
||||||
|
)
|
||||||
|
|
||||||
ac := s.Gin.Group("/account")
|
s.AccountInit()
|
||||||
ac.POST("/signup", s.Signup)
|
s.MeInit()
|
||||||
ac.POST("/login", s.Login)
|
s.FileInit()
|
||||||
ac.GET("/logout", s.RequireAuthToken, s.Logout)
|
|
||||||
|
|
||||||
s.Gin.GET("/me", s.RequireSession, func(c *gin.Context) {
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
|
||||||
"status": "success",
|
|
||||||
"user": s.CurrentSession(c).Account.Login,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
file := s.Gin.Group("/file")
|
|
||||||
file.Use(s.RequireSession)
|
|
||||||
file.POST("", s.FileCreate)
|
|
||||||
file.HEAD("/:checksum", s.FileExists)
|
|
||||||
file.GET("/:checksum", s.FileGet)
|
|
||||||
|
|
||||||
file.POST("/chunk", s.FileCreateChunk)
|
|
||||||
file.HEAD("/chunk/:checksum", s.FileChunkExists)
|
|
||||||
|
|
||||||
file.GET("/analyze/:checksum", s.FileAnalyze)
|
|
||||||
|
|
||||||
s.Gin.NoRoute(func(c *gin.Context) {
|
s.Gin.NoRoute(func(c *gin.Context) {
|
||||||
s.Error(c, http.StatusNotFound, photoserrors.ErrReqNotFound)
|
s.Error(c, http.StatusNotFound, photoserrors.ErrReqNotFound)
|
||||||
|
18
internal/photos/api/me.go
Normal file
18
internal/photos/api/me.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Service) Me(c *gin.Context) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"status": "success",
|
||||||
|
"user": s.CurrentSession(c).Account.Login,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) MeInit() {
|
||||||
|
s.Gin.GET("/me", s.RequireSession, s.Me)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user