Files
query-orchestration/api/queryService/client.go
T

61 lines
1.5 KiB
Go
Raw Normal View History

2025-01-21 18:24:14 +00:00
package queryservice
import (
"fmt"
"net/http"
2025-03-05 12:05:46 +00:00
2025-01-21 18:24:14 +00:00
"queryorchestration/internal/client"
"github.com/labstack/echo/v4"
)
func (s *Controllers) CreateClient(ctx echo.Context) error {
req := ClientCreate{}
if err := ctx.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
_, err := s.svc.Client.Create(ctx.Request().Context(), client.CreateParams{
Name: req.Name,
ExternalId: req.Id,
})
2025-01-21 18:24:14 +00:00
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to create client: %s", err))
}
return ctx.JSON(http.StatusCreated, ClientIDBody{
Id: req.Id,
2025-01-21 18:24:14 +00:00
})
}
func (s *Controllers) GetClient(ctx echo.Context, id string) error {
client, err := s.svc.Client.GetByExternalId(ctx.Request().Context(), id)
2025-01-21 18:24:14 +00:00
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to get client: %s", err))
2025-01-21 18:24:14 +00:00
}
return ctx.JSON(http.StatusOK, DocClient{
Id: client.ExternalID,
Uid: client.ID,
2025-01-21 18:24:14 +00:00
Name: client.Name,
CanSync: client.CanSync,
})
}
func (s *Controllers) UpdateClient(ctx echo.Context, id string) error {
2025-01-21 18:24:14 +00:00
req := ClientUpdate{}
if err := ctx.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
err := s.svc.Client.UpdateByExternalId(ctx.Request().Context(), id, &client.Update{
2025-01-21 18:24:14 +00:00
Name: req.Name,
CanSync: req.CanSync,
})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to update query: %s", err))
}
return ctx.NoContent(http.StatusOK)
}