Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OSE-166] Scaffolding for /v1/presentations/submissions #171

Merged

Conversation

andresuribe87
Copy link
Contributor

@andresuribe87 andresuribe87 commented Nov 11, 2022

This adds the routing for Create, Get, List, and Review endpoints for submissions. None of the business logic nor tests were added. Only simple routing, request types, and response types.

@codecov-commenter
Copy link

codecov-commenter commented Nov 11, 2022

Codecov Report

Attention: Patch coverage is 34.61538% with 17 lines in your changes missing coverage. Please review.

Project coverage is 26.52%. Comparing base (3c91cb6) to head (4ef3ccf).
Report is 319 commits behind head on main.

Files with missing lines Patch % Lines
pkg/server/router/presentation.go 5.55% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #171      +/-   ##
==========================================
+ Coverage   26.37%   26.52%   +0.15%     
==========================================
  Files          21       21              
  Lines        1623     1640      +17     
==========================================
+ Hits          428      435       +7     
- Misses       1123     1133      +10     
  Partials       72       72              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andresuribe87 andresuribe87 marked this pull request as ready for review November 11, 2022 15:16
}

type CreateSubmissionRequest struct {
PresentationJwt keyaccess.JWT `json:"presentationJwt" validate:"required"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: PresentationJWT

question: this better as SubmissionJWT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used SubmissionJWT

// @Failure 500 {string} string "Internal server error"
// @Router /v1/presentations/submissions [put]
func (sr SubmissionRouter) CreateSubmission(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
resp := Operation{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var resp Operation

https://github.com/uber-go/guide/blob/master/style.md#use-var-for-zero-value-structs

note - don't think our README points to this style doc even though it should. may need to add it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Heavy +1 to adding it as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty - feel free to add to the README

// @Failure 400 {string} string "Bad request"
// @Router /v1/presentations/submission/{id} [get]
func (sr SubmissionRouter) GetSubmission(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
resp := GetSubmissionResponse{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resp := GetSubmissionResponse{}
var resp GetSubmissionResponse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// @Failure 500 {string} string "Internal server error"
// @Router /v1/presentations/submissions [get]
func (sr SubmissionRouter) ReviewSubmission(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
return framework.Respond(ctx, w, ReviewSubmissionResponse{}, http.StatusOK)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there value in putting ReviewSubmissionResponse{} over nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. That said, this will change when the implementation is done.

Comment on lines 104 to 106
return s.PresentationAPI(service)
case svcframework.Submission:
return s.SubmissionAPI(service)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a working assumption that the PresentationAPI was going to be including the SubmissionAPI similar to how the ApplicationAPI is under the ManifestAPI. They should be the same service because they are a part of the same spec/group of functionality IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Grouped everything under the same API.


return
}
func (s *SSIServer) SubmissionAPI(service svcframework.Service) (err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

along with above - would like to see this a part of the PresentationAPI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

submissionStorage, err := submissionstorage.NewSubmissionStorage(s)
if err != nil {
errMsg := "could not instantiate storage for the submission service"
return nil, util.LoggingErrorMsg(err, errMsg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could include the errMsg inline here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


if !request.IsValid() {
errMsg := fmt.Sprintf("invalid create presentation submission request: %+v", request)
return nil, util.LoggingNewError(errMsg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use LoggingNewErrorf

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

storedSubmission, err := s.storage.GetSubmission(request.ID)
if err != nil {
err := errors.Wrapf(err, "error getting presentation submission: %s", request.ID)
return nil, util.LoggingError(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use LoggingNewErrorf

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
if storedSubmission == nil {
err := fmt.Errorf("presentation submission with id<%s> could not be found", request.ID)
return nil, util.LoggingError(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use LoggingErrorf

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used LoggingNewErrorf

namespace = "presentation_submission"
)

type BoltSubmissionStorage struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think this should be merged into the presentation storage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

Copy link
Contributor Author

@andresuribe87 andresuribe87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// @Failure 500 {string} string "Internal server error"
// @Router /v1/presentations/submissions [put]
func (sr SubmissionRouter) CreateSubmission(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
resp := Operation{}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Heavy +1 to adding it as well.

// @Failure 400 {string} string "Bad request"
// @Router /v1/presentations/submission/{id} [get]
func (sr SubmissionRouter) GetSubmission(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
resp := GetSubmissionResponse{}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// @Failure 500 {string} string "Internal server error"
// @Router /v1/presentations/submissions [get]
func (sr SubmissionRouter) ReviewSubmission(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
return framework.Respond(ctx, w, ReviewSubmissionResponse{}, http.StatusOK)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. That said, this will change when the implementation is done.

Comment on lines 104 to 106
return s.PresentationAPI(service)
case svcframework.Submission:
return s.SubmissionAPI(service)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Grouped everything under the same API.


return
}
func (s *SSIServer) SubmissionAPI(service svcframework.Service) (err error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


if !request.IsValid() {
errMsg := fmt.Sprintf("invalid create presentation submission request: %+v", request)
return nil, util.LoggingNewError(errMsg)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

storedSubmission, err := s.storage.GetSubmission(request.ID)
if err != nil {
err := errors.Wrapf(err, "error getting presentation submission: %s", request.ID)
return nil, util.LoggingError(err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
if storedSubmission == nil {
err := fmt.Errorf("presentation submission with id<%s> could not be found", request.ID)
return nil, util.LoggingError(err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used LoggingNewErrorf

namespace = "presentation_submission"
)

type BoltSubmissionStorage struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

type CreateSubmissionRequest struct {
PresentationJwt keyaccess.JWT `json:"presentationJwt" validate:"required"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used SubmissionJWT

}

type ListSubmissionRequest struct {
Filter string `json:"filter"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where's the right place to put doc on how the filter syntax works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added below.


// ListSubmissions godoc
// @Summary List Submissions
// @Description List existing submissions according to a filtering query.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe here with a link to the filter syntax we use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added here. Will likely expand on this once I do the implementation.

presentationStorage, err := presentationstorage.NewPresentationStorage(s)
if err != nil {
errMsg := "could not instantiate storage for the presentation definition service"
return nil, util.LoggingErrorMsg(err, errMsg)
return nil, util.LoggingErrorMsg(err, "could not instantiate storage for the presentation definition service")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presentation service

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

if err != nil {
errMsg := fmt.Sprintf("could not store submission definition: %s", id)
logrus.WithError(err).Error(errMsg)
return errors.Wrapf(err, errMsg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could use the util.Logging... whatever as it combines the error creation, logging, and error return here and the rest of this file. but NBD

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small comments, approving

@andresuribe87 andresuribe87 merged commit 114818b into TBD54566975:main Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants