From b31a8a90ff2c029ed7c392b0122a5a4194ab87fb Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 27 Nov 2024 17:46:54 -0800 Subject: [PATCH] generate and edit submissions interface --- pkg/api/oas_client_gen.go | 891 ++++++++++++++++++--- pkg/api/oas_handlers_gen.go | 1111 +++++++++++++++++++++++--- pkg/api/oas_parameters_gen.go | 630 ++++++++++++--- pkg/api/oas_response_decoders_gen.go | 459 +++++++++-- pkg/api/oas_response_encoders_gen.go | 63 +- pkg/api/oas_router_gen.go | 476 ++++++++++- pkg/api/oas_schemas_gen.go | 27 +- pkg/api/oas_server_gen.go | 54 +- pkg/api/oas_unimplemented_gen.go | 81 +- pkg/service/submissions.go | 69 +- 10 files changed, 3400 insertions(+), 461 deletions(-) diff --git a/pkg/api/oas_client_gen.go b/pkg/api/oas_client_gen.go index 48df807..7753a3d 100644 --- a/pkg/api/oas_client_gen.go +++ b/pkg/api/oas_client_gen.go @@ -23,6 +23,54 @@ import ( // Invoker invokes operations described by OpenAPI v3 specification. type Invoker interface { + // ActionSubmissionPublish invokes actionSubmissionPublish operation. + // + // Role Validator changes status from Publishing -> Published. + // + // PATCH /submissions/{SubmissionID}/status/publish + ActionSubmissionPublish(ctx context.Context, params ActionSubmissionPublishParams) error + // ActionSubmissionReject invokes actionSubmissionReject operation. + // + // Role Reviewer changes status from Submitted -> Rejected. + // + // PATCH /submissions/{SubmissionID}/status/reject + ActionSubmissionReject(ctx context.Context, params ActionSubmissionRejectParams) error + // ActionSubmissionRequestChanges invokes actionSubmissionRequestChanges operation. + // + // Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested. + // + // PATCH /submissions/{SubmissionID}/status/request-changes + ActionSubmissionRequestChanges(ctx context.Context, params ActionSubmissionRequestChangesParams) error + // ActionSubmissionRevoke invokes actionSubmissionRevoke operation. + // + // Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction. + // + // PATCH /submissions/{SubmissionID}/status/revoke + ActionSubmissionRevoke(ctx context.Context, params ActionSubmissionRevokeParams) error + // ActionSubmissionSubmit invokes actionSubmissionSubmit operation. + // + // Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted. + // + // PATCH /submissions/{SubmissionID}/status/submit + ActionSubmissionSubmit(ctx context.Context, params ActionSubmissionSubmitParams) error + // ActionSubmissionTriggerPublish invokes actionSubmissionTriggerPublish operation. + // + // Role Admin changes status from Validated -> Publishing. + // + // PATCH /submissions/{SubmissionID}/status/trigger-publish + ActionSubmissionTriggerPublish(ctx context.Context, params ActionSubmissionTriggerPublishParams) error + // ActionSubmissionTriggerValidate invokes actionSubmissionTriggerValidate operation. + // + // Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating. + // + // PATCH /submissions/{SubmissionID}/status/trigger-validate + ActionSubmissionTriggerValidate(ctx context.Context, params ActionSubmissionTriggerValidateParams) error + // ActionSubmissionValidate invokes actionSubmissionValidate operation. + // + // Role Validator changes status from Validating -> Validated. + // + // PATCH /submissions/{SubmissionID}/status/validate + ActionSubmissionValidate(ctx context.Context, params ActionSubmissionValidateParams) error // CreateSubmission invokes createSubmission operation. // // Create new submission. @@ -53,12 +101,6 @@ type Invoker interface { // // PATCH /submissions/{SubmissionID}/model PatchSubmissionModel(ctx context.Context, params PatchSubmissionModelParams) error - // PatchSubmissionStatus invokes patchSubmissionStatus operation. - // - // Update status following role restrictions. - // - // PATCH /submissions/{SubmissionID}/status - PatchSubmissionStatus(ctx context.Context, params PatchSubmissionStatusParams) error } // Client implements OAS client. @@ -113,6 +155,734 @@ func (c *Client) requestURL(ctx context.Context) *url.URL { return u } +// ActionSubmissionPublish invokes actionSubmissionPublish operation. +// +// Role Validator changes status from Publishing -> Published. +// +// PATCH /submissions/{SubmissionID}/status/publish +func (c *Client) ActionSubmissionPublish(ctx context.Context, params ActionSubmissionPublishParams) error { + _, err := c.sendActionSubmissionPublish(ctx, params) + return err +} + +func (c *Client) sendActionSubmissionPublish(ctx context.Context, params ActionSubmissionPublishParams) (res *ActionSubmissionPublishOK, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionPublish"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/publish"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + // Use floating point division here for higher precision (instead of Millisecond method). + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "ActionSubmissionPublish", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + var pathParts [3]string + pathParts[0] = "/submissions/" + { + // Encode "SubmissionID" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "SubmissionID", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.Int64ToString(params.SubmissionID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + encoded, err := e.Result() + if err != nil { + return res, errors.Wrap(err, "encode path") + } + pathParts[1] = encoded + } + pathParts[2] = "/status/publish" + uri.AddPathParts(u, pathParts[:]...) + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "PATCH", u) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeActionSubmissionPublishResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + +// ActionSubmissionReject invokes actionSubmissionReject operation. +// +// Role Reviewer changes status from Submitted -> Rejected. +// +// PATCH /submissions/{SubmissionID}/status/reject +func (c *Client) ActionSubmissionReject(ctx context.Context, params ActionSubmissionRejectParams) error { + _, err := c.sendActionSubmissionReject(ctx, params) + return err +} + +func (c *Client) sendActionSubmissionReject(ctx context.Context, params ActionSubmissionRejectParams) (res *ActionSubmissionRejectOK, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionReject"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/reject"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + // Use floating point division here for higher precision (instead of Millisecond method). + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "ActionSubmissionReject", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + var pathParts [3]string + pathParts[0] = "/submissions/" + { + // Encode "SubmissionID" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "SubmissionID", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.Int64ToString(params.SubmissionID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + encoded, err := e.Result() + if err != nil { + return res, errors.Wrap(err, "encode path") + } + pathParts[1] = encoded + } + pathParts[2] = "/status/reject" + uri.AddPathParts(u, pathParts[:]...) + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "PATCH", u) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeActionSubmissionRejectResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + +// ActionSubmissionRequestChanges invokes actionSubmissionRequestChanges operation. +// +// Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested. +// +// PATCH /submissions/{SubmissionID}/status/request-changes +func (c *Client) ActionSubmissionRequestChanges(ctx context.Context, params ActionSubmissionRequestChangesParams) error { + _, err := c.sendActionSubmissionRequestChanges(ctx, params) + return err +} + +func (c *Client) sendActionSubmissionRequestChanges(ctx context.Context, params ActionSubmissionRequestChangesParams) (res *ActionSubmissionRequestChangesOK, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionRequestChanges"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/request-changes"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + // Use floating point division here for higher precision (instead of Millisecond method). + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "ActionSubmissionRequestChanges", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + var pathParts [3]string + pathParts[0] = "/submissions/" + { + // Encode "SubmissionID" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "SubmissionID", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.Int64ToString(params.SubmissionID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + encoded, err := e.Result() + if err != nil { + return res, errors.Wrap(err, "encode path") + } + pathParts[1] = encoded + } + pathParts[2] = "/status/request-changes" + uri.AddPathParts(u, pathParts[:]...) + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "PATCH", u) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeActionSubmissionRequestChangesResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + +// ActionSubmissionRevoke invokes actionSubmissionRevoke operation. +// +// Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction. +// +// PATCH /submissions/{SubmissionID}/status/revoke +func (c *Client) ActionSubmissionRevoke(ctx context.Context, params ActionSubmissionRevokeParams) error { + _, err := c.sendActionSubmissionRevoke(ctx, params) + return err +} + +func (c *Client) sendActionSubmissionRevoke(ctx context.Context, params ActionSubmissionRevokeParams) (res *ActionSubmissionRevokeOK, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionRevoke"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/revoke"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + // Use floating point division here for higher precision (instead of Millisecond method). + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "ActionSubmissionRevoke", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + var pathParts [3]string + pathParts[0] = "/submissions/" + { + // Encode "SubmissionID" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "SubmissionID", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.Int64ToString(params.SubmissionID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + encoded, err := e.Result() + if err != nil { + return res, errors.Wrap(err, "encode path") + } + pathParts[1] = encoded + } + pathParts[2] = "/status/revoke" + uri.AddPathParts(u, pathParts[:]...) + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "PATCH", u) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeActionSubmissionRevokeResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + +// ActionSubmissionSubmit invokes actionSubmissionSubmit operation. +// +// Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted. +// +// PATCH /submissions/{SubmissionID}/status/submit +func (c *Client) ActionSubmissionSubmit(ctx context.Context, params ActionSubmissionSubmitParams) error { + _, err := c.sendActionSubmissionSubmit(ctx, params) + return err +} + +func (c *Client) sendActionSubmissionSubmit(ctx context.Context, params ActionSubmissionSubmitParams) (res *ActionSubmissionSubmitOK, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionSubmit"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/submit"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + // Use floating point division here for higher precision (instead of Millisecond method). + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "ActionSubmissionSubmit", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + var pathParts [3]string + pathParts[0] = "/submissions/" + { + // Encode "SubmissionID" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "SubmissionID", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.Int64ToString(params.SubmissionID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + encoded, err := e.Result() + if err != nil { + return res, errors.Wrap(err, "encode path") + } + pathParts[1] = encoded + } + pathParts[2] = "/status/submit" + uri.AddPathParts(u, pathParts[:]...) + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "PATCH", u) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeActionSubmissionSubmitResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + +// ActionSubmissionTriggerPublish invokes actionSubmissionTriggerPublish operation. +// +// Role Admin changes status from Validated -> Publishing. +// +// PATCH /submissions/{SubmissionID}/status/trigger-publish +func (c *Client) ActionSubmissionTriggerPublish(ctx context.Context, params ActionSubmissionTriggerPublishParams) error { + _, err := c.sendActionSubmissionTriggerPublish(ctx, params) + return err +} + +func (c *Client) sendActionSubmissionTriggerPublish(ctx context.Context, params ActionSubmissionTriggerPublishParams) (res *ActionSubmissionTriggerPublishOK, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionTriggerPublish"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/trigger-publish"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + // Use floating point division here for higher precision (instead of Millisecond method). + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "ActionSubmissionTriggerPublish", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + var pathParts [3]string + pathParts[0] = "/submissions/" + { + // Encode "SubmissionID" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "SubmissionID", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.Int64ToString(params.SubmissionID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + encoded, err := e.Result() + if err != nil { + return res, errors.Wrap(err, "encode path") + } + pathParts[1] = encoded + } + pathParts[2] = "/status/trigger-publish" + uri.AddPathParts(u, pathParts[:]...) + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "PATCH", u) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeActionSubmissionTriggerPublishResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + +// ActionSubmissionTriggerValidate invokes actionSubmissionTriggerValidate operation. +// +// Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating. +// +// PATCH /submissions/{SubmissionID}/status/trigger-validate +func (c *Client) ActionSubmissionTriggerValidate(ctx context.Context, params ActionSubmissionTriggerValidateParams) error { + _, err := c.sendActionSubmissionTriggerValidate(ctx, params) + return err +} + +func (c *Client) sendActionSubmissionTriggerValidate(ctx context.Context, params ActionSubmissionTriggerValidateParams) (res *ActionSubmissionTriggerValidateOK, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionTriggerValidate"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/trigger-validate"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + // Use floating point division here for higher precision (instead of Millisecond method). + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "ActionSubmissionTriggerValidate", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + var pathParts [3]string + pathParts[0] = "/submissions/" + { + // Encode "SubmissionID" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "SubmissionID", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.Int64ToString(params.SubmissionID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + encoded, err := e.Result() + if err != nil { + return res, errors.Wrap(err, "encode path") + } + pathParts[1] = encoded + } + pathParts[2] = "/status/trigger-validate" + uri.AddPathParts(u, pathParts[:]...) + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "PATCH", u) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeActionSubmissionTriggerValidateResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + +// ActionSubmissionValidate invokes actionSubmissionValidate operation. +// +// Role Validator changes status from Validating -> Validated. +// +// PATCH /submissions/{SubmissionID}/status/validate +func (c *Client) ActionSubmissionValidate(ctx context.Context, params ActionSubmissionValidateParams) error { + _, err := c.sendActionSubmissionValidate(ctx, params) + return err +} + +func (c *Client) sendActionSubmissionValidate(ctx context.Context, params ActionSubmissionValidateParams) (res *ActionSubmissionValidateOK, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionValidate"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/validate"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + // Use floating point division here for higher precision (instead of Millisecond method). + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "ActionSubmissionValidate", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + var pathParts [3]string + pathParts[0] = "/submissions/" + { + // Encode "SubmissionID" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "SubmissionID", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.Int64ToString(params.SubmissionID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + encoded, err := e.Result() + if err != nil { + return res, errors.Wrap(err, "encode path") + } + pathParts[1] = encoded + } + pathParts[2] = "/status/validate" + uri.AddPathParts(u, pathParts[:]...) + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "PATCH", u) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeActionSubmissionValidateResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + // CreateSubmission invokes createSubmission operation. // // Create new submission. @@ -598,112 +1368,3 @@ func (c *Client) sendPatchSubmissionModel(ctx context.Context, params PatchSubmi return result, nil } - -// PatchSubmissionStatus invokes patchSubmissionStatus operation. -// -// Update status following role restrictions. -// -// PATCH /submissions/{SubmissionID}/status -func (c *Client) PatchSubmissionStatus(ctx context.Context, params PatchSubmissionStatusParams) error { - _, err := c.sendPatchSubmissionStatus(ctx, params) - return err -} - -func (c *Client) sendPatchSubmissionStatus(ctx context.Context, params PatchSubmissionStatusParams) (res *PatchSubmissionStatusOK, err error) { - otelAttrs := []attribute.KeyValue{ - otelogen.OperationID("patchSubmissionStatus"), - semconv.HTTPRequestMethodKey.String("PATCH"), - semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status"), - } - - // Run stopwatch. - startTime := time.Now() - defer func() { - // Use floating point division here for higher precision (instead of Millisecond method). - elapsedDuration := time.Since(startTime) - c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) - }() - - // Increment request counter. - c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) - - // Start a span for this request. - ctx, span := c.cfg.Tracer.Start(ctx, "PatchSubmissionStatus", - trace.WithAttributes(otelAttrs...), - clientSpanKind, - ) - // Track stage for error reporting. - var stage string - defer func() { - if err != nil { - span.RecordError(err) - span.SetStatus(codes.Error, stage) - c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) - } - span.End() - }() - - stage = "BuildURL" - u := uri.Clone(c.requestURL(ctx)) - var pathParts [3]string - pathParts[0] = "/submissions/" - { - // Encode "SubmissionID" parameter. - e := uri.NewPathEncoder(uri.PathEncoderConfig{ - Param: "SubmissionID", - Style: uri.PathStyleSimple, - Explode: false, - }) - if err := func() error { - return e.EncodeValue(conv.Int64ToString(params.SubmissionID)) - }(); err != nil { - return res, errors.Wrap(err, "encode path") - } - encoded, err := e.Result() - if err != nil { - return res, errors.Wrap(err, "encode path") - } - pathParts[1] = encoded - } - pathParts[2] = "/status" - uri.AddPathParts(u, pathParts[:]...) - - stage = "EncodeQueryParams" - q := uri.NewQueryEncoder() - { - // Encode "Status" parameter. - cfg := uri.QueryParameterEncodingConfig{ - Name: "Status", - Style: uri.QueryStyleForm, - Explode: true, - } - - if err := q.EncodeParam(cfg, func(e uri.Encoder) error { - return e.EncodeValue(conv.Int32ToString(params.Status)) - }); err != nil { - return res, errors.Wrap(err, "encode query") - } - } - u.RawQuery = q.Values().Encode() - - stage = "EncodeRequest" - r, err := ht.NewRequest(ctx, "PATCH", u) - if err != nil { - return res, errors.Wrap(err, "create request") - } - - stage = "SendRequest" - resp, err := c.cfg.Client.Do(r) - if err != nil { - return res, errors.Wrap(err, "do request") - } - defer resp.Body.Close() - - stage = "DecodeResponse" - result, err := decodePatchSubmissionStatusResponse(resp) - if err != nil { - return res, errors.Wrap(err, "decode response") - } - - return result, nil -} diff --git a/pkg/api/oas_handlers_gen.go b/pkg/api/oas_handlers_gen.go index 7b8897d..7ed915c 100644 --- a/pkg/api/oas_handlers_gen.go +++ b/pkg/api/oas_handlers_gen.go @@ -20,6 +20,990 @@ import ( "github.com/ogen-go/ogen/otelogen" ) +// handleActionSubmissionPublishRequest handles actionSubmissionPublish operation. +// +// Role Validator changes status from Publishing -> Published. +// +// PATCH /submissions/{SubmissionID}/status/publish +func (s *Server) handleActionSubmissionPublishRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionPublish"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/publish"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "ActionSubmissionPublish", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Add Labeler to context. + labeler := &Labeler{attrs: otelAttrs} + ctx = contextWithLabeler(ctx, labeler) + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + attrOpt := metric.WithAttributeSet(labeler.AttributeSet()) + + // Increment request counter. + s.requests.Add(ctx, 1, attrOpt) + + // Use floating point division here for higher precision (instead of Millisecond method). + s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt) + }() + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet())) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "ActionSubmissionPublish", + ID: "actionSubmissionPublish", + } + ) + params, err := decodeActionSubmissionPublishParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response *ActionSubmissionPublishOK + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "ActionSubmissionPublish", + OperationSummary: "Role Validator changes status from Publishing -> Published", + OperationID: "actionSubmissionPublish", + Body: nil, + Params: middleware.Parameters{ + { + Name: "SubmissionID", + In: "path", + }: params.SubmissionID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ActionSubmissionPublishParams + Response = *ActionSubmissionPublishOK + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackActionSubmissionPublishParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + err = s.h.ActionSubmissionPublish(ctx, params) + return response, err + }, + ) + } else { + err = s.h.ActionSubmissionPublish(ctx, params) + } + if err != nil { + if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { + if err := encodeErrorResponse(errRes, w, span); err != nil { + defer recordError("Internal", err) + } + return + } + if errors.Is(err, ht.ErrNotImplemented) { + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + defer recordError("Internal", err) + } + return + } + + if err := encodeActionSubmissionPublishResponse(response, w, span); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleActionSubmissionRejectRequest handles actionSubmissionReject operation. +// +// Role Reviewer changes status from Submitted -> Rejected. +// +// PATCH /submissions/{SubmissionID}/status/reject +func (s *Server) handleActionSubmissionRejectRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionReject"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/reject"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "ActionSubmissionReject", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Add Labeler to context. + labeler := &Labeler{attrs: otelAttrs} + ctx = contextWithLabeler(ctx, labeler) + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + attrOpt := metric.WithAttributeSet(labeler.AttributeSet()) + + // Increment request counter. + s.requests.Add(ctx, 1, attrOpt) + + // Use floating point division here for higher precision (instead of Millisecond method). + s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt) + }() + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet())) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "ActionSubmissionReject", + ID: "actionSubmissionReject", + } + ) + params, err := decodeActionSubmissionRejectParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response *ActionSubmissionRejectOK + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "ActionSubmissionReject", + OperationSummary: "Role Reviewer changes status from Submitted -> Rejected", + OperationID: "actionSubmissionReject", + Body: nil, + Params: middleware.Parameters{ + { + Name: "SubmissionID", + In: "path", + }: params.SubmissionID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ActionSubmissionRejectParams + Response = *ActionSubmissionRejectOK + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackActionSubmissionRejectParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + err = s.h.ActionSubmissionReject(ctx, params) + return response, err + }, + ) + } else { + err = s.h.ActionSubmissionReject(ctx, params) + } + if err != nil { + if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { + if err := encodeErrorResponse(errRes, w, span); err != nil { + defer recordError("Internal", err) + } + return + } + if errors.Is(err, ht.ErrNotImplemented) { + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + defer recordError("Internal", err) + } + return + } + + if err := encodeActionSubmissionRejectResponse(response, w, span); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleActionSubmissionRequestChangesRequest handles actionSubmissionRequestChanges operation. +// +// Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested. +// +// PATCH /submissions/{SubmissionID}/status/request-changes +func (s *Server) handleActionSubmissionRequestChangesRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionRequestChanges"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/request-changes"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "ActionSubmissionRequestChanges", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Add Labeler to context. + labeler := &Labeler{attrs: otelAttrs} + ctx = contextWithLabeler(ctx, labeler) + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + attrOpt := metric.WithAttributeSet(labeler.AttributeSet()) + + // Increment request counter. + s.requests.Add(ctx, 1, attrOpt) + + // Use floating point division here for higher precision (instead of Millisecond method). + s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt) + }() + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet())) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "ActionSubmissionRequestChanges", + ID: "actionSubmissionRequestChanges", + } + ) + params, err := decodeActionSubmissionRequestChangesParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response *ActionSubmissionRequestChangesOK + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "ActionSubmissionRequestChanges", + OperationSummary: "Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested", + OperationID: "actionSubmissionRequestChanges", + Body: nil, + Params: middleware.Parameters{ + { + Name: "SubmissionID", + In: "path", + }: params.SubmissionID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ActionSubmissionRequestChangesParams + Response = *ActionSubmissionRequestChangesOK + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackActionSubmissionRequestChangesParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + err = s.h.ActionSubmissionRequestChanges(ctx, params) + return response, err + }, + ) + } else { + err = s.h.ActionSubmissionRequestChanges(ctx, params) + } + if err != nil { + if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { + if err := encodeErrorResponse(errRes, w, span); err != nil { + defer recordError("Internal", err) + } + return + } + if errors.Is(err, ht.ErrNotImplemented) { + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + defer recordError("Internal", err) + } + return + } + + if err := encodeActionSubmissionRequestChangesResponse(response, w, span); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleActionSubmissionRevokeRequest handles actionSubmissionRevoke operation. +// +// Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction. +// +// PATCH /submissions/{SubmissionID}/status/revoke +func (s *Server) handleActionSubmissionRevokeRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionRevoke"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/revoke"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "ActionSubmissionRevoke", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Add Labeler to context. + labeler := &Labeler{attrs: otelAttrs} + ctx = contextWithLabeler(ctx, labeler) + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + attrOpt := metric.WithAttributeSet(labeler.AttributeSet()) + + // Increment request counter. + s.requests.Add(ctx, 1, attrOpt) + + // Use floating point division here for higher precision (instead of Millisecond method). + s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt) + }() + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet())) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "ActionSubmissionRevoke", + ID: "actionSubmissionRevoke", + } + ) + params, err := decodeActionSubmissionRevokeParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response *ActionSubmissionRevokeOK + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "ActionSubmissionRevoke", + OperationSummary: "Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction", + OperationID: "actionSubmissionRevoke", + Body: nil, + Params: middleware.Parameters{ + { + Name: "SubmissionID", + In: "path", + }: params.SubmissionID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ActionSubmissionRevokeParams + Response = *ActionSubmissionRevokeOK + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackActionSubmissionRevokeParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + err = s.h.ActionSubmissionRevoke(ctx, params) + return response, err + }, + ) + } else { + err = s.h.ActionSubmissionRevoke(ctx, params) + } + if err != nil { + if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { + if err := encodeErrorResponse(errRes, w, span); err != nil { + defer recordError("Internal", err) + } + return + } + if errors.Is(err, ht.ErrNotImplemented) { + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + defer recordError("Internal", err) + } + return + } + + if err := encodeActionSubmissionRevokeResponse(response, w, span); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleActionSubmissionSubmitRequest handles actionSubmissionSubmit operation. +// +// Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted. +// +// PATCH /submissions/{SubmissionID}/status/submit +func (s *Server) handleActionSubmissionSubmitRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionSubmit"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/submit"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "ActionSubmissionSubmit", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Add Labeler to context. + labeler := &Labeler{attrs: otelAttrs} + ctx = contextWithLabeler(ctx, labeler) + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + attrOpt := metric.WithAttributeSet(labeler.AttributeSet()) + + // Increment request counter. + s.requests.Add(ctx, 1, attrOpt) + + // Use floating point division here for higher precision (instead of Millisecond method). + s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt) + }() + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet())) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "ActionSubmissionSubmit", + ID: "actionSubmissionSubmit", + } + ) + params, err := decodeActionSubmissionSubmitParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response *ActionSubmissionSubmitOK + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "ActionSubmissionSubmit", + OperationSummary: "Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted", + OperationID: "actionSubmissionSubmit", + Body: nil, + Params: middleware.Parameters{ + { + Name: "SubmissionID", + In: "path", + }: params.SubmissionID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ActionSubmissionSubmitParams + Response = *ActionSubmissionSubmitOK + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackActionSubmissionSubmitParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + err = s.h.ActionSubmissionSubmit(ctx, params) + return response, err + }, + ) + } else { + err = s.h.ActionSubmissionSubmit(ctx, params) + } + if err != nil { + if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { + if err := encodeErrorResponse(errRes, w, span); err != nil { + defer recordError("Internal", err) + } + return + } + if errors.Is(err, ht.ErrNotImplemented) { + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + defer recordError("Internal", err) + } + return + } + + if err := encodeActionSubmissionSubmitResponse(response, w, span); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleActionSubmissionTriggerPublishRequest handles actionSubmissionTriggerPublish operation. +// +// Role Admin changes status from Validated -> Publishing. +// +// PATCH /submissions/{SubmissionID}/status/trigger-publish +func (s *Server) handleActionSubmissionTriggerPublishRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionTriggerPublish"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/trigger-publish"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "ActionSubmissionTriggerPublish", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Add Labeler to context. + labeler := &Labeler{attrs: otelAttrs} + ctx = contextWithLabeler(ctx, labeler) + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + attrOpt := metric.WithAttributeSet(labeler.AttributeSet()) + + // Increment request counter. + s.requests.Add(ctx, 1, attrOpt) + + // Use floating point division here for higher precision (instead of Millisecond method). + s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt) + }() + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet())) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "ActionSubmissionTriggerPublish", + ID: "actionSubmissionTriggerPublish", + } + ) + params, err := decodeActionSubmissionTriggerPublishParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response *ActionSubmissionTriggerPublishOK + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "ActionSubmissionTriggerPublish", + OperationSummary: "Role Admin changes status from Validated -> Publishing", + OperationID: "actionSubmissionTriggerPublish", + Body: nil, + Params: middleware.Parameters{ + { + Name: "SubmissionID", + In: "path", + }: params.SubmissionID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ActionSubmissionTriggerPublishParams + Response = *ActionSubmissionTriggerPublishOK + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackActionSubmissionTriggerPublishParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + err = s.h.ActionSubmissionTriggerPublish(ctx, params) + return response, err + }, + ) + } else { + err = s.h.ActionSubmissionTriggerPublish(ctx, params) + } + if err != nil { + if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { + if err := encodeErrorResponse(errRes, w, span); err != nil { + defer recordError("Internal", err) + } + return + } + if errors.Is(err, ht.ErrNotImplemented) { + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + defer recordError("Internal", err) + } + return + } + + if err := encodeActionSubmissionTriggerPublishResponse(response, w, span); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleActionSubmissionTriggerValidateRequest handles actionSubmissionTriggerValidate operation. +// +// Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating. +// +// PATCH /submissions/{SubmissionID}/status/trigger-validate +func (s *Server) handleActionSubmissionTriggerValidateRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionTriggerValidate"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/trigger-validate"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "ActionSubmissionTriggerValidate", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Add Labeler to context. + labeler := &Labeler{attrs: otelAttrs} + ctx = contextWithLabeler(ctx, labeler) + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + attrOpt := metric.WithAttributeSet(labeler.AttributeSet()) + + // Increment request counter. + s.requests.Add(ctx, 1, attrOpt) + + // Use floating point division here for higher precision (instead of Millisecond method). + s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt) + }() + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet())) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "ActionSubmissionTriggerValidate", + ID: "actionSubmissionTriggerValidate", + } + ) + params, err := decodeActionSubmissionTriggerValidateParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response *ActionSubmissionTriggerValidateOK + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "ActionSubmissionTriggerValidate", + OperationSummary: "Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating", + OperationID: "actionSubmissionTriggerValidate", + Body: nil, + Params: middleware.Parameters{ + { + Name: "SubmissionID", + In: "path", + }: params.SubmissionID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ActionSubmissionTriggerValidateParams + Response = *ActionSubmissionTriggerValidateOK + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackActionSubmissionTriggerValidateParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + err = s.h.ActionSubmissionTriggerValidate(ctx, params) + return response, err + }, + ) + } else { + err = s.h.ActionSubmissionTriggerValidate(ctx, params) + } + if err != nil { + if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { + if err := encodeErrorResponse(errRes, w, span); err != nil { + defer recordError("Internal", err) + } + return + } + if errors.Is(err, ht.ErrNotImplemented) { + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + defer recordError("Internal", err) + } + return + } + + if err := encodeActionSubmissionTriggerValidateResponse(response, w, span); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleActionSubmissionValidateRequest handles actionSubmissionValidate operation. +// +// Role Validator changes status from Validating -> Validated. +// +// PATCH /submissions/{SubmissionID}/status/validate +func (s *Server) handleActionSubmissionValidateRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("actionSubmissionValidate"), + semconv.HTTPRequestMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/validate"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "ActionSubmissionValidate", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Add Labeler to context. + labeler := &Labeler{attrs: otelAttrs} + ctx = contextWithLabeler(ctx, labeler) + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + attrOpt := metric.WithAttributeSet(labeler.AttributeSet()) + + // Increment request counter. + s.requests.Add(ctx, 1, attrOpt) + + // Use floating point division here for higher precision (instead of Millisecond method). + s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt) + }() + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet())) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "ActionSubmissionValidate", + ID: "actionSubmissionValidate", + } + ) + params, err := decodeActionSubmissionValidateParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response *ActionSubmissionValidateOK + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "ActionSubmissionValidate", + OperationSummary: "Role Validator changes status from Validating -> Validated", + OperationID: "actionSubmissionValidate", + Body: nil, + Params: middleware.Parameters{ + { + Name: "SubmissionID", + In: "path", + }: params.SubmissionID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ActionSubmissionValidateParams + Response = *ActionSubmissionValidateOK + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackActionSubmissionValidateParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + err = s.h.ActionSubmissionValidate(ctx, params) + return response, err + }, + ) + } else { + err = s.h.ActionSubmissionValidate(ctx, params) + } + if err != nil { + if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { + if err := encodeErrorResponse(errRes, w, span); err != nil { + defer recordError("Internal", err) + } + return + } + if errors.Is(err, ht.ErrNotImplemented) { + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + defer recordError("Internal", err) + } + return + } + + if err := encodeActionSubmissionValidateResponse(response, w, span); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + // handleCreateSubmissionRequest handles createSubmission operation. // // Create new submission. @@ -646,130 +1630,3 @@ func (s *Server) handlePatchSubmissionModelRequest(args [1]string, argsEscaped b return } } - -// handlePatchSubmissionStatusRequest handles patchSubmissionStatus operation. -// -// Update status following role restrictions. -// -// PATCH /submissions/{SubmissionID}/status -func (s *Server) handlePatchSubmissionStatusRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { - otelAttrs := []attribute.KeyValue{ - otelogen.OperationID("patchSubmissionStatus"), - semconv.HTTPRequestMethodKey.String("PATCH"), - semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status"), - } - - // Start a span for this request. - ctx, span := s.cfg.Tracer.Start(r.Context(), "PatchSubmissionStatus", - trace.WithAttributes(otelAttrs...), - serverSpanKind, - ) - defer span.End() - - // Add Labeler to context. - labeler := &Labeler{attrs: otelAttrs} - ctx = contextWithLabeler(ctx, labeler) - - // Run stopwatch. - startTime := time.Now() - defer func() { - elapsedDuration := time.Since(startTime) - attrOpt := metric.WithAttributeSet(labeler.AttributeSet()) - - // Increment request counter. - s.requests.Add(ctx, 1, attrOpt) - - // Use floating point division here for higher precision (instead of Millisecond method). - s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt) - }() - - var ( - recordError = func(stage string, err error) { - span.RecordError(err) - span.SetStatus(codes.Error, stage) - s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet())) - } - err error - opErrContext = ogenerrors.OperationContext{ - Name: "PatchSubmissionStatus", - ID: "patchSubmissionStatus", - } - ) - params, err := decodePatchSubmissionStatusParams(args, argsEscaped, r) - if err != nil { - err = &ogenerrors.DecodeParamsError{ - OperationContext: opErrContext, - Err: err, - } - defer recordError("DecodeParams", err) - s.cfg.ErrorHandler(ctx, w, r, err) - return - } - - var response *PatchSubmissionStatusOK - if m := s.cfg.Middleware; m != nil { - mreq := middleware.Request{ - Context: ctx, - OperationName: "PatchSubmissionStatus", - OperationSummary: "Update status following role restrictions", - OperationID: "patchSubmissionStatus", - Body: nil, - Params: middleware.Parameters{ - { - Name: "SubmissionID", - In: "path", - }: params.SubmissionID, - { - Name: "Status", - In: "query", - }: params.Status, - }, - Raw: r, - } - - type ( - Request = struct{} - Params = PatchSubmissionStatusParams - Response = *PatchSubmissionStatusOK - ) - response, err = middleware.HookMiddleware[ - Request, - Params, - Response, - ]( - m, - mreq, - unpackPatchSubmissionStatusParams, - func(ctx context.Context, request Request, params Params) (response Response, err error) { - err = s.h.PatchSubmissionStatus(ctx, params) - return response, err - }, - ) - } else { - err = s.h.PatchSubmissionStatus(ctx, params) - } - if err != nil { - if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - if err := encodeErrorResponse(errRes, w, span); err != nil { - defer recordError("Internal", err) - } - return - } - if errors.Is(err, ht.ErrNotImplemented) { - s.cfg.ErrorHandler(ctx, w, r, err) - return - } - if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { - defer recordError("Internal", err) - } - return - } - - if err := encodePatchSubmissionStatusResponse(response, w, span); err != nil { - defer recordError("EncodeResponse", err) - if !errors.Is(err, ht.ErrInternalServerErrorResponse) { - s.cfg.ErrorHandler(ctx, w, r, err) - } - return - } -} diff --git a/pkg/api/oas_parameters_gen.go b/pkg/api/oas_parameters_gen.go index aa105a0..ae4cf96 100644 --- a/pkg/api/oas_parameters_gen.go +++ b/pkg/api/oas_parameters_gen.go @@ -15,6 +15,526 @@ import ( "github.com/ogen-go/ogen/validate" ) +// ActionSubmissionPublishParams is parameters of actionSubmissionPublish operation. +type ActionSubmissionPublishParams struct { + SubmissionID int64 +} + +func unpackActionSubmissionPublishParams(packed middleware.Parameters) (params ActionSubmissionPublishParams) { + { + key := middleware.ParameterKey{ + Name: "SubmissionID", + In: "path", + } + params.SubmissionID = packed[key].(int64) + } + return params +} + +func decodeActionSubmissionPublishParams(args [1]string, argsEscaped bool, r *http.Request) (params ActionSubmissionPublishParams, _ error) { + // Decode path: SubmissionID. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "SubmissionID", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt64(val) + if err != nil { + return err + } + + params.SubmissionID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "SubmissionID", + In: "path", + Err: err, + } + } + return params, nil +} + +// ActionSubmissionRejectParams is parameters of actionSubmissionReject operation. +type ActionSubmissionRejectParams struct { + SubmissionID int64 +} + +func unpackActionSubmissionRejectParams(packed middleware.Parameters) (params ActionSubmissionRejectParams) { + { + key := middleware.ParameterKey{ + Name: "SubmissionID", + In: "path", + } + params.SubmissionID = packed[key].(int64) + } + return params +} + +func decodeActionSubmissionRejectParams(args [1]string, argsEscaped bool, r *http.Request) (params ActionSubmissionRejectParams, _ error) { + // Decode path: SubmissionID. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "SubmissionID", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt64(val) + if err != nil { + return err + } + + params.SubmissionID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "SubmissionID", + In: "path", + Err: err, + } + } + return params, nil +} + +// ActionSubmissionRequestChangesParams is parameters of actionSubmissionRequestChanges operation. +type ActionSubmissionRequestChangesParams struct { + SubmissionID int64 +} + +func unpackActionSubmissionRequestChangesParams(packed middleware.Parameters) (params ActionSubmissionRequestChangesParams) { + { + key := middleware.ParameterKey{ + Name: "SubmissionID", + In: "path", + } + params.SubmissionID = packed[key].(int64) + } + return params +} + +func decodeActionSubmissionRequestChangesParams(args [1]string, argsEscaped bool, r *http.Request) (params ActionSubmissionRequestChangesParams, _ error) { + // Decode path: SubmissionID. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "SubmissionID", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt64(val) + if err != nil { + return err + } + + params.SubmissionID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "SubmissionID", + In: "path", + Err: err, + } + } + return params, nil +} + +// ActionSubmissionRevokeParams is parameters of actionSubmissionRevoke operation. +type ActionSubmissionRevokeParams struct { + SubmissionID int64 +} + +func unpackActionSubmissionRevokeParams(packed middleware.Parameters) (params ActionSubmissionRevokeParams) { + { + key := middleware.ParameterKey{ + Name: "SubmissionID", + In: "path", + } + params.SubmissionID = packed[key].(int64) + } + return params +} + +func decodeActionSubmissionRevokeParams(args [1]string, argsEscaped bool, r *http.Request) (params ActionSubmissionRevokeParams, _ error) { + // Decode path: SubmissionID. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "SubmissionID", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt64(val) + if err != nil { + return err + } + + params.SubmissionID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "SubmissionID", + In: "path", + Err: err, + } + } + return params, nil +} + +// ActionSubmissionSubmitParams is parameters of actionSubmissionSubmit operation. +type ActionSubmissionSubmitParams struct { + SubmissionID int64 +} + +func unpackActionSubmissionSubmitParams(packed middleware.Parameters) (params ActionSubmissionSubmitParams) { + { + key := middleware.ParameterKey{ + Name: "SubmissionID", + In: "path", + } + params.SubmissionID = packed[key].(int64) + } + return params +} + +func decodeActionSubmissionSubmitParams(args [1]string, argsEscaped bool, r *http.Request) (params ActionSubmissionSubmitParams, _ error) { + // Decode path: SubmissionID. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "SubmissionID", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt64(val) + if err != nil { + return err + } + + params.SubmissionID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "SubmissionID", + In: "path", + Err: err, + } + } + return params, nil +} + +// ActionSubmissionTriggerPublishParams is parameters of actionSubmissionTriggerPublish operation. +type ActionSubmissionTriggerPublishParams struct { + SubmissionID int64 +} + +func unpackActionSubmissionTriggerPublishParams(packed middleware.Parameters) (params ActionSubmissionTriggerPublishParams) { + { + key := middleware.ParameterKey{ + Name: "SubmissionID", + In: "path", + } + params.SubmissionID = packed[key].(int64) + } + return params +} + +func decodeActionSubmissionTriggerPublishParams(args [1]string, argsEscaped bool, r *http.Request) (params ActionSubmissionTriggerPublishParams, _ error) { + // Decode path: SubmissionID. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "SubmissionID", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt64(val) + if err != nil { + return err + } + + params.SubmissionID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "SubmissionID", + In: "path", + Err: err, + } + } + return params, nil +} + +// ActionSubmissionTriggerValidateParams is parameters of actionSubmissionTriggerValidate operation. +type ActionSubmissionTriggerValidateParams struct { + SubmissionID int64 +} + +func unpackActionSubmissionTriggerValidateParams(packed middleware.Parameters) (params ActionSubmissionTriggerValidateParams) { + { + key := middleware.ParameterKey{ + Name: "SubmissionID", + In: "path", + } + params.SubmissionID = packed[key].(int64) + } + return params +} + +func decodeActionSubmissionTriggerValidateParams(args [1]string, argsEscaped bool, r *http.Request) (params ActionSubmissionTriggerValidateParams, _ error) { + // Decode path: SubmissionID. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "SubmissionID", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt64(val) + if err != nil { + return err + } + + params.SubmissionID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "SubmissionID", + In: "path", + Err: err, + } + } + return params, nil +} + +// ActionSubmissionValidateParams is parameters of actionSubmissionValidate operation. +type ActionSubmissionValidateParams struct { + SubmissionID int64 +} + +func unpackActionSubmissionValidateParams(packed middleware.Parameters) (params ActionSubmissionValidateParams) { + { + key := middleware.ParameterKey{ + Name: "SubmissionID", + In: "path", + } + params.SubmissionID = packed[key].(int64) + } + return params +} + +func decodeActionSubmissionValidateParams(args [1]string, argsEscaped bool, r *http.Request) (params ActionSubmissionValidateParams, _ error) { + // Decode path: SubmissionID. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "SubmissionID", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt64(val) + if err != nil { + return err + } + + params.SubmissionID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "SubmissionID", + In: "path", + Err: err, + } + } + return params, nil +} + // GetSubmissionParams is parameters of getSubmission operation. type GetSubmissionParams struct { SubmissionID int64 @@ -394,113 +914,3 @@ func decodePatchSubmissionModelParams(args [1]string, argsEscaped bool, r *http. } return params, nil } - -// PatchSubmissionStatusParams is parameters of patchSubmissionStatus operation. -type PatchSubmissionStatusParams struct { - SubmissionID int64 - Status int32 -} - -func unpackPatchSubmissionStatusParams(packed middleware.Parameters) (params PatchSubmissionStatusParams) { - { - key := middleware.ParameterKey{ - Name: "SubmissionID", - In: "path", - } - params.SubmissionID = packed[key].(int64) - } - { - key := middleware.ParameterKey{ - Name: "Status", - In: "query", - } - params.Status = packed[key].(int32) - } - return params -} - -func decodePatchSubmissionStatusParams(args [1]string, argsEscaped bool, r *http.Request) (params PatchSubmissionStatusParams, _ error) { - q := uri.NewQueryDecoder(r.URL.Query()) - // Decode path: SubmissionID. - if err := func() error { - param := args[0] - if argsEscaped { - unescaped, err := url.PathUnescape(args[0]) - if err != nil { - return errors.Wrap(err, "unescape path") - } - param = unescaped - } - if len(param) > 0 { - d := uri.NewPathDecoder(uri.PathDecoderConfig{ - Param: "SubmissionID", - Value: param, - Style: uri.PathStyleSimple, - Explode: false, - }) - - if err := func() error { - val, err := d.DecodeValue() - if err != nil { - return err - } - - c, err := conv.ToInt64(val) - if err != nil { - return err - } - - params.SubmissionID = c - return nil - }(); err != nil { - return err - } - } else { - return validate.ErrFieldRequired - } - return nil - }(); err != nil { - return params, &ogenerrors.DecodeParamError{ - Name: "SubmissionID", - In: "path", - Err: err, - } - } - // Decode query: Status. - if err := func() error { - cfg := uri.QueryParameterDecodingConfig{ - Name: "Status", - Style: uri.QueryStyleForm, - Explode: true, - } - - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - val, err := d.DecodeValue() - if err != nil { - return err - } - - c, err := conv.ToInt32(val) - if err != nil { - return err - } - - params.Status = c - return nil - }); err != nil { - return err - } - } else { - return validate.ErrFieldRequired - } - return nil - }(); err != nil { - return params, &ogenerrors.DecodeParamError{ - Name: "Status", - In: "query", - Err: err, - } - } - return params, nil -} diff --git a/pkg/api/oas_response_decoders_gen.go b/pkg/api/oas_response_decoders_gen.go index 02ca7ea..8f4dea2 100644 --- a/pkg/api/oas_response_decoders_gen.go +++ b/pkg/api/oas_response_decoders_gen.go @@ -14,6 +14,414 @@ import ( "github.com/ogen-go/ogen/validate" ) +func decodeActionSubmissionPublishResponse(resp *http.Response) (res *ActionSubmissionPublishOK, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + return &ActionSubmissionPublishOK{}, nil + } + // Convenient error response. + defRes, err := func() (res *ErrorStatusCode, err error) { + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response Error + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &ErrorStatusCode{ + StatusCode: resp.StatusCode, + Response: response, + }, nil + default: + return res, validate.InvalidContentType(ct) + } + }() + if err != nil { + return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) + } + return res, errors.Wrap(defRes, "error") +} + +func decodeActionSubmissionRejectResponse(resp *http.Response) (res *ActionSubmissionRejectOK, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + return &ActionSubmissionRejectOK{}, nil + } + // Convenient error response. + defRes, err := func() (res *ErrorStatusCode, err error) { + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response Error + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &ErrorStatusCode{ + StatusCode: resp.StatusCode, + Response: response, + }, nil + default: + return res, validate.InvalidContentType(ct) + } + }() + if err != nil { + return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) + } + return res, errors.Wrap(defRes, "error") +} + +func decodeActionSubmissionRequestChangesResponse(resp *http.Response) (res *ActionSubmissionRequestChangesOK, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + return &ActionSubmissionRequestChangesOK{}, nil + } + // Convenient error response. + defRes, err := func() (res *ErrorStatusCode, err error) { + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response Error + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &ErrorStatusCode{ + StatusCode: resp.StatusCode, + Response: response, + }, nil + default: + return res, validate.InvalidContentType(ct) + } + }() + if err != nil { + return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) + } + return res, errors.Wrap(defRes, "error") +} + +func decodeActionSubmissionRevokeResponse(resp *http.Response) (res *ActionSubmissionRevokeOK, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + return &ActionSubmissionRevokeOK{}, nil + } + // Convenient error response. + defRes, err := func() (res *ErrorStatusCode, err error) { + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response Error + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &ErrorStatusCode{ + StatusCode: resp.StatusCode, + Response: response, + }, nil + default: + return res, validate.InvalidContentType(ct) + } + }() + if err != nil { + return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) + } + return res, errors.Wrap(defRes, "error") +} + +func decodeActionSubmissionSubmitResponse(resp *http.Response) (res *ActionSubmissionSubmitOK, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + return &ActionSubmissionSubmitOK{}, nil + } + // Convenient error response. + defRes, err := func() (res *ErrorStatusCode, err error) { + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response Error + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &ErrorStatusCode{ + StatusCode: resp.StatusCode, + Response: response, + }, nil + default: + return res, validate.InvalidContentType(ct) + } + }() + if err != nil { + return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) + } + return res, errors.Wrap(defRes, "error") +} + +func decodeActionSubmissionTriggerPublishResponse(resp *http.Response) (res *ActionSubmissionTriggerPublishOK, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + return &ActionSubmissionTriggerPublishOK{}, nil + } + // Convenient error response. + defRes, err := func() (res *ErrorStatusCode, err error) { + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response Error + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &ErrorStatusCode{ + StatusCode: resp.StatusCode, + Response: response, + }, nil + default: + return res, validate.InvalidContentType(ct) + } + }() + if err != nil { + return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) + } + return res, errors.Wrap(defRes, "error") +} + +func decodeActionSubmissionTriggerValidateResponse(resp *http.Response) (res *ActionSubmissionTriggerValidateOK, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + return &ActionSubmissionTriggerValidateOK{}, nil + } + // Convenient error response. + defRes, err := func() (res *ErrorStatusCode, err error) { + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response Error + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &ErrorStatusCode{ + StatusCode: resp.StatusCode, + Response: response, + }, nil + default: + return res, validate.InvalidContentType(ct) + } + }() + if err != nil { + return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) + } + return res, errors.Wrap(defRes, "error") +} + +func decodeActionSubmissionValidateResponse(resp *http.Response) (res *ActionSubmissionValidateOK, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + return &ActionSubmissionValidateOK{}, nil + } + // Convenient error response. + defRes, err := func() (res *ErrorStatusCode, err error) { + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response Error + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &ErrorStatusCode{ + StatusCode: resp.StatusCode, + Response: response, + }, nil + default: + return res, validate.InvalidContentType(ct) + } + }() + if err != nil { + return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) + } + return res, errors.Wrap(defRes, "error") +} + func decodeCreateSubmissionResponse(resp *http.Response) (res *ID, _ error) { switch resp.StatusCode { case 200: @@ -381,54 +789,3 @@ func decodePatchSubmissionModelResponse(resp *http.Response) (res *PatchSubmissi } return res, errors.Wrap(defRes, "error") } - -func decodePatchSubmissionStatusResponse(resp *http.Response) (res *PatchSubmissionStatusOK, _ error) { - switch resp.StatusCode { - case 200: - // Code 200. - return &PatchSubmissionStatusOK{}, nil - } - // Convenient error response. - defRes, err := func() (res *ErrorStatusCode, err error) { - ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) - if err != nil { - return res, errors.Wrap(err, "parse media type") - } - switch { - case ct == "application/json": - buf, err := io.ReadAll(resp.Body) - if err != nil { - return res, err - } - d := jx.DecodeBytes(buf) - - var response Error - if err := func() error { - if err := response.Decode(d); err != nil { - return err - } - if err := d.Skip(); err != io.EOF { - return errors.New("unexpected trailing data") - } - return nil - }(); err != nil { - err = &ogenerrors.DecodeBodyError{ - ContentType: ct, - Body: buf, - Err: err, - } - return res, err - } - return &ErrorStatusCode{ - StatusCode: resp.StatusCode, - Response: response, - }, nil - default: - return res, validate.InvalidContentType(ct) - } - }() - if err != nil { - return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) - } - return res, errors.Wrap(defRes, "error") -} diff --git a/pkg/api/oas_response_encoders_gen.go b/pkg/api/oas_response_encoders_gen.go index e938130..6e265a5 100644 --- a/pkg/api/oas_response_encoders_gen.go +++ b/pkg/api/oas_response_encoders_gen.go @@ -13,6 +13,62 @@ import ( ht "github.com/ogen-go/ogen/http" ) +func encodeActionSubmissionPublishResponse(response *ActionSubmissionPublishOK, w http.ResponseWriter, span trace.Span) error { + w.WriteHeader(200) + span.SetStatus(codes.Ok, http.StatusText(200)) + + return nil +} + +func encodeActionSubmissionRejectResponse(response *ActionSubmissionRejectOK, w http.ResponseWriter, span trace.Span) error { + w.WriteHeader(200) + span.SetStatus(codes.Ok, http.StatusText(200)) + + return nil +} + +func encodeActionSubmissionRequestChangesResponse(response *ActionSubmissionRequestChangesOK, w http.ResponseWriter, span trace.Span) error { + w.WriteHeader(200) + span.SetStatus(codes.Ok, http.StatusText(200)) + + return nil +} + +func encodeActionSubmissionRevokeResponse(response *ActionSubmissionRevokeOK, w http.ResponseWriter, span trace.Span) error { + w.WriteHeader(200) + span.SetStatus(codes.Ok, http.StatusText(200)) + + return nil +} + +func encodeActionSubmissionSubmitResponse(response *ActionSubmissionSubmitOK, w http.ResponseWriter, span trace.Span) error { + w.WriteHeader(200) + span.SetStatus(codes.Ok, http.StatusText(200)) + + return nil +} + +func encodeActionSubmissionTriggerPublishResponse(response *ActionSubmissionTriggerPublishOK, w http.ResponseWriter, span trace.Span) error { + w.WriteHeader(200) + span.SetStatus(codes.Ok, http.StatusText(200)) + + return nil +} + +func encodeActionSubmissionTriggerValidateResponse(response *ActionSubmissionTriggerValidateOK, w http.ResponseWriter, span trace.Span) error { + w.WriteHeader(200) + span.SetStatus(codes.Ok, http.StatusText(200)) + + return nil +} + +func encodeActionSubmissionValidateResponse(response *ActionSubmissionValidateOK, w http.ResponseWriter, span trace.Span) error { + w.WriteHeader(200) + span.SetStatus(codes.Ok, http.StatusText(200)) + + return nil +} + func encodeCreateSubmissionResponse(response *ID, w http.ResponseWriter, span trace.Span) error { w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) @@ -73,13 +129,6 @@ func encodePatchSubmissionModelResponse(response *PatchSubmissionModelOK, w http return nil } -func encodePatchSubmissionStatusResponse(response *PatchSubmissionStatusOK, w http.ResponseWriter, span trace.Span) error { - w.WriteHeader(200) - span.SetStatus(codes.Ok, http.StatusText(200)) - - return nil -} - func encodeErrorResponse(response *ErrorStatusCode, w http.ResponseWriter, span trace.Span) error { w.Header().Set("Content-Type", "application/json; charset=utf-8") code := response.StatusCode diff --git a/pkg/api/oas_router_gen.go b/pkg/api/oas_router_gen.go index 7317574..c45af2b 100644 --- a/pkg/api/oas_router_gen.go +++ b/pkg/api/oas_router_gen.go @@ -158,26 +158,232 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } elem = origElem - case 's': // Prefix: "status" + case 's': // Prefix: "status/" origElem := elem - if l := len("status"); len(elem) >= l && elem[0:l] == "status" { + if l := len("status/"); len(elem) >= l && elem[0:l] == "status/" { elem = elem[l:] } else { break } if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "PATCH": - s.handlePatchSubmissionStatusRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "PATCH") + break + } + switch elem[0] { + case 'p': // Prefix: "publish" + origElem := elem + if l := len("publish"); len(elem) >= l && elem[0:l] == "publish" { + elem = elem[l:] + } else { + break } - return + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "PATCH": + s.handleActionSubmissionPublishRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "PATCH") + } + + return + } + + elem = origElem + case 'r': // Prefix: "re" + origElem := elem + if l := len("re"); len(elem) >= l && elem[0:l] == "re" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'j': // Prefix: "ject" + origElem := elem + if l := len("ject"); len(elem) >= l && elem[0:l] == "ject" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "PATCH": + s.handleActionSubmissionRejectRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "PATCH") + } + + return + } + + elem = origElem + case 'q': // Prefix: "quest-changes" + origElem := elem + if l := len("quest-changes"); len(elem) >= l && elem[0:l] == "quest-changes" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "PATCH": + s.handleActionSubmissionRequestChangesRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "PATCH") + } + + return + } + + elem = origElem + case 'v': // Prefix: "voke" + origElem := elem + if l := len("voke"); len(elem) >= l && elem[0:l] == "voke" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "PATCH": + s.handleActionSubmissionRevokeRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "PATCH") + } + + return + } + + elem = origElem + } + + elem = origElem + case 's': // Prefix: "submit" + origElem := elem + if l := len("submit"); len(elem) >= l && elem[0:l] == "submit" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "PATCH": + s.handleActionSubmissionSubmitRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "PATCH") + } + + return + } + + elem = origElem + case 't': // Prefix: "trigger-" + origElem := elem + if l := len("trigger-"); len(elem) >= l && elem[0:l] == "trigger-" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'p': // Prefix: "publish" + origElem := elem + if l := len("publish"); len(elem) >= l && elem[0:l] == "publish" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "PATCH": + s.handleActionSubmissionTriggerPublishRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "PATCH") + } + + return + } + + elem = origElem + case 'v': // Prefix: "validate" + origElem := elem + if l := len("validate"); len(elem) >= l && elem[0:l] == "validate" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "PATCH": + s.handleActionSubmissionTriggerValidateRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "PATCH") + } + + return + } + + elem = origElem + } + + elem = origElem + case 'v': // Prefix: "validate" + origElem := elem + if l := len("validate"); len(elem) >= l && elem[0:l] == "validate" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "PATCH": + s.handleActionSubmissionValidateRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "PATCH") + } + + return + } + + elem = origElem } elem = origElem @@ -395,28 +601,248 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { } elem = origElem - case 's': // Prefix: "status" + case 's': // Prefix: "status/" origElem := elem - if l := len("status"); len(elem) >= l && elem[0:l] == "status" { + if l := len("status/"); len(elem) >= l && elem[0:l] == "status/" { elem = elem[l:] } else { break } if len(elem) == 0 { - // Leaf node. - switch method { - case "PATCH": - r.name = "PatchSubmissionStatus" - r.summary = "Update status following role restrictions" - r.operationID = "patchSubmissionStatus" - r.pathPattern = "/submissions/{SubmissionID}/status" - r.args = args - r.count = 1 - return r, true - default: - return + break + } + switch elem[0] { + case 'p': // Prefix: "publish" + origElem := elem + if l := len("publish"); len(elem) >= l && elem[0:l] == "publish" { + elem = elem[l:] + } else { + break } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "PATCH": + r.name = "ActionSubmissionPublish" + r.summary = "Role Validator changes status from Publishing -> Published" + r.operationID = "actionSubmissionPublish" + r.pathPattern = "/submissions/{SubmissionID}/status/publish" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + case 'r': // Prefix: "re" + origElem := elem + if l := len("re"); len(elem) >= l && elem[0:l] == "re" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'j': // Prefix: "ject" + origElem := elem + if l := len("ject"); len(elem) >= l && elem[0:l] == "ject" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "PATCH": + r.name = "ActionSubmissionReject" + r.summary = "Role Reviewer changes status from Submitted -> Rejected" + r.operationID = "actionSubmissionReject" + r.pathPattern = "/submissions/{SubmissionID}/status/reject" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + case 'q': // Prefix: "quest-changes" + origElem := elem + if l := len("quest-changes"); len(elem) >= l && elem[0:l] == "quest-changes" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "PATCH": + r.name = "ActionSubmissionRequestChanges" + r.summary = "Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested" + r.operationID = "actionSubmissionRequestChanges" + r.pathPattern = "/submissions/{SubmissionID}/status/request-changes" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + case 'v': // Prefix: "voke" + origElem := elem + if l := len("voke"); len(elem) >= l && elem[0:l] == "voke" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "PATCH": + r.name = "ActionSubmissionRevoke" + r.summary = "Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction" + r.operationID = "actionSubmissionRevoke" + r.pathPattern = "/submissions/{SubmissionID}/status/revoke" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + } + + elem = origElem + case 's': // Prefix: "submit" + origElem := elem + if l := len("submit"); len(elem) >= l && elem[0:l] == "submit" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "PATCH": + r.name = "ActionSubmissionSubmit" + r.summary = "Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted" + r.operationID = "actionSubmissionSubmit" + r.pathPattern = "/submissions/{SubmissionID}/status/submit" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + case 't': // Prefix: "trigger-" + origElem := elem + if l := len("trigger-"); len(elem) >= l && elem[0:l] == "trigger-" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'p': // Prefix: "publish" + origElem := elem + if l := len("publish"); len(elem) >= l && elem[0:l] == "publish" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "PATCH": + r.name = "ActionSubmissionTriggerPublish" + r.summary = "Role Admin changes status from Validated -> Publishing" + r.operationID = "actionSubmissionTriggerPublish" + r.pathPattern = "/submissions/{SubmissionID}/status/trigger-publish" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + case 'v': // Prefix: "validate" + origElem := elem + if l := len("validate"); len(elem) >= l && elem[0:l] == "validate" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "PATCH": + r.name = "ActionSubmissionTriggerValidate" + r.summary = "Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating" + r.operationID = "actionSubmissionTriggerValidate" + r.pathPattern = "/submissions/{SubmissionID}/status/trigger-validate" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + } + + elem = origElem + case 'v': // Prefix: "validate" + origElem := elem + if l := len("validate"); len(elem) >= l && elem[0:l] == "validate" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "PATCH": + r.name = "ActionSubmissionValidate" + r.summary = "Role Validator changes status from Validating -> Validated" + r.operationID = "actionSubmissionValidate" + r.pathPattern = "/submissions/{SubmissionID}/status/validate" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem } elem = origElem diff --git a/pkg/api/oas_schemas_gen.go b/pkg/api/oas_schemas_gen.go index c3ba10d..b7b8265 100644 --- a/pkg/api/oas_schemas_gen.go +++ b/pkg/api/oas_schemas_gen.go @@ -10,6 +10,30 @@ func (s *ErrorStatusCode) Error() string { return fmt.Sprintf("code %d: %+v", s.StatusCode, s.Response) } +// ActionSubmissionPublishOK is response for ActionSubmissionPublish operation. +type ActionSubmissionPublishOK struct{} + +// ActionSubmissionRejectOK is response for ActionSubmissionReject operation. +type ActionSubmissionRejectOK struct{} + +// ActionSubmissionRequestChangesOK is response for ActionSubmissionRequestChanges operation. +type ActionSubmissionRequestChangesOK struct{} + +// ActionSubmissionRevokeOK is response for ActionSubmissionRevoke operation. +type ActionSubmissionRevokeOK struct{} + +// ActionSubmissionSubmitOK is response for ActionSubmissionSubmit operation. +type ActionSubmissionSubmitOK struct{} + +// ActionSubmissionTriggerPublishOK is response for ActionSubmissionTriggerPublish operation. +type ActionSubmissionTriggerPublishOK struct{} + +// ActionSubmissionTriggerValidateOK is response for ActionSubmissionTriggerValidate operation. +type ActionSubmissionTriggerValidateOK struct{} + +// ActionSubmissionValidateOK is response for ActionSubmissionValidate operation. +type ActionSubmissionValidateOK struct{} + // Represents error object. // Ref: #/components/schemas/Error type Error struct { @@ -386,9 +410,6 @@ type PatchSubmissionCompletedOK struct{} // PatchSubmissionModelOK is response for PatchSubmissionModel operation. type PatchSubmissionModelOK struct{} -// PatchSubmissionStatusOK is response for PatchSubmissionStatus operation. -type PatchSubmissionStatusOK struct{} - // Ref: #/components/schemas/Submission type Submission struct { ID OptInt64 `json:"ID"` diff --git a/pkg/api/oas_server_gen.go b/pkg/api/oas_server_gen.go index 63dbd03..0e0b450 100644 --- a/pkg/api/oas_server_gen.go +++ b/pkg/api/oas_server_gen.go @@ -8,6 +8,54 @@ import ( // Handler handles operations described by OpenAPI v3 specification. type Handler interface { + // ActionSubmissionPublish implements actionSubmissionPublish operation. + // + // Role Validator changes status from Publishing -> Published. + // + // PATCH /submissions/{SubmissionID}/status/publish + ActionSubmissionPublish(ctx context.Context, params ActionSubmissionPublishParams) error + // ActionSubmissionReject implements actionSubmissionReject operation. + // + // Role Reviewer changes status from Submitted -> Rejected. + // + // PATCH /submissions/{SubmissionID}/status/reject + ActionSubmissionReject(ctx context.Context, params ActionSubmissionRejectParams) error + // ActionSubmissionRequestChanges implements actionSubmissionRequestChanges operation. + // + // Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested. + // + // PATCH /submissions/{SubmissionID}/status/request-changes + ActionSubmissionRequestChanges(ctx context.Context, params ActionSubmissionRequestChangesParams) error + // ActionSubmissionRevoke implements actionSubmissionRevoke operation. + // + // Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction. + // + // PATCH /submissions/{SubmissionID}/status/revoke + ActionSubmissionRevoke(ctx context.Context, params ActionSubmissionRevokeParams) error + // ActionSubmissionSubmit implements actionSubmissionSubmit operation. + // + // Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted. + // + // PATCH /submissions/{SubmissionID}/status/submit + ActionSubmissionSubmit(ctx context.Context, params ActionSubmissionSubmitParams) error + // ActionSubmissionTriggerPublish implements actionSubmissionTriggerPublish operation. + // + // Role Admin changes status from Validated -> Publishing. + // + // PATCH /submissions/{SubmissionID}/status/trigger-publish + ActionSubmissionTriggerPublish(ctx context.Context, params ActionSubmissionTriggerPublishParams) error + // ActionSubmissionTriggerValidate implements actionSubmissionTriggerValidate operation. + // + // Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating. + // + // PATCH /submissions/{SubmissionID}/status/trigger-validate + ActionSubmissionTriggerValidate(ctx context.Context, params ActionSubmissionTriggerValidateParams) error + // ActionSubmissionValidate implements actionSubmissionValidate operation. + // + // Role Validator changes status from Validating -> Validated. + // + // PATCH /submissions/{SubmissionID}/status/validate + ActionSubmissionValidate(ctx context.Context, params ActionSubmissionValidateParams) error // CreateSubmission implements createSubmission operation. // // Create new submission. @@ -38,12 +86,6 @@ type Handler interface { // // PATCH /submissions/{SubmissionID}/model PatchSubmissionModel(ctx context.Context, params PatchSubmissionModelParams) error - // PatchSubmissionStatus implements patchSubmissionStatus operation. - // - // Update status following role restrictions. - // - // PATCH /submissions/{SubmissionID}/status - PatchSubmissionStatus(ctx context.Context, params PatchSubmissionStatusParams) error // NewError creates *ErrorStatusCode from error returned by handler. // // Used for common default response. diff --git a/pkg/api/oas_unimplemented_gen.go b/pkg/api/oas_unimplemented_gen.go index bd7d9b9..ee67f65 100644 --- a/pkg/api/oas_unimplemented_gen.go +++ b/pkg/api/oas_unimplemented_gen.go @@ -13,6 +13,78 @@ type UnimplementedHandler struct{} var _ Handler = UnimplementedHandler{} +// ActionSubmissionPublish implements actionSubmissionPublish operation. +// +// Role Validator changes status from Publishing -> Published. +// +// PATCH /submissions/{SubmissionID}/status/publish +func (UnimplementedHandler) ActionSubmissionPublish(ctx context.Context, params ActionSubmissionPublishParams) error { + return ht.ErrNotImplemented +} + +// ActionSubmissionReject implements actionSubmissionReject operation. +// +// Role Reviewer changes status from Submitted -> Rejected. +// +// PATCH /submissions/{SubmissionID}/status/reject +func (UnimplementedHandler) ActionSubmissionReject(ctx context.Context, params ActionSubmissionRejectParams) error { + return ht.ErrNotImplemented +} + +// ActionSubmissionRequestChanges implements actionSubmissionRequestChanges operation. +// +// Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested. +// +// PATCH /submissions/{SubmissionID}/status/request-changes +func (UnimplementedHandler) ActionSubmissionRequestChanges(ctx context.Context, params ActionSubmissionRequestChangesParams) error { + return ht.ErrNotImplemented +} + +// ActionSubmissionRevoke implements actionSubmissionRevoke operation. +// +// Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction. +// +// PATCH /submissions/{SubmissionID}/status/revoke +func (UnimplementedHandler) ActionSubmissionRevoke(ctx context.Context, params ActionSubmissionRevokeParams) error { + return ht.ErrNotImplemented +} + +// ActionSubmissionSubmit implements actionSubmissionSubmit operation. +// +// Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted. +// +// PATCH /submissions/{SubmissionID}/status/submit +func (UnimplementedHandler) ActionSubmissionSubmit(ctx context.Context, params ActionSubmissionSubmitParams) error { + return ht.ErrNotImplemented +} + +// ActionSubmissionTriggerPublish implements actionSubmissionTriggerPublish operation. +// +// Role Admin changes status from Validated -> Publishing. +// +// PATCH /submissions/{SubmissionID}/status/trigger-publish +func (UnimplementedHandler) ActionSubmissionTriggerPublish(ctx context.Context, params ActionSubmissionTriggerPublishParams) error { + return ht.ErrNotImplemented +} + +// ActionSubmissionTriggerValidate implements actionSubmissionTriggerValidate operation. +// +// Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating. +// +// PATCH /submissions/{SubmissionID}/status/trigger-validate +func (UnimplementedHandler) ActionSubmissionTriggerValidate(ctx context.Context, params ActionSubmissionTriggerValidateParams) error { + return ht.ErrNotImplemented +} + +// ActionSubmissionValidate implements actionSubmissionValidate operation. +// +// Role Validator changes status from Validating -> Validated. +// +// PATCH /submissions/{SubmissionID}/status/validate +func (UnimplementedHandler) ActionSubmissionValidate(ctx context.Context, params ActionSubmissionValidateParams) error { + return ht.ErrNotImplemented +} + // CreateSubmission implements createSubmission operation. // // Create new submission. @@ -58,15 +130,6 @@ func (UnimplementedHandler) PatchSubmissionModel(ctx context.Context, params Pat return ht.ErrNotImplemented } -// PatchSubmissionStatus implements patchSubmissionStatus operation. -// -// Update status following role restrictions. -// -// PATCH /submissions/{SubmissionID}/status -func (UnimplementedHandler) PatchSubmissionStatus(ctx context.Context, params PatchSubmissionStatusParams) error { - return ht.ErrNotImplemented -} - // NewError creates *ErrorStatusCode from error returned by handler. // // Used for common default response. diff --git a/pkg/service/submissions.go b/pkg/service/submissions.go index 42cd8af..b5ee685 100644 --- a/pkg/service/submissions.go +++ b/pkg/service/submissions.go @@ -130,14 +130,67 @@ func (svc *Service) PatchSubmissionModel(ctx context.Context, params api.PatchSu return err } -// PatchSubmissionStatus implements patchSubmissionStatus operation. +// ActionSubmissionPublish invokes actionSubmissionPublish operation. // -// Update status following role restrictions. +// Role Validator changes status from Publishing -> Published. // -// PATCH /submissions/{SubmissionID}/status -func (svc *Service) PatchSubmissionStatus(ctx context.Context, params api.PatchSubmissionStatusParams) error { - pmap := datastore.Optional() - pmap.AddNotNil("status", params.Status) - err := svc.DB.Submissions().Update(ctx, params.SubmissionID, pmap) - return err +// PATCH /submissions/{SubmissionID}/status/publish +func (svc *Service) ActionSubmissionPublish(ctx context.Context, params api.ActionSubmissionPublishParams) error { + return nil +} +// ActionSubmissionReject invokes actionSubmissionReject operation. +// +// Role Reviewer changes status from Submitted -> Rejected. +// +// PATCH /submissions/{SubmissionID}/status/reject +func (svc *Service) ActionSubmissionReject(ctx context.Context, params api.ActionSubmissionRejectParams) error { + return nil +} +// ActionSubmissionRequestChanges invokes actionSubmissionRequestChanges operation. +// +// Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested. +// +// PATCH /submissions/{SubmissionID}/status/request-changes +func (svc *Service) ActionSubmissionRequestChanges(ctx context.Context, params api.ActionSubmissionRequestChangesParams) error { + return nil +} +// ActionSubmissionRevoke invokes actionSubmissionRevoke operation. +// +// Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction. +// +// PATCH /submissions/{SubmissionID}/status/revoke +func (svc *Service) ActionSubmissionRevoke(ctx context.Context, params api.ActionSubmissionRevokeParams) error { + return nil +} +// ActionSubmissionSubmit invokes actionSubmissionSubmit operation. +// +// Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted. +// +// PATCH /submissions/{SubmissionID}/status/submit +func (svc *Service) ActionSubmissionSubmit(ctx context.Context, params api.ActionSubmissionSubmitParams) error { + return nil +} +// ActionSubmissionTriggerPublish invokes actionSubmissionTriggerPublish operation. +// +// Role Admin changes status from Validated -> Publishing. +// +// PATCH /submissions/{SubmissionID}/status/trigger-publish +func (svc *Service) ActionSubmissionTriggerPublish(ctx context.Context, params api.ActionSubmissionTriggerPublishParams) error { + return nil +} +// ActionSubmissionTriggerValidate invokes actionSubmissionTriggerValidate operation. +// +// Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating. +// +// PATCH /submissions/{SubmissionID}/status/trigger-validate +func (svc *Service) ActionSubmissionTriggerValidate(ctx context.Context, params api.ActionSubmissionTriggerValidateParams) error { + return nil +} +// ActionSubmissionValidate invokes actionSubmissionValidate operation. +// +// Role Validator changes status from Validating -> Validated. +// +// PATCH /submissions/{SubmissionID}/status/validate +func (svc *Service) ActionSubmissionValidate(ctx context.Context, params api.ActionSubmissionValidateParams) error { + return nil }