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

View File

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

View File

@ -125,172 +125,6 @@ func (s *Error) UnmarshalJSON(data []byte) error {
return s.Decode(d) 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. // Encode encodes int32 as json.
func (o OptInt32) Encode(e *jx.Encoder) { func (o OptInt32) Encode(e *jx.Encoder) {
if !o.Set { if !o.Set {
@ -361,39 +195,6 @@ func (s *OptInt64) UnmarshalJSON(data []byte) error {
return s.Decode(d) 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. // Encode encodes string as json.
func (o OptString) Encode(e *jx.Encoder) { func (o OptString) Encode(e *jx.Encoder) {
if !o.Set { if !o.Set {
@ -429,48 +230,15 @@ func (s *OptString) UnmarshalJSON(data []byte) error {
return s.Decode(d) 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. // Encode implements json.Marshaler.
func (s *Rank) Encode(e *jx.Encoder) { func (s *Submission) Encode(e *jx.Encoder) {
e.ObjStart() e.ObjStart()
s.encodeFields(e) s.encodeFields(e)
e.ObjEnd() e.ObjEnd()
} }
// encodeFields encodes fields. // encodeFields encodes fields.
func (s *Rank) encodeFields(e *jx.Encoder) { func (s *Submission) encodeFields(e *jx.Encoder) {
{ {
if s.ID.Set { if s.ID.Set {
e.FieldStart("ID") e.FieldStart("ID")
@ -478,21 +246,15 @@ func (s *Rank) encodeFields(e *jx.Encoder) {
} }
} }
{ {
if s.User.Set { if s.DisplayName.Set {
e.FieldStart("User") e.FieldStart("DisplayName")
s.User.Encode(e) s.DisplayName.Encode(e)
} }
} }
{ {
if s.StyleID.Set { if s.Creator.Set {
e.FieldStart("StyleID") e.FieldStart("Creator")
s.StyleID.Encode(e) s.Creator.Encode(e)
}
}
{
if s.ModeID.Set {
e.FieldStart("ModeID")
s.ModeID.Encode(e)
} }
} }
{ {
@ -502,40 +264,25 @@ func (s *Rank) encodeFields(e *jx.Encoder) {
} }
} }
{ {
if s.Rank.Set { if s.Date.Set {
e.FieldStart("Rank") e.FieldStart("Date")
s.Rank.Encode(e) s.Date.Encode(e)
}
}
{
if s.Skill.Set {
e.FieldStart("Skill")
s.Skill.Encode(e)
}
}
{
if s.UpdatedAt.Set {
e.FieldStart("UpdatedAt")
s.UpdatedAt.Encode(e)
} }
} }
} }
var jsonFieldsNameOfRank = [8]string{ var jsonFieldsNameOfSubmission = [5]string{
0: "ID", 0: "ID",
1: "User", 1: "DisplayName",
2: "StyleID", 2: "Creator",
3: "ModeID", 3: "GameID",
4: "GameID", 4: "Date",
5: "Rank",
6: "Skill",
7: "UpdatedAt",
} }
// Decode decodes Rank from json. // Decode decodes Submission from json.
func (s *Rank) Decode(d *jx.Decoder) error { func (s *Submission) Decode(d *jx.Decoder) error {
if s == nil { 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 { 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 { }(); err != nil {
return errors.Wrap(err, "decode field \"ID\"") return errors.Wrap(err, "decode field \"ID\"")
} }
case "User": case "DisplayName":
if err := func() error { if err := func() error {
s.User.Reset() s.DisplayName.Reset()
if err := s.User.Decode(d); err != nil { if err := s.DisplayName.Decode(d); err != nil {
return err return err
} }
return nil return nil
}(); err != 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 { if err := func() error {
s.StyleID.Reset() s.Creator.Reset()
if err := s.StyleID.Decode(d); err != nil { if err := s.Creator.Decode(d); err != nil {
return err return err
} }
return nil return nil
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"StyleID\"") return errors.Wrap(err, "decode field \"Creator\"")
}
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": case "GameID":
if err := func() error { if err := func() error {
@ -590,178 +327,6 @@ func (s *Rank) Decode(d *jx.Decoder) error {
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"GameID\"") 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": case "Date":
if err := func() error { if err := func() error {
s.Date.Reset() s.Date.Reset()
@ -772,153 +337,26 @@ func (s *Time) Decode(d *jx.Decoder) error {
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"Date\"") 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: default:
return d.Skip() return d.Skip()
} }
return nil return nil
}); err != nil { }); err != nil {
return errors.Wrap(err, "decode Time") return errors.Wrap(err, "decode Submission")
} }
return nil return nil
} }
// MarshalJSON implements stdjson.Marshaler. // MarshalJSON implements stdjson.Marshaler.
func (s *Time) MarshalJSON() ([]byte, error) { func (s *Submission) MarshalJSON() ([]byte, error) {
e := jx.Encoder{} e := jx.Encoder{}
s.Encode(&e) s.Encode(&e)
return e.Bytes(), nil return e.Bytes(), nil
} }
// UnmarshalJSON implements stdjson.Unmarshaler. // UnmarshalJSON implements stdjson.Unmarshaler.
func (s *Time) UnmarshalJSON(data []byte) error { func (s *Submission) 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 {
d := jx.DecodeBytes(data) d := jx.DecodeBytes(data)
return s.Decode(d) return s.Decode(d)
} }

View File

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

View File

@ -3,7 +3,6 @@
package api package api
import ( import (
"fmt"
"io" "io"
"mime" "mime"
"net/http" "net/http"
@ -15,7 +14,7 @@ import (
"github.com/ogen-go/ogen/validate" "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 { switch resp.StatusCode {
case 200: case 200:
// Code 200. // Code 200.
@ -31,7 +30,7 @@ func decodeGetUserResponse(resp *http.Response) (res *User, _ error) {
} }
d := jx.DecodeBytes(buf) d := jx.DecodeBytes(buf)
var response User var response Submission
if err := func() error { if err := func() error {
if err := response.Decode(d); err != nil { if err := response.Decode(d); err != nil {
return err return err
@ -98,7 +97,7 @@ func decodeGetUserResponse(resp *http.Response) (res *User, _ error) {
return res, errors.Wrap(defRes, "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 { switch resp.StatusCode {
case 200: case 200:
// Code 200. // Code 200.
@ -114,7 +113,7 @@ func decodeGetUserRankResponse(resp *http.Response) (res *Rank, _ error) {
} }
d := jx.DecodeBytes(buf) d := jx.DecodeBytes(buf)
var response Rank var response Submission
if err := func() error { if err := func() error {
if err := response.Decode(d); err != nil { if err := response.Decode(d); err != nil {
return err return err
@ -131,15 +130,6 @@ func decodeGetUserRankResponse(resp *http.Response) (res *Rank, _ error) {
} }
return res, err 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 return &response, nil
default: default:
return res, validate.InvalidContentType(ct) return res, validate.InvalidContentType(ct)
@ -190,7 +180,7 @@ func decodeGetUserRankResponse(resp *http.Response) (res *Rank, _ error) {
return res, errors.Wrap(defRes, "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 { switch resp.StatusCode {
case 200: case 200:
// Code 200. // Code 200.
@ -206,128 +196,11 @@ func decodeListRanksResponse(resp *http.Response) (res []Rank, _ error) {
} }
d := jx.DecodeBytes(buf) d := jx.DecodeBytes(buf)
var response []Rank var response []Submission
if err := func() error { if err := func() error {
response = make([]Rank, 0) response = make([]Submission, 0)
if err := d.Arr(func(d *jx.Decoder) error { if err := d.Arr(func(d *jx.Decoder) error {
var elem Rank var elem Submission
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
if err := elem.Decode(d); err != nil { if err := elem.Decode(d); err != nil {
return err return err
} }
@ -406,3 +279,156 @@ func decodeListTimesResponse(resp *http.Response) (res []Time, _ error) {
} }
return res, errors.Wrap(defRes, "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" 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.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200) w.WriteHeader(200)
span.SetStatus(codes.Ok, http.StatusText(200)) span.SetStatus(codes.Ok, http.StatusText(200))
@ -27,7 +27,7 @@ func encodeGetUserResponse(response *User, w http.ResponseWriter, span trace.Spa
return nil 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.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200) w.WriteHeader(200)
span.SetStatus(codes.Ok, http.StatusText(200)) span.SetStatus(codes.Ok, http.StatusText(200))
@ -41,7 +41,7 @@ func encodeGetUserRankResponse(response *Rank, w http.ResponseWriter, span trace
return nil 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.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200) w.WriteHeader(200)
span.SetStatus(codes.Ok, http.StatusText(200)) span.SetStatus(codes.Ok, http.StatusText(200))
@ -59,20 +59,23 @@ func encodeListRanksResponse(response []Rank, w http.ResponseWriter, span trace.
return nil return nil
} }
func encodeListTimesResponse(response []Time, w http.ResponseWriter, span trace.Span) error { func encodePatchSubmissionCompletedResponse(response *PatchSubmissionCompletedOK, w http.ResponseWriter, span trace.Span) error {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200) w.WriteHeader(200)
span.SetStatus(codes.Ok, http.StatusText(200)) span.SetStatus(codes.Ok, http.StatusText(200))
e := new(jx.Encoder) return nil
e.ArrStart() }
for _, elem := range response {
elem.Encode(e) func encodePatchSubmissionModelResponse(response *PatchSubmissionModelOK, w http.ResponseWriter, span trace.Span) error {
} w.WriteHeader(200)
e.ArrEnd() span.SetStatus(codes.Ok, http.StatusText(200))
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write") 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 return nil
} }

View File

@ -49,69 +49,36 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
break break
} }
switch elem[0] { switch elem[0] {
case '/': // Prefix: "/" case '/': // Prefix: "/submissions"
origElem := elem origElem := elem
if l := len("/"); len(elem) >= l && elem[0:l] == "/" { if l := len("/submissions"); len(elem) >= l && elem[0:l] == "/submissions" {
elem = elem[l:] elem = elem[l:]
} else { } else {
break break
} }
if len(elem) == 0 { if len(elem) == 0 {
break 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] { switch elem[0] {
case 'r': // Prefix: "ranks" case '/': // Prefix: "/"
origElem := elem origElem := elem
if l := len("ranks"); len(elem) >= l && elem[0:l] == "ranks" { if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
elem = elem[l:] elem = elem[l:]
} else { } else {
break break
} }
if len(elem) == 0 { // Param: "SubmissionID"
// Leaf node.
switch r.Method {
case "GET":
s.handleListRanksRequest([0]string{}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "GET")
}
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 r.Method {
case "GET":
s.handleListTimesRequest([0]string{}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "GET")
}
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 "/" // Match until "/"
idx := strings.IndexByte(elem, '/') idx := strings.IndexByte(elem, '/')
if idx < 0 { if idx < 0 {
@ -123,7 +90,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if len(elem) == 0 { if len(elem) == 0 {
switch r.Method { switch r.Method {
case "GET": case "GET":
s.handleGetUserRequest([1]string{ s.handleGetSubmissionRequest([1]string{
args[0], args[0],
}, elemIsEscaped, w, r) }, elemIsEscaped, w, r)
default: default:
@ -133,26 +100,87 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
switch elem[0] { switch elem[0] {
case '/': // Prefix: "/rank" case '/': // Prefix: "/"
origElem := elem origElem := elem
if l := len("/rank"); len(elem) >= l && elem[0:l] == "/rank" { if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
elem = elem[l:] elem = elem[l:]
} else { } else {
break break
} }
if len(elem) == 0 { if len(elem) == 0 {
// Leaf node. break
switch r.Method { }
case "GET": switch elem[0] {
s.handleGetUserRankRequest([1]string{ case 'c': // Prefix: "completed"
args[0], origElem := elem
}, elemIsEscaped, w, r) if l := len("completed"); len(elem) >= l && elem[0:l] == "completed" {
default: elem = elem[l:]
s.notAllowed(w, r, "GET") } else {
break
} }
return if len(elem) == 0 {
// Leaf node.
switch r.Method {
case "PATCH":
s.handlePatchSubmissionCompletedRequest([1]string{
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "PATCH")
}
return
}
elem = origElem
case 'm': // Prefix: "model"
origElem := elem
if l := len("model"); len(elem) >= l && elem[0:l] == "model" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch r.Method {
case "PATCH":
s.handlePatchSubmissionModelRequest([1]string{
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "PATCH")
}
return
}
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 r.Method {
case "PATCH":
s.handlePatchSubmissionStatusRequest([1]string{
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "PATCH")
}
return
}
elem = origElem
} }
elem = origElem elem = origElem
@ -242,77 +270,46 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
break break
} }
switch elem[0] { switch elem[0] {
case '/': // Prefix: "/" case '/': // Prefix: "/submissions"
origElem := elem origElem := elem
if l := len("/"); len(elem) >= l && elem[0:l] == "/" { if l := len("/submissions"); len(elem) >= l && elem[0:l] == "/submissions" {
elem = elem[l:] elem = elem[l:]
} else { } else {
break break
} }
if len(elem) == 0 { if len(elem) == 0 {
break 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] { switch elem[0] {
case 'r': // Prefix: "ranks" case '/': // Prefix: "/"
origElem := elem origElem := elem
if l := len("ranks"); len(elem) >= l && elem[0:l] == "ranks" { if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
elem = elem[l:] elem = elem[l:]
} else { } else {
break break
} }
if len(elem) == 0 { // Param: "SubmissionID"
// 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 "/" // Match until "/"
idx := strings.IndexByte(elem, '/') idx := strings.IndexByte(elem, '/')
if idx < 0 { if idx < 0 {
@ -324,10 +321,10 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
if len(elem) == 0 { if len(elem) == 0 {
switch method { switch method {
case "GET": case "GET":
r.name = "GetUser" r.name = "GetSubmission"
r.summary = "Retrieve user with ID" r.summary = "Retrieve map with ID"
r.operationID = "getUser" r.operationID = "getSubmission"
r.pathPattern = "/users/{UserID}" r.pathPattern = "/submissions/{SubmissionID}"
r.args = args r.args = args
r.count = 1 r.count = 1
return r, true return r, true
@ -336,28 +333,93 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
} }
} }
switch elem[0] { switch elem[0] {
case '/': // Prefix: "/rank" case '/': // Prefix: "/"
origElem := elem origElem := elem
if l := len("/rank"); len(elem) >= l && elem[0:l] == "/rank" { if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
elem = elem[l:] elem = elem[l:]
} else { } else {
break break
} }
if len(elem) == 0 { if len(elem) == 0 {
// Leaf node. break
switch method { }
case "GET": switch elem[0] {
r.name = "GetUserRank" case 'c': // Prefix: "completed"
r.summary = "Retrieve rank of user" origElem := elem
r.operationID = "getUserRank" if l := len("completed"); len(elem) >= l && elem[0:l] == "completed" {
r.pathPattern = "/users/{UserID}/rank" elem = elem[l:]
r.args = args } else {
r.count = 1 break
return r, true
default:
return
} }
if len(elem) == 0 {
// Leaf node.
switch method {
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
default:
return
}
}
elem = origElem
case 'm': // Prefix: "model"
origElem := elem
if l := len("model"); len(elem) >= l && elem[0:l] == "model" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch method {
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
default:
return
}
}
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 elem = origElem

View File

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

View File

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

View File

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

View File

@ -121,167 +121,8 @@ func (s *Pagination) DecodeURI(d uri.Decoder) error {
return nil return nil
} }
// EncodeURI encodes RankFilter as URI form. // EncodeURI encodes SubmissionFilter as URI form.
func (s *RankFilter) EncodeURI(e uri.Encoder) error { func (s *SubmissionFilter) 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 {
if err := e.EncodeField("ID", func(e uri.Encoder) error { if err := e.EncodeField("ID", func(e uri.Encoder) error {
if val, ok := s.ID.Get(); ok { if val, ok := s.ID.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val)) return e.EncodeValue(conv.Int64ToString(val))
@ -290,45 +131,21 @@ func (s *TimeFilter) EncodeURI(e uri.Encoder) error {
}); err != nil { }); err != nil {
return errors.Wrap(err, "encode field \"ID\"") return errors.Wrap(err, "encode field \"ID\"")
} }
if err := e.EncodeField("Time", func(e uri.Encoder) error { if err := e.EncodeField("DisplayName", func(e uri.Encoder) error {
if val, ok := s.Time.Get(); ok { if val, ok := s.DisplayName.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val)) return e.EncodeValue(conv.StringToString(val))
} }
return nil return nil
}); err != 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 err := e.EncodeField("Creator", func(e uri.Encoder) error {
if val, ok := s.UserID.Get(); ok { if val, ok := s.Creator.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val)) return e.EncodeValue(conv.StringToString(val))
} }
return nil return nil
}); err != nil { }); err != nil {
return errors.Wrap(err, "encode field \"UserID\"") return errors.Wrap(err, "encode field \"Creator\"")
}
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\"")
} }
if err := e.EncodeField("GameID", func(e uri.Encoder) error { if err := e.EncodeField("GameID", func(e uri.Encoder) error {
if val, ok := s.GameID.Get(); ok { if val, ok := s.GameID.Get(); ok {
@ -338,23 +155,29 @@ func (s *TimeFilter) EncodeURI(e uri.Encoder) error {
}); err != nil { }); err != nil {
return errors.Wrap(err, "encode field \"GameID\"") 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 return nil
} }
var uriFieldsNameOfTimeFilter = [7]string{ var uriFieldsNameOfSubmissionFilter = [5]string{
0: "ID", 0: "ID",
1: "Time", 1: "DisplayName",
2: "UserID", 2: "Creator",
3: "MapID", 3: "GameID",
4: "StyleID", 4: "Date",
5: "ModeID",
6: "GameID",
} }
// DecodeURI decodes TimeFilter from URI form. // DecodeURI decodes SubmissionFilter from URI form.
func (s *TimeFilter) DecodeURI(d uri.Decoder) error { func (s *SubmissionFilter) DecodeURI(d uri.Decoder) error {
if s == nil { 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 { 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 { }(); err != nil {
return errors.Wrap(err, "decode field \"ID\"") return errors.Wrap(err, "decode field \"ID\"")
} }
case "Time": case "DisplayName":
if err := func() error { if err := func() error {
var sDotTimeVal int64 var sDotDisplayNameVal string
if err := func() error { if err := func() error {
val, err := d.DecodeValue() val, err := d.DecodeValue()
if err != nil { if err != nil {
return err return err
} }
c, err := conv.ToInt64(val) c, err := conv.ToString(val)
if err != nil { if err != nil {
return err return err
} }
sDotTimeVal = c sDotDisplayNameVal = c
return nil return nil
}(); err != nil { }(); err != nil {
return err return err
} }
s.Time.SetTo(sDotTimeVal) s.DisplayName.SetTo(sDotDisplayNameVal)
return nil return nil
}(); err != 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 { if err := func() error {
var sDotUserIDVal int64 var sDotCreatorVal string
if err := func() error { if err := func() error {
val, err := d.DecodeValue() val, err := d.DecodeValue()
if err != nil { if err != nil {
return err return err
} }
c, err := conv.ToInt64(val) c, err := conv.ToString(val)
if err != nil { if err != nil {
return err return err
} }
sDotUserIDVal = c sDotCreatorVal = c
return nil return nil
}(); err != nil { }(); err != nil {
return err return err
} }
s.UserID.SetTo(sDotUserIDVal) s.Creator.SetTo(sDotCreatorVal)
return nil return nil
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"UserID\"") return errors.Wrap(err, "decode field \"Creator\"")
}
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\"")
} }
case "GameID": case "GameID":
if err := func() error { if err := func() error {
@ -527,12 +278,36 @@ func (s *TimeFilter) DecodeURI(d uri.Decoder) error {
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"GameID\"") 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: default:
return nil return nil
} }
return nil return nil
}); err != nil { }); err != nil {
return errors.Wrap(err, "decode TimeFilter") return errors.Wrap(err, "decode SubmissionFilter")
} }
return nil return nil

View File

@ -59,51 +59,3 @@ func (s *Pagination) Validate() error {
} }
return nil 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
}