Files
status/router/controller/service/public_get.go
ostiwe 7bc4ce8c96 refactor!: Use gin router instead chi router
- Removed chi dependencies
- Updated router registration logic
2025-11-04 19:20:00 +03:00

52 lines
1.2 KiB
Go

package service
import (
"net/http"
"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/transform"
"github.com/gin-gonic/gin"
)
type PublicGetServicesController struct {
serviceRepository repository.Service
}
func (p *PublicGetServicesController) New() controller.Controller {
return &PublicGetServicesController{
serviceRepository: repository.NewServiceRepository(),
}
}
func (p *PublicGetServicesController) Handler() gin.HandlerFunc {
return func(c *gin.Context) {
items, err := p.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 (p *PublicGetServicesController) Method() string {
return http.MethodGet
}
func (p *PublicGetServicesController) Path() string {
return "/api/v1/public/services"
}