package queryapi import ( "fmt" "net/http" "queryorchestration/internal/client" clientupdate "queryorchestration/internal/client/update" "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, ID: req.Id, }) 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, }) } func (s *Controllers) GetClient(ctx echo.Context, id ClientID) error { client, err := s.svc.Client.Get(ctx.Request().Context(), id) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to get client: %s", err)) } return ctx.JSON(http.StatusOK, DocClient{ Id: client.ID, Name: client.Name, CanSync: client.CanSync, }) } func (s *Controllers) UpdateClient(ctx echo.Context, id ClientID) error { req := ClientUpdate{} if err := ctx.Bind(&req); err != nil { return echo.NewHTTPError(http.StatusBadRequest, err) } err := s.svc.ClientUpdate.Update(ctx.Request().Context(), id, &clientupdate.Update{ 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) } // ListClients returns all clients in the system. func (s *Controllers) ListClients(ctx echo.Context) error { clients, err := s.svc.Client.List(ctx.Request().Context()) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Unable to list clients: %s", err)) } // Convert to API response format apiClients := make([]DocClient, len(clients)) for i, c := range clients { apiClients[i] = DocClient{ Id: c.ID, Name: c.Name, CanSync: c.CanSync, } } return ctx.JSON(http.StatusOK, ClientListResponse{ Clients: apiClients, //nolint:gosec // Client count is bounded by maxItems: 10000 in OpenAPI spec TotalCount: int32(len(apiClients)), }) }