You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
![]()
4 weeks ago
|
package column
|
||
|
|
||
|
import (
|
||
|
"cls/internal/application/column"
|
||
|
"cls/internal/infrastructure/middleware/auth"
|
||
|
"cls/internal/interfaces"
|
||
|
"cls/pkg/logger"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
type ColumnHandler struct {
|
||
|
service *column.Service
|
||
|
authMiddleware *auth.AuthMiddleware
|
||
|
log logger.Logger
|
||
|
}
|
||
|
|
||
|
var _ interfaces.Handler = (*ColumnHandler)(nil)
|
||
|
|
||
|
func NewColumnHandler(service *column.Service, authMiddleware *auth.AuthMiddleware, log logger.New) *ColumnHandler {
|
||
|
return &ColumnHandler{service, authMiddleware, log("cls:interfaces:column")}
|
||
|
}
|
||
|
|
||
|
func (ch *ColumnHandler) RegisterRouters(app gin.IRouter) {
|
||
|
auth := app.Group("/column")
|
||
|
{
|
||
|
auth.GET("/get", ch.getColumnByName)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (ch *ColumnHandler) getColumnByName(c *gin.Context) {
|
||
|
ePhone, err := ch.authMiddleware.DecodeToken(c)
|
||
|
if err != nil {
|
||
|
ePhone = ""
|
||
|
}
|
||
|
dto, err := ch.service.GetColumn(ePhone, c.Query("title"))
|
||
|
if err != nil {
|
||
|
c.AbortWithStatus(http.StatusInternalServerError)
|
||
|
} else {
|
||
|
c.AbortWithStatusJSON(http.StatusOK, dto)
|
||
|
}
|
||
|
}
|