diff --git a/openapi.yaml b/openapi.yaml index d638862..cce218b 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -515,7 +515,8 @@ components: - DisplayName - Creator - GameID - - Date + - CreatedAt + - UpdatedAt - Submitter - AssetID - AssetVersion @@ -537,7 +538,10 @@ components: GameID: type: integer format: int32 - Date: + CreatedAt: + type: integer + format: int64 + UpdatedAt: type: integer format: int64 Submitter: @@ -577,9 +581,6 @@ components: GameID: type: integer format: int32 - Date: - type: integer - format: int64 SubmissionCreate: required: - DisplayName diff --git a/pkg/api/oas_json_gen.go b/pkg/api/oas_json_gen.go index 2b70ed3..3e51c3a 100644 --- a/pkg/api/oas_json_gen.go +++ b/pkg/api/oas_json_gen.go @@ -1166,8 +1166,12 @@ func (s *Submission) encodeFields(e *jx.Encoder) { e.Int32(s.GameID) } { - e.FieldStart("Date") - e.Int64(s.Date) + e.FieldStart("CreatedAt") + e.Int64(s.CreatedAt) + } + { + e.FieldStart("UpdatedAt") + e.Int64(s.UpdatedAt) } { e.FieldStart("Submitter") @@ -1201,19 +1205,20 @@ func (s *Submission) encodeFields(e *jx.Encoder) { } } -var jsonFieldsNameOfSubmission = [12]string{ +var jsonFieldsNameOfSubmission = [13]string{ 0: "ID", 1: "DisplayName", 2: "Creator", 3: "GameID", - 4: "Date", - 5: "Submitter", - 6: "AssetID", - 7: "AssetVersion", - 8: "Completed", - 9: "SubmissionType", - 10: "TargetAssetID", - 11: "StatusID", + 4: "CreatedAt", + 5: "UpdatedAt", + 6: "Submitter", + 7: "AssetID", + 8: "AssetVersion", + 9: "Completed", + 10: "SubmissionType", + 11: "TargetAssetID", + 12: "StatusID", } // Decode decodes Submission from json. @@ -1273,20 +1278,32 @@ func (s *Submission) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"GameID\"") } - case "Date": + case "CreatedAt": requiredBitSet[0] |= 1 << 4 if err := func() error { v, err := d.Int64() - s.Date = int64(v) + s.CreatedAt = int64(v) if err != nil { return err } return nil }(); err != nil { - return errors.Wrap(err, "decode field \"Date\"") + return errors.Wrap(err, "decode field \"CreatedAt\"") + } + case "UpdatedAt": + requiredBitSet[0] |= 1 << 5 + if err := func() error { + v, err := d.Int64() + s.UpdatedAt = int64(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"UpdatedAt\"") } case "Submitter": - requiredBitSet[0] |= 1 << 5 + requiredBitSet[0] |= 1 << 6 if err := func() error { v, err := d.Int64() s.Submitter = int64(v) @@ -1298,7 +1315,7 @@ func (s *Submission) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"Submitter\"") } case "AssetID": - requiredBitSet[0] |= 1 << 6 + requiredBitSet[0] |= 1 << 7 if err := func() error { v, err := d.Int64() s.AssetID = int64(v) @@ -1310,7 +1327,7 @@ func (s *Submission) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"AssetID\"") } case "AssetVersion": - requiredBitSet[0] |= 1 << 7 + requiredBitSet[1] |= 1 << 0 if err := func() error { v, err := d.Int64() s.AssetVersion = int64(v) @@ -1322,7 +1339,7 @@ func (s *Submission) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"AssetVersion\"") } case "Completed": - requiredBitSet[1] |= 1 << 0 + requiredBitSet[1] |= 1 << 1 if err := func() error { v, err := d.Bool() s.Completed = bool(v) @@ -1334,7 +1351,7 @@ func (s *Submission) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"Completed\"") } case "SubmissionType": - requiredBitSet[1] |= 1 << 1 + requiredBitSet[1] |= 1 << 2 if err := func() error { v, err := d.Int32() s.SubmissionType = int32(v) @@ -1356,7 +1373,7 @@ func (s *Submission) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"TargetAssetID\"") } case "StatusID": - requiredBitSet[1] |= 1 << 3 + requiredBitSet[1] |= 1 << 4 if err := func() error { v, err := d.Int32() s.StatusID = int32(v) @@ -1378,7 +1395,7 @@ func (s *Submission) Decode(d *jx.Decoder) error { var failures []validate.FieldError for i, mask := range [2]uint8{ 0b11111111, - 0b00001011, + 0b00010111, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. diff --git a/pkg/api/oas_parameters_gen.go b/pkg/api/oas_parameters_gen.go index 41b3903..1ee7167 100644 --- a/pkg/api/oas_parameters_gen.go +++ b/pkg/api/oas_parameters_gen.go @@ -1022,7 +1022,7 @@ func decodeListSubmissionsParams(args [0]string, argsEscaped bool, r *http.Reque Name: "filter", Style: uri.QueryStyleForm, Explode: true, - Fields: []uri.QueryParameterObjectField{{Name: "ID", Required: true}, {Name: "DisplayName", Required: false}, {Name: "Creator", Required: false}, {Name: "GameID", Required: false}, {Name: "Date", Required: false}}, + Fields: []uri.QueryParameterObjectField{{Name: "ID", Required: true}, {Name: "DisplayName", Required: false}, {Name: "Creator", Required: false}, {Name: "GameID", Required: false}}, } if err := q.HasParam(cfg); err == nil { diff --git a/pkg/api/oas_schemas_gen.go b/pkg/api/oas_schemas_gen.go index 739d439..2ba4e30 100644 --- a/pkg/api/oas_schemas_gen.go +++ b/pkg/api/oas_schemas_gen.go @@ -585,7 +585,8 @@ type Submission struct { DisplayName string `json:"DisplayName"` Creator string `json:"Creator"` GameID int32 `json:"GameID"` - Date int64 `json:"Date"` + CreatedAt int64 `json:"CreatedAt"` + UpdatedAt int64 `json:"UpdatedAt"` Submitter int64 `json:"Submitter"` AssetID int64 `json:"AssetID"` AssetVersion int64 `json:"AssetVersion"` @@ -615,9 +616,14 @@ func (s *Submission) GetGameID() int32 { return s.GameID } -// GetDate returns the value of Date. -func (s *Submission) GetDate() int64 { - return s.Date +// GetCreatedAt returns the value of CreatedAt. +func (s *Submission) GetCreatedAt() int64 { + return s.CreatedAt +} + +// GetUpdatedAt returns the value of UpdatedAt. +func (s *Submission) GetUpdatedAt() int64 { + return s.UpdatedAt } // GetSubmitter returns the value of Submitter. @@ -675,9 +681,14 @@ func (s *Submission) SetGameID(val int32) { s.GameID = val } -// SetDate sets the value of Date. -func (s *Submission) SetDate(val int64) { - s.Date = val +// SetCreatedAt sets the value of CreatedAt. +func (s *Submission) SetCreatedAt(val int64) { + s.CreatedAt = val +} + +// SetUpdatedAt sets the value of UpdatedAt. +func (s *Submission) SetUpdatedAt(val int64) { + s.UpdatedAt = val } // SetSubmitter sets the value of Submitter. @@ -791,7 +802,6 @@ type SubmissionFilter struct { DisplayName OptString `json:"DisplayName"` Creator OptString `json:"Creator"` GameID OptInt32 `json:"GameID"` - Date OptInt64 `json:"Date"` } // GetID returns the value of ID. @@ -814,11 +824,6 @@ func (s *SubmissionFilter) GetGameID() OptInt32 { return s.GameID } -// GetDate returns the value of Date. -func (s *SubmissionFilter) GetDate() OptInt64 { - return s.Date -} - // SetID sets the value of ID. func (s *SubmissionFilter) SetID(val int64) { s.ID = val @@ -839,11 +844,6 @@ func (s *SubmissionFilter) SetGameID(val OptInt32) { s.GameID = val } -// SetDate sets the value of Date. -func (s *SubmissionFilter) SetDate(val OptInt64) { - s.Date = val -} - // UpdateScriptOK is response for UpdateScript operation. type UpdateScriptOK struct{} diff --git a/pkg/api/oas_uri_gen.go b/pkg/api/oas_uri_gen.go index c5ae0d3..e80687d 100644 --- a/pkg/api/oas_uri_gen.go +++ b/pkg/api/oas_uri_gen.go @@ -152,23 +152,14 @@ func (s *SubmissionFilter) EncodeURI(e uri.Encoder) error { }); err != nil { return errors.Wrap(err, "encode field \"GameID\"") } - if err := e.EncodeField("Date", func(e uri.Encoder) error { - if val, ok := s.Date.Get(); ok { - return e.EncodeValue(conv.Int64ToString(val)) - } - return nil - }); err != nil { - return errors.Wrap(err, "encode field \"Date\"") - } return nil } -var uriFieldsNameOfSubmissionFilter = [5]string{ +var uriFieldsNameOfSubmissionFilter = [4]string{ 0: "ID", 1: "DisplayName", 2: "Creator", 3: "GameID", - 4: "Date", } // DecodeURI decodes SubmissionFilter from URI form. @@ -270,30 +261,6 @@ func (s *SubmissionFilter) DecodeURI(d uri.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"GameID\"") } - case "Date": - if err := func() error { - var sDotDateVal int64 - if err := func() error { - val, err := d.DecodeValue() - if err != nil { - return err - } - - c, err := conv.ToInt64(val) - if err != nil { - return err - } - - sDotDateVal = c - return nil - }(); err != nil { - return err - } - s.Date.SetTo(sDotDateVal) - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"Date\"") - } default: return nil } diff --git a/pkg/model/policy.go b/pkg/model/policy.go index 2f13b4a..c1ff56e 100644 --- a/pkg/model/policy.go +++ b/pkg/model/policy.go @@ -1,5 +1,7 @@ package model +import "time" + type Policy int32 const( @@ -10,7 +12,7 @@ const( ) type ScriptPolicy struct { - ID int64 + ID int64 `gorm:"primaryKey"` // Hash of the source code that leads to this policy. // If this is a replacement mapping, the original source may not be pointed to by any policy. // The original source should still exist in the scripts table, which can be located by the same hash. @@ -20,4 +22,6 @@ type ScriptPolicy struct { // or 0 (other) ToScriptID int64 Policy Policy + CreatedAt time.Time + UpdatedAt time.Time } diff --git a/pkg/model/script.go b/pkg/model/script.go index 6d1b83f..f9a088b 100644 --- a/pkg/model/script.go +++ b/pkg/model/script.go @@ -1,8 +1,12 @@ package model +import "time" + type Script struct { - ID int64 + ID int64 `gorm:"primaryKey"` Hash uint64 Source string SubmissionID int64 // which submission did this script first appear in + CreatedAt time.Time + UpdatedAt time.Time } diff --git a/pkg/model/submission.go b/pkg/model/submission.go index 8b28743..5fb5a91 100644 --- a/pkg/model/submission.go +++ b/pkg/model/submission.go @@ -19,11 +19,12 @@ const( ) type Submission struct { - ID int64 + ID int64 `gorm:"primaryKey"` DisplayName string Creator string GameID int32 - Date time.Time + CreatedAt time.Time + UpdatedAt time.Time Submitter int64 // UserID AssetID int64 AssetVersion int64 diff --git a/pkg/service/submissions.go b/pkg/service/submissions.go index 4f2945c..bc595d6 100644 --- a/pkg/service/submissions.go +++ b/pkg/service/submissions.go @@ -1,7 +1,6 @@ package service import ( - "time" "errors" "context" "git.itzana.me/strafesnet/maps-service/pkg/api" @@ -26,7 +25,6 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio DisplayName: request.DisplayName, Creator: request.Creator, GameID: request.GameID, - Date: time.Now(), Submitter: int64(userInfo.UserID), AssetID: request.AssetID, AssetVersion: request.AssetVersion, @@ -57,7 +55,8 @@ func (svc *Service) GetSubmission(ctx context.Context, params api.GetSubmissionP DisplayName: submission.DisplayName, Creator: submission.Creator, GameID: submission.GameID, - Date: submission.Date.Unix(), + CreatedAt: submission.CreatedAt.Unix(), + UpdatedAt: submission.UpdatedAt.Unix(), Submitter: submission.Submitter, AssetID: submission.AssetID, AssetVersion: submission.AssetVersion, @@ -96,7 +95,8 @@ func (svc *Service) ListSubmissions(ctx context.Context, request api.ListSubmiss DisplayName: items[i].DisplayName, Creator: items[i].Creator, GameID: items[i].GameID, - Date: items[i].Date.Unix(), + CreatedAt: items[i].CreatedAt.Unix(), + UpdatedAt: items[i].UpdatedAt.Unix(), Submitter: items[i].Submitter, AssetID: items[i].AssetID, AssetVersion: items[i].AssetVersion,