Repository: TBD54566975/ssi-service
Pull request #259 (2023-01-18 18:55:39)

Random renaming todos
For ease of readability.

codecov-commenter: # [Codecov](https://codecov.io/gh/TBD54566975/ssi-service/pull/259?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) Report
> Merging [#259](https://codecov.io/gh/TBD54566975/ssi-service/pull/259?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) (14724dc) into [main](https://codecov.io/gh/TBD54566975/ssi-service/commit/b2d967be6df9eafbc9c46ac4a17fd0c987bf6162?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) (b2d967b) will **not change** coverage.
> The diff coverage is `50.00%`.

```diff
@@           Coverage Diff           @@
##             main     #259   +/-   ##
=======================================
  Coverage   24.87%   24.87%           
=======================================
  Files          31       31           
  Lines        3063     3063           
=======================================
  Hits          762      762           
  Misses       2184     2184           
  Partials      117      117           
```


| [Impacted Files](https://codecov.io/gh/TBD54566975/ssi-service/pull/259?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) | Coverage Δ | |
|---|---|---|
| [pkg/server/router/presentation.go](https://codecov.io/gh/TBD54566975/ssi-service/pull/259?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975#diff-cGtnL3NlcnZlci9yb3V0ZXIvcHJlc2VudGF0aW9uLmdv) | `3.46% <0.00%> (ø)` | |
| [pkg/server/server.go](https://codecov.io/gh/TBD54566975/ssi-service/pull/259?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975#diff-cGtnL3NlcnZlci9zZXJ2ZXIuZ28=) | `81.96% <100.00%> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975)


Patch:
diff --git a/pkg/server/router/presentation.go b/pkg/server/router/presentation.go
index af4659f..6108ead 100644
--- a/pkg/server/router/presentation.go
+++ b/pkg/server/router/presentation.go
@@ -47,7 +47,7 @@ type CreatePresentationDefinitionResponse struct {
 	PresentationDefinition exchange.PresentationDefinition `json:"presentation_definition"`
 }
 
-// CreatePresentationDefinition godoc
+// CreateDefinition godoc
 //
 //	@Summary		Create PresentationDefinition
 //	@Description	Create presentation definition
@@ -59,7 +59,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 {
@@ -124,7 +124,7 @@ type GetPresentationDefinitionResponse struct {
 	PresentationDefinition exchange.PresentationDefinition `json:"presentation_definition"`
 }
 
-// GetPresentationDefinition godoc
+// GetDefinition godoc
 //
 //	@Summary		Get PresentationDefinition
 //	@Description	Get a presentation definition by its ID
@@ -135,7 +135,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"
@@ -190,7 +190,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
@@ -202,7 +202,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"
@@ -261,7 +261,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"
@@ -303,7 +303,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"
@@ -347,7 +347,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"
@@ -418,7 +418,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 6fb3ee0..e948525 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/service/presentation/storage.go b/pkg/service/presentation/storage.go
index 782b547..248c17c 100644
--- a/pkg/service/presentation/storage.go
+++ b/pkg/service/presentation/storage.go
@@ -172,12 +172,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 7a04479..d34659a 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 {


Test patch:
diff --git a/pkg/server/server_presentation_test.go b/pkg/server/server_presentation_test.go
index 506c2a1..c1d2505 100644
--- a/pkg/server/server_presentation_test.go
+++ b/pkg/server/server_presentation_test.go
@@ -62,7 +62,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))
@@ -91,13 +91,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))
 		}
 	})
 
@@ -142,7 +142,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)
 	})
@@ -153,7 +153,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) {
@@ -162,7 +162,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()
 	})
 
@@ -644,7 +644,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