refactor!: Use gin router instead chi router

- Removed chi dependencies
- Updated router registration logic
This commit is contained in:
2025-11-04 13:44:18 +03:00
parent 7e9653606e
commit 7bc4ce8c96
13 changed files with 499 additions and 294 deletions

View File

@@ -0,0 +1,60 @@
package service
import (
"net/http"
"git.ostiwe.com/ostiwe-com/status/modules/jwt"
"git.ostiwe.com/ostiwe-com/status/modules/log"
http2 "git.ostiwe.com/ostiwe-com/status/pkg/http"
"git.ostiwe.com/ostiwe-com/status/repository"
"git.ostiwe.com/ostiwe-com/status/router/controller"
"git.ostiwe.com/ostiwe-com/status/router/midlleware"
"git.ostiwe.com/ostiwe-com/status/transform"
"github.com/gin-gonic/gin"
)
type GetServices struct {
serviceRepository repository.Service
}
func (g *GetServices) New() controller.Controller {
return &GetServices{
serviceRepository: repository.NewServiceRepository(),
}
}
func (g *GetServices) Handler() gin.HandlerFunc {
return func(c *gin.Context) {
items, err := g.serviceRepository.All(c.Request.Context(), -1, 0, true)
if err != nil {
log.Global.Get(log.SERVER).Error(err)
writeErr := http2.NewResponseErrBuilder().
WithMessage("Fetch service error").
WithStatusCode(http.StatusInternalServerError).
Send(c)
if writeErr != nil {
log.Global.Get(log.SERVER).Error(writeErr)
}
return
}
c.JSON(http.StatusOK, transform.PublicServices(items...))
}
}
func (g *GetServices) Method() string {
return http.MethodGet
}
func (g *GetServices) Path() string {
return "/api/v1/services"
}
func (g *GetServices) Middlewares() []gin.HandlerFunc {
return []gin.HandlerFunc{
jwt.AuthMiddleware.MiddlewareFunc(),
midlleware.SetUserFromJWT(),
}
}