Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Renaming methods for readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
andresuribe87 committed Jan 18, 2023
1 parent ab1724e commit 3b4dea3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
20 changes: 10 additions & 10 deletions pkg/server/router/presentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type CreatePresentationDefinitionResponse struct {
PresentationDefinition exchange.PresentationDefinition `json:"presentation_definition"`
}

// CreatePresentationDefinition godoc
// CreateDefinition godoc
//
// @Summary Create PresentationDefinition
// @Description Create presentation definition
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions pkg/server/server_presentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
}
})

Expand Down Expand Up @@ -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)
})
Expand All @@ -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) {
Expand All @@ -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()
})

Expand Down Expand Up @@ -616,7 +616,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
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/presentation/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,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 {
Expand Down
9 changes: 4 additions & 5 deletions pkg/service/presentation/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"go.einride.tech/aip/filtering"
)

type StoredPresentation struct {
type StoredDefinition struct {
ID string `json:"id"`
PresentationDefinition exchange.PresentationDefinition `json:"presentationDefinition"`
}
Expand All @@ -19,10 +19,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 {
Expand Down

0 comments on commit 3b4dea3

Please sign in to comment.