diff --git a/pkg/server/router/presentation.go b/pkg/server/router/presentation.go index bb54c9d2b..8e85c7649 100644 --- a/pkg/server/router/presentation.go +++ b/pkg/server/router/presentation.go @@ -56,7 +56,7 @@ type CreatePresentationDefinitionResponse struct { PresentationDefinitionJWT keyaccess.JWT `json:"presentationDefinitionJWT"` } -// CreatePresentationDefinition godoc +// CreateDefinition godoc // // @Summary Create PresentationDefinition // @Description Create presentation definition @@ -68,7 +68,7 @@ type CreatePresentationDefinitionResponse struct { // @Failure 400 {string} string "Bad request" // @Failure 500 {string} string "Internal server error" // @Router /v1/presentation/definition [put] -func (pr PresentationRouter) CreatePresentationDefinition(ctx context.Context, w http.ResponseWriter, r *http.Request) error { +func (pr PresentationRouter) CreateDefinition(ctx context.Context, w http.ResponseWriter, r *http.Request) error { var request CreatePresentationDefinitionRequest errMsg := "Invalid Presentation Definition Request" if err := framework.Decode(r, &request); err != nil { @@ -141,7 +141,7 @@ type GetPresentationDefinitionResponse struct { PresentationDefinitionJWT keyaccess.JWT `json:"presentationDefinitionJWT"` } -// GetPresentationDefinition godoc +// GetDefinition godoc // // @Summary Get PresentationDefinition // @Description Get a presentation definition by its ID @@ -152,7 +152,7 @@ type GetPresentationDefinitionResponse struct { // @Success 200 {object} GetPresentationDefinitionResponse // @Failure 400 {string} string "Bad request" // @Router /v1/presentation/definition/{id} [get] -func (pr PresentationRouter) GetPresentationDefinition(ctx context.Context, w http.ResponseWriter, _ *http.Request) error { +func (pr PresentationRouter) GetDefinition(ctx context.Context, w http.ResponseWriter, _ *http.Request) error { id := framework.GetParam(ctx, IDParam) if id == nil { errMsg := "cannot get presentation without ID parameter" @@ -208,7 +208,7 @@ func (pr PresentationRouter) ListDefinitions(ctx context.Context, w http.Respons return framework.Respond(ctx, w, resp, http.StatusOK) } -// DeletePresentationDefinition godoc +// DeleteDefinition godoc // // @Summary Delete PresentationDefinition // @Description Delete a presentation definition by its ID @@ -220,7 +220,7 @@ func (pr PresentationRouter) ListDefinitions(ctx context.Context, w http.Respons // @Failure 400 {string} string "Bad request" // @Failure 500 {string} string "Internal server error" // @Router /v1/presentation/definition/{id} [delete] -func (pr PresentationRouter) DeletePresentationDefinition(ctx context.Context, w http.ResponseWriter, _ *http.Request) error { +func (pr PresentationRouter) DeleteDefinition(ctx context.Context, w http.ResponseWriter, _ *http.Request) error { id := framework.GetParam(ctx, IDParam) if id == nil { errMsg := "cannot delete a presentation without an ID parameter" @@ -279,7 +279,7 @@ func (r CreateSubmissionRequest) toServiceRequest() (*model.CreateSubmissionRequ // // @Summary Create Submission // @Description Creates a submission in this server ready to be reviewed. -// @Tags SubmissionAPI +// @Tags PresentationSubmissionAPI // @Accept json // @Produce json // @Param request body CreateSubmissionRequest true "request body" @@ -321,7 +321,7 @@ type GetSubmissionResponse struct { // // @Summary Get Submission // @Description Get a submission by its ID -// @Tags SubmissionAPI +// @Tags PresentationSubmissionAPI // @Accept json // @Produce json // @Param id path string true "ID" @@ -365,7 +365,7 @@ type ListSubmissionResponse struct { // // @Summary List Submissions // @Description List existing submissions according to a filtering query. The `filter` field follows the syntax described in https://google.aip.dev/160. -// @Tags SubmissionAPI +// @Tags PresentationSubmissionAPI // @Accept json // @Produce json // @Param request body ListSubmissionRequest true "request body" @@ -436,7 +436,7 @@ type ReviewSubmissionResponse struct { // // @Summary Review a pending submission // @Description Reviews a pending submission. After this method is called, the operation with `id==presentations/submissions/{submission_id}` will be updated with the result of this invocation. -// @Tags SubmissionAPI +// @Tags PresentationSubmissionAPI // @Accept json // @Produce json // @Param request body ReviewSubmissionRequest true "request body" diff --git a/pkg/server/server.go b/pkg/server/server.go index 6fb3ee0be..e94852565 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -181,10 +181,10 @@ func (s *SSIServer) PresentationAPI(service svcframework.Service) (err error) { handlerPath := V1Prefix + PresentationsPrefix + DefinitionsPrefix - s.Handle(http.MethodPut, handlerPath, pRouter.CreatePresentationDefinition) - s.Handle(http.MethodGet, path.Join(handlerPath, "/:id"), pRouter.GetPresentationDefinition) + s.Handle(http.MethodPut, handlerPath, pRouter.CreateDefinition) + s.Handle(http.MethodGet, path.Join(handlerPath, "/:id"), pRouter.GetDefinition) s.Handle(http.MethodGet, handlerPath, pRouter.ListDefinitions) - s.Handle(http.MethodDelete, path.Join(handlerPath, "/:id"), pRouter.DeletePresentationDefinition) + s.Handle(http.MethodDelete, path.Join(handlerPath, "/:id"), pRouter.DeleteDefinition) submissionHandlerPath := V1Prefix + PresentationsPrefix + SubmissionsPrefix diff --git a/pkg/server/server_presentation_test.go b/pkg/server/server_presentation_test.go index 18cce9919..05de245eb 100644 --- a/pkg/server/server_presentation_test.go +++ b/pkg/server/server_presentation_test.go @@ -65,7 +65,7 @@ func TestPresentationAPI(t *testing.T) { // We can get the PD after it's created. req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/presentations/definitions/%s", createdID), nil) w := httptest.NewRecorder() - assert.NoError(tt, pRouter.GetPresentationDefinition(newRequestContextWithParams(map[string]string{"id": createdID}), w, req)) + assert.NoError(tt, pRouter.GetDefinition(newRequestContextWithParams(map[string]string{"id": createdID}), w, req)) var resp router.GetPresentationDefinitionResponse assert.NoError(tt, json.NewDecoder(w.Body).Decode(&resp)) @@ -94,13 +94,13 @@ func TestPresentationAPI(t *testing.T) { // The PD can be deleted. req := httptest.NewRequest(http.MethodDelete, fmt.Sprintf("https://ssi-service.com/v1/presentations/definitions/%s", createdID), nil) w := httptest.NewRecorder() - assert.NoError(t, pRouter.DeletePresentationDefinition(newRequestContextWithParams(map[string]string{"id": createdID}), w, req)) + assert.NoError(t, pRouter.DeleteDefinition(newRequestContextWithParams(map[string]string{"id": createdID}), w, req)) } { // And we cannot get the PD after it's been deleted. req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/presentations/definitions/%s", createdID), nil) w := httptest.NewRecorder() - assert.Error(tt, pRouter.GetPresentationDefinition(newRequestContextWithParams(map[string]string{"id": createdID}), w, req)) + assert.Error(tt, pRouter.GetDefinition(newRequestContextWithParams(map[string]string{"id": createdID}), w, req)) } }) @@ -147,7 +147,7 @@ func TestPresentationAPI(t *testing.T) { req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/presentations/definitions", value) w := httptest.NewRecorder() - err = pRouter.CreatePresentationDefinition(newRequestContext(), w, req) + err = pRouter.CreateDefinition(newRequestContext(), w, req) assert.Error(t, err) }) @@ -158,7 +158,7 @@ func TestPresentationAPI(t *testing.T) { req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/presentations/definitions/%s", pd.ID), nil) w := httptest.NewRecorder() - assert.Error(tt, pRouter.GetPresentationDefinition(newRequestContext(), w, req)) + assert.Error(tt, pRouter.GetDefinition(newRequestContext(), w, req)) }) t.Run("Delete without an ID returns error", func(tt *testing.T) { @@ -167,7 +167,7 @@ func TestPresentationAPI(t *testing.T) { req := httptest.NewRequest(http.MethodDelete, fmt.Sprintf("https://ssi-service.com/v1/presentations/definitions/%s", pd.ID), nil) w := httptest.NewRecorder() - assert.Error(tt, pRouter.DeletePresentationDefinition(newRequestContext(), w, req)) + assert.Error(tt, pRouter.DeleteDefinition(newRequestContext(), w, req)) w.Flush() }) @@ -666,7 +666,7 @@ func createPresentationDefinition(t *testing.T, pRouter *router.PresentationRout req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/presentations/definitions", value) w := httptest.NewRecorder() - assert.NoError(t, pRouter.CreatePresentationDefinition(newRequestContext(), w, req)) + assert.NoError(t, pRouter.CreateDefinition(newRequestContext(), w, req)) var resp router.CreatePresentationDefinitionResponse assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) return resp diff --git a/pkg/service/presentation/storage.go b/pkg/service/presentation/storage.go index e6406d30b..eec68e906 100644 --- a/pkg/service/presentation/storage.go +++ b/pkg/service/presentation/storage.go @@ -173,12 +173,12 @@ func (ps *Storage) GetSubmission(ctx context.Context, id string) (*prestorage.St return &stored, nil } -func (ps *Storage) ListDefinitions(ctx context.Context) ([]prestorage.StoredPresentation, error) { +func (ps *Storage) ListDefinitions(ctx context.Context) ([]prestorage.StoredDefinition, error) { m, err := ps.db.ReadAll(ctx, presentationDefinitionNamespace) if err != nil { return nil, errors.Wrap(err, "reading all") } - ts := make([]prestorage.StoredPresentation, len(m)) + ts := make([]prestorage.StoredDefinition, len(m)) i := 0 for k, v := range m { if err = json.Unmarshal(v, &ts[i]); err != nil { diff --git a/pkg/service/presentation/storage/storage.go b/pkg/service/presentation/storage/storage.go index 7a04479d9..d34659a1c 100644 --- a/pkg/service/presentation/storage/storage.go +++ b/pkg/service/presentation/storage/storage.go @@ -9,7 +9,7 @@ import ( "go.einride.tech/aip/filtering" ) -type StoredPresentation struct { +type StoredDefinition struct { ID string `json:"id"` PresentationDefinition exchange.PresentationDefinition `json:"presentationDefinition"` } @@ -20,10 +20,9 @@ type Storage interface { } type DefinitionStorage interface { - // TODO: rename to Definition - StorePresentation(schema StoredPresentation) error - GetPresentation(id string) (*StoredPresentation, error) - DeletePresentation(id string) error + StoreDefinition(schema StoredDefinition) error + GetDefinition(id string) (*StoredDefinition, error) + DeleteDefinition(id string) error } type StoredSubmission struct {