WIP: add missing handlers, services nd repositories
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/models"
|
||||
"kontor-api-echo/internal/repository"
|
||||
"kontor-api-echo/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type AssignmentHandler struct {
|
||||
Service *service.AssignmentService
|
||||
}
|
||||
|
||||
func NewAssignmentHandler(db *bun.DB) *AssignmentHandler {
|
||||
handler := &AssignmentHandler{Service: service.NewAssignmentService(repository.NewAssignmentRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *AssignmentHandler) List(c *echo.Context) {
|
||||
assignments, err := handler.Service.List(c.Request().Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertAssignmentsToDtos(assignments)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
Reference in New Issue
Block a user