run generate

This commit is contained in:
Quaternions 2024-11-26 12:39:10 -08:00
parent 4c31cf7c19
commit 781ee07a4a
12 changed files with 1615 additions and 2307 deletions

View File

@ -12,7 +12,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/metric"
semconv "go.opentelemetry.io/otel/semconv/v1.19.0"
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
"go.opentelemetry.io/otel/trace"
"github.com/ogen-go/ogen/conv"
@ -23,30 +23,42 @@ import (
// Invoker invokes operations described by OpenAPI v3 specification.
type Invoker interface {
// GetUser invokes getUser operation.
// CreateSubmission invokes createSubmission operation.
//
// Retrieve user with ID.
// Create new submission.
//
// GET /users/{UserID}
GetUser(ctx context.Context, params GetUserParams) (*User, error)
// GetUserRank invokes getUserRank operation.
// POST /submissions
CreateSubmission(ctx context.Context) (*Submission, error)
// GetSubmission invokes getSubmission operation.
//
// Retrieve rank of user.
// Retrieve map with ID.
//
// GET /users/{UserID}/rank
GetUserRank(ctx context.Context, params GetUserRankParams) (*Rank, error)
// ListRanks invokes listRanks operation.
// GET /submissions/{SubmissionID}
GetSubmission(ctx context.Context, params GetSubmissionParams) (*Submission, error)
// ListSubmissions invokes listSubmissions operation.
//
// Get list of ranks.
// Get list of submissions.
//
// GET /ranks
ListRanks(ctx context.Context, params ListRanksParams) ([]Rank, error)
// ListTimes invokes listTimes operation.
// GET /submissions
ListSubmissions(ctx context.Context, params ListSubmissionsParams) ([]Submission, error)
// PatchSubmissionCompleted invokes patchSubmissionCompleted operation.
//
// Get list of times.
// Retrieve map with ID.
//
// GET /times
ListTimes(ctx context.Context, params ListTimesParams) ([]Time, error)
// PATCH /submissions/{SubmissionID}/completed
PatchSubmissionCompleted(ctx context.Context, params PatchSubmissionCompletedParams) error
// PatchSubmissionModel invokes patchSubmissionModel operation.
//
// Update model following role restrictions.
//
// 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.
@ -101,21 +113,21 @@ func (c *Client) requestURL(ctx context.Context) *url.URL {
return u
}
// GetUser invokes getUser operation.
// CreateSubmission invokes createSubmission operation.
//
// Retrieve user with ID.
// Create new submission.
//
// GET /users/{UserID}
func (c *Client) GetUser(ctx context.Context, params GetUserParams) (*User, error) {
res, err := c.sendGetUser(ctx, params)
// POST /submissions
func (c *Client) CreateSubmission(ctx context.Context) (*Submission, error) {
res, err := c.sendCreateSubmission(ctx)
return res, err
}
func (c *Client) sendGetUser(ctx context.Context, params GetUserParams) (res *User, err error) {
func (c *Client) sendCreateSubmission(ctx context.Context) (res *Submission, err error) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("getUser"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/users/{UserID}"),
otelogen.OperationID("createSubmission"),
semconv.HTTPRequestMethodKey.String("POST"),
semconv.HTTPRouteKey.String("/submissions"),
}
// Run stopwatch.
@ -130,7 +142,79 @@ func (c *Client) sendGetUser(ctx context.Context, params GetUserParams) (res *Us
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
// Start a span for this request.
ctx, span := c.cfg.Tracer.Start(ctx, "GetUser",
ctx, span := c.cfg.Tracer.Start(ctx, "CreateSubmission",
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 [1]string
pathParts[0] = "/submissions"
uri.AddPathParts(u, pathParts[:]...)
stage = "EncodeRequest"
r, err := ht.NewRequest(ctx, "POST", 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 := decodeCreateSubmissionResponse(resp)
if err != nil {
return res, errors.Wrap(err, "decode response")
}
return result, nil
}
// GetSubmission invokes getSubmission operation.
//
// Retrieve map with ID.
//
// GET /submissions/{SubmissionID}
func (c *Client) GetSubmission(ctx context.Context, params GetSubmissionParams) (*Submission, error) {
res, err := c.sendGetSubmission(ctx, params)
return res, err
}
func (c *Client) sendGetSubmission(ctx context.Context, params GetSubmissionParams) (res *Submission, err error) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("getSubmission"),
semconv.HTTPRequestMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}"),
}
// 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, "GetSubmission",
trace.WithAttributes(otelAttrs...),
clientSpanKind,
)
@ -148,16 +232,16 @@ func (c *Client) sendGetUser(ctx context.Context, params GetUserParams) (res *Us
stage = "BuildURL"
u := uri.Clone(c.requestURL(ctx))
var pathParts [2]string
pathParts[0] = "/users/"
pathParts[0] = "/submissions/"
{
// Encode "UserID" parameter.
// Encode "SubmissionID" parameter.
e := uri.NewPathEncoder(uri.PathEncoderConfig{
Param: "UserID",
Param: "SubmissionID",
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
return e.EncodeValue(conv.Int64ToString(params.UserID))
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
}(); err != nil {
return res, errors.Wrap(err, "encode path")
}
@ -183,7 +267,7 @@ func (c *Client) sendGetUser(ctx context.Context, params GetUserParams) (res *Us
defer resp.Body.Close()
stage = "DecodeResponse"
result, err := decodeGetUserResponse(resp)
result, err := decodeGetSubmissionResponse(resp)
if err != nil {
return res, errors.Wrap(err, "decode response")
}
@ -191,21 +275,21 @@ func (c *Client) sendGetUser(ctx context.Context, params GetUserParams) (res *Us
return result, nil
}
// GetUserRank invokes getUserRank operation.
// ListSubmissions invokes listSubmissions operation.
//
// Retrieve rank of user.
// Get list of submissions.
//
// GET /users/{UserID}/rank
func (c *Client) GetUserRank(ctx context.Context, params GetUserRankParams) (*Rank, error) {
res, err := c.sendGetUserRank(ctx, params)
// GET /submissions
func (c *Client) ListSubmissions(ctx context.Context, params ListSubmissionsParams) ([]Submission, error) {
res, err := c.sendListSubmissions(ctx, params)
return res, err
}
func (c *Client) sendGetUserRank(ctx context.Context, params GetUserRankParams) (res *Rank, err error) {
func (c *Client) sendListSubmissions(ctx context.Context, params ListSubmissionsParams) (res []Submission, err error) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("getUserRank"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/users/{UserID}/rank"),
otelogen.OperationID("listSubmissions"),
semconv.HTTPRequestMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/submissions"),
}
// Run stopwatch.
@ -220,7 +304,114 @@ func (c *Client) sendGetUserRank(ctx context.Context, params GetUserRankParams)
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
// Start a span for this request.
ctx, span := c.cfg.Tracer.Start(ctx, "GetUserRank",
ctx, span := c.cfg.Tracer.Start(ctx, "ListSubmissions",
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 [1]string
pathParts[0] = "/submissions"
uri.AddPathParts(u, pathParts[:]...)
stage = "EncodeQueryParams"
q := uri.NewQueryEncoder()
{
// Encode "page" parameter.
cfg := uri.QueryParameterEncodingConfig{
Name: "page",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
return params.Page.EncodeURI(e)
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
}
{
// Encode "filter" parameter.
cfg := uri.QueryParameterEncodingConfig{
Name: "filter",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
if val, ok := params.Filter.Get(); ok {
return val.EncodeURI(e)
}
return nil
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
}
u.RawQuery = q.Values().Encode()
stage = "EncodeRequest"
r, err := ht.NewRequest(ctx, "GET", 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 := decodeListSubmissionsResponse(resp)
if err != nil {
return res, errors.Wrap(err, "decode response")
}
return result, nil
}
// PatchSubmissionCompleted invokes patchSubmissionCompleted operation.
//
// Retrieve map with ID.
//
// PATCH /submissions/{SubmissionID}/completed
func (c *Client) PatchSubmissionCompleted(ctx context.Context, params PatchSubmissionCompletedParams) error {
_, err := c.sendPatchSubmissionCompleted(ctx, params)
return err
}
func (c *Client) sendPatchSubmissionCompleted(ctx context.Context, params PatchSubmissionCompletedParams) (res *PatchSubmissionCompletedOK, err error) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("patchSubmissionCompleted"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/completed"),
}
// 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, "PatchSubmissionCompleted",
trace.WithAttributes(otelAttrs...),
clientSpanKind,
)
@ -238,16 +429,16 @@ func (c *Client) sendGetUserRank(ctx context.Context, params GetUserRankParams)
stage = "BuildURL"
u := uri.Clone(c.requestURL(ctx))
var pathParts [3]string
pathParts[0] = "/users/"
pathParts[0] = "/submissions/"
{
// Encode "UserID" parameter.
// Encode "SubmissionID" parameter.
e := uri.NewPathEncoder(uri.PathEncoderConfig{
Param: "UserID",
Param: "SubmissionID",
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
return e.EncodeValue(conv.Int64ToString(params.UserID))
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
}(); err != nil {
return res, errors.Wrap(err, "encode path")
}
@ -257,49 +448,21 @@ func (c *Client) sendGetUserRank(ctx context.Context, params GetUserRankParams)
}
pathParts[1] = encoded
}
pathParts[2] = "/rank"
pathParts[2] = "/completed"
uri.AddPathParts(u, pathParts[:]...)
stage = "EncodeQueryParams"
q := uri.NewQueryEncoder()
{
// Encode "StyleID" parameter.
// Encode "Completed" parameter.
cfg := uri.QueryParameterEncodingConfig{
Name: "StyleID",
Name: "Completed",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
return e.EncodeValue(conv.Int32ToString(params.StyleID))
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
}
{
// Encode "GameID" parameter.
cfg := uri.QueryParameterEncodingConfig{
Name: "GameID",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
return e.EncodeValue(conv.Int32ToString(params.GameID))
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
}
{
// Encode "ModeID" parameter.
cfg := uri.QueryParameterEncodingConfig{
Name: "ModeID",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
return e.EncodeValue(conv.Int32ToString(params.ModeID))
return e.EncodeValue(conv.BoolToString(params.Completed))
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
@ -307,7 +470,7 @@ func (c *Client) sendGetUserRank(ctx context.Context, params GetUserRankParams)
u.RawQuery = q.Values().Encode()
stage = "EncodeRequest"
r, err := ht.NewRequest(ctx, "GET", u)
r, err := ht.NewRequest(ctx, "PATCH", u)
if err != nil {
return res, errors.Wrap(err, "create request")
}
@ -320,7 +483,7 @@ func (c *Client) sendGetUserRank(ctx context.Context, params GetUserRankParams)
defer resp.Body.Close()
stage = "DecodeResponse"
result, err := decodeGetUserRankResponse(resp)
result, err := decodePatchSubmissionCompletedResponse(resp)
if err != nil {
return res, errors.Wrap(err, "decode response")
}
@ -328,21 +491,21 @@ func (c *Client) sendGetUserRank(ctx context.Context, params GetUserRankParams)
return result, nil
}
// ListRanks invokes listRanks operation.
// PatchSubmissionModel invokes patchSubmissionModel operation.
//
// Get list of ranks.
// Update model following role restrictions.
//
// GET /ranks
func (c *Client) ListRanks(ctx context.Context, params ListRanksParams) ([]Rank, error) {
res, err := c.sendListRanks(ctx, params)
return res, err
// PATCH /submissions/{SubmissionID}/model
func (c *Client) PatchSubmissionModel(ctx context.Context, params PatchSubmissionModelParams) error {
_, err := c.sendPatchSubmissionModel(ctx, params)
return err
}
func (c *Client) sendListRanks(ctx context.Context, params ListRanksParams) (res []Rank, err error) {
func (c *Client) sendPatchSubmissionModel(ctx context.Context, params PatchSubmissionModelParams) (res *PatchSubmissionModelOK, err error) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("listRanks"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/ranks"),
otelogen.OperationID("patchSubmissionModel"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/model"),
}
// Run stopwatch.
@ -357,7 +520,7 @@ func (c *Client) sendListRanks(ctx context.Context, params ListRanksParams) (res
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
// Start a span for this request.
ctx, span := c.cfg.Tracer.Start(ctx, "ListRanks",
ctx, span := c.cfg.Tracer.Start(ctx, "PatchSubmissionModel",
trace.WithAttributes(otelAttrs...),
clientSpanKind,
)
@ -374,39 +537,55 @@ func (c *Client) sendListRanks(ctx context.Context, params ListRanksParams) (res
stage = "BuildURL"
u := uri.Clone(c.requestURL(ctx))
var pathParts [1]string
pathParts[0] = "/ranks"
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] = "/model"
uri.AddPathParts(u, pathParts[:]...)
stage = "EncodeQueryParams"
q := uri.NewQueryEncoder()
{
// Encode "page" parameter.
// Encode "ModelID" parameter.
cfg := uri.QueryParameterEncodingConfig{
Name: "page",
Name: "ModelID",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
return params.Page.EncodeURI(e)
return e.EncodeValue(conv.Int64ToString(params.ModelID))
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
}
{
// Encode "filter" parameter.
// Encode "VersionID" parameter.
cfg := uri.QueryParameterEncodingConfig{
Name: "filter",
Name: "VersionID",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
if val, ok := params.Filter.Get(); ok {
return val.EncodeURI(e)
}
return nil
return e.EncodeValue(conv.Int64ToString(params.VersionID))
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
@ -414,7 +593,7 @@ func (c *Client) sendListRanks(ctx context.Context, params ListRanksParams) (res
u.RawQuery = q.Values().Encode()
stage = "EncodeRequest"
r, err := ht.NewRequest(ctx, "GET", u)
r, err := ht.NewRequest(ctx, "PATCH", u)
if err != nil {
return res, errors.Wrap(err, "create request")
}
@ -427,7 +606,7 @@ func (c *Client) sendListRanks(ctx context.Context, params ListRanksParams) (res
defer resp.Body.Close()
stage = "DecodeResponse"
result, err := decodeListRanksResponse(resp)
result, err := decodePatchSubmissionModelResponse(resp)
if err != nil {
return res, errors.Wrap(err, "decode response")
}
@ -435,21 +614,21 @@ func (c *Client) sendListRanks(ctx context.Context, params ListRanksParams) (res
return result, nil
}
// ListTimes invokes listTimes operation.
// PatchSubmissionStatus invokes patchSubmissionStatus operation.
//
// Get list of times.
// Update status following role restrictions.
//
// GET /times
func (c *Client) ListTimes(ctx context.Context, params ListTimesParams) ([]Time, error) {
res, err := c.sendListTimes(ctx, params)
return res, err
// PATCH /submissions/{SubmissionID}/status
func (c *Client) PatchSubmissionStatus(ctx context.Context, params PatchSubmissionStatusParams) error {
_, err := c.sendPatchSubmissionStatus(ctx, params)
return err
}
func (c *Client) sendListTimes(ctx context.Context, params ListTimesParams) (res []Time, err error) {
func (c *Client) sendPatchSubmissionStatus(ctx context.Context, params PatchSubmissionStatusParams) (res *PatchSubmissionStatusOK, err error) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("listTimes"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/times"),
otelogen.OperationID("patchSubmissionStatus"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status"),
}
// Run stopwatch.
@ -464,7 +643,7 @@ func (c *Client) sendListTimes(ctx context.Context, params ListTimesParams) (res
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
// Start a span for this request.
ctx, span := c.cfg.Tracer.Start(ctx, "ListTimes",
ctx, span := c.cfg.Tracer.Start(ctx, "PatchSubmissionStatus",
trace.WithAttributes(otelAttrs...),
clientSpanKind,
)
@ -481,39 +660,41 @@ func (c *Client) sendListTimes(ctx context.Context, params ListTimesParams) (res
stage = "BuildURL"
u := uri.Clone(c.requestURL(ctx))
var pathParts [1]string
pathParts[0] = "/times"
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 "page" parameter.
// Encode "Status" parameter.
cfg := uri.QueryParameterEncodingConfig{
Name: "page",
Name: "Status",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
return params.Page.EncodeURI(e)
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
}
{
// Encode "filter" parameter.
cfg := uri.QueryParameterEncodingConfig{
Name: "filter",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
if val, ok := params.Filter.Get(); ok {
return val.EncodeURI(e)
}
return nil
return e.EncodeValue(conv.Int32ToString(params.Status))
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
@ -521,7 +702,7 @@ func (c *Client) sendListTimes(ctx context.Context, params ListTimesParams) (res
u.RawQuery = q.Values().Encode()
stage = "EncodeRequest"
r, err := ht.NewRequest(ctx, "GET", u)
r, err := ht.NewRequest(ctx, "PATCH", u)
if err != nil {
return res, errors.Wrap(err, "create request")
}
@ -534,7 +715,7 @@ func (c *Client) sendListTimes(ctx context.Context, params ListTimesParams) (res
defer resp.Body.Close()
stage = "DecodeResponse"
result, err := decodeListTimesResponse(resp)
result, err := decodePatchSubmissionStatusResponse(resp)
if err != nil {
return res, errors.Wrap(err, "decode response")
}

View File

@ -11,7 +11,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/metric"
semconv "go.opentelemetry.io/otel/semconv/v1.19.0"
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
"go.opentelemetry.io/otel/trace"
ht "github.com/ogen-go/ogen/http"
@ -20,20 +20,20 @@ import (
"github.com/ogen-go/ogen/otelogen"
)
// handleGetUserRequest handles getUser operation.
// handleCreateSubmissionRequest handles createSubmission operation.
//
// Retrieve user with ID.
// Create new submission.
//
// GET /users/{UserID}
func (s *Server) handleGetUserRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
// POST /submissions
func (s *Server) handleCreateSubmissionRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("getUser"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/users/{UserID}"),
otelogen.OperationID("createSubmission"),
semconv.HTTPRequestMethodKey.String("POST"),
semconv.HTTPRouteKey.String("/submissions"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "GetUser",
ctx, span := s.cfg.Tracer.Start(r.Context(), "CreateSubmission",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
@ -63,43 +63,24 @@ func (s *Server) handleGetUserRequest(args [1]string, argsEscaped bool, w http.R
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "GetUser",
ID: "getUser",
}
)
params, err := decodeGetUserParams(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 *User
var response *Submission
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "GetUser",
OperationSummary: "Retrieve user with ID",
OperationID: "getUser",
OperationName: "CreateSubmission",
OperationSummary: "Create new submission",
OperationID: "createSubmission",
Body: nil,
Params: middleware.Parameters{
{
Name: "UserID",
In: "path",
}: params.UserID,
},
Params: middleware.Parameters{},
Raw: r,
}
type (
Request = struct{}
Params = GetUserParams
Response = *User
Params = struct{}
Response = *Submission
)
response, err = middleware.HookMiddleware[
Request,
@ -108,14 +89,14 @@ func (s *Server) handleGetUserRequest(args [1]string, argsEscaped bool, w http.R
](
m,
mreq,
unpackGetUserParams,
nil,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.GetUser(ctx, params)
response, err = s.h.CreateSubmission(ctx)
return response, err
},
)
} else {
response, err = s.h.GetUser(ctx, params)
response, err = s.h.CreateSubmission(ctx)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
@ -134,7 +115,7 @@ func (s *Server) handleGetUserRequest(args [1]string, argsEscaped bool, w http.R
return
}
if err := encodeGetUserResponse(response, w, span); err != nil {
if err := encodeCreateSubmissionResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
@ -143,20 +124,20 @@ func (s *Server) handleGetUserRequest(args [1]string, argsEscaped bool, w http.R
}
}
// handleGetUserRankRequest handles getUserRank operation.
// handleGetSubmissionRequest handles getSubmission operation.
//
// Retrieve rank of user.
// Retrieve map with ID.
//
// GET /users/{UserID}/rank
func (s *Server) handleGetUserRankRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
// GET /submissions/{SubmissionID}
func (s *Server) handleGetSubmissionRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("getUserRank"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/users/{UserID}/rank"),
otelogen.OperationID("getSubmission"),
semconv.HTTPRequestMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "GetUserRank",
ctx, span := s.cfg.Tracer.Start(r.Context(), "GetSubmission",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
@ -187,11 +168,11 @@ func (s *Server) handleGetUserRankRequest(args [1]string, argsEscaped bool, w ht
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "GetUserRank",
ID: "getUserRank",
Name: "GetSubmission",
ID: "getSubmission",
}
)
params, err := decodeGetUserRankParams(args, argsEscaped, r)
params, err := decodeGetSubmissionParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
@ -202,39 +183,27 @@ func (s *Server) handleGetUserRankRequest(args [1]string, argsEscaped bool, w ht
return
}
var response *Rank
var response *Submission
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "GetUserRank",
OperationSummary: "Retrieve rank of user",
OperationID: "getUserRank",
OperationName: "GetSubmission",
OperationSummary: "Retrieve map with ID",
OperationID: "getSubmission",
Body: nil,
Params: middleware.Parameters{
{
Name: "UserID",
Name: "SubmissionID",
In: "path",
}: params.UserID,
{
Name: "StyleID",
In: "query",
}: params.StyleID,
{
Name: "GameID",
In: "query",
}: params.GameID,
{
Name: "ModeID",
In: "query",
}: params.ModeID,
}: params.SubmissionID,
},
Raw: r,
}
type (
Request = struct{}
Params = GetUserRankParams
Response = *Rank
Params = GetSubmissionParams
Response = *Submission
)
response, err = middleware.HookMiddleware[
Request,
@ -243,14 +212,14 @@ func (s *Server) handleGetUserRankRequest(args [1]string, argsEscaped bool, w ht
](
m,
mreq,
unpackGetUserRankParams,
unpackGetSubmissionParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.GetUserRank(ctx, params)
response, err = s.h.GetSubmission(ctx, params)
return response, err
},
)
} else {
response, err = s.h.GetUserRank(ctx, params)
response, err = s.h.GetSubmission(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
@ -269,7 +238,7 @@ func (s *Server) handleGetUserRankRequest(args [1]string, argsEscaped bool, w ht
return
}
if err := encodeGetUserRankResponse(response, w, span); err != nil {
if err := encodeGetSubmissionResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
@ -278,20 +247,20 @@ func (s *Server) handleGetUserRankRequest(args [1]string, argsEscaped bool, w ht
}
}
// handleListRanksRequest handles listRanks operation.
// handleListSubmissionsRequest handles listSubmissions operation.
//
// Get list of ranks.
// Get list of submissions.
//
// GET /ranks
func (s *Server) handleListRanksRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
// GET /submissions
func (s *Server) handleListSubmissionsRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("listRanks"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/ranks"),
otelogen.OperationID("listSubmissions"),
semconv.HTTPRequestMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/submissions"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListRanks",
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListSubmissions",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
@ -322,11 +291,11 @@ func (s *Server) handleListRanksRequest(args [0]string, argsEscaped bool, w http
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "ListRanks",
ID: "listRanks",
Name: "ListSubmissions",
ID: "listSubmissions",
}
)
params, err := decodeListRanksParams(args, argsEscaped, r)
params, err := decodeListSubmissionsParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
@ -337,13 +306,13 @@ func (s *Server) handleListRanksRequest(args [0]string, argsEscaped bool, w http
return
}
var response []Rank
var response []Submission
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ListRanks",
OperationSummary: "Get list of ranks",
OperationID: "listRanks",
OperationName: "ListSubmissions",
OperationSummary: "Get list of submissions",
OperationID: "listSubmissions",
Body: nil,
Params: middleware.Parameters{
{
@ -360,8 +329,8 @@ func (s *Server) handleListRanksRequest(args [0]string, argsEscaped bool, w http
type (
Request = struct{}
Params = ListRanksParams
Response = []Rank
Params = ListSubmissionsParams
Response = []Submission
)
response, err = middleware.HookMiddleware[
Request,
@ -370,14 +339,14 @@ func (s *Server) handleListRanksRequest(args [0]string, argsEscaped bool, w http
](
m,
mreq,
unpackListRanksParams,
unpackListSubmissionsParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ListRanks(ctx, params)
response, err = s.h.ListSubmissions(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ListRanks(ctx, params)
response, err = s.h.ListSubmissions(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
@ -396,7 +365,7 @@ func (s *Server) handleListRanksRequest(args [0]string, argsEscaped bool, w http
return
}
if err := encodeListRanksResponse(response, w, span); err != nil {
if err := encodeListSubmissionsResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
@ -405,20 +374,20 @@ func (s *Server) handleListRanksRequest(args [0]string, argsEscaped bool, w http
}
}
// handleListTimesRequest handles listTimes operation.
// handlePatchSubmissionCompletedRequest handles patchSubmissionCompleted operation.
//
// Get list of times.
// Retrieve map with ID.
//
// GET /times
func (s *Server) handleListTimesRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
// PATCH /submissions/{SubmissionID}/completed
func (s *Server) handlePatchSubmissionCompletedRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("listTimes"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/times"),
otelogen.OperationID("patchSubmissionCompleted"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/completed"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListTimes",
ctx, span := s.cfg.Tracer.Start(r.Context(), "PatchSubmissionCompleted",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
@ -449,11 +418,11 @@ func (s *Server) handleListTimesRequest(args [0]string, argsEscaped bool, w http
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "ListTimes",
ID: "listTimes",
Name: "PatchSubmissionCompleted",
ID: "patchSubmissionCompleted",
}
)
params, err := decodeListTimesParams(args, argsEscaped, r)
params, err := decodePatchSubmissionCompletedParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
@ -464,31 +433,31 @@ func (s *Server) handleListTimesRequest(args [0]string, argsEscaped bool, w http
return
}
var response []Time
var response *PatchSubmissionCompletedOK
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ListTimes",
OperationSummary: "Get list of times",
OperationID: "listTimes",
OperationName: "PatchSubmissionCompleted",
OperationSummary: "Retrieve map with ID",
OperationID: "patchSubmissionCompleted",
Body: nil,
Params: middleware.Parameters{
{
Name: "page",
In: "query",
}: params.Page,
Name: "SubmissionID",
In: "path",
}: params.SubmissionID,
{
Name: "filter",
Name: "Completed",
In: "query",
}: params.Filter,
}: params.Completed,
},
Raw: r,
}
type (
Request = struct{}
Params = ListTimesParams
Response = []Time
Params = PatchSubmissionCompletedParams
Response = *PatchSubmissionCompletedOK
)
response, err = middleware.HookMiddleware[
Request,
@ -497,14 +466,14 @@ func (s *Server) handleListTimesRequest(args [0]string, argsEscaped bool, w http
](
m,
mreq,
unpackListTimesParams,
unpackPatchSubmissionCompletedParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ListTimes(ctx, params)
err = s.h.PatchSubmissionCompleted(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ListTimes(ctx, params)
err = s.h.PatchSubmissionCompleted(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
@ -523,7 +492,265 @@ func (s *Server) handleListTimesRequest(args [0]string, argsEscaped bool, w http
return
}
if err := encodeListTimesResponse(response, w, span); err != nil {
if err := encodePatchSubmissionCompletedResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
// handlePatchSubmissionModelRequest handles patchSubmissionModel operation.
//
// Update model following role restrictions.
//
// PATCH /submissions/{SubmissionID}/model
func (s *Server) handlePatchSubmissionModelRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("patchSubmissionModel"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/model"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "PatchSubmissionModel",
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: "PatchSubmissionModel",
ID: "patchSubmissionModel",
}
)
params, err := decodePatchSubmissionModelParams(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 *PatchSubmissionModelOK
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "PatchSubmissionModel",
OperationSummary: "Update model following role restrictions",
OperationID: "patchSubmissionModel",
Body: nil,
Params: middleware.Parameters{
{
Name: "SubmissionID",
In: "path",
}: params.SubmissionID,
{
Name: "ModelID",
In: "query",
}: params.ModelID,
{
Name: "VersionID",
In: "query",
}: params.VersionID,
},
Raw: r,
}
type (
Request = struct{}
Params = PatchSubmissionModelParams
Response = *PatchSubmissionModelOK
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackPatchSubmissionModelParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
err = s.h.PatchSubmissionModel(ctx, params)
return response, err
},
)
} else {
err = s.h.PatchSubmissionModel(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 := encodePatchSubmissionModelResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
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)

View File

@ -125,172 +125,6 @@ func (s *Error) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode implements json.Marshaler.
func (s *Map) Encode(e *jx.Encoder) {
e.ObjStart()
s.encodeFields(e)
e.ObjEnd()
}
// encodeFields encodes fields.
func (s *Map) encodeFields(e *jx.Encoder) {
{
if s.ID.Set {
e.FieldStart("ID")
s.ID.Encode(e)
}
}
{
if s.DisplayName.Set {
e.FieldStart("DisplayName")
s.DisplayName.Encode(e)
}
}
{
if s.Creator.Set {
e.FieldStart("Creator")
s.Creator.Encode(e)
}
}
{
if s.GameID.Set {
e.FieldStart("GameID")
s.GameID.Encode(e)
}
}
{
if s.Date.Set {
e.FieldStart("Date")
s.Date.Encode(e)
}
}
}
var jsonFieldsNameOfMap = [5]string{
0: "ID",
1: "DisplayName",
2: "Creator",
3: "GameID",
4: "Date",
}
// Decode decodes Map from json.
func (s *Map) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode Map to nil")
}
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
switch string(k) {
case "ID":
if err := func() error {
s.ID.Reset()
if err := s.ID.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"ID\"")
}
case "DisplayName":
if err := func() error {
s.DisplayName.Reset()
if err := s.DisplayName.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"DisplayName\"")
}
case "Creator":
if err := func() error {
s.Creator.Reset()
if err := s.Creator.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"Creator\"")
}
case "GameID":
if err := func() error {
s.GameID.Reset()
if err := s.GameID.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"GameID\"")
}
case "Date":
if err := func() error {
s.Date.Reset()
if err := s.Date.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"Date\"")
}
default:
return d.Skip()
}
return nil
}); err != nil {
return errors.Wrap(err, "decode Map")
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *Map) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *Map) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes float64 as json.
func (o OptFloat64) Encode(e *jx.Encoder) {
if !o.Set {
return
}
e.Float64(float64(o.Value))
}
// Decode decodes float64 from json.
func (o *OptFloat64) Decode(d *jx.Decoder) error {
if o == nil {
return errors.New("invalid: unable to decode OptFloat64 to nil")
}
o.Set = true
v, err := d.Float64()
if err != nil {
return err
}
o.Value = float64(v)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s OptFloat64) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *OptFloat64) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes int32 as json.
func (o OptInt32) Encode(e *jx.Encoder) {
if !o.Set {
@ -361,39 +195,6 @@ func (s *OptInt64) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode encodes Map as json.
func (o OptMap) Encode(e *jx.Encoder) {
if !o.Set {
return
}
o.Value.Encode(e)
}
// Decode decodes Map from json.
func (o *OptMap) Decode(d *jx.Decoder) error {
if o == nil {
return errors.New("invalid: unable to decode OptMap to nil")
}
o.Set = true
if err := o.Value.Decode(d); err != nil {
return err
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s OptMap) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *OptMap) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes string as json.
func (o OptString) Encode(e *jx.Encoder) {
if !o.Set {
@ -429,48 +230,15 @@ func (s *OptString) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode encodes User as json.
func (o OptUser) Encode(e *jx.Encoder) {
if !o.Set {
return
}
o.Value.Encode(e)
}
// Decode decodes User from json.
func (o *OptUser) Decode(d *jx.Decoder) error {
if o == nil {
return errors.New("invalid: unable to decode OptUser to nil")
}
o.Set = true
if err := o.Value.Decode(d); err != nil {
return err
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s OptUser) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *OptUser) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode implements json.Marshaler.
func (s *Rank) Encode(e *jx.Encoder) {
func (s *Submission) Encode(e *jx.Encoder) {
e.ObjStart()
s.encodeFields(e)
e.ObjEnd()
}
// encodeFields encodes fields.
func (s *Rank) encodeFields(e *jx.Encoder) {
func (s *Submission) encodeFields(e *jx.Encoder) {
{
if s.ID.Set {
e.FieldStart("ID")
@ -478,21 +246,15 @@ func (s *Rank) encodeFields(e *jx.Encoder) {
}
}
{
if s.User.Set {
e.FieldStart("User")
s.User.Encode(e)
if s.DisplayName.Set {
e.FieldStart("DisplayName")
s.DisplayName.Encode(e)
}
}
{
if s.StyleID.Set {
e.FieldStart("StyleID")
s.StyleID.Encode(e)
}
}
{
if s.ModeID.Set {
e.FieldStart("ModeID")
s.ModeID.Encode(e)
if s.Creator.Set {
e.FieldStart("Creator")
s.Creator.Encode(e)
}
}
{
@ -502,40 +264,25 @@ func (s *Rank) encodeFields(e *jx.Encoder) {
}
}
{
if s.Rank.Set {
e.FieldStart("Rank")
s.Rank.Encode(e)
}
}
{
if s.Skill.Set {
e.FieldStart("Skill")
s.Skill.Encode(e)
}
}
{
if s.UpdatedAt.Set {
e.FieldStart("UpdatedAt")
s.UpdatedAt.Encode(e)
if s.Date.Set {
e.FieldStart("Date")
s.Date.Encode(e)
}
}
}
var jsonFieldsNameOfRank = [8]string{
var jsonFieldsNameOfSubmission = [5]string{
0: "ID",
1: "User",
2: "StyleID",
3: "ModeID",
4: "GameID",
5: "Rank",
6: "Skill",
7: "UpdatedAt",
1: "DisplayName",
2: "Creator",
3: "GameID",
4: "Date",
}
// Decode decodes Rank from json.
func (s *Rank) Decode(d *jx.Decoder) error {
// Decode decodes Submission from json.
func (s *Submission) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode Rank to nil")
return errors.New("invalid: unable to decode Submission to nil")
}
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
@ -550,35 +297,25 @@ func (s *Rank) Decode(d *jx.Decoder) error {
}(); err != nil {
return errors.Wrap(err, "decode field \"ID\"")
}
case "User":
case "DisplayName":
if err := func() error {
s.User.Reset()
if err := s.User.Decode(d); err != nil {
s.DisplayName.Reset()
if err := s.DisplayName.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"User\"")
return errors.Wrap(err, "decode field \"DisplayName\"")
}
case "StyleID":
case "Creator":
if err := func() error {
s.StyleID.Reset()
if err := s.StyleID.Decode(d); err != nil {
s.Creator.Reset()
if err := s.Creator.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"StyleID\"")
}
case "ModeID":
if err := func() error {
s.ModeID.Reset()
if err := s.ModeID.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"ModeID\"")
return errors.Wrap(err, "decode field \"Creator\"")
}
case "GameID":
if err := func() error {
@ -590,178 +327,6 @@ func (s *Rank) Decode(d *jx.Decoder) error {
}(); err != nil {
return errors.Wrap(err, "decode field \"GameID\"")
}
case "Rank":
if err := func() error {
s.Rank.Reset()
if err := s.Rank.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"Rank\"")
}
case "Skill":
if err := func() error {
s.Skill.Reset()
if err := s.Skill.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"Skill\"")
}
case "UpdatedAt":
if err := func() error {
s.UpdatedAt.Reset()
if err := s.UpdatedAt.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"UpdatedAt\"")
}
default:
return d.Skip()
}
return nil
}); err != nil {
return errors.Wrap(err, "decode Rank")
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *Rank) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *Rank) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode implements json.Marshaler.
func (s *Time) Encode(e *jx.Encoder) {
e.ObjStart()
s.encodeFields(e)
e.ObjEnd()
}
// encodeFields encodes fields.
func (s *Time) encodeFields(e *jx.Encoder) {
{
if s.ID.Set {
e.FieldStart("ID")
s.ID.Encode(e)
}
}
{
if s.Time.Set {
e.FieldStart("Time")
s.Time.Encode(e)
}
}
{
if s.User.Set {
e.FieldStart("User")
s.User.Encode(e)
}
}
{
if s.Map.Set {
e.FieldStart("Map")
s.Map.Encode(e)
}
}
{
if s.Date.Set {
e.FieldStart("Date")
s.Date.Encode(e)
}
}
{
if s.StyleID.Set {
e.FieldStart("StyleID")
s.StyleID.Encode(e)
}
}
{
if s.ModeID.Set {
e.FieldStart("ModeID")
s.ModeID.Encode(e)
}
}
{
if s.GameID.Set {
e.FieldStart("GameID")
s.GameID.Encode(e)
}
}
}
var jsonFieldsNameOfTime = [8]string{
0: "ID",
1: "Time",
2: "User",
3: "Map",
4: "Date",
5: "StyleID",
6: "ModeID",
7: "GameID",
}
// Decode decodes Time from json.
func (s *Time) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode Time to nil")
}
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
switch string(k) {
case "ID":
if err := func() error {
s.ID.Reset()
if err := s.ID.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"ID\"")
}
case "Time":
if err := func() error {
s.Time.Reset()
if err := s.Time.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"Time\"")
}
case "User":
if err := func() error {
s.User.Reset()
if err := s.User.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"User\"")
}
case "Map":
if err := func() error {
s.Map.Reset()
if err := s.Map.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"Map\"")
}
case "Date":
if err := func() error {
s.Date.Reset()
@ -772,153 +337,26 @@ func (s *Time) Decode(d *jx.Decoder) error {
}(); err != nil {
return errors.Wrap(err, "decode field \"Date\"")
}
case "StyleID":
if err := func() error {
s.StyleID.Reset()
if err := s.StyleID.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"StyleID\"")
}
case "ModeID":
if err := func() error {
s.ModeID.Reset()
if err := s.ModeID.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"ModeID\"")
}
case "GameID":
if err := func() error {
s.GameID.Reset()
if err := s.GameID.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"GameID\"")
}
default:
return d.Skip()
}
return nil
}); err != nil {
return errors.Wrap(err, "decode Time")
return errors.Wrap(err, "decode Submission")
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *Time) MarshalJSON() ([]byte, error) {
func (s *Submission) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *Time) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode implements json.Marshaler.
func (s *User) Encode(e *jx.Encoder) {
e.ObjStart()
s.encodeFields(e)
e.ObjEnd()
}
// encodeFields encodes fields.
func (s *User) encodeFields(e *jx.Encoder) {
{
if s.ID.Set {
e.FieldStart("ID")
s.ID.Encode(e)
}
}
{
if s.Username.Set {
e.FieldStart("Username")
s.Username.Encode(e)
}
}
{
if s.StateID.Set {
e.FieldStart("StateID")
s.StateID.Encode(e)
}
}
}
var jsonFieldsNameOfUser = [3]string{
0: "ID",
1: "Username",
2: "StateID",
}
// Decode decodes User from json.
func (s *User) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode User to nil")
}
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
switch string(k) {
case "ID":
if err := func() error {
s.ID.Reset()
if err := s.ID.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"ID\"")
}
case "Username":
if err := func() error {
s.Username.Reset()
if err := s.Username.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"Username\"")
}
case "StateID":
if err := func() error {
s.StateID.Reset()
if err := s.StateID.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"StateID\"")
}
default:
return d.Skip()
}
return nil
}); err != nil {
return errors.Wrap(err, "decode User")
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *User) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *User) UnmarshalJSON(data []byte) error {
func (s *Submission) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}

View File

@ -15,24 +15,24 @@ import (
"github.com/ogen-go/ogen/validate"
)
// GetUserParams is parameters of getUser operation.
type GetUserParams struct {
UserID int64
// GetSubmissionParams is parameters of getSubmission operation.
type GetSubmissionParams struct {
SubmissionID int64
}
func unpackGetUserParams(packed middleware.Parameters) (params GetUserParams) {
func unpackGetSubmissionParams(packed middleware.Parameters) (params GetSubmissionParams) {
{
key := middleware.ParameterKey{
Name: "UserID",
Name: "SubmissionID",
In: "path",
}
params.UserID = packed[key].(int64)
params.SubmissionID = packed[key].(int64)
}
return params
}
func decodeGetUserParams(args [1]string, argsEscaped bool, r *http.Request) (params GetUserParams, _ error) {
// Decode path: UserID.
func decodeGetSubmissionParams(args [1]string, argsEscaped bool, r *http.Request) (params GetSubmissionParams, _ error) {
// Decode path: SubmissionID.
if err := func() error {
param := args[0]
if argsEscaped {
@ -44,7 +44,7 @@ func decodeGetUserParams(args [1]string, argsEscaped bool, r *http.Request) (par
}
if len(param) > 0 {
d := uri.NewPathDecoder(uri.PathDecoderConfig{
Param: "UserID",
Param: "SubmissionID",
Value: param,
Style: uri.PathStyleSimple,
Explode: false,
@ -61,7 +61,7 @@ func decodeGetUserParams(args [1]string, argsEscaped bool, r *http.Request) (par
return err
}
params.UserID = c
params.SubmissionID = c
return nil
}(); err != nil {
return err
@ -72,7 +72,7 @@ func decodeGetUserParams(args [1]string, argsEscaped bool, r *http.Request) (par
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "UserID",
Name: "SubmissionID",
In: "path",
Err: err,
}
@ -80,211 +80,13 @@ func decodeGetUserParams(args [1]string, argsEscaped bool, r *http.Request) (par
return params, nil
}
// GetUserRankParams is parameters of getUserRank operation.
type GetUserRankParams struct {
UserID int64
StyleID int32
GameID int32
ModeID int32
}
func unpackGetUserRankParams(packed middleware.Parameters) (params GetUserRankParams) {
{
key := middleware.ParameterKey{
Name: "UserID",
In: "path",
}
params.UserID = packed[key].(int64)
}
{
key := middleware.ParameterKey{
Name: "StyleID",
In: "query",
}
params.StyleID = packed[key].(int32)
}
{
key := middleware.ParameterKey{
Name: "GameID",
In: "query",
}
params.GameID = packed[key].(int32)
}
{
key := middleware.ParameterKey{
Name: "ModeID",
In: "query",
}
params.ModeID = packed[key].(int32)
}
return params
}
func decodeGetUserRankParams(args [1]string, argsEscaped bool, r *http.Request) (params GetUserRankParams, _ error) {
q := uri.NewQueryDecoder(r.URL.Query())
// Decode path: UserID.
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: "UserID",
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.UserID = c
return nil
}(); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "UserID",
In: "path",
Err: err,
}
}
// Decode query: StyleID.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "StyleID",
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.StyleID = c
return nil
}); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "StyleID",
In: "query",
Err: err,
}
}
// Decode query: GameID.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "GameID",
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.GameID = c
return nil
}); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "GameID",
In: "query",
Err: err,
}
}
// Decode query: ModeID.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "ModeID",
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.ModeID = c
return nil
}); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "ModeID",
In: "query",
Err: err,
}
}
return params, nil
}
// ListRanksParams is parameters of listRanks operation.
type ListRanksParams struct {
// ListSubmissionsParams is parameters of listSubmissions operation.
type ListSubmissionsParams struct {
Page Pagination
Filter OptRankFilter
Filter OptSubmissionFilter
}
func unpackListRanksParams(packed middleware.Parameters) (params ListRanksParams) {
func unpackListSubmissionsParams(packed middleware.Parameters) (params ListSubmissionsParams) {
{
key := middleware.ParameterKey{
Name: "page",
@ -298,13 +100,13 @@ func unpackListRanksParams(packed middleware.Parameters) (params ListRanksParams
In: "query",
}
if v, ok := packed[key]; ok {
params.Filter = v.(OptRankFilter)
params.Filter = v.(OptSubmissionFilter)
}
}
return params
}
func decodeListRanksParams(args [0]string, argsEscaped bool, r *http.Request) (params ListRanksParams, _ error) {
func decodeListSubmissionsParams(args [0]string, argsEscaped bool, r *http.Request) (params ListSubmissionsParams, _ error) {
q := uri.NewQueryDecoder(r.URL.Query())
// Decode query: page.
if err := func() error {
@ -346,12 +148,12 @@ func decodeListRanksParams(args [0]string, argsEscaped bool, r *http.Request) (p
Name: "filter",
Style: uri.QueryStyleForm,
Explode: true,
Fields: []uri.QueryParameterObjectField{{Name: "StyleID", Required: false}, {Name: "GameID", Required: false}, {Name: "ModeID", Required: false}, {Name: "Sort", Required: false}},
Fields: []uri.QueryParameterObjectField{{Name: "ID", Required: false}, {Name: "DisplayName", Required: false}, {Name: "Creator", Required: false}, {Name: "GameID", Required: false}, {Name: "Date", Required: false}},
}
if err := q.HasParam(cfg); err == nil {
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
var paramsDotFilterVal RankFilter
var paramsDotFilterVal SubmissionFilter
if err := func() error {
return paramsDotFilterVal.DecodeURI(d)
}(); err != nil {
@ -374,53 +176,62 @@ func decodeListRanksParams(args [0]string, argsEscaped bool, r *http.Request) (p
return params, nil
}
// ListTimesParams is parameters of listTimes operation.
type ListTimesParams struct {
Page Pagination
Filter OptTimeFilter
// PatchSubmissionCompletedParams is parameters of patchSubmissionCompleted operation.
type PatchSubmissionCompletedParams struct {
SubmissionID int64
Completed bool
}
func unpackListTimesParams(packed middleware.Parameters) (params ListTimesParams) {
func unpackPatchSubmissionCompletedParams(packed middleware.Parameters) (params PatchSubmissionCompletedParams) {
{
key := middleware.ParameterKey{
Name: "page",
In: "query",
Name: "SubmissionID",
In: "path",
}
params.Page = packed[key].(Pagination)
params.SubmissionID = packed[key].(int64)
}
{
key := middleware.ParameterKey{
Name: "filter",
Name: "Completed",
In: "query",
}
if v, ok := packed[key]; ok {
params.Filter = v.(OptTimeFilter)
}
params.Completed = packed[key].(bool)
}
return params
}
func decodeListTimesParams(args [0]string, argsEscaped bool, r *http.Request) (params ListTimesParams, _ error) {
func decodePatchSubmissionCompletedParams(args [1]string, argsEscaped bool, r *http.Request) (params PatchSubmissionCompletedParams, _ error) {
q := uri.NewQueryDecoder(r.URL.Query())
// Decode query: page.
// Decode path: SubmissionID.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "page",
Style: uri.QueryStyleForm,
Explode: true,
Fields: []uri.QueryParameterObjectField{{Name: "Page", Required: true}, {Name: "Limit", Required: true}},
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
}
if err := q.HasParam(cfg); err == nil {
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
return params.Page.DecodeURI(d)
}); err != nil {
return err
}
if err := func() error {
if err := params.Page.Validate(); err != nil {
c, err := conv.ToInt64(val)
if err != nil {
return err
}
params.SubmissionID = c
return nil
}(); err != nil {
return err
@ -431,38 +242,307 @@ func decodeListTimesParams(args [0]string, argsEscaped bool, r *http.Request) (p
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "page",
In: "query",
Name: "SubmissionID",
In: "path",
Err: err,
}
}
// Decode query: filter.
// Decode query: Completed.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "filter",
Name: "Completed",
Style: uri.QueryStyleForm,
Explode: true,
Fields: []uri.QueryParameterObjectField{{Name: "ID", Required: false}, {Name: "Time", Required: false}, {Name: "UserID", Required: false}, {Name: "MapID", Required: false}, {Name: "StyleID", Required: false}, {Name: "ModeID", Required: false}, {Name: "GameID", Required: false}},
}
if err := q.HasParam(cfg); err == nil {
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
var paramsDotFilterVal TimeFilter
if err := func() error {
return paramsDotFilterVal.DecodeURI(d)
}(); err != nil {
val, err := d.DecodeValue()
if err != nil {
return err
}
params.Filter.SetTo(paramsDotFilterVal)
c, err := conv.ToBool(val)
if err != nil {
return err
}
params.Completed = c
return nil
}); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "filter",
Name: "Completed",
In: "query",
Err: err,
}
}
return params, nil
}
// PatchSubmissionModelParams is parameters of patchSubmissionModel operation.
type PatchSubmissionModelParams struct {
SubmissionID int64
ModelID int64
VersionID int64
}
func unpackPatchSubmissionModelParams(packed middleware.Parameters) (params PatchSubmissionModelParams) {
{
key := middleware.ParameterKey{
Name: "SubmissionID",
In: "path",
}
params.SubmissionID = packed[key].(int64)
}
{
key := middleware.ParameterKey{
Name: "ModelID",
In: "query",
}
params.ModelID = packed[key].(int64)
}
{
key := middleware.ParameterKey{
Name: "VersionID",
In: "query",
}
params.VersionID = packed[key].(int64)
}
return params
}
func decodePatchSubmissionModelParams(args [1]string, argsEscaped bool, r *http.Request) (params PatchSubmissionModelParams, _ 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: ModelID.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "ModelID",
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.ToInt64(val)
if err != nil {
return err
}
params.ModelID = c
return nil
}); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "ModelID",
In: "query",
Err: err,
}
}
// Decode query: VersionID.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "VersionID",
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.ToInt64(val)
if err != nil {
return err
}
params.VersionID = c
return nil
}); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "VersionID",
In: "query",
Err: err,
}
}
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,
}

View File

@ -3,7 +3,6 @@
package api
import (
"fmt"
"io"
"mime"
"net/http"
@ -15,7 +14,7 @@ import (
"github.com/ogen-go/ogen/validate"
)
func decodeGetUserResponse(resp *http.Response) (res *User, _ error) {
func decodeCreateSubmissionResponse(resp *http.Response) (res *Submission, _ error) {
switch resp.StatusCode {
case 200:
// Code 200.
@ -31,7 +30,7 @@ func decodeGetUserResponse(resp *http.Response) (res *User, _ error) {
}
d := jx.DecodeBytes(buf)
var response User
var response Submission
if err := func() error {
if err := response.Decode(d); err != nil {
return err
@ -98,7 +97,7 @@ func decodeGetUserResponse(resp *http.Response) (res *User, _ error) {
return res, errors.Wrap(defRes, "error")
}
func decodeGetUserRankResponse(resp *http.Response) (res *Rank, _ error) {
func decodeGetSubmissionResponse(resp *http.Response) (res *Submission, _ error) {
switch resp.StatusCode {
case 200:
// Code 200.
@ -114,7 +113,7 @@ func decodeGetUserRankResponse(resp *http.Response) (res *Rank, _ error) {
}
d := jx.DecodeBytes(buf)
var response Rank
var response Submission
if err := func() error {
if err := response.Decode(d); err != nil {
return err
@ -131,15 +130,6 @@ func decodeGetUserRankResponse(resp *http.Response) (res *Rank, _ error) {
}
return res, err
}
// Validate response.
if err := func() error {
if err := response.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
return res, errors.Wrap(err, "validate")
}
return &response, nil
default:
return res, validate.InvalidContentType(ct)
@ -190,7 +180,7 @@ func decodeGetUserRankResponse(resp *http.Response) (res *Rank, _ error) {
return res, errors.Wrap(defRes, "error")
}
func decodeListRanksResponse(resp *http.Response) (res []Rank, _ error) {
func decodeListSubmissionsResponse(resp *http.Response) (res []Submission, _ error) {
switch resp.StatusCode {
case 200:
// Code 200.
@ -206,128 +196,11 @@ func decodeListRanksResponse(resp *http.Response) (res []Rank, _ error) {
}
d := jx.DecodeBytes(buf)
var response []Rank
var response []Submission
if err := func() error {
response = make([]Rank, 0)
response = make([]Submission, 0)
if err := d.Arr(func(d *jx.Decoder) error {
var elem Rank
if err := elem.Decode(d); err != nil {
return err
}
response = append(response, elem)
return nil
}); 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
}
// Validate response.
if err := func() error {
if response == nil {
return errors.New("nil is invalid value")
}
var failures []validate.FieldError
for i, elem := range response {
if err := func() error {
if err := elem.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: fmt.Sprintf("[%d]", i),
Error: err,
})
}
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}(); err != nil {
return res, errors.Wrap(err, "validate")
}
return response, nil
default:
return res, validate.InvalidContentType(ct)
}
}
// 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 decodeListTimesResponse(resp *http.Response) (res []Time, _ error) {
switch resp.StatusCode {
case 200:
// Code 200.
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 []Time
if err := func() error {
response = make([]Time, 0)
if err := d.Arr(func(d *jx.Decoder) error {
var elem Time
var elem Submission
if err := elem.Decode(d); err != nil {
return err
}
@ -406,3 +279,156 @@ func decodeListTimesResponse(resp *http.Response) (res []Time, _ error) {
}
return res, errors.Wrap(defRes, "error")
}
func decodePatchSubmissionCompletedResponse(resp *http.Response) (res *PatchSubmissionCompletedOK, _ error) {
switch resp.StatusCode {
case 200:
// Code 200.
return &PatchSubmissionCompletedOK{}, 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 decodePatchSubmissionModelResponse(resp *http.Response) (res *PatchSubmissionModelOK, _ error) {
switch resp.StatusCode {
case 200:
// Code 200.
return &PatchSubmissionModelOK{}, 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 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")
}

View File

@ -13,7 +13,7 @@ import (
ht "github.com/ogen-go/ogen/http"
)
func encodeGetUserResponse(response *User, w http.ResponseWriter, span trace.Span) error {
func encodeCreateSubmissionResponse(response *Submission, w http.ResponseWriter, span trace.Span) error {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
span.SetStatus(codes.Ok, http.StatusText(200))
@ -27,7 +27,7 @@ func encodeGetUserResponse(response *User, w http.ResponseWriter, span trace.Spa
return nil
}
func encodeGetUserRankResponse(response *Rank, w http.ResponseWriter, span trace.Span) error {
func encodeGetSubmissionResponse(response *Submission, w http.ResponseWriter, span trace.Span) error {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
span.SetStatus(codes.Ok, http.StatusText(200))
@ -41,7 +41,7 @@ func encodeGetUserRankResponse(response *Rank, w http.ResponseWriter, span trace
return nil
}
func encodeListRanksResponse(response []Rank, w http.ResponseWriter, span trace.Span) error {
func encodeListSubmissionsResponse(response []Submission, w http.ResponseWriter, span trace.Span) error {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
span.SetStatus(codes.Ok, http.StatusText(200))
@ -59,20 +59,23 @@ func encodeListRanksResponse(response []Rank, w http.ResponseWriter, span trace.
return nil
}
func encodeListTimesResponse(response []Time, w http.ResponseWriter, span trace.Span) error {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
func encodePatchSubmissionCompletedResponse(response *PatchSubmissionCompletedOK, w http.ResponseWriter, span trace.Span) error {
w.WriteHeader(200)
span.SetStatus(codes.Ok, http.StatusText(200))
e := new(jx.Encoder)
e.ArrStart()
for _, elem := range response {
elem.Encode(e)
}
e.ArrEnd()
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
}
func encodePatchSubmissionModelResponse(response *PatchSubmissionModelOK, w http.ResponseWriter, span trace.Span) error {
w.WriteHeader(200)
span.SetStatus(codes.Ok, http.StatusText(200))
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
}

View File

@ -49,6 +49,57 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
break
}
switch elem[0] {
case '/': // Prefix: "/submissions"
origElem := elem
if l := len("/submissions"); len(elem) >= l && elem[0:l] == "/submissions" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
switch r.Method {
case "GET":
s.handleListSubmissionsRequest([0]string{}, elemIsEscaped, w, r)
case "POST":
s.handleCreateSubmissionRequest([0]string{}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "GET,POST")
}
return
}
switch elem[0] {
case '/': // Prefix: "/"
origElem := elem
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
elem = elem[l:]
} else {
break
}
// Param: "SubmissionID"
// Match until "/"
idx := strings.IndexByte(elem, '/')
if idx < 0 {
idx = len(elem)
}
args[0] = elem[:idx]
elem = elem[idx:]
if len(elem) == 0 {
switch r.Method {
case "GET":
s.handleGetSubmissionRequest([1]string{
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "GET")
}
return
}
switch elem[0] {
case '/': // Prefix: "/"
origElem := elem
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
@ -61,9 +112,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
break
}
switch elem[0] {
case 'r': // Prefix: "ranks"
case 'c': // Prefix: "completed"
origElem := elem
if l := len("ranks"); len(elem) >= l && elem[0:l] == "ranks" {
if l := len("completed"); len(elem) >= l && elem[0:l] == "completed" {
elem = elem[l:]
} else {
break
@ -72,19 +123,21 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if len(elem) == 0 {
// Leaf node.
switch r.Method {
case "GET":
s.handleListRanksRequest([0]string{}, elemIsEscaped, w, r)
case "PATCH":
s.handlePatchSubmissionCompletedRequest([1]string{
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "GET")
s.notAllowed(w, r, "PATCH")
}
return
}
elem = origElem
case 't': // Prefix: "times"
case 'm': // Prefix: "model"
origElem := elem
if l := len("times"); len(elem) >= l && elem[0:l] == "times" {
if l := len("model"); len(elem) >= l && elem[0:l] == "model" {
elem = elem[l:]
} else {
break
@ -93,49 +146,21 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if len(elem) == 0 {
// Leaf node.
switch r.Method {
case "GET":
s.handleListTimesRequest([0]string{}, elemIsEscaped, w, r)
case "PATCH":
s.handlePatchSubmissionModelRequest([1]string{
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "GET")
s.notAllowed(w, r, "PATCH")
}
return
}
elem = origElem
case 'u': // Prefix: "users/"
case 's': // Prefix: "status"
origElem := elem
if l := len("users/"); len(elem) >= l && elem[0:l] == "users/" {
elem = elem[l:]
} else {
break
}
// Param: "UserID"
// Match until "/"
idx := strings.IndexByte(elem, '/')
if idx < 0 {
idx = len(elem)
}
args[0] = elem[:idx]
elem = elem[idx:]
if len(elem) == 0 {
switch r.Method {
case "GET":
s.handleGetUserRequest([1]string{
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "GET")
}
return
}
switch elem[0] {
case '/': // Prefix: "/rank"
origElem := elem
if l := len("/rank"); len(elem) >= l && elem[0:l] == "/rank" {
if l := len("status"); len(elem) >= l && elem[0:l] == "status" {
elem = elem[l:]
} else {
break
@ -144,12 +169,12 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if len(elem) == 0 {
// Leaf node.
switch r.Method {
case "GET":
s.handleGetUserRankRequest([1]string{
case "PATCH":
s.handlePatchSubmissionStatusRequest([1]string{
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "GET")
s.notAllowed(w, r, "PATCH")
}
return
@ -163,6 +188,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
elem = origElem
}
elem = origElem
}
}
s.notFound(w, r)
}
@ -242,6 +270,69 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
break
}
switch elem[0] {
case '/': // Prefix: "/submissions"
origElem := elem
if l := len("/submissions"); len(elem) >= l && elem[0:l] == "/submissions" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
switch method {
case "GET":
r.name = "ListSubmissions"
r.summary = "Get list of submissions"
r.operationID = "listSubmissions"
r.pathPattern = "/submissions"
r.args = args
r.count = 0
return r, true
case "POST":
r.name = "CreateSubmission"
r.summary = "Create new submission"
r.operationID = "createSubmission"
r.pathPattern = "/submissions"
r.args = args
r.count = 0
return r, true
default:
return
}
}
switch elem[0] {
case '/': // Prefix: "/"
origElem := elem
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
elem = elem[l:]
} else {
break
}
// Param: "SubmissionID"
// Match until "/"
idx := strings.IndexByte(elem, '/')
if idx < 0 {
idx = len(elem)
}
args[0] = elem[:idx]
elem = elem[idx:]
if len(elem) == 0 {
switch method {
case "GET":
r.name = "GetSubmission"
r.summary = "Retrieve map with ID"
r.operationID = "getSubmission"
r.pathPattern = "/submissions/{SubmissionID}"
r.args = args
r.count = 1
return r, true
default:
return
}
}
switch elem[0] {
case '/': // Prefix: "/"
origElem := elem
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
@ -254,9 +345,9 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
break
}
switch elem[0] {
case 'r': // Prefix: "ranks"
case 'c': // Prefix: "completed"
origElem := elem
if l := len("ranks"); len(elem) >= l && elem[0:l] == "ranks" {
if l := len("completed"); len(elem) >= l && elem[0:l] == "completed" {
elem = elem[l:]
} else {
break
@ -265,69 +356,11 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
if len(elem) == 0 {
// Leaf node.
switch method {
case "GET":
r.name = "ListRanks"
r.summary = "Get list of ranks"
r.operationID = "listRanks"
r.pathPattern = "/ranks"
r.args = args
r.count = 0
return r, true
default:
return
}
}
elem = origElem
case 't': // Prefix: "times"
origElem := elem
if l := len("times"); len(elem) >= l && elem[0:l] == "times" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch method {
case "GET":
r.name = "ListTimes"
r.summary = "Get list of times"
r.operationID = "listTimes"
r.pathPattern = "/times"
r.args = args
r.count = 0
return r, true
default:
return
}
}
elem = origElem
case 'u': // Prefix: "users/"
origElem := elem
if l := len("users/"); len(elem) >= l && elem[0:l] == "users/" {
elem = elem[l:]
} else {
break
}
// Param: "UserID"
// Match until "/"
idx := strings.IndexByte(elem, '/')
if idx < 0 {
idx = len(elem)
}
args[0] = elem[:idx]
elem = elem[idx:]
if len(elem) == 0 {
switch method {
case "GET":
r.name = "GetUser"
r.summary = "Retrieve user with ID"
r.operationID = "getUser"
r.pathPattern = "/users/{UserID}"
case "PATCH":
r.name = "PatchSubmissionCompleted"
r.summary = "Retrieve map with ID"
r.operationID = "patchSubmissionCompleted"
r.pathPattern = "/submissions/{SubmissionID}/completed"
r.args = args
r.count = 1
return r, true
@ -335,10 +368,11 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
return
}
}
switch elem[0] {
case '/': // Prefix: "/rank"
elem = origElem
case 'm': // Prefix: "model"
origElem := elem
if l := len("/rank"); len(elem) >= l && elem[0:l] == "/rank" {
if l := len("model"); len(elem) >= l && elem[0:l] == "model" {
elem = elem[l:]
} else {
break
@ -347,11 +381,11 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
if len(elem) == 0 {
// Leaf node.
switch method {
case "GET":
r.name = "GetUserRank"
r.summary = "Retrieve rank of user"
r.operationID = "getUserRank"
r.pathPattern = "/users/{UserID}/rank"
case "PATCH":
r.name = "PatchSubmissionModel"
r.summary = "Update model following role restrictions"
r.operationID = "patchSubmissionModel"
r.pathPattern = "/submissions/{SubmissionID}/model"
r.args = args
r.count = 1
return r, true
@ -360,6 +394,34 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
}
}
elem = origElem
case 's': // Prefix: "status"
origElem := elem
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
}
}
elem = origElem
}
elem = origElem
}

View File

@ -63,111 +63,6 @@ func (s *ErrorStatusCode) SetResponse(val Error) {
s.Response = val
}
// Ref: #/components/schemas/Map
type Map struct {
ID OptInt64 `json:"ID"`
DisplayName OptString `json:"DisplayName"`
Creator OptString `json:"Creator"`
GameID OptInt32 `json:"GameID"`
Date OptInt64 `json:"Date"`
}
// GetID returns the value of ID.
func (s *Map) GetID() OptInt64 {
return s.ID
}
// GetDisplayName returns the value of DisplayName.
func (s *Map) GetDisplayName() OptString {
return s.DisplayName
}
// GetCreator returns the value of Creator.
func (s *Map) GetCreator() OptString {
return s.Creator
}
// GetGameID returns the value of GameID.
func (s *Map) GetGameID() OptInt32 {
return s.GameID
}
// GetDate returns the value of Date.
func (s *Map) GetDate() OptInt64 {
return s.Date
}
// SetID sets the value of ID.
func (s *Map) SetID(val OptInt64) {
s.ID = val
}
// SetDisplayName sets the value of DisplayName.
func (s *Map) SetDisplayName(val OptString) {
s.DisplayName = val
}
// SetCreator sets the value of Creator.
func (s *Map) SetCreator(val OptString) {
s.Creator = val
}
// SetGameID sets the value of GameID.
func (s *Map) SetGameID(val OptInt32) {
s.GameID = val
}
// SetDate sets the value of Date.
func (s *Map) SetDate(val OptInt64) {
s.Date = val
}
// NewOptFloat64 returns new OptFloat64 with value set to v.
func NewOptFloat64(v float64) OptFloat64 {
return OptFloat64{
Value: v,
Set: true,
}
}
// OptFloat64 is optional float64.
type OptFloat64 struct {
Value float64
Set bool
}
// IsSet returns true if OptFloat64 was set.
func (o OptFloat64) IsSet() bool { return o.Set }
// Reset unsets value.
func (o *OptFloat64) Reset() {
var v float64
o.Value = v
o.Set = false
}
// SetTo sets value to v.
func (o *OptFloat64) SetTo(v float64) {
o.Set = true
o.Value = v
}
// Get returns value and boolean that denotes whether value was set.
func (o OptFloat64) Get() (v float64, ok bool) {
if !o.Set {
return v, false
}
return o.Value, true
}
// Or returns value if set, or given parameter if does not.
func (o OptFloat64) Or(d float64) float64 {
if v, ok := o.Get(); ok {
return v
}
return d
}
// NewOptInt32 returns new OptInt32 with value set to v.
func NewOptInt32(v int32) OptInt32 {
return OptInt32{
@ -260,98 +155,6 @@ func (o OptInt64) Or(d int64) int64 {
return d
}
// NewOptMap returns new OptMap with value set to v.
func NewOptMap(v Map) OptMap {
return OptMap{
Value: v,
Set: true,
}
}
// OptMap is optional Map.
type OptMap struct {
Value Map
Set bool
}
// IsSet returns true if OptMap was set.
func (o OptMap) IsSet() bool { return o.Set }
// Reset unsets value.
func (o *OptMap) Reset() {
var v Map
o.Value = v
o.Set = false
}
// SetTo sets value to v.
func (o *OptMap) SetTo(v Map) {
o.Set = true
o.Value = v
}
// Get returns value and boolean that denotes whether value was set.
func (o OptMap) Get() (v Map, ok bool) {
if !o.Set {
return v, false
}
return o.Value, true
}
// Or returns value if set, or given parameter if does not.
func (o OptMap) Or(d Map) Map {
if v, ok := o.Get(); ok {
return v
}
return d
}
// NewOptRankFilter returns new OptRankFilter with value set to v.
func NewOptRankFilter(v RankFilter) OptRankFilter {
return OptRankFilter{
Value: v,
Set: true,
}
}
// OptRankFilter is optional RankFilter.
type OptRankFilter struct {
Value RankFilter
Set bool
}
// IsSet returns true if OptRankFilter was set.
func (o OptRankFilter) IsSet() bool { return o.Set }
// Reset unsets value.
func (o *OptRankFilter) Reset() {
var v RankFilter
o.Value = v
o.Set = false
}
// SetTo sets value to v.
func (o *OptRankFilter) SetTo(v RankFilter) {
o.Set = true
o.Value = v
}
// Get returns value and boolean that denotes whether value was set.
func (o OptRankFilter) Get() (v RankFilter, ok bool) {
if !o.Set {
return v, false
}
return o.Value, true
}
// Or returns value if set, or given parameter if does not.
func (o OptRankFilter) Or(d RankFilter) RankFilter {
if v, ok := o.Get(); ok {
return v
}
return d
}
// NewOptString returns new OptString with value set to v.
func NewOptString(v string) OptString {
return OptString{
@ -398,38 +201,38 @@ func (o OptString) Or(d string) string {
return d
}
// NewOptTimeFilter returns new OptTimeFilter with value set to v.
func NewOptTimeFilter(v TimeFilter) OptTimeFilter {
return OptTimeFilter{
// NewOptSubmissionFilter returns new OptSubmissionFilter with value set to v.
func NewOptSubmissionFilter(v SubmissionFilter) OptSubmissionFilter {
return OptSubmissionFilter{
Value: v,
Set: true,
}
}
// OptTimeFilter is optional TimeFilter.
type OptTimeFilter struct {
Value TimeFilter
// OptSubmissionFilter is optional SubmissionFilter.
type OptSubmissionFilter struct {
Value SubmissionFilter
Set bool
}
// IsSet returns true if OptTimeFilter was set.
func (o OptTimeFilter) IsSet() bool { return o.Set }
// IsSet returns true if OptSubmissionFilter was set.
func (o OptSubmissionFilter) IsSet() bool { return o.Set }
// Reset unsets value.
func (o *OptTimeFilter) Reset() {
var v TimeFilter
func (o *OptSubmissionFilter) Reset() {
var v SubmissionFilter
o.Value = v
o.Set = false
}
// SetTo sets value to v.
func (o *OptTimeFilter) SetTo(v TimeFilter) {
func (o *OptSubmissionFilter) SetTo(v SubmissionFilter) {
o.Set = true
o.Value = v
}
// Get returns value and boolean that denotes whether value was set.
func (o OptTimeFilter) Get() (v TimeFilter, ok bool) {
func (o OptSubmissionFilter) Get() (v SubmissionFilter, ok bool) {
if !o.Set {
return v, false
}
@ -437,53 +240,7 @@ func (o OptTimeFilter) Get() (v TimeFilter, ok bool) {
}
// Or returns value if set, or given parameter if does not.
func (o OptTimeFilter) Or(d TimeFilter) TimeFilter {
if v, ok := o.Get(); ok {
return v
}
return d
}
// NewOptUser returns new OptUser with value set to v.
func NewOptUser(v User) OptUser {
return OptUser{
Value: v,
Set: true,
}
}
// OptUser is optional User.
type OptUser struct {
Value User
Set bool
}
// IsSet returns true if OptUser was set.
func (o OptUser) IsSet() bool { return o.Set }
// Reset unsets value.
func (o *OptUser) Reset() {
var v User
o.Value = v
o.Set = false
}
// SetTo sets value to v.
func (o *OptUser) SetTo(v User) {
o.Set = true
o.Value = v
}
// Get returns value and boolean that denotes whether value was set.
func (o OptUser) Get() (v User, ok bool) {
if !o.Set {
return v, false
}
return o.Value, true
}
// Or returns value if set, or given parameter if does not.
func (o OptUser) Or(d User) User {
func (o OptSubmissionFilter) Or(d SubmissionFilter) SubmissionFilter {
if v, ok := o.Get(); ok {
return v
}
@ -516,352 +273,129 @@ func (s *Pagination) SetLimit(val int32) {
s.Limit = val
}
// Ref: #/components/schemas/Rank
type Rank struct {
// PatchSubmissionCompletedOK is response for PatchSubmissionCompleted operation.
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"`
User OptUser `json:"User"`
StyleID OptInt32 `json:"StyleID"`
ModeID OptInt32 `json:"ModeID"`
DisplayName OptString `json:"DisplayName"`
Creator OptString `json:"Creator"`
GameID OptInt32 `json:"GameID"`
Rank OptFloat64 `json:"Rank"`
Skill OptFloat64 `json:"Skill"`
UpdatedAt OptInt64 `json:"UpdatedAt"`
}
// GetID returns the value of ID.
func (s *Rank) GetID() OptInt64 {
return s.ID
}
// GetUser returns the value of User.
func (s *Rank) GetUser() OptUser {
return s.User
}
// GetStyleID returns the value of StyleID.
func (s *Rank) GetStyleID() OptInt32 {
return s.StyleID
}
// GetModeID returns the value of ModeID.
func (s *Rank) GetModeID() OptInt32 {
return s.ModeID
}
// GetGameID returns the value of GameID.
func (s *Rank) GetGameID() OptInt32 {
return s.GameID
}
// GetRank returns the value of Rank.
func (s *Rank) GetRank() OptFloat64 {
return s.Rank
}
// GetSkill returns the value of Skill.
func (s *Rank) GetSkill() OptFloat64 {
return s.Skill
}
// GetUpdatedAt returns the value of UpdatedAt.
func (s *Rank) GetUpdatedAt() OptInt64 {
return s.UpdatedAt
}
// SetID sets the value of ID.
func (s *Rank) SetID(val OptInt64) {
s.ID = val
}
// SetUser sets the value of User.
func (s *Rank) SetUser(val OptUser) {
s.User = val
}
// SetStyleID sets the value of StyleID.
func (s *Rank) SetStyleID(val OptInt32) {
s.StyleID = val
}
// SetModeID sets the value of ModeID.
func (s *Rank) SetModeID(val OptInt32) {
s.ModeID = val
}
// SetGameID sets the value of GameID.
func (s *Rank) SetGameID(val OptInt32) {
s.GameID = val
}
// SetRank sets the value of Rank.
func (s *Rank) SetRank(val OptFloat64) {
s.Rank = val
}
// SetSkill sets the value of Skill.
func (s *Rank) SetSkill(val OptFloat64) {
s.Skill = val
}
// SetUpdatedAt sets the value of UpdatedAt.
func (s *Rank) SetUpdatedAt(val OptInt64) {
s.UpdatedAt = val
}
// Ref: #/components/schemas/RankFilter
type RankFilter struct {
StyleID OptInt32 `json:"StyleID"`
GameID OptInt32 `json:"GameID"`
ModeID OptInt32 `json:"ModeID"`
Sort OptInt64 `json:"Sort"`
}
// GetStyleID returns the value of StyleID.
func (s *RankFilter) GetStyleID() OptInt32 {
return s.StyleID
}
// GetGameID returns the value of GameID.
func (s *RankFilter) GetGameID() OptInt32 {
return s.GameID
}
// GetModeID returns the value of ModeID.
func (s *RankFilter) GetModeID() OptInt32 {
return s.ModeID
}
// GetSort returns the value of Sort.
func (s *RankFilter) GetSort() OptInt64 {
return s.Sort
}
// SetStyleID sets the value of StyleID.
func (s *RankFilter) SetStyleID(val OptInt32) {
s.StyleID = val
}
// SetGameID sets the value of GameID.
func (s *RankFilter) SetGameID(val OptInt32) {
s.GameID = val
}
// SetModeID sets the value of ModeID.
func (s *RankFilter) SetModeID(val OptInt32) {
s.ModeID = val
}
// SetSort sets the value of Sort.
func (s *RankFilter) SetSort(val OptInt64) {
s.Sort = val
}
// Ref: #/components/schemas/Time
type Time struct {
ID OptInt64 `json:"ID"`
Time OptInt64 `json:"Time"`
User OptUser `json:"User"`
Map OptMap `json:"Map"`
Date OptInt64 `json:"Date"`
StyleID OptInt32 `json:"StyleID"`
ModeID OptInt32 `json:"ModeID"`
GameID OptInt32 `json:"GameID"`
}
// GetID returns the value of ID.
func (s *Time) GetID() OptInt64 {
func (s *Submission) GetID() OptInt64 {
return s.ID
}
// GetTime returns the value of Time.
func (s *Time) GetTime() OptInt64 {
return s.Time
// GetDisplayName returns the value of DisplayName.
func (s *Submission) GetDisplayName() OptString {
return s.DisplayName
}
// GetUser returns the value of User.
func (s *Time) GetUser() OptUser {
return s.User
// GetCreator returns the value of Creator.
func (s *Submission) GetCreator() OptString {
return s.Creator
}
// GetMap returns the value of Map.
func (s *Time) GetMap() OptMap {
return s.Map
// GetGameID returns the value of GameID.
func (s *Submission) GetGameID() OptInt32 {
return s.GameID
}
// GetDate returns the value of Date.
func (s *Time) GetDate() OptInt64 {
func (s *Submission) GetDate() OptInt64 {
return s.Date
}
// GetStyleID returns the value of StyleID.
func (s *Time) GetStyleID() OptInt32 {
return s.StyleID
}
// GetModeID returns the value of ModeID.
func (s *Time) GetModeID() OptInt32 {
return s.ModeID
}
// GetGameID returns the value of GameID.
func (s *Time) GetGameID() OptInt32 {
return s.GameID
}
// SetID sets the value of ID.
func (s *Time) SetID(val OptInt64) {
func (s *Submission) SetID(val OptInt64) {
s.ID = val
}
// SetTime sets the value of Time.
func (s *Time) SetTime(val OptInt64) {
s.Time = val
// SetDisplayName sets the value of DisplayName.
func (s *Submission) SetDisplayName(val OptString) {
s.DisplayName = val
}
// SetUser sets the value of User.
func (s *Time) SetUser(val OptUser) {
s.User = val
// SetCreator sets the value of Creator.
func (s *Submission) SetCreator(val OptString) {
s.Creator = val
}
// SetMap sets the value of Map.
func (s *Time) SetMap(val OptMap) {
s.Map = val
// SetGameID sets the value of GameID.
func (s *Submission) SetGameID(val OptInt32) {
s.GameID = val
}
// SetDate sets the value of Date.
func (s *Time) SetDate(val OptInt64) {
func (s *Submission) SetDate(val OptInt64) {
s.Date = val
}
// SetStyleID sets the value of StyleID.
func (s *Time) SetStyleID(val OptInt32) {
s.StyleID = val
}
// SetModeID sets the value of ModeID.
func (s *Time) SetModeID(val OptInt32) {
s.ModeID = val
}
// SetGameID sets the value of GameID.
func (s *Time) SetGameID(val OptInt32) {
s.GameID = val
}
// Ref: #/components/schemas/TimeFilter
type TimeFilter struct {
// Ref: #/components/schemas/SubmissionFilter
type SubmissionFilter struct {
ID OptInt64 `json:"ID"`
Time OptInt64 `json:"Time"`
UserID OptInt64 `json:"UserID"`
MapID OptInt64 `json:"MapID"`
StyleID OptInt32 `json:"StyleID"`
ModeID OptInt32 `json:"ModeID"`
DisplayName OptString `json:"DisplayName"`
Creator OptString `json:"Creator"`
GameID OptInt32 `json:"GameID"`
Date OptInt64 `json:"Date"`
}
// GetID returns the value of ID.
func (s *TimeFilter) GetID() OptInt64 {
func (s *SubmissionFilter) GetID() OptInt64 {
return s.ID
}
// GetTime returns the value of Time.
func (s *TimeFilter) GetTime() OptInt64 {
return s.Time
// GetDisplayName returns the value of DisplayName.
func (s *SubmissionFilter) GetDisplayName() OptString {
return s.DisplayName
}
// GetUserID returns the value of UserID.
func (s *TimeFilter) GetUserID() OptInt64 {
return s.UserID
}
// GetMapID returns the value of MapID.
func (s *TimeFilter) GetMapID() OptInt64 {
return s.MapID
}
// GetStyleID returns the value of StyleID.
func (s *TimeFilter) GetStyleID() OptInt32 {
return s.StyleID
}
// GetModeID returns the value of ModeID.
func (s *TimeFilter) GetModeID() OptInt32 {
return s.ModeID
// GetCreator returns the value of Creator.
func (s *SubmissionFilter) GetCreator() OptString {
return s.Creator
}
// GetGameID returns the value of GameID.
func (s *TimeFilter) GetGameID() OptInt32 {
func (s *SubmissionFilter) GetGameID() OptInt32 {
return s.GameID
}
// GetDate returns the value of Date.
func (s *SubmissionFilter) GetDate() OptInt64 {
return s.Date
}
// SetID sets the value of ID.
func (s *TimeFilter) SetID(val OptInt64) {
func (s *SubmissionFilter) SetID(val OptInt64) {
s.ID = val
}
// SetTime sets the value of Time.
func (s *TimeFilter) SetTime(val OptInt64) {
s.Time = val
// SetDisplayName sets the value of DisplayName.
func (s *SubmissionFilter) SetDisplayName(val OptString) {
s.DisplayName = val
}
// SetUserID sets the value of UserID.
func (s *TimeFilter) SetUserID(val OptInt64) {
s.UserID = val
}
// SetMapID sets the value of MapID.
func (s *TimeFilter) SetMapID(val OptInt64) {
s.MapID = val
}
// SetStyleID sets the value of StyleID.
func (s *TimeFilter) SetStyleID(val OptInt32) {
s.StyleID = val
}
// SetModeID sets the value of ModeID.
func (s *TimeFilter) SetModeID(val OptInt32) {
s.ModeID = val
// SetCreator sets the value of Creator.
func (s *SubmissionFilter) SetCreator(val OptString) {
s.Creator = val
}
// SetGameID sets the value of GameID.
func (s *TimeFilter) SetGameID(val OptInt32) {
func (s *SubmissionFilter) SetGameID(val OptInt32) {
s.GameID = val
}
// Ref: #/components/schemas/User
type User struct {
ID OptInt64 `json:"ID"`
Username OptString `json:"Username"`
StateID OptInt32 `json:"StateID"`
}
// GetID returns the value of ID.
func (s *User) GetID() OptInt64 {
return s.ID
}
// GetUsername returns the value of Username.
func (s *User) GetUsername() OptString {
return s.Username
}
// GetStateID returns the value of StateID.
func (s *User) GetStateID() OptInt32 {
return s.StateID
}
// SetID sets the value of ID.
func (s *User) SetID(val OptInt64) {
s.ID = val
}
// SetUsername sets the value of Username.
func (s *User) SetUsername(val OptString) {
s.Username = val
}
// SetStateID sets the value of StateID.
func (s *User) SetStateID(val OptInt32) {
s.StateID = val
// SetDate sets the value of Date.
func (s *SubmissionFilter) SetDate(val OptInt64) {
s.Date = val
}

View File

@ -8,30 +8,42 @@ import (
// Handler handles operations described by OpenAPI v3 specification.
type Handler interface {
// GetUser implements getUser operation.
// CreateSubmission implements createSubmission operation.
//
// Retrieve user with ID.
// Create new submission.
//
// GET /users/{UserID}
GetUser(ctx context.Context, params GetUserParams) (*User, error)
// GetUserRank implements getUserRank operation.
// POST /submissions
CreateSubmission(ctx context.Context) (*Submission, error)
// GetSubmission implements getSubmission operation.
//
// Retrieve rank of user.
// Retrieve map with ID.
//
// GET /users/{UserID}/rank
GetUserRank(ctx context.Context, params GetUserRankParams) (*Rank, error)
// ListRanks implements listRanks operation.
// GET /submissions/{SubmissionID}
GetSubmission(ctx context.Context, params GetSubmissionParams) (*Submission, error)
// ListSubmissions implements listSubmissions operation.
//
// Get list of ranks.
// Get list of submissions.
//
// GET /ranks
ListRanks(ctx context.Context, params ListRanksParams) ([]Rank, error)
// ListTimes implements listTimes operation.
// GET /submissions
ListSubmissions(ctx context.Context, params ListSubmissionsParams) ([]Submission, error)
// PatchSubmissionCompleted implements patchSubmissionCompleted operation.
//
// Get list of times.
// Retrieve map with ID.
//
// GET /times
ListTimes(ctx context.Context, params ListTimesParams) ([]Time, error)
// PATCH /submissions/{SubmissionID}/completed
PatchSubmissionCompleted(ctx context.Context, params PatchSubmissionCompletedParams) error
// PatchSubmissionModel implements patchSubmissionModel operation.
//
// Update model following role restrictions.
//
// 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.

View File

@ -13,40 +13,58 @@ type UnimplementedHandler struct{}
var _ Handler = UnimplementedHandler{}
// GetUser implements getUser operation.
// CreateSubmission implements createSubmission operation.
//
// Retrieve user with ID.
// Create new submission.
//
// GET /users/{UserID}
func (UnimplementedHandler) GetUser(ctx context.Context, params GetUserParams) (r *User, _ error) {
// POST /submissions
func (UnimplementedHandler) CreateSubmission(ctx context.Context) (r *Submission, _ error) {
return r, ht.ErrNotImplemented
}
// GetUserRank implements getUserRank operation.
// GetSubmission implements getSubmission operation.
//
// Retrieve rank of user.
// Retrieve map with ID.
//
// GET /users/{UserID}/rank
func (UnimplementedHandler) GetUserRank(ctx context.Context, params GetUserRankParams) (r *Rank, _ error) {
// GET /submissions/{SubmissionID}
func (UnimplementedHandler) GetSubmission(ctx context.Context, params GetSubmissionParams) (r *Submission, _ error) {
return r, ht.ErrNotImplemented
}
// ListRanks implements listRanks operation.
// ListSubmissions implements listSubmissions operation.
//
// Get list of ranks.
// Get list of submissions.
//
// GET /ranks
func (UnimplementedHandler) ListRanks(ctx context.Context, params ListRanksParams) (r []Rank, _ error) {
// GET /submissions
func (UnimplementedHandler) ListSubmissions(ctx context.Context, params ListSubmissionsParams) (r []Submission, _ error) {
return r, ht.ErrNotImplemented
}
// ListTimes implements listTimes operation.
// PatchSubmissionCompleted implements patchSubmissionCompleted operation.
//
// Get list of times.
// Retrieve map with ID.
//
// GET /times
func (UnimplementedHandler) ListTimes(ctx context.Context, params ListTimesParams) (r []Time, _ error) {
return r, ht.ErrNotImplemented
// PATCH /submissions/{SubmissionID}/completed
func (UnimplementedHandler) PatchSubmissionCompleted(ctx context.Context, params PatchSubmissionCompletedParams) error {
return ht.ErrNotImplemented
}
// PatchSubmissionModel implements patchSubmissionModel operation.
//
// Update model following role restrictions.
//
// PATCH /submissions/{SubmissionID}/model
func (UnimplementedHandler) PatchSubmissionModel(ctx context.Context, params PatchSubmissionModelParams) error {
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.

View File

@ -121,167 +121,8 @@ func (s *Pagination) DecodeURI(d uri.Decoder) error {
return nil
}
// EncodeURI encodes RankFilter as URI form.
func (s *RankFilter) EncodeURI(e uri.Encoder) error {
if err := e.EncodeField("StyleID", func(e uri.Encoder) error {
if val, ok := s.StyleID.Get(); ok {
return e.EncodeValue(conv.Int32ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"StyleID\"")
}
if err := e.EncodeField("GameID", func(e uri.Encoder) error {
if val, ok := s.GameID.Get(); ok {
return e.EncodeValue(conv.Int32ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"GameID\"")
}
if err := e.EncodeField("ModeID", func(e uri.Encoder) error {
if val, ok := s.ModeID.Get(); ok {
return e.EncodeValue(conv.Int32ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"ModeID\"")
}
if err := e.EncodeField("Sort", func(e uri.Encoder) error {
if val, ok := s.Sort.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"Sort\"")
}
return nil
}
var uriFieldsNameOfRankFilter = [4]string{
0: "StyleID",
1: "GameID",
2: "ModeID",
3: "Sort",
}
// DecodeURI decodes RankFilter from URI form.
func (s *RankFilter) DecodeURI(d uri.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode RankFilter to nil")
}
if err := d.DecodeFields(func(k string, d uri.Decoder) error {
switch k {
case "StyleID":
if err := func() error {
var sDotStyleIDVal int32
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt32(val)
if err != nil {
return err
}
sDotStyleIDVal = c
return nil
}(); err != nil {
return err
}
s.StyleID.SetTo(sDotStyleIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"StyleID\"")
}
case "GameID":
if err := func() error {
var sDotGameIDVal int32
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt32(val)
if err != nil {
return err
}
sDotGameIDVal = c
return nil
}(); err != nil {
return err
}
s.GameID.SetTo(sDotGameIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"GameID\"")
}
case "ModeID":
if err := func() error {
var sDotModeIDVal int32
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt32(val)
if err != nil {
return err
}
sDotModeIDVal = c
return nil
}(); err != nil {
return err
}
s.ModeID.SetTo(sDotModeIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"ModeID\"")
}
case "Sort":
if err := func() error {
var sDotSortVal int64
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt64(val)
if err != nil {
return err
}
sDotSortVal = c
return nil
}(); err != nil {
return err
}
s.Sort.SetTo(sDotSortVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"Sort\"")
}
default:
return nil
}
return nil
}); err != nil {
return errors.Wrap(err, "decode RankFilter")
}
return nil
}
// EncodeURI encodes TimeFilter as URI form.
func (s *TimeFilter) EncodeURI(e uri.Encoder) error {
// EncodeURI encodes SubmissionFilter as URI form.
func (s *SubmissionFilter) EncodeURI(e uri.Encoder) error {
if err := e.EncodeField("ID", func(e uri.Encoder) error {
if val, ok := s.ID.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val))
@ -290,45 +131,21 @@ func (s *TimeFilter) EncodeURI(e uri.Encoder) error {
}); err != nil {
return errors.Wrap(err, "encode field \"ID\"")
}
if err := e.EncodeField("Time", func(e uri.Encoder) error {
if val, ok := s.Time.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val))
if err := e.EncodeField("DisplayName", func(e uri.Encoder) error {
if val, ok := s.DisplayName.Get(); ok {
return e.EncodeValue(conv.StringToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"Time\"")
return errors.Wrap(err, "encode field \"DisplayName\"")
}
if err := e.EncodeField("UserID", func(e uri.Encoder) error {
if val, ok := s.UserID.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val))
if err := e.EncodeField("Creator", func(e uri.Encoder) error {
if val, ok := s.Creator.Get(); ok {
return e.EncodeValue(conv.StringToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"UserID\"")
}
if err := e.EncodeField("MapID", func(e uri.Encoder) error {
if val, ok := s.MapID.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"MapID\"")
}
if err := e.EncodeField("StyleID", func(e uri.Encoder) error {
if val, ok := s.StyleID.Get(); ok {
return e.EncodeValue(conv.Int32ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"StyleID\"")
}
if err := e.EncodeField("ModeID", func(e uri.Encoder) error {
if val, ok := s.ModeID.Get(); ok {
return e.EncodeValue(conv.Int32ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"ModeID\"")
return errors.Wrap(err, "encode field \"Creator\"")
}
if err := e.EncodeField("GameID", func(e uri.Encoder) error {
if val, ok := s.GameID.Get(); ok {
@ -338,23 +155,29 @@ func (s *TimeFilter) EncodeURI(e uri.Encoder) error {
}); err != nil {
return errors.Wrap(err, "encode field \"GameID\"")
}
if err := e.EncodeField("Date", func(e uri.Encoder) error {
if val, ok := s.Date.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"Date\"")
}
return nil
}
var uriFieldsNameOfTimeFilter = [7]string{
var uriFieldsNameOfSubmissionFilter = [5]string{
0: "ID",
1: "Time",
2: "UserID",
3: "MapID",
4: "StyleID",
5: "ModeID",
6: "GameID",
1: "DisplayName",
2: "Creator",
3: "GameID",
4: "Date",
}
// DecodeURI decodes TimeFilter from URI form.
func (s *TimeFilter) DecodeURI(d uri.Decoder) error {
// DecodeURI decodes SubmissionFilter from URI form.
func (s *SubmissionFilter) DecodeURI(d uri.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode TimeFilter to nil")
return errors.New("invalid: unable to decode SubmissionFilter to nil")
}
if err := d.DecodeFields(func(k string, d uri.Decoder) error {
@ -383,125 +206,53 @@ func (s *TimeFilter) DecodeURI(d uri.Decoder) error {
}(); err != nil {
return errors.Wrap(err, "decode field \"ID\"")
}
case "Time":
case "DisplayName":
if err := func() error {
var sDotTimeVal int64
var sDotDisplayNameVal string
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt64(val)
c, err := conv.ToString(val)
if err != nil {
return err
}
sDotTimeVal = c
sDotDisplayNameVal = c
return nil
}(); err != nil {
return err
}
s.Time.SetTo(sDotTimeVal)
s.DisplayName.SetTo(sDotDisplayNameVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"Time\"")
return errors.Wrap(err, "decode field \"DisplayName\"")
}
case "UserID":
case "Creator":
if err := func() error {
var sDotUserIDVal int64
var sDotCreatorVal string
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt64(val)
c, err := conv.ToString(val)
if err != nil {
return err
}
sDotUserIDVal = c
sDotCreatorVal = c
return nil
}(); err != nil {
return err
}
s.UserID.SetTo(sDotUserIDVal)
s.Creator.SetTo(sDotCreatorVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"UserID\"")
}
case "MapID":
if err := func() error {
var sDotMapIDVal int64
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt64(val)
if err != nil {
return err
}
sDotMapIDVal = c
return nil
}(); err != nil {
return err
}
s.MapID.SetTo(sDotMapIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"MapID\"")
}
case "StyleID":
if err := func() error {
var sDotStyleIDVal int32
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt32(val)
if err != nil {
return err
}
sDotStyleIDVal = c
return nil
}(); err != nil {
return err
}
s.StyleID.SetTo(sDotStyleIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"StyleID\"")
}
case "ModeID":
if err := func() error {
var sDotModeIDVal int32
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt32(val)
if err != nil {
return err
}
sDotModeIDVal = c
return nil
}(); err != nil {
return err
}
s.ModeID.SetTo(sDotModeIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"ModeID\"")
return errors.Wrap(err, "decode field \"Creator\"")
}
case "GameID":
if err := func() error {
@ -527,12 +278,36 @@ func (s *TimeFilter) DecodeURI(d uri.Decoder) error {
}(); err != nil {
return errors.Wrap(err, "decode field \"GameID\"")
}
case "Date":
if err := func() error {
var sDotDateVal int64
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt64(val)
if err != nil {
return err
}
sDotDateVal = c
return nil
}(); err != nil {
return err
}
s.Date.SetTo(sDotDateVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"Date\"")
}
default:
return nil
}
return nil
}); err != nil {
return errors.Wrap(err, "decode TimeFilter")
return errors.Wrap(err, "decode SubmissionFilter")
}
return nil

View File

@ -59,51 +59,3 @@ func (s *Pagination) Validate() error {
}
return nil
}
func (s *Rank) Validate() error {
if s == nil {
return validate.ErrNilPointer
}
var failures []validate.FieldError
if err := func() error {
if value, ok := s.Rank.Get(); ok {
if err := func() error {
if err := (validate.Float{}).Validate(float64(value)); err != nil {
return errors.Wrap(err, "float")
}
return nil
}(); err != nil {
return err
}
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "Rank",
Error: err,
})
}
if err := func() error {
if value, ok := s.Skill.Get(); ok {
if err := func() error {
if err := (validate.Float{}).Validate(float64(value)); err != nil {
return errors.Wrap(err, "float")
}
return nil
}(); err != nil {
return err
}
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "Skill",
Error: err,
})
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}