package queryservice import ( "fmt" "net/http" "queryorchestration/internal/client" "github.com/google/uuid" "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) } id, err := s.svc.Client.Create(ctx.Request().Context(), req.Name) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to create client: %s", err)) } return ctx.JSON(http.StatusCreated, IdMessage{ Id: id.String(), }) } func (s *Controllers) GetClient(ctx echo.Context, id string) error { uid, err := uuid.Parse(id) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID") } client, err := s.svc.Client.Get(ctx.Request().Context(), uid) if err != nil { return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to get client: %s", err)) } return ctx.JSON(http.StatusOK, JobClient{ Id: client.ID.String(), Name: client.Name, CanSync: client.CanSync, }) } func (s *Controllers) UpdateClient(ctx echo.Context, id string) error { req := ClientUpdate{} if err := ctx.Bind(&req); err != nil { return echo.NewHTTPError(http.StatusBadRequest, err) } uid, err := uuid.Parse(id) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID") } err = s.svc.Client.Update(ctx.Request().Context(), &client.Update{ ID: uid, 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) }