31 lines
796 B
Go
31 lines
796 B
Go
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 MailAccountHandler struct {
|
|
Service *service.MailAccountService
|
|
}
|
|
|
|
func NewMailAccountHandler(db *bun.DB) *MailAccountHandler {
|
|
handler := &MailAccountHandler{Service: service.NewMailAccountService(repository.NewMailAccountRepository(db))}
|
|
return handler
|
|
}
|
|
|
|
func (handler *MailAccountHandler) List(c *echo.Context) {
|
|
mailaccounts, err := handler.Service.List(c.Request().Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, map[string]any{"error": err.Error()})
|
|
return
|
|
}
|
|
dtos := models.ConvertMailAccountsToDtos(mailaccounts)
|
|
c.JSON(http.StatusOK, dtos)
|
|
}
|