Merged in feature/clientexternalid (pull request #99)
Client External ID * normalizeexternalid * cleanopenapi * cleanopenapi * changingpublic * noprecommit * testing * precommit * processtest * nodb * tests * tests
This commit is contained in:
+12
-10
@@ -7,7 +7,6 @@ import (
|
||||
"queryorchestration/internal/client"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/oapi-codegen/runtime/types"
|
||||
)
|
||||
|
||||
func (s *Controllers) CreateClient(ctx echo.Context) error {
|
||||
@@ -16,37 +15,40 @@ func (s *Controllers) CreateClient(ctx echo.Context) error {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
||||
}
|
||||
|
||||
id, err := s.svc.Client.Create(ctx.Request().Context(), req.Name)
|
||||
_, err := s.svc.Client.Create(ctx.Request().Context(), client.CreateParams{
|
||||
Name: req.Name,
|
||||
ExternalId: req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to create client: %s", err))
|
||||
}
|
||||
|
||||
return ctx.JSON(http.StatusCreated, IdMessage{
|
||||
Id: id,
|
||||
return ctx.JSON(http.StatusCreated, ClientIDBody{
|
||||
Id: req.Id,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Controllers) GetClient(ctx echo.Context, id types.UUID) error {
|
||||
client, err := s.svc.Client.Get(ctx.Request().Context(), id)
|
||||
func (s *Controllers) GetClient(ctx echo.Context, id string) error {
|
||||
client, err := s.svc.Client.GetByExternalId(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,
|
||||
Id: client.ExternalID,
|
||||
Uid: client.ID,
|
||||
Name: client.Name,
|
||||
CanSync: client.CanSync,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Controllers) UpdateClient(ctx echo.Context, id types.UUID) error {
|
||||
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)
|
||||
}
|
||||
|
||||
err := s.svc.Client.Update(ctx.Request().Context(), &client.Update{
|
||||
ID: id,
|
||||
err := s.svc.Client.UpdateByExternalId(ctx.Request().Context(), id, &client.Update{
|
||||
Name: req.Name,
|
||||
CanSync: req.CanSync,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user