change api to do IdMessage

This commit is contained in:
Quaternions 2024-11-27 16:13:43 -08:00
parent f87c4dab8f
commit f7aff4bbaa
10 changed files with 96 additions and 12 deletions

View File

@ -62,7 +62,7 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/Submission" $ref: "#/components/schemas/Id"
default: default:
description: General Error description: General Error
content: content:
@ -186,6 +186,12 @@ paths:
$ref: "#/components/schemas/Error" $ref: "#/components/schemas/Error"
components: components:
schemas: schemas:
Id:
type: object
properties:
ID:
type: integer
format: int64
User: User:
type: object type: object
properties: properties:

View File

@ -28,7 +28,7 @@ type Invoker interface {
// Create new submission. // Create new submission.
// //
// POST /submissions // POST /submissions
CreateSubmission(ctx context.Context) (*Submission, error) CreateSubmission(ctx context.Context) (*ID, error)
// GetSubmission invokes getSubmission operation. // GetSubmission invokes getSubmission operation.
// //
// Retrieve map with ID. // Retrieve map with ID.
@ -118,12 +118,12 @@ func (c *Client) requestURL(ctx context.Context) *url.URL {
// Create new submission. // Create new submission.
// //
// POST /submissions // POST /submissions
func (c *Client) CreateSubmission(ctx context.Context) (*Submission, error) { func (c *Client) CreateSubmission(ctx context.Context) (*ID, error) {
res, err := c.sendCreateSubmission(ctx) res, err := c.sendCreateSubmission(ctx)
return res, err return res, err
} }
func (c *Client) sendCreateSubmission(ctx context.Context) (res *Submission, err error) { func (c *Client) sendCreateSubmission(ctx context.Context) (res *ID, err error) {
otelAttrs := []attribute.KeyValue{ otelAttrs := []attribute.KeyValue{
otelogen.OperationID("createSubmission"), otelogen.OperationID("createSubmission"),
semconv.HTTPRequestMethodKey.String("POST"), semconv.HTTPRequestMethodKey.String("POST"),

View File

@ -65,7 +65,7 @@ func (s *Server) handleCreateSubmissionRequest(args [0]string, argsEscaped bool,
err error err error
) )
var response *Submission var response *ID
if m := s.cfg.Middleware; m != nil { if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{ mreq := middleware.Request{
Context: ctx, Context: ctx,
@ -80,7 +80,7 @@ func (s *Server) handleCreateSubmissionRequest(args [0]string, argsEscaped bool,
type ( type (
Request = struct{} Request = struct{}
Params = struct{} Params = struct{}
Response = *Submission Response = *ID
) )
response, err = middleware.HookMiddleware[ response, err = middleware.HookMiddleware[
Request, Request,

View File

@ -125,6 +125,69 @@ func (s *Error) UnmarshalJSON(data []byte) error {
return s.Decode(d) return s.Decode(d)
} }
// Encode implements json.Marshaler.
func (s *ID) Encode(e *jx.Encoder) {
e.ObjStart()
s.encodeFields(e)
e.ObjEnd()
}
// encodeFields encodes fields.
func (s *ID) encodeFields(e *jx.Encoder) {
{
if s.ID.Set {
e.FieldStart("ID")
s.ID.Encode(e)
}
}
}
var jsonFieldsNameOfID = [1]string{
0: "ID",
}
// Decode decodes ID from json.
func (s *ID) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ID 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\"")
}
default:
return d.Skip()
}
return nil
}); err != nil {
return errors.Wrap(err, "decode ID")
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *ID) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ID) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes bool as json. // Encode encodes bool as json.
func (o OptBool) Encode(e *jx.Encoder) { func (o OptBool) Encode(e *jx.Encoder) {
if !o.Set { if !o.Set {

View File

@ -14,7 +14,7 @@ import (
"github.com/ogen-go/ogen/validate" "github.com/ogen-go/ogen/validate"
) )
func decodeCreateSubmissionResponse(resp *http.Response) (res *Submission, _ error) { func decodeCreateSubmissionResponse(resp *http.Response) (res *ID, _ error) {
switch resp.StatusCode { switch resp.StatusCode {
case 200: case 200:
// Code 200. // Code 200.
@ -30,7 +30,7 @@ func decodeCreateSubmissionResponse(resp *http.Response) (res *Submission, _ err
} }
d := jx.DecodeBytes(buf) d := jx.DecodeBytes(buf)
var response Submission var response ID
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

View File

@ -13,7 +13,7 @@ import (
ht "github.com/ogen-go/ogen/http" ht "github.com/ogen-go/ogen/http"
) )
func encodeCreateSubmissionResponse(response *Submission, w http.ResponseWriter, span trace.Span) error { func encodeCreateSubmissionResponse(response *ID, 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))

View File

@ -63,6 +63,21 @@ func (s *ErrorStatusCode) SetResponse(val Error) {
s.Response = val s.Response = val
} }
// Ref: #/components/schemas/Id
type ID struct {
ID OptInt64 `json:"ID"`
}
// GetID returns the value of ID.
func (s *ID) GetID() OptInt64 {
return s.ID
}
// SetID sets the value of ID.
func (s *ID) SetID(val OptInt64) {
s.ID = val
}
// NewOptBool returns new OptBool with value set to v. // NewOptBool returns new OptBool with value set to v.
func NewOptBool(v bool) OptBool { func NewOptBool(v bool) OptBool {
return OptBool{ return OptBool{

View File

@ -13,7 +13,7 @@ type Handler interface {
// Create new submission. // Create new submission.
// //
// POST /submissions // POST /submissions
CreateSubmission(ctx context.Context) (*Submission, error) CreateSubmission(ctx context.Context) (*ID, error)
// GetSubmission implements getSubmission operation. // GetSubmission implements getSubmission operation.
// //
// Retrieve map with ID. // Retrieve map with ID.

View File

@ -18,7 +18,7 @@ var _ Handler = UnimplementedHandler{}
// Create new submission. // Create new submission.
// //
// POST /submissions // POST /submissions
func (UnimplementedHandler) CreateSubmission(ctx context.Context) (r *Submission, _ error) { func (UnimplementedHandler) CreateSubmission(ctx context.Context) (r *ID, _ error) {
return r, ht.ErrNotImplemented return r, ht.ErrNotImplemented
} }

View File

@ -6,7 +6,7 @@ import (
) )
// POST /submissions // POST /submissions
func (svc *Service) CreateSubmission(ctx context.Context) (*api.Submission, error) { func (svc *Service) CreateSubmission(ctx context.Context) (*api.ID, error) {
return nil, nil return nil, nil
} }