Merged in jb/openapi (pull request #22)
add openapi infra * add openapi infra Includes generated stubs and all deps * generatetolocation * basesetupoffunctionsandclient * round1controllertests * passintegrationtests * cleanupfromfullsuite * storedjson * fixjsonyaml * fixtests Approved-by: Michael McGuinness
This commit is contained in:
committed by
Michael McGuinness
parent
5ca36b0502
commit
174644b63c
@@ -0,0 +1,143 @@
|
||||
package queryservice
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"queryorchestration/internal/query"
|
||||
queryprocessor "queryorchestration/internal/queryProcessor"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func (s *Controllers) ListQueries(ctx echo.Context) error {
|
||||
filters := query.ListFilters{}
|
||||
|
||||
queries, err := s.svc.Query.List(ctx.Request().Context(), filters)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to list query: %s", err))
|
||||
}
|
||||
|
||||
outQueries, err := parseQueries(queries)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to list query: %s", err))
|
||||
}
|
||||
|
||||
return ctx.JSON(http.StatusOK, ListQueries{
|
||||
Queries: outQueries,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Controllers) GetQueryById(ctx echo.Context, id string) error {
|
||||
uid, err := uuid.Parse(id)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID")
|
||||
}
|
||||
|
||||
query, err := s.svc.Query.Get(ctx.Request().Context(), uid)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to get query: %s", err))
|
||||
}
|
||||
|
||||
qt, err := parseQuery(query)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to get query: %s", err))
|
||||
}
|
||||
|
||||
return ctx.JSON(http.StatusOK, qt)
|
||||
}
|
||||
|
||||
func (s *Controllers) CreateQuery(ctx echo.Context) error {
|
||||
req := QueryCreate{}
|
||||
if err := ctx.Bind(&req); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
||||
}
|
||||
|
||||
requiredQueryIDs := []uuid.UUID{}
|
||||
if req.RequiredQueries != nil {
|
||||
requiredQueryIDs := make([]uuid.UUID, len(*req.RequiredQueries))
|
||||
for index, id := range *req.RequiredQueries {
|
||||
parsedID, err := uuid.Parse(id)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Required ID")
|
||||
}
|
||||
|
||||
requiredQueryIDs[index] = parsedID
|
||||
}
|
||||
}
|
||||
|
||||
qt, err := parseSpecQueryType(req.Type)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Query Type")
|
||||
}
|
||||
|
||||
id, err := s.svc.Query.Create(ctx.Request().Context(), &queryprocessor.Create{
|
||||
Type: qt,
|
||||
RequiredQueryIDs: requiredQueryIDs,
|
||||
})
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to create query: %s", err))
|
||||
}
|
||||
|
||||
return ctx.JSON(http.StatusCreated, IdMessage{
|
||||
Id: id.String(),
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Controllers) UpdateQuery(ctx echo.Context, id string) error {
|
||||
uid, err := uuid.Parse(id)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID")
|
||||
}
|
||||
|
||||
err = s.svc.Query.Update(ctx.Request().Context(), &queryprocessor.Update{
|
||||
ID: uid,
|
||||
})
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to update query: %s", err))
|
||||
}
|
||||
|
||||
return ctx.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
func (s *Controllers) DeprecateQuery(ctx echo.Context, id string) error {
|
||||
uid, err := uuid.Parse(id)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID")
|
||||
}
|
||||
|
||||
err = s.svc.Query.Deprecate(ctx.Request().Context(), uid)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to deprecate query: %s", err))
|
||||
}
|
||||
|
||||
return ctx.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
func (s *Controllers) TestQuery(ctx echo.Context, id string) error {
|
||||
queryId, err := uuid.Parse(id)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Query ID")
|
||||
}
|
||||
req := QueryTestRequest{}
|
||||
if err := ctx.Bind(&req); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
||||
}
|
||||
docId, err := uuid.Parse(req.DocumentId)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Doc ID")
|
||||
}
|
||||
|
||||
value, err := s.svc.Query.Test(ctx.Request().Context(), query.Test{
|
||||
QueryID: queryId,
|
||||
QueryVersion: req.QueryVersion,
|
||||
DocumentID: docId,
|
||||
})
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to test query: %s", err))
|
||||
}
|
||||
|
||||
return ctx.JSON(http.StatusOK, QueryTestResponse{
|
||||
Value: value,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user