From 073667d5adc9e7c3eb2f97d169bd71b975749bc2 Mon Sep 17 00:00:00 2001 From: ymk <81808708+yk-eukarya@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:23:29 +0200 Subject: [PATCH] imp --- server/e2e/integration_schema_test.go | 56 +- server/internal/adapter/integration/model.go | 41 +- server/internal/adapter/integration/schema.go | 26 +- .../adapter/integration/server.gen.go | 677 +++++++++--------- .../internal/infrastructure/memory/model.go | 15 + server/internal/infrastructure/mongo/model.go | 10 + .../infrastructure/mongo/model_test.go | 109 +++ server/internal/usecase/interactor/model.go | 4 + server/internal/usecase/interfaces/model.go | 2 + server/internal/usecase/repo/model.go | 1 + server/pkg/integrationapi/schema.go | 9 +- server/pkg/integrationapi/types.gen.go | 49 +- server/pkg/schema/schema.go | 2 +- server/schemas/integration.yml | 20 +- 14 files changed, 612 insertions(+), 409 deletions(-) diff --git a/server/e2e/integration_schema_test.go b/server/e2e/integration_schema_test.go index 275edd89d0..aeef48a664 100644 --- a/server/e2e/integration_schema_test.go +++ b/server/e2e/integration_schema_test.go @@ -10,24 +10,24 @@ import ( // POST /api/models/{modelId}/fields func TestIntegrationFieldCreateAPI(t *testing.T) { - endpoint := "/api/models/{modelId}/fields" + endpoint := "/api/schemata/{schemaId}/fields" e := StartServer(t, &app.Config{}, true, baseSeeder) - e.POST(endpoint, id.NewModelID()). + e.POST(endpoint, id.NewSchemaID()). Expect(). Status(http.StatusUnauthorized) - e.POST(endpoint, id.NewModelID()). + e.POST(endpoint, id.NewSchemaID()). WithHeader("authorization", "secret_abc"). Expect(). Status(http.StatusUnauthorized) - e.POST(endpoint, id.NewModelID()). + e.POST(endpoint, id.NewSchemaID()). WithHeader("authorization", "Bearer secret_abc"). Expect(). Status(http.StatusUnauthorized) - e.POST(endpoint, id.NewModelID()). + e.POST(endpoint, id.NewSchemaID()). WithHeader("authorization", "Bearer "+secret). Expect(). Status(http.StatusNotFound) @@ -38,7 +38,7 @@ func TestIntegrationFieldCreateAPI(t *testing.T) { Expect(). Status(http.StatusBadRequest) - obj1 := e.POST(endpoint, mId1). + obj1 := e.POST(endpoint, sid1). WithHeader("authorization", "Bearer "+secret). WithJSON(map[string]interface{}{ "key": "fKey1", @@ -72,10 +72,10 @@ func TestIntegrationFieldCreateAPI(t *testing.T) { // PATCH /api/models/{modelId}/fields/{FieldIdOrKey} func TestIntegrationFieldUpdateAPI(t *testing.T) { - endpoint := "/api/models/{modelId}/fields/{fieldIdOrKey}" + endpoint := "/api/schemata/{schemaId}/fields/{fieldIdOrKey}" e := StartServer(t, &app.Config{}, true, baseSeeder) - obj := e.POST("/api/models/{modelId}/fields", mId1). + obj := e.POST("/api/schemata/{schemaId}/fields", sid1). WithHeader("authorization", "Bearer "+secret). WithJSON(map[string]interface{}{ "key": "fKey1", @@ -91,22 +91,22 @@ func TestIntegrationFieldUpdateAPI(t *testing.T) { Expect(). Status(http.StatusUnauthorized) - e.PATCH(endpoint, id.NewModelID(), id.NewFieldID()). + e.PATCH(endpoint, id.NewSchemaID(), id.NewFieldID()). WithHeader("authorization", "secret_abc"). Expect(). Status(http.StatusUnauthorized) - e.PATCH(endpoint, id.NewModelID(), id.NewFieldID()). + e.PATCH(endpoint, id.NewSchemaID(), id.NewFieldID()). WithHeader("authorization", "Bearer secret_abc"). Expect(). Status(http.StatusUnauthorized) - e.PATCH(endpoint, id.NewModelID(), id.NewFieldID()). + e.PATCH(endpoint, id.NewSchemaID(), id.NewFieldID()). WithHeader("authorization", "Bearer "+secret). Expect(). Status(http.StatusNotFound) - e.PATCH(endpoint, id.NewModelID(), fId). + e.PATCH(endpoint, id.NewSchemaID(), fId). WithHeader("authorization", "Bearer "+secret). Expect(). Status(http.StatusNotFound) @@ -117,7 +117,7 @@ func TestIntegrationFieldUpdateAPI(t *testing.T) { Expect(). Status(http.StatusBadRequest) - e.PATCH(endpoint, mId1, fId). + e.PATCH(endpoint, sid1, fId). WithHeader("authorization", "Bearer "+secret). WithJSON(map[string]interface{}{ "key": "fKey1Updated", @@ -135,7 +135,7 @@ func TestIntegrationFieldUpdateAPI(t *testing.T) { HasValue("multiple", true). HasValue("required", true) - e.PATCH(endpoint, mId1, "fKey1Updated"). + e.PATCH(endpoint, sid1, "fKey1Updated"). WithHeader("authorization", "Bearer "+secret). WithJSON(map[string]interface{}{ "key": "fKey1Updated1", @@ -174,10 +174,10 @@ func TestIntegrationFieldUpdateAPI(t *testing.T) { // DELETE /api/models/{modelId}/fields/{FieldIdOrKey} func TestIntegrationFieldDeleteAPI(t *testing.T) { - endpoint := "/api/models/{modelId}/fields/{fieldIdOrKey}" + endpoint := "/api/schemata/{schemaId}/fields/{fieldIdOrKey}" e := StartServer(t, &app.Config{}, true, baseSeeder) - obj := e.POST("/api/models/{modelId}/fields", mId1). + obj := e.POST("/api/schemata/{schemaId}/fields", sid1). WithHeader("authorization", "Bearer "+secret). WithJSON(map[string]interface{}{ "key": "fKey1", @@ -189,26 +189,26 @@ func TestIntegrationFieldDeleteAPI(t *testing.T) { Status(http.StatusOK) fId := obj.JSON().Object().Value("id").String().Raw() - e.DELETE(endpoint, id.NewModelID(), id.NewFieldID()). + e.DELETE(endpoint, id.NewSchemaID(), id.NewFieldID()). Expect(). Status(http.StatusUnauthorized) - e.DELETE(endpoint, id.NewModelID(), id.NewFieldID()). + e.DELETE(endpoint, id.NewSchemaID(), id.NewFieldID()). WithHeader("authorization", "secret_abc"). Expect(). Status(http.StatusUnauthorized) - e.DELETE(endpoint, id.NewModelID(), id.NewFieldID()). + e.DELETE(endpoint, id.NewSchemaID(), id.NewFieldID()). WithHeader("authorization", "Bearer secret_abc"). Expect(). Status(http.StatusUnauthorized) - e.DELETE(endpoint, id.NewModelID(), id.NewFieldID()). + e.DELETE(endpoint, id.NewSchemaID(), id.NewFieldID()). WithHeader("authorization", "Bearer "+secret). Expect(). Status(http.StatusNotFound) - e.DELETE(endpoint, id.NewModelID(), fId). + e.DELETE(endpoint, id.NewSchemaID(), fId). WithHeader("authorization", "Bearer "+secret). Expect(). Status(http.StatusNotFound) @@ -219,7 +219,7 @@ func TestIntegrationFieldDeleteAPI(t *testing.T) { Expect(). Status(http.StatusBadRequest) - e.DELETE(endpoint, mId1, fId). + e.DELETE(endpoint, sid1, fId). WithHeader("authorization", "Bearer "+secret). Expect(). Status(http.StatusOK). @@ -227,7 +227,7 @@ func TestIntegrationFieldDeleteAPI(t *testing.T) { Object(). HasValue("id", fId) - obj = e.POST("/api/models/{modelId}/fields", mId1). + obj = e.POST("/api/schemata/{schemaId}/fields", sid1). WithHeader("authorization", "Bearer "+secret). WithJSON(map[string]interface{}{ "key": "fKey1", @@ -239,7 +239,7 @@ func TestIntegrationFieldDeleteAPI(t *testing.T) { Status(http.StatusOK) fId = obj.JSON().Object().Value("id").String().Raw() - e.DELETE(endpoint, mId1, "fKey1"). + e.DELETE(endpoint, sid1, "fKey1"). WithHeader("authorization", "Bearer "+secret). Expect(). Status(http.StatusOK). @@ -340,7 +340,7 @@ func TestIntegrationFieldUpdateWithProjectAPI(t *testing.T) { endpoint := "/api/projects/{projectIdOrAlias}/models/{modelIdOrKey}/fields/{fieldIdOrKey}" e := StartServer(t, &app.Config{}, true, baseSeeder) - obj := e.POST("/api/models/{modelId}/fields", mId1). + obj := e.POST("/api/schemata/{schemaId}/fields", sid1). WithHeader("authorization", "Bearer "+secret). WithJSON(map[string]interface{}{ "key": "fKey1", @@ -436,7 +436,7 @@ func TestIntegrationFieldDeleteWithProjectAPI(t *testing.T) { endpoint := "/api/projects/{projectIdOrAlias}/models/{modelIdOrKey}/fields/{fieldIdOrKey}" e := StartServer(t, &app.Config{}, true, baseSeeder) - obj := e.POST("/api/models/{modelId}/fields", mId1). + obj := e.POST("/api/schemata/{schemaId}/fields", sid1). WithHeader("authorization", "Bearer "+secret). WithJSON(map[string]interface{}{ "key": "fKey1", @@ -480,7 +480,7 @@ func TestIntegrationFieldDeleteWithProjectAPI(t *testing.T) { Object(). HasValue("id", fId) - obj = e.POST("/api/models/{modelId}/fields", mId1). + obj = e.POST("/api/schemata/{schemaId}/fields", sid1). WithHeader("authorization", "Bearer "+secret). WithJSON(map[string]interface{}{ "key": "fKey1", @@ -500,7 +500,7 @@ func TestIntegrationFieldDeleteWithProjectAPI(t *testing.T) { Object(). HasValue("id", fId) - obj = e.POST("/api/models/{modelId}/fields", mId1). + obj = e.POST("/api/schemata/{schemaId}/fields", sid1). WithHeader("authorization", "Bearer "+secret). WithJSON(map[string]interface{}{ "key": "fKey1", diff --git a/server/internal/adapter/integration/model.go b/server/internal/adapter/integration/model.go index 7fd92a7f34..d40581102b 100644 --- a/server/internal/adapter/integration/model.go +++ b/server/internal/adapter/integration/model.go @@ -31,11 +31,15 @@ func (s *Server) ModelFilter(ctx context.Context, request ModelFilterRequestObje models := make([]integrationapi.Model, 0, len(ms)) for _, m := range ms { + sp, err := uc.Schema.FindByModel(ctx, m.ID(), op) + if err != nil { + return nil, err + } lastModified, err := uc.Item.LastModifiedByModel(ctx, m.ID(), op) if err != nil && !errors.Is(err, rerror.ErrNotFound) { return nil, err } - models = append(models, integrationapi.NewModel(m, lastModified)) + models = append(models, integrationapi.NewModel(m, sp, lastModified)) } return ModelFilter200JSONResponse{ @@ -73,12 +77,17 @@ func (s *Server) ModelCreate(ctx context.Context, request ModelCreateRequestObje return ModelCreate400Response{}, err } + sp, err := uc.Schema.FindByModel(ctx, m.ID(), op) + if err != nil { + return nil, err + } + lastModified, err := uc.Item.LastModifiedByModel(ctx, m.ID(), op) if err != nil && !errors.Is(err, rerror.ErrNotFound) { return nil, err } - return ModelCreate200JSONResponse(integrationapi.NewModel(m, lastModified)), nil + return ModelCreate200JSONResponse(integrationapi.NewModel(m, sp, lastModified)), nil } func (s *Server) ModelGet(ctx context.Context, request ModelGetRequestObject) (ModelGetResponseObject, error) { @@ -90,12 +99,17 @@ func (s *Server) ModelGet(ctx context.Context, request ModelGetRequestObject) (M return nil, err } + sp, err := uc.Schema.FindByModel(ctx, m.ID(), op) + if err != nil { + return nil, err + } + lastModified, err := uc.Item.LastModifiedByModel(ctx, request.ModelId, op) if err != nil && !errors.Is(err, rerror.ErrNotFound) { return nil, err } - return ModelGet200JSONResponse(integrationapi.NewModel(m, lastModified)), nil + return ModelGet200JSONResponse(integrationapi.NewModel(m, sp, lastModified)), nil } func (s *Server) ModelGetWithProject(ctx context.Context, request ModelGetWithProjectRequestObject) (ModelGetWithProjectResponseObject, error) { @@ -118,6 +132,11 @@ func (s *Server) ModelGetWithProject(ctx context.Context, request ModelGetWithPr return ModelGetWithProject500Response{}, nil } + sp, err := uc.Schema.FindByModel(ctx, m.ID(), op) + if err != nil { + return nil, err + } + lastModified, err := uc.Item.LastModifiedByModel(ctx, m.ID(), op) if err != nil { if errors.Is(err, rerror.ErrNotFound) { @@ -126,7 +145,7 @@ func (s *Server) ModelGetWithProject(ctx context.Context, request ModelGetWithPr return ModelGetWithProject500Response{}, nil } - return ModelGetWithProject200JSONResponse(integrationapi.NewModel(m, lastModified)), nil + return ModelGetWithProject200JSONResponse(integrationapi.NewModel(m, sp, lastModified)), nil } func (s *Server) ModelUpdate(ctx context.Context, request ModelUpdateRequestObject) (ModelUpdateResponseObject, error) { @@ -148,12 +167,17 @@ func (s *Server) ModelUpdate(ctx context.Context, request ModelUpdateRequestObje return ModelUpdate400Response{}, err } + sp, err := uc.Schema.FindByModel(ctx, m.ID(), op) + if err != nil { + return nil, err + } + lastModified, err := uc.Item.LastModifiedByModel(ctx, request.ModelId, op) if err != nil { return nil, err } - return ModelUpdate200JSONResponse(integrationapi.NewModel(m, lastModified)), nil + return ModelUpdate200JSONResponse(integrationapi.NewModel(m, sp, lastModified)), nil } func (s *Server) ModelUpdateWithProject(ctx context.Context, request ModelUpdateWithProjectRequestObject) (ModelUpdateWithProjectResponseObject, error) { @@ -191,12 +215,17 @@ func (s *Server) ModelUpdateWithProject(ctx context.Context, request ModelUpdate return ModelUpdateWithProject400Response{}, err } + sp, err := uc.Schema.FindByModel(ctx, m.ID(), op) + if err != nil { + return nil, err + } + lastModified, err := uc.Item.LastModifiedByModel(ctx, m.ID(), op) if err != nil { return nil, err } - return ModelUpdateWithProject200JSONResponse(integrationapi.NewModel(m, lastModified)), nil + return ModelUpdateWithProject200JSONResponse(integrationapi.NewModel(m, sp, lastModified)), nil } func (s *Server) ModelDelete(ctx context.Context, request ModelDeleteRequestObject) (ModelDeleteResponseObject, error) { diff --git a/server/internal/adapter/integration/schema.go b/server/internal/adapter/integration/schema.go index 7c9513b95e..5ef21515ec 100644 --- a/server/internal/adapter/integration/schema.go +++ b/server/internal/adapter/integration/schema.go @@ -24,7 +24,7 @@ func (s *Server) FieldCreate(ctx context.Context, request FieldCreateRequestObje uc := adapter.Usecases(ctx) op := adapter.Operator(ctx) - sch, err := uc.Schema.FindByModel(ctx, request.ModelId, op) + sch, err := uc.Schema.FindByID(ctx, request.SchemaId, op) if err != nil { if errors.Is(err, rerror.ErrNotFound) { return FieldCreate400Response{}, err @@ -32,14 +32,19 @@ func (s *Server) FieldCreate(ctx context.Context, request FieldCreateRequestObje return FieldCreate400Response{}, err } + m, err := uc.Model.FindBySchema(ctx, sch.ID(), op) + if err != nil { + return FieldCreate400Response{}, err + } + tp, dv, err := FromSchemaTypeProperty(*request.Body.Type, *request.Body.Multiple) if err != nil { return nil, err } param := interfaces.CreateFieldParam{ - ModelID: &request.ModelId, - SchemaID: sch.Schema().ID(), + ModelID: m.ID().Ref(), + SchemaID: sch.ID(), Type: integrationapi.FromValueType(request.Body.Type), Name: *request.Body.Key, Description: nil, @@ -130,7 +135,7 @@ func (s *Server) FieldUpdate(ctx context.Context, request FieldUpdateRequestObje uc := adapter.Usecases(ctx) op := adapter.Operator(ctx) - sch, err := uc.Schema.FindByModel(ctx, request.ModelId, op) + sch, err := uc.Schema.FindByID(ctx, request.SchemaId, op) if err != nil { if errors.Is(err, rerror.ErrNotFound) { return FieldUpdate400Response{}, err @@ -138,6 +143,11 @@ func (s *Server) FieldUpdate(ctx context.Context, request FieldUpdateRequestObje return FieldUpdate400Response{}, err } + m, err := uc.Model.FindBySchema(ctx, sch.ID(), op) + if err != nil { + return FieldUpdate400Response{}, err + } + idOrKey := (*string)(&request.FieldIdOrKey) f := sch.FieldByIDOrKey(id.FieldIDFromRef(idOrKey), id.NewKeyFromPtr(idOrKey)) if f == nil { @@ -146,8 +156,8 @@ func (s *Server) FieldUpdate(ctx context.Context, request FieldUpdateRequestObje param := interfaces.UpdateFieldParam{ FieldID: f.ID(), - ModelID: &request.ModelId, - SchemaID: sch.Schema().ID(), + ModelID: m.ID().Ref(), + SchemaID: sch.ID(), Name: request.Body.Key, Description: nil, Key: request.Body.Key, @@ -243,7 +253,7 @@ func (s *Server) FieldDelete(ctx context.Context, request FieldDeleteRequestObje uc := adapter.Usecases(ctx) op := adapter.Operator(ctx) - sch, err := uc.Schema.FindByModel(ctx, request.ModelId, op) + sch, err := uc.Schema.FindByID(ctx, request.SchemaId, op) if err != nil { if errors.Is(err, rerror.ErrNotFound) { return FieldDelete400Response{}, err @@ -257,7 +267,7 @@ func (s *Server) FieldDelete(ctx context.Context, request FieldDeleteRequestObje return FieldDelete400Response{}, rerror.ErrNotFound } - err = uc.Schema.DeleteField(ctx, sch.Schema().ID(), f.ID(), op) + err = uc.Schema.DeleteField(ctx, sch.ID(), f.ID(), op) if err != nil { return FieldDelete400Response{}, err } diff --git a/server/internal/adapter/integration/server.gen.go b/server/internal/adapter/integration/server.gen.go index ac6b9f1f60..dc98ef71b4 100644 --- a/server/internal/adapter/integration/server.gen.go +++ b/server/internal/adapter/integration/server.gen.go @@ -74,15 +74,6 @@ type ServerInterface interface { // Update a model. // (PATCH /models/{modelId}) ModelUpdate(ctx echo.Context, modelId ModelIdParam) error - // create a field - // (POST /models/{modelId}/fields) - FieldCreate(ctx echo.Context, modelId ModelIdParam) error - // delete a field - // (DELETE /models/{modelId}/fields/{fieldIdOrKey}) - FieldDelete(ctx echo.Context, modelId ModelIdParam, fieldIdOrKey FieldIdOrKeyParam) error - // update a field - // (PATCH /models/{modelId}/fields/{fieldIdOrKey}) - FieldUpdate(ctx echo.Context, modelId ModelIdParam, fieldIdOrKey FieldIdOrKeyParam) error // Returns a list of items. // (GET /models/{modelId}/items) ItemFilter(ctx echo.Context, modelId ModelIdParam, params ItemFilterParams) error @@ -128,6 +119,15 @@ type ServerInterface interface { // Upload an asset. // (POST /projects/{projectId}/assets/uploads) AssetUploadCreate(ctx echo.Context, projectId ProjectIdParam) error + // create a field + // (POST /schemata/{schemaId}/fields) + FieldCreate(ctx echo.Context, schemaId SchemaIdParam) error + // delete a field + // (DELETE /schemata/{schemaId}/fields/{fieldIdOrKey}) + FieldDelete(ctx echo.Context, schemaId SchemaIdParam, fieldIdOrKey FieldIdOrKeyParam) error + // update a field + // (PATCH /schemata/{schemaId}/fields/{fieldIdOrKey}) + FieldUpdate(ctx echo.Context, schemaId SchemaIdParam, fieldIdOrKey FieldIdOrKeyParam) error // Returns a list of projects. // (GET /{workspaceId}/projects) ProjectFilter(ctx echo.Context, workspaceId WorkspaceIdParam, params ProjectFilterParams) error @@ -470,76 +470,6 @@ func (w *ServerInterfaceWrapper) ModelUpdate(ctx echo.Context) error { return err } -// FieldCreate converts echo context to params. -func (w *ServerInterfaceWrapper) FieldCreate(ctx echo.Context) error { - var err error - // ------------- Path parameter "modelId" ------------- - var modelId ModelIdParam - - err = runtime.BindStyledParameterWithOptions("simple", "modelId", ctx.Param("modelId"), &modelId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter modelId: %s", err)) - } - - ctx.Set(BearerAuthScopes, []string{}) - - // Invoke the callback with all the unmarshaled arguments - err = w.Handler.FieldCreate(ctx, modelId) - return err -} - -// FieldDelete converts echo context to params. -func (w *ServerInterfaceWrapper) FieldDelete(ctx echo.Context) error { - var err error - // ------------- Path parameter "modelId" ------------- - var modelId ModelIdParam - - err = runtime.BindStyledParameterWithOptions("simple", "modelId", ctx.Param("modelId"), &modelId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter modelId: %s", err)) - } - - // ------------- Path parameter "fieldIdOrKey" ------------- - var fieldIdOrKey FieldIdOrKeyParam - - err = runtime.BindStyledParameterWithOptions("simple", "fieldIdOrKey", ctx.Param("fieldIdOrKey"), &fieldIdOrKey, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter fieldIdOrKey: %s", err)) - } - - ctx.Set(BearerAuthScopes, []string{}) - - // Invoke the callback with all the unmarshaled arguments - err = w.Handler.FieldDelete(ctx, modelId, fieldIdOrKey) - return err -} - -// FieldUpdate converts echo context to params. -func (w *ServerInterfaceWrapper) FieldUpdate(ctx echo.Context) error { - var err error - // ------------- Path parameter "modelId" ------------- - var modelId ModelIdParam - - err = runtime.BindStyledParameterWithOptions("simple", "modelId", ctx.Param("modelId"), &modelId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter modelId: %s", err)) - } - - // ------------- Path parameter "fieldIdOrKey" ------------- - var fieldIdOrKey FieldIdOrKeyParam - - err = runtime.BindStyledParameterWithOptions("simple", "fieldIdOrKey", ctx.Param("fieldIdOrKey"), &fieldIdOrKey, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter fieldIdOrKey: %s", err)) - } - - ctx.Set(BearerAuthScopes, []string{}) - - // Invoke the callback with all the unmarshaled arguments - err = w.Handler.FieldUpdate(ctx, modelId, fieldIdOrKey) - return err -} - // ItemFilter converts echo context to params. func (w *ServerInterfaceWrapper) ItemFilter(ctx echo.Context) error { var err error @@ -1047,6 +977,76 @@ func (w *ServerInterfaceWrapper) AssetUploadCreate(ctx echo.Context) error { return err } +// FieldCreate converts echo context to params. +func (w *ServerInterfaceWrapper) FieldCreate(ctx echo.Context) error { + var err error + // ------------- Path parameter "schemaId" ------------- + var schemaId SchemaIdParam + + err = runtime.BindStyledParameterWithOptions("simple", "schemaId", ctx.Param("schemaId"), &schemaId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter schemaId: %s", err)) + } + + ctx.Set(BearerAuthScopes, []string{}) + + // Invoke the callback with all the unmarshaled arguments + err = w.Handler.FieldCreate(ctx, schemaId) + return err +} + +// FieldDelete converts echo context to params. +func (w *ServerInterfaceWrapper) FieldDelete(ctx echo.Context) error { + var err error + // ------------- Path parameter "schemaId" ------------- + var schemaId SchemaIdParam + + err = runtime.BindStyledParameterWithOptions("simple", "schemaId", ctx.Param("schemaId"), &schemaId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter schemaId: %s", err)) + } + + // ------------- Path parameter "fieldIdOrKey" ------------- + var fieldIdOrKey FieldIdOrKeyParam + + err = runtime.BindStyledParameterWithOptions("simple", "fieldIdOrKey", ctx.Param("fieldIdOrKey"), &fieldIdOrKey, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter fieldIdOrKey: %s", err)) + } + + ctx.Set(BearerAuthScopes, []string{}) + + // Invoke the callback with all the unmarshaled arguments + err = w.Handler.FieldDelete(ctx, schemaId, fieldIdOrKey) + return err +} + +// FieldUpdate converts echo context to params. +func (w *ServerInterfaceWrapper) FieldUpdate(ctx echo.Context) error { + var err error + // ------------- Path parameter "schemaId" ------------- + var schemaId SchemaIdParam + + err = runtime.BindStyledParameterWithOptions("simple", "schemaId", ctx.Param("schemaId"), &schemaId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter schemaId: %s", err)) + } + + // ------------- Path parameter "fieldIdOrKey" ------------- + var fieldIdOrKey FieldIdOrKeyParam + + err = runtime.BindStyledParameterWithOptions("simple", "fieldIdOrKey", ctx.Param("fieldIdOrKey"), &fieldIdOrKey, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter fieldIdOrKey: %s", err)) + } + + ctx.Set(BearerAuthScopes, []string{}) + + // Invoke the callback with all the unmarshaled arguments + err = w.Handler.FieldUpdate(ctx, schemaId, fieldIdOrKey) + return err +} + // ProjectFilter converts echo context to params. func (w *ServerInterfaceWrapper) ProjectFilter(ctx echo.Context) error { var err error @@ -1125,9 +1125,6 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL router.DELETE(baseURL+"/models/:modelId", wrapper.ModelDelete) router.GET(baseURL+"/models/:modelId", wrapper.ModelGet) router.PATCH(baseURL+"/models/:modelId", wrapper.ModelUpdate) - router.POST(baseURL+"/models/:modelId/fields", wrapper.FieldCreate) - router.DELETE(baseURL+"/models/:modelId/fields/:fieldIdOrKey", wrapper.FieldDelete) - router.PATCH(baseURL+"/models/:modelId/fields/:fieldIdOrKey", wrapper.FieldUpdate) router.GET(baseURL+"/models/:modelId/items", wrapper.ItemFilter) router.POST(baseURL+"/models/:modelId/items", wrapper.ItemCreate) router.GET(baseURL+"/projects/:projectIdOrAlias/models", wrapper.ModelFilter) @@ -1143,6 +1140,9 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL router.GET(baseURL+"/projects/:projectId/assets", wrapper.AssetFilter) router.POST(baseURL+"/projects/:projectId/assets", wrapper.AssetCreate) router.POST(baseURL+"/projects/:projectId/assets/uploads", wrapper.AssetUploadCreate) + router.POST(baseURL+"/schemata/:schemaId/fields", wrapper.FieldCreate) + router.DELETE(baseURL+"/schemata/:schemaId/fields/:fieldIdOrKey", wrapper.FieldDelete) + router.PATCH(baseURL+"/schemata/:schemaId/fields/:fieldIdOrKey", wrapper.FieldUpdate) router.GET(baseURL+"/:workspaceId/projects", wrapper.ProjectFilter) } @@ -1826,108 +1826,6 @@ func (response ModelUpdate401Response) VisitModelUpdateResponse(w http.ResponseW return nil } -type FieldCreateRequestObject struct { - ModelId ModelIdParam `json:"modelId"` - Body *FieldCreateJSONRequestBody -} - -type FieldCreateResponseObject interface { - VisitFieldCreateResponse(w http.ResponseWriter) error -} - -type FieldCreate200JSONResponse SchemaField - -func (response FieldCreate200JSONResponse) VisitFieldCreateResponse(w http.ResponseWriter) error { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(200) - - return json.NewEncoder(w).Encode(response) -} - -type FieldCreate400Response struct { -} - -func (response FieldCreate400Response) VisitFieldCreateResponse(w http.ResponseWriter) error { - w.WriteHeader(400) - return nil -} - -type FieldCreate401Response = UnauthorizedErrorResponse - -func (response FieldCreate401Response) VisitFieldCreateResponse(w http.ResponseWriter) error { - w.WriteHeader(401) - return nil -} - -type FieldDeleteRequestObject struct { - ModelId ModelIdParam `json:"modelId"` - FieldIdOrKey FieldIdOrKeyParam `json:"fieldIdOrKey"` -} - -type FieldDeleteResponseObject interface { - VisitFieldDeleteResponse(w http.ResponseWriter) error -} - -type FieldDelete200JSONResponse struct { - Id *id.FieldID `json:"id,omitempty"` -} - -func (response FieldDelete200JSONResponse) VisitFieldDeleteResponse(w http.ResponseWriter) error { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(200) - - return json.NewEncoder(w).Encode(response) -} - -type FieldDelete400Response struct { -} - -func (response FieldDelete400Response) VisitFieldDeleteResponse(w http.ResponseWriter) error { - w.WriteHeader(400) - return nil -} - -type FieldDelete401Response = UnauthorizedErrorResponse - -func (response FieldDelete401Response) VisitFieldDeleteResponse(w http.ResponseWriter) error { - w.WriteHeader(401) - return nil -} - -type FieldUpdateRequestObject struct { - ModelId ModelIdParam `json:"modelId"` - FieldIdOrKey FieldIdOrKeyParam `json:"fieldIdOrKey"` - Body *FieldUpdateJSONRequestBody -} - -type FieldUpdateResponseObject interface { - VisitFieldUpdateResponse(w http.ResponseWriter) error -} - -type FieldUpdate200JSONResponse SchemaField - -func (response FieldUpdate200JSONResponse) VisitFieldUpdateResponse(w http.ResponseWriter) error { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(200) - - return json.NewEncoder(w).Encode(response) -} - -type FieldUpdate400Response struct { -} - -func (response FieldUpdate400Response) VisitFieldUpdateResponse(w http.ResponseWriter) error { - w.WriteHeader(400) - return nil -} - -type FieldUpdate401Response = UnauthorizedErrorResponse - -func (response FieldUpdate401Response) VisitFieldUpdateResponse(w http.ResponseWriter) error { - w.WriteHeader(401) - return nil -} - type ItemFilterRequestObject struct { ModelId ModelIdParam `json:"modelId"` Params ItemFilterParams @@ -2599,6 +2497,108 @@ func (response AssetUploadCreate404Response) VisitAssetUploadCreateResponse(w ht return nil } +type FieldCreateRequestObject struct { + SchemaId SchemaIdParam `json:"schemaId"` + Body *FieldCreateJSONRequestBody +} + +type FieldCreateResponseObject interface { + VisitFieldCreateResponse(w http.ResponseWriter) error +} + +type FieldCreate200JSONResponse SchemaField + +func (response FieldCreate200JSONResponse) VisitFieldCreateResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(200) + + return json.NewEncoder(w).Encode(response) +} + +type FieldCreate400Response struct { +} + +func (response FieldCreate400Response) VisitFieldCreateResponse(w http.ResponseWriter) error { + w.WriteHeader(400) + return nil +} + +type FieldCreate401Response = UnauthorizedErrorResponse + +func (response FieldCreate401Response) VisitFieldCreateResponse(w http.ResponseWriter) error { + w.WriteHeader(401) + return nil +} + +type FieldDeleteRequestObject struct { + SchemaId SchemaIdParam `json:"schemaId"` + FieldIdOrKey FieldIdOrKeyParam `json:"fieldIdOrKey"` +} + +type FieldDeleteResponseObject interface { + VisitFieldDeleteResponse(w http.ResponseWriter) error +} + +type FieldDelete200JSONResponse struct { + Id *id.FieldID `json:"id,omitempty"` +} + +func (response FieldDelete200JSONResponse) VisitFieldDeleteResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(200) + + return json.NewEncoder(w).Encode(response) +} + +type FieldDelete400Response struct { +} + +func (response FieldDelete400Response) VisitFieldDeleteResponse(w http.ResponseWriter) error { + w.WriteHeader(400) + return nil +} + +type FieldDelete401Response = UnauthorizedErrorResponse + +func (response FieldDelete401Response) VisitFieldDeleteResponse(w http.ResponseWriter) error { + w.WriteHeader(401) + return nil +} + +type FieldUpdateRequestObject struct { + SchemaId SchemaIdParam `json:"schemaId"` + FieldIdOrKey FieldIdOrKeyParam `json:"fieldIdOrKey"` + Body *FieldUpdateJSONRequestBody +} + +type FieldUpdateResponseObject interface { + VisitFieldUpdateResponse(w http.ResponseWriter) error +} + +type FieldUpdate200JSONResponse SchemaField + +func (response FieldUpdate200JSONResponse) VisitFieldUpdateResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(200) + + return json.NewEncoder(w).Encode(response) +} + +type FieldUpdate400Response struct { +} + +func (response FieldUpdate400Response) VisitFieldUpdateResponse(w http.ResponseWriter) error { + w.WriteHeader(400) + return nil +} + +type FieldUpdate401Response = UnauthorizedErrorResponse + +func (response FieldUpdate401Response) VisitFieldUpdateResponse(w http.ResponseWriter) error { + w.WriteHeader(401) + return nil +} + type ProjectFilterRequestObject struct { WorkspaceId WorkspaceIdParam `json:"workspaceId"` Params ProjectFilterParams @@ -2702,15 +2702,6 @@ type StrictServerInterface interface { // Update a model. // (PATCH /models/{modelId}) ModelUpdate(ctx context.Context, request ModelUpdateRequestObject) (ModelUpdateResponseObject, error) - // create a field - // (POST /models/{modelId}/fields) - FieldCreate(ctx context.Context, request FieldCreateRequestObject) (FieldCreateResponseObject, error) - // delete a field - // (DELETE /models/{modelId}/fields/{fieldIdOrKey}) - FieldDelete(ctx context.Context, request FieldDeleteRequestObject) (FieldDeleteResponseObject, error) - // update a field - // (PATCH /models/{modelId}/fields/{fieldIdOrKey}) - FieldUpdate(ctx context.Context, request FieldUpdateRequestObject) (FieldUpdateResponseObject, error) // Returns a list of items. // (GET /models/{modelId}/items) ItemFilter(ctx context.Context, request ItemFilterRequestObject) (ItemFilterResponseObject, error) @@ -2756,6 +2747,15 @@ type StrictServerInterface interface { // Upload an asset. // (POST /projects/{projectId}/assets/uploads) AssetUploadCreate(ctx context.Context, request AssetUploadCreateRequestObject) (AssetUploadCreateResponseObject, error) + // create a field + // (POST /schemata/{schemaId}/fields) + FieldCreate(ctx context.Context, request FieldCreateRequestObject) (FieldCreateResponseObject, error) + // delete a field + // (DELETE /schemata/{schemaId}/fields/{fieldIdOrKey}) + FieldDelete(ctx context.Context, request FieldDeleteRequestObject) (FieldDeleteResponseObject, error) + // update a field + // (PATCH /schemata/{schemaId}/fields/{fieldIdOrKey}) + FieldUpdate(ctx context.Context, request FieldUpdateRequestObject) (FieldUpdateResponseObject, error) // Returns a list of projects. // (GET /{workspaceId}/projects) ProjectFilter(ctx context.Context, request ProjectFilterRequestObject) (ProjectFilterResponseObject, error) @@ -3214,95 +3214,6 @@ func (sh *strictHandler) ModelUpdate(ctx echo.Context, modelId ModelIdParam) err return nil } -// FieldCreate operation middleware -func (sh *strictHandler) FieldCreate(ctx echo.Context, modelId ModelIdParam) error { - var request FieldCreateRequestObject - - request.ModelId = modelId - - var body FieldCreateJSONRequestBody - if err := ctx.Bind(&body); err != nil { - return err - } - request.Body = &body - - handler := func(ctx echo.Context, request interface{}) (interface{}, error) { - return sh.ssi.FieldCreate(ctx.Request().Context(), request.(FieldCreateRequestObject)) - } - for _, middleware := range sh.middlewares { - handler = middleware(handler, "FieldCreate") - } - - response, err := handler(ctx, request) - - if err != nil { - return err - } else if validResponse, ok := response.(FieldCreateResponseObject); ok { - return validResponse.VisitFieldCreateResponse(ctx.Response()) - } else if response != nil { - return fmt.Errorf("unexpected response type: %T", response) - } - return nil -} - -// FieldDelete operation middleware -func (sh *strictHandler) FieldDelete(ctx echo.Context, modelId ModelIdParam, fieldIdOrKey FieldIdOrKeyParam) error { - var request FieldDeleteRequestObject - - request.ModelId = modelId - request.FieldIdOrKey = fieldIdOrKey - - handler := func(ctx echo.Context, request interface{}) (interface{}, error) { - return sh.ssi.FieldDelete(ctx.Request().Context(), request.(FieldDeleteRequestObject)) - } - for _, middleware := range sh.middlewares { - handler = middleware(handler, "FieldDelete") - } - - response, err := handler(ctx, request) - - if err != nil { - return err - } else if validResponse, ok := response.(FieldDeleteResponseObject); ok { - return validResponse.VisitFieldDeleteResponse(ctx.Response()) - } else if response != nil { - return fmt.Errorf("unexpected response type: %T", response) - } - return nil -} - -// FieldUpdate operation middleware -func (sh *strictHandler) FieldUpdate(ctx echo.Context, modelId ModelIdParam, fieldIdOrKey FieldIdOrKeyParam) error { - var request FieldUpdateRequestObject - - request.ModelId = modelId - request.FieldIdOrKey = fieldIdOrKey - - var body FieldUpdateJSONRequestBody - if err := ctx.Bind(&body); err != nil { - return err - } - request.Body = &body - - handler := func(ctx echo.Context, request interface{}) (interface{}, error) { - return sh.ssi.FieldUpdate(ctx.Request().Context(), request.(FieldUpdateRequestObject)) - } - for _, middleware := range sh.middlewares { - handler = middleware(handler, "FieldUpdate") - } - - response, err := handler(ctx, request) - - if err != nil { - return err - } else if validResponse, ok := response.(FieldUpdateResponseObject); ok { - return validResponse.VisitFieldUpdateResponse(ctx.Response()) - } else if response != nil { - return fmt.Errorf("unexpected response type: %T", response) - } - return nil -} - // ItemFilter operation middleware func (sh *strictHandler) ItemFilter(ctx echo.Context, modelId ModelIdParam, params ItemFilterParams) error { var request ItemFilterRequestObject @@ -3755,6 +3666,95 @@ func (sh *strictHandler) AssetUploadCreate(ctx echo.Context, projectId ProjectId return nil } +// FieldCreate operation middleware +func (sh *strictHandler) FieldCreate(ctx echo.Context, schemaId SchemaIdParam) error { + var request FieldCreateRequestObject + + request.SchemaId = schemaId + + var body FieldCreateJSONRequestBody + if err := ctx.Bind(&body); err != nil { + return err + } + request.Body = &body + + handler := func(ctx echo.Context, request interface{}) (interface{}, error) { + return sh.ssi.FieldCreate(ctx.Request().Context(), request.(FieldCreateRequestObject)) + } + for _, middleware := range sh.middlewares { + handler = middleware(handler, "FieldCreate") + } + + response, err := handler(ctx, request) + + if err != nil { + return err + } else if validResponse, ok := response.(FieldCreateResponseObject); ok { + return validResponse.VisitFieldCreateResponse(ctx.Response()) + } else if response != nil { + return fmt.Errorf("unexpected response type: %T", response) + } + return nil +} + +// FieldDelete operation middleware +func (sh *strictHandler) FieldDelete(ctx echo.Context, schemaId SchemaIdParam, fieldIdOrKey FieldIdOrKeyParam) error { + var request FieldDeleteRequestObject + + request.SchemaId = schemaId + request.FieldIdOrKey = fieldIdOrKey + + handler := func(ctx echo.Context, request interface{}) (interface{}, error) { + return sh.ssi.FieldDelete(ctx.Request().Context(), request.(FieldDeleteRequestObject)) + } + for _, middleware := range sh.middlewares { + handler = middleware(handler, "FieldDelete") + } + + response, err := handler(ctx, request) + + if err != nil { + return err + } else if validResponse, ok := response.(FieldDeleteResponseObject); ok { + return validResponse.VisitFieldDeleteResponse(ctx.Response()) + } else if response != nil { + return fmt.Errorf("unexpected response type: %T", response) + } + return nil +} + +// FieldUpdate operation middleware +func (sh *strictHandler) FieldUpdate(ctx echo.Context, schemaId SchemaIdParam, fieldIdOrKey FieldIdOrKeyParam) error { + var request FieldUpdateRequestObject + + request.SchemaId = schemaId + request.FieldIdOrKey = fieldIdOrKey + + var body FieldUpdateJSONRequestBody + if err := ctx.Bind(&body); err != nil { + return err + } + request.Body = &body + + handler := func(ctx echo.Context, request interface{}) (interface{}, error) { + return sh.ssi.FieldUpdate(ctx.Request().Context(), request.(FieldUpdateRequestObject)) + } + for _, middleware := range sh.middlewares { + handler = middleware(handler, "FieldUpdate") + } + + response, err := handler(ctx, request) + + if err != nil { + return err + } else if validResponse, ok := response.(FieldUpdateResponseObject); ok { + return validResponse.VisitFieldUpdateResponse(ctx.Response()) + } else if response != nil { + return fmt.Errorf("unexpected response type: %T", response) + } + return nil +} + // ProjectFilter operation middleware func (sh *strictHandler) ProjectFilter(ctx echo.Context, workspaceId WorkspaceIdParam, params ProjectFilterParams) error { var request ProjectFilterRequestObject @@ -3784,62 +3784,63 @@ func (sh *strictHandler) ProjectFilter(ctx echo.Context, workspaceId WorkspaceId // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xd3W/bOBL/VwTdPapx9rr7krdcky5yt90WmxTFoSgKWhrb3EikSlJJs4b/9wOHlExb", - "1Jctbz7qlzaWKHo485tvmlqGMc9yzoApGZ4tw5wIkoECgZ+IlKCukg/6ov6cgIwFzRXlLDwLry4CPgvU", - "AgIJKcQKkgAfCKOQ6vs5UYswChnJIDwr5wqjUMC3ggpIwjMlCohCGS8gI3p+9ZDroVIJyuZhFH5/Neev", - "7EWanJzjFBfhahWZ6RoIu84hpjMKMrhfgFqAMHQFCVEkIAICyKaQJJAElCH9AmSRKlkS/q0A8bBFeejS", - "+U8Bs/As/MdkzbyJuSsnOPoSv0AvQtMa8ywDNoiR9hE/K6v59mHmGzuJYeeMQppcJe/Ff+GhhUoR3MJD", - "SSw+U7Iw4wmkMrBf7yXb/Y6dKTejTt7iXBdmLr0AqiAbwmA93k+mmWkf1l7pGQxfkS0D+YrPlHzNBf8T", - "4gYguLPvTDBOcuLy0k7byczBhO7D1Hc4heFqTubQQN1HCUmguBW0oYzMoUG17a01EQnMSJGq8OynKMwo", - "o1mR4d8lHUzBHIQhAsSH0egwc/lJ+eU0CjPy3dJyetpNmRGFBsZ5SolsBR7RI0qJtgpxe9qdpWknQsyZ", - "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eHnBa", - "7cNkWW0763amFiaP5lNbW0p1UZq1BIQFGwbiaBo2TUPUOX5rpyMaE6LiRTtMPubJD29NDA+C8xcCQVlk", - "GREPzsIceYddRggDgcnS7MRstTY633o0K+Ps8xxgYqhNEZ+3WLfWs5aoSZydoH87FVSFYLJ88KTqYbgS", - "NUnBMFNV7dXrYaaczeN6VQfT962yQB0V508ZDlH4i58mBYKRNJAg7kAEYOYbAp4tEMgTL36Gyd/dAL7h", - "d7x2thV+I/ujavPakJ8NjFfTG7cI99gu9KhSrW7WwfW2QtUda3fur599Iam//oaXlfmjYPeJ7msm05v3", - "Oxg4pv3PP+2voabFLvTN+R2IPL+U3zUMR5PgmoQx830HIsd03033XwL8amGIlnZQz/a9tsf8cnSytM3d", - "VkODW28ezcS4P0HsbWDMryQfQ7K7pPOW2rXIcM198nnzZD2hwgkO3OWzLPYkA8F/rt//HmCYGPBZUEgQ", - "ASMZyB825V7LySPiYc5i43fCPXLuVoiM7BW6Nm817W9q2KL12K6kC+GGKg3xZ2Fu6oiogdHnGibrmsi+", - "SPWmOlgiGTnJeZIb6f5e8LobE/tAuCo9PWUIm116AQnKHdslgm2drRXBk6V7GEZryIPTPVrIU+0I7RPy", - "PE9BVqFPoyD384vdWVT98JWWRAqpGtlZHm3Uy7RRRelmh9moqhjbEfGnVCIvcHxwT9UimNFUgYZPQFhi", - "TmSgbO5vs7zFsYMbfetDIXqo1sYpGT3Gr0+W6TPYPQGmx/hdW5TRtgjwHIugstm+sy3Kj00nsqxM43MM", - "62FkPuDXjj5dX43r28bdvY0n95wtW8/dqQ4E6h6IJxy84YVZVzX21HuYT1+ve8xxmyzTGN3lngkEVjnH", - "zR+ObeDd2sBPSit2SSwad9Zon21/AScny+1TuVbWn/fw32ZgQz2m8s4jmuU1Zb2wV5Uyjvb4JdQc5ShF", - "R//hdocN7RrtPa5iZIN/rFw+i7JPY6Okn3mu0i1fBWhz5RcbvZkGc20GfaJq8aE6FPFJ98du1geIJj+a", - "YaxLdPR224h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z0NtQuogJcL+/gs5VZzrLW", + "QKUglObQsQ6mRDJTqFLf5/rhRiXjX8fHSiSrXCbK89Q43LM/ucZ2mxkbl3j3EGXTpGu9xXUlah2FP2vw", + "NupBuvBhSyxBuVYo0EGO6vdTG0uX0581yy+q58/NN/5eVW3WSjFyqZbVxHj4dS2VomhB+69KDe+E895V", + "Pq8Ike66ry/+91ZNZrV1YWvZvyEXM1Mr0EF7K5lMYv03XQGdUETc1w9Mdenahi8zOkx87KKtZ059q44V", + "oV1F/OXr+usmc5Rz2p1LojCnvIcPzpSLYmrHwMW/afK4ExO0lYr8RK1XrNd71B8ltzV56fUxTqd+mK3K", + "5Yz9xtSwyZPZ1M46YJOUei4BIkFNQRxUQ101RL3tN1bQKmWCRLzsZpNPefLDaxONg+D0lbAgL7IMsUdn", + "Yg69wz4lpByB2Uqv8O3UNjLeejIt46wfHqFisAkRXzZZN+ZTUVQHzo7TvxkKioIRbjselYUnl6I6KBin", + "qso1oAPUlLMpQc5qb/K+kRZocsXpc2aHKPzFD5MARlAacGB3wALQ441hng0m4Ede/hlHf3djQc3uePVs", + "J/tNbI/KFYdjtqNMl9ObNgn31Cb0IFKdZtbh602BahrW/thf9n0lob98w+uK/BVhd/HuGyrTG/c7PHAI", + "+19+2N/gmg69MDTmd1jk5YX8rmI4qARXJUwZ7zsscgj33XD/NbBfww2R1A6a0b5X9+gdybOVKe52Khq1", + "XurJVIy7tXWwgjE7+Z6AstuE8+W+Q0syNech8bzu2Qyo1AB7rvIZFHuCgeA/Vx9+D5SbGNB5UHBgAUEZ", + "8B825K7o5CHxOGNR238+IObuZJGJrULfSri29U0t692e2pT0cbiGSrL4i1A3TY5oMKPPNMzKMLFHF8nw", + "TiJDtQ/usVgGc5wKkMQMEEn0Bl9MFv4E0DvVdnQKstpjPMB1qm26HtC+OkthSGP3zIMB7bdNnkabJFDb", + "ooPSgPq2StvLtr3qa52SnUIJaJqP2DzjE/P1tI7GtOvK1FkVJ6vOkybKIzD6G6oNs2e00PMq2x57j6/o", + "dYEO1rdpfWuaaYq8d9MIt2dxpk3fHBLU2yWon5VUjOFivTC5o+YnbbZZ0M5nq81zaNbGng+w37phi6dY", + "WucJ1XIF2SDeK52sgz5+DdEQnyQc8h/ntF/XrlXfq1lMrPAPMdVL0M7tKZxh6rkMt9RBcxvpuPrMz2tZ", + "oxZ1rRt9xmL5sTwG7Fln7q6rI/OSH00xNik6eSJwQk445ASfXU5wayPYPIFzmoziJrsdDOFLNITPYWlN", + "T7JytGWdVQH008qY14FU0bh2IPchQs9yf/HfK3a1reQDhK9MeLwIL9SePmJlxWR3dpOV2co9nLrTN7XG", + "zTkBO2kaCgXVc/BQy633wwJ5O6Mf1j9VCDjy8ddTeiz9nZoHuHcsmlFz2p8bc9DBr1MHF9ZhmVgH/63V", + "1zrDHwqx+93FcihSHtIBQ4uU5XH+T58d6Cl17sNoHqqeP0TVs43jWyzn2mycH2EdzQkko8yj2i77ylYn", + "PaXpMsfDvDCT9RLOrtnB6ujpHTV3iU9gd5q2oz6JM5u+IHBvduJLiWQKSJVLMKez6YctEjpx3ZXf4vwc", + "5MwYcHvCV/mBEfUZAPdob/0VD09oRm/Bn69u/axB85AwHRsiJmZzyrI39uy3jhV49ZOJbzBBavlf8xTX", + "IbP0HBI/+YK9Hc6TevnieFau8SkloFMSe+zhrMhTikyS2ytxl5wXUuA+/fGbEjVkPuYiaKD7lseytAjb", + "J9WqFLmdFcOku5J+A7KonVrsGIW4YFwfJ71LoWg98Z7cfrD7zm+GB/9HPybQPy0HemlGeQ27pxoM3yl4", + "mooCzVb2aOPti0r175QNqgsdEpGHROQExaB2Lu4s97QWcp5/9eYl0jKpVV6mKLxsaJz91U4OeuqgpyYo", + "mKyczyauS6d3RMan7LLpx5oc5T4Wtk+cyHBnPSjDYh0WT45lv3n8EtKn9Aq7e9Y/k/m3ZvYtdlwX86PF", + "2HhV3vhI6Z5Thuv1+v8BAAD//8KIn+ESfwAA", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/server/internal/infrastructure/memory/model.go b/server/internal/infrastructure/memory/model.go index f309fbfbdf..e405b54fc6 100644 --- a/server/internal/infrastructure/memory/model.go +++ b/server/internal/infrastructure/memory/model.go @@ -134,6 +134,21 @@ func (r *Model) FindByID(_ context.Context, mid id.ModelID) (*model.Model, error return nil, rerror.ErrNotFound } +func (r *Model) FindBySchema(_ context.Context, sid id.SchemaID) (*model.Model, error) { + if r.err != nil { + return nil, r.err + } + + m := r.data.Find(func(_ id.ModelID, m *model.Model) bool { + return (m.Schema() == sid || (m.Metadata() != nil && *m.Metadata() == sid)) && r.f.CanRead(m.Project()) + }) + + if m != nil { + return m, nil + } + return nil, rerror.ErrNotFound +} + func (r *Model) FindByIDs(_ context.Context, ids id.ModelIDList) (model.List, error) { if r.err != nil { return nil, r.err diff --git a/server/internal/infrastructure/mongo/model.go b/server/internal/infrastructure/mongo/model.go index dba7844729..41163387c3 100644 --- a/server/internal/infrastructure/mongo/model.go +++ b/server/internal/infrastructure/mongo/model.go @@ -2,6 +2,7 @@ package mongo import ( "context" + "github.com/reearth/reearth-cms/server/internal/infrastructure/mongo/mongodoc" "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/id" @@ -43,6 +44,15 @@ func (r *Model) FindByID(ctx context.Context, modelID id.ModelID) (*model.Model, }) } +func (r *Model) FindBySchema(ctx context.Context, schemaID id.SchemaID) (*model.Model, error) { + return r.findOne(ctx, bson.M{ + "$or": bson.A{ + bson.M{"schema": schemaID.String()}, + bson.M{"metadata": schemaID.String()}, + }, + }) +} + func (r *Model) FindByIDs(ctx context.Context, ids id.ModelIDList) (model.List, error) { if len(ids) == 0 { return nil, nil diff --git a/server/internal/infrastructure/mongo/model_test.go b/server/internal/infrastructure/mongo/model_test.go index d7e16449c0..d593103700 100644 --- a/server/internal/infrastructure/mongo/model_test.go +++ b/server/internal/infrastructure/mongo/model_test.go @@ -141,6 +141,115 @@ func TestModelRepo_FindByID(t *testing.T) { } } +func TestModelRepo_FindBySchema(t *testing.T) { + mocknow := time.Now().Truncate(time.Millisecond).UTC() + pid1 := id.NewProjectID() + id1 := id.NewModelID() + sid1 := id.NewSchemaID() + k := key.New("T123456") + m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() + + tests := []struct { + name string + seeds model.List + arg id.SchemaID + filter *repo.ProjectFilter + want *model.Model + wantErr error + }{ + { + name: "Not found in empty db", + seeds: model.List{}, + arg: id.NewSchemaID(), + want: nil, + wantErr: rerror.ErrNotFound, + }, + { + name: "Not found", + seeds: model.List{ + model.New().NewID().Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild(), + }, + arg: id.NewSchemaID(), + want: nil, + wantErr: rerror.ErrNotFound, + }, + { + name: "Found 1", + seeds: model.List{ + m1, + }, + arg: sid1, + want: m1, + wantErr: nil, + }, + { + name: "Found 2", + seeds: model.List{ + m1, + model.New().NewID().Project(id.NewProjectID()).Schema(id.NewSchemaID()).Key(k).UpdatedAt(mocknow).MustBuild(), + model.New().NewID().Project(id.NewProjectID()).Schema(id.NewSchemaID()).Key(k).UpdatedAt(mocknow).MustBuild(), + }, + arg: sid1, + want: m1, + wantErr: nil, + }, + { + name: "project filter operation success", + seeds: model.List{ + m1, + model.New().NewID().Project(id.NewProjectID()).Schema(id.NewSchemaID()).Key(k).UpdatedAt(mocknow).MustBuild(), + model.New().NewID().Project(id.NewProjectID()).Schema(id.NewSchemaID()).Key(k).UpdatedAt(mocknow).MustBuild(), + }, + arg: sid1, + filter: &repo.ProjectFilter{Readable: []id.ProjectID{pid1}, Writable: []id.ProjectID{pid1}}, + want: m1, + wantErr: nil, + }, + { + name: "project filter operation denied", + seeds: model.List{ + m1, + model.New().NewID().Project(id.NewProjectID()).Schema(id.NewSchemaID()).Key(k).UpdatedAt(mocknow).MustBuild(), + model.New().NewID().Project(id.NewProjectID()).Schema(id.NewSchemaID()).Key(k).UpdatedAt(mocknow).MustBuild(), + }, + arg: sid1, + filter: &repo.ProjectFilter{Readable: []id.ProjectID{}, Writable: []id.ProjectID{}}, + want: nil, + wantErr: nil, + }, + } + + initDB := mongotest.Connect(t) + + for _, tc := range tests { + tc := tc + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + client := mongox.NewClientWithDatabase(initDB(t)) + + r := NewModel(client) + ctx := context.Background() + + for _, a := range tc.seeds { + err := r.Save(ctx, a.Clone()) + assert.NoError(t, err) + } + + if tc.filter != nil { + r = r.Filtered(*tc.filter) + } + + got, err := r.FindBySchema(ctx, tc.arg) + if tc.wantErr != nil { + assert.ErrorIs(t, err, tc.wantErr) + return + } + assert.Equal(t, tc.want, got) + }) + } +} + func TestModelRepo_FindByIDs(t *testing.T) { mocknow := time.Now().Truncate(time.Millisecond).UTC() pid1 := id.NewProjectID() diff --git a/server/internal/usecase/interactor/model.go b/server/internal/usecase/interactor/model.go index b3f2ac22f5..d2f26aafe1 100644 --- a/server/internal/usecase/interactor/model.go +++ b/server/internal/usecase/interactor/model.go @@ -34,6 +34,10 @@ func (i Model) FindByID(ctx context.Context, id id.ModelID, operator *usecase.Op return i.repos.Model.FindByID(ctx, id) } +func (i Model) FindBySchema(ctx context.Context, id id.SchemaID, operator *usecase.Operator) (*model.Model, error) { + return i.repos.Model.FindBySchema(ctx, id) +} + func (i Model) FindByIDs(ctx context.Context, ids []id.ModelID, operator *usecase.Operator) (model.List, error) { return i.repos.Model.FindByIDs(ctx, ids) } diff --git a/server/internal/usecase/interfaces/model.go b/server/internal/usecase/interfaces/model.go index 29ae420378..3eb2afffcf 100644 --- a/server/internal/usecase/interfaces/model.go +++ b/server/internal/usecase/interfaces/model.go @@ -2,6 +2,7 @@ package interfaces import ( "context" + "github.com/reearth/reearth-cms/server/internal/usecase" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/model" @@ -42,6 +43,7 @@ var ( type Model interface { FindByID(context.Context, id.ModelID, *usecase.Operator) (*model.Model, error) + FindBySchema(context.Context, id.SchemaID, *usecase.Operator) (*model.Model, error) FindByIDs(context.Context, []id.ModelID, *usecase.Operator) (model.List, error) FindByProject(context.Context, id.ProjectID, *usecasex.Pagination, *usecase.Operator) (model.List, *usecasex.PageInfo, error) FindByKey(context.Context, id.ProjectID, string, *usecase.Operator) (*model.Model, error) diff --git a/server/internal/usecase/repo/model.go b/server/internal/usecase/repo/model.go index 269f94e415..0c7456f1de 100644 --- a/server/internal/usecase/repo/model.go +++ b/server/internal/usecase/repo/model.go @@ -11,6 +11,7 @@ import ( type Model interface { Filtered(ProjectFilter) Model FindByID(context.Context, id.ModelID) (*model.Model, error) + FindBySchema(context.Context, id.SchemaID) (*model.Model, error) FindByIDs(context.Context, id.ModelIDList) (model.List, error) FindByProject(context.Context, id.ProjectID, *usecasex.Pagination) (model.List, *usecasex.PageInfo, error) FindByKey(context.Context, id.ProjectID, string) (*model.Model, error) diff --git a/server/pkg/integrationapi/schema.go b/server/pkg/integrationapi/schema.go index 53513dbfdf..3ef8e5bb8f 100644 --- a/server/pkg/integrationapi/schema.go +++ b/server/pkg/integrationapi/schema.go @@ -40,13 +40,13 @@ func NewItemModelSchema(i item.ItemModelSchema, assets *AssetContext) ItemModelS ReferencedItems: lo.Map(i.ReferencedItems, func(itm *version.Value[*item.Item], _ int) *VersionedItem { return lo.ToPtr(NewVersionedItem(itm, nil, nil, nil, nil, nil, nil)) }), - Model: NewModel(i.Model, time.Time{}), + Model: NewModel(i.Model, nil, time.Time{}), Schema: NewSchema(i.Schema), Changes: NewItemFieldChanges(i.Changes), } } -func NewModel(m *model.Model, lastModified time.Time) Model { +func NewModel(m *model.Model, sp *schema.Package, lastModified time.Time) Model { var metadata *id.SchemaID if m.Metadata() != nil { metadata = m.Metadata().Ref() @@ -59,7 +59,9 @@ func NewModel(m *model.Model, lastModified time.Time) Model { Public: util.ToPtrIfNotEmpty(m.Public()), ProjectId: m.Project().Ref(), SchemaId: m.Schema().Ref(), + Schema: util.ToPtrIfNotEmpty(NewSchema(sp.Schema())), MetadataSchemaId: metadata, + MetadataSchema: util.ToPtrIfNotEmpty(NewSchema(sp.MetaSchema())), CreatedAt: lo.ToPtr(m.ID().Timestamp()), UpdatedAt: lo.ToPtr(m.UpdatedAt()), LastModified: util.ToPtrIfNotEmpty(lastModified), @@ -67,6 +69,9 @@ func NewModel(m *model.Model, lastModified time.Time) Model { } func NewSchema(i *schema.Schema) Schema { + if i == nil { + return Schema{} + } fs := lo.Map(i.Fields(), func(f *schema.Field, _ int) SchemaField { return SchemaField{ Id: f.ID().Ref(), diff --git a/server/pkg/integrationapi/types.gen.go b/server/pkg/integrationapi/types.gen.go index bc7c70a272..d9fa886023 100644 --- a/server/pkg/integrationapi/types.gen.go +++ b/server/pkg/integrationapi/types.gen.go @@ -359,10 +359,12 @@ type Model struct { Id *id.ModelID `json:"id,omitempty"` Key *string `json:"key,omitempty"` LastModified *time.Time `json:"lastModified,omitempty"` + MetadataSchema *Schema `json:"metadataSchema,omitempty"` MetadataSchemaId *id.SchemaID `json:"metadataSchemaId,omitempty"` Name *string `json:"name,omitempty"` ProjectId *id.ProjectID `json:"projectId,omitempty"` Public *bool `json:"public,omitempty"` + Schema *Schema `json:"schema,omitempty"` SchemaId *id.SchemaID `json:"schemaId,omitempty"` UpdatedAt *time.Time `json:"updatedAt,omitempty"` } @@ -475,6 +477,9 @@ type ProjectIdParam = id.ProjectID // RefParam defines model for refParam. type RefParam string +// SchemaIdParam defines model for schemaIdParam. +type SchemaIdParam = id.SchemaID + // SortDirParam defines model for sortDirParam. type SortDirParam string @@ -530,22 +535,6 @@ type ModelUpdateJSONBody struct { Name *string `json:"name,omitempty"` } -// FieldCreateJSONBody defines parameters for FieldCreate. -type FieldCreateJSONBody struct { - Key *string `json:"key,omitempty"` - Multiple *bool `json:"multiple,omitempty"` - Required *bool `json:"required,omitempty"` - Type *ValueType `json:"type,omitempty"` -} - -// FieldUpdateJSONBody defines parameters for FieldUpdate. -type FieldUpdateJSONBody struct { - Key *string `json:"key,omitempty"` - Multiple *bool `json:"multiple,omitempty"` - Required *bool `json:"required,omitempty"` - Type *ValueType `json:"type,omitempty"` -} - // ItemFilterJSONBody defines parameters for ItemFilter. type ItemFilterJSONBody struct { Filter *Condition `json:"filter,omitempty"` @@ -715,6 +704,22 @@ type AssetUploadCreateJSONBody struct { Name *string `json:"name,omitempty"` } +// FieldCreateJSONBody defines parameters for FieldCreate. +type FieldCreateJSONBody struct { + Key *string `json:"key,omitempty"` + Multiple *bool `json:"multiple,omitempty"` + Required *bool `json:"required,omitempty"` + Type *ValueType `json:"type,omitempty"` +} + +// FieldUpdateJSONBody defines parameters for FieldUpdate. +type FieldUpdateJSONBody struct { + Key *string `json:"key,omitempty"` + Multiple *bool `json:"multiple,omitempty"` + Required *bool `json:"required,omitempty"` + Type *ValueType `json:"type,omitempty"` +} + // ProjectFilterParams defines parameters for ProjectFilter. type ProjectFilterParams struct { // Page Used to select the page @@ -742,12 +747,6 @@ type ItemCommentUpdateJSONRequestBody ItemCommentUpdateJSONBody // ModelUpdateJSONRequestBody defines body for ModelUpdate for application/json ContentType. type ModelUpdateJSONRequestBody ModelUpdateJSONBody -// FieldCreateJSONRequestBody defines body for FieldCreate for application/json ContentType. -type FieldCreateJSONRequestBody FieldCreateJSONBody - -// FieldUpdateJSONRequestBody defines body for FieldUpdate for application/json ContentType. -type FieldUpdateJSONRequestBody FieldUpdateJSONBody - // ItemFilterJSONRequestBody defines body for ItemFilter for application/json ContentType. type ItemFilterJSONRequestBody ItemFilterJSONBody @@ -777,3 +776,9 @@ type AssetCreateMultipartRequestBody AssetCreateMultipartBody // AssetUploadCreateJSONRequestBody defines body for AssetUploadCreate for application/json ContentType. type AssetUploadCreateJSONRequestBody AssetUploadCreateJSONBody + +// FieldCreateJSONRequestBody defines body for FieldCreate for application/json ContentType. +type FieldCreateJSONRequestBody FieldCreateJSONBody + +// FieldUpdateJSONRequestBody defines body for FieldUpdate for application/json ContentType. +type FieldUpdateJSONRequestBody FieldUpdateJSONBody diff --git a/server/pkg/schema/schema.go b/server/pkg/schema/schema.go index c6551933c5..7251435405 100644 --- a/server/pkg/schema/schema.go +++ b/server/pkg/schema/schema.go @@ -2,8 +2,8 @@ package schema import ( "errors" - "github.com/reearth/reearth-cms/server/pkg/id" + "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" diff --git a/server/schemas/integration.yml b/server/schemas/integration.yml index a06c32f930..ccb2ab9946 100644 --- a/server/schemas/integration.yml +++ b/server/schemas/integration.yml @@ -199,9 +199,9 @@ paths: description: Invalid request parameter value '401': $ref: '#/components/responses/UnauthorizedError' - '/models/{modelId}/fields': + '/schemata/{schemaId}/fields': parameters: - - $ref: '#/components/parameters/modelIdParam' + - $ref: '#/components/parameters/schemaIdParam' post: operationId: FieldCreate summary: create a field @@ -235,9 +235,9 @@ paths: description: Invalid request parameter value '401': $ref: '#/components/responses/UnauthorizedError' - '/models/{modelId}/fields/{fieldIdOrKey}': + '/schemata/{schemaId}/fields/{fieldIdOrKey}': parameters: - - $ref: '#/components/parameters/modelIdParam' + - $ref: '#/components/parameters/schemaIdParam' - $ref: '#/components/parameters/fieldIdOrKeyParam' patch: operationId: FieldUpdate @@ -1187,6 +1187,14 @@ components: schema: type: string x-go-type: id.ModelID + schemaIdParam: + name: schemaId + in: path + description: ID of the schema in the model + required: true + schema: + type: string + x-go-type: id.SchemaID fieldIdParam: name: fieldId in: path @@ -1324,9 +1332,13 @@ components: schemaId: x-go-type: id.SchemaID type: string + schema: + $ref: '#/components/schemas/schema' metadataSchemaId: x-go-type: id.SchemaID type: string + metadataSchema: + $ref: '#/components/schemas/schema' name: type: string description: