diff --git a/pkg/model/nats.go b/pkg/model/nats.go index 9e92cce..44d3cae 100644 --- a/pkg/model/nats.go +++ b/pkg/model/nats.go @@ -8,22 +8,22 @@ package model type ValidateRequest struct { // submission_id is passed back in the response message SubmissionID int64 - ModelID uint64 - ModelVersion uint64 - ValidatedModelID uint64 // optional value + ModelID int64 + ModelVersion int64 + ValidatedModelID int64 // optional value } // Create a new map type PublishNewRequest struct { SubmissionID int64 - ModelID uint64 - ModelVersion uint64 + ModelID int64 + ModelVersion int64 ModelName string } type PublishFixRequest struct { SubmissionID int64 - ModelID uint64 - ModelVersion uint64 - TargetAssetID uint64 + ModelID int64 + ModelVersion int64 + TargetAssetID int64 } diff --git a/pkg/model/policy.go b/pkg/model/policy.go index 41e7dfd..d63a5a6 100644 --- a/pkg/model/policy.go +++ b/pkg/model/policy.go @@ -17,7 +17,7 @@ type ScriptPolicy struct { // 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. - FromScriptHash uint64 + FromScriptHash int64 // postgres does not support unsigned integers, so we have to pretend // The ID of the replacement source (ScriptPolicyReplace) // or verbatim source (ScriptPolicyAllowed) // or 0 (other) diff --git a/pkg/model/script.go b/pkg/model/script.go index 5989bee..e736c98 100644 --- a/pkg/model/script.go +++ b/pkg/model/script.go @@ -26,7 +26,7 @@ func HashParse(hash string) (uint64, error){ type Script struct { ID int64 `gorm:"primaryKey"` Name string - Hash uint64 + Hash int64 // postgres does not support unsigned integers, so we have to pretend Source string SubmissionID int64 // which submission did this script first appear in CreatedAt time.Time diff --git a/pkg/model/submission.go b/pkg/model/submission.go index ed283fc..3cc74b1 100644 --- a/pkg/model/submission.go +++ b/pkg/model/submission.go @@ -29,10 +29,10 @@ type Submission struct { GameID int32 CreatedAt time.Time UpdatedAt time.Time - Submitter uint64 // UserID - AssetID uint64 - AssetVersion uint64 + Submitter int64 // UserID + AssetID int64 + AssetVersion int64 Completed bool // Has this version of the map been completed at least once on maptest - TargetAssetID uint64 // where to upload map fix. if the TargetAssetID is 0, it's a new map. + TargetAssetID int64 // where to upload map fix. if the TargetAssetID is 0, it's a new map. StatusID Status } diff --git a/pkg/service/script_policy.go b/pkg/service/script_policy.go index 9655cc2..fcd7b5f 100644 --- a/pkg/service/script_policy.go +++ b/pkg/service/script_policy.go @@ -59,7 +59,7 @@ func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptP if err != nil { return nil, err } - filter.AddNotNil("from_script_hash", hash) + filter.AddNotNil("from_script_hash", int64(hash)) // No type safety! } if params.ToScriptID.IsSet(){ filter.AddNotNil("to_script_id", params.ToScriptID.Value) @@ -80,7 +80,7 @@ func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptP for i := 0; i < len(items); i++ { resp = append(resp, api.ScriptPolicy{ ID: items[i].ID, - FromScriptHash: model.HashFormat(items[i].FromScriptHash), + FromScriptHash: model.HashFormat(uint64(items[i].FromScriptHash)), ToScriptID: items[i].ToScriptID, Policy: int32(items[i].Policy), }) @@ -127,7 +127,7 @@ func (svc *Service) GetScriptPolicy(ctx context.Context, params api.GetScriptPol return &api.ScriptPolicy{ ID: policy.ID, - FromScriptHash: model.HashFormat(policy.FromScriptHash), + FromScriptHash: model.HashFormat(uint64(policy.FromScriptHash)), ToScriptID: policy.ToScriptID, Policy: int32(policy.Policy), }, nil diff --git a/pkg/service/scripts.go b/pkg/service/scripts.go index 6dfa8ce..6be5ed9 100644 --- a/pkg/service/scripts.go +++ b/pkg/service/scripts.go @@ -26,7 +26,7 @@ func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*a script, err := svc.DB.Scripts().Create(ctx, model.Script{ ID: 0, Name: req.Name, - Hash: model.HashSource(req.Source), + Hash: int64(model.HashSource(req.Source)), Source: req.Source, SubmissionID: req.SubmissionID.Or(0), }) @@ -52,7 +52,7 @@ func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParam if err != nil { return nil, err } - filter.AddNotNil("hash", hash) + filter.AddNotNil("hash", int64(hash)) // No type safety! } if params.Name.IsSet(){ filter.AddNotNil("name", params.Name.Value) @@ -76,7 +76,7 @@ func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParam for i := 0; i < len(items); i++ { resp = append(resp, api.Script{ ID: items[i].ID, - Hash: model.HashFormat(items[i].Hash), + Hash: model.HashFormat(uint64(items[i].Hash)), Source: items[i].Source, SubmissionID: items[i].SubmissionID, }) @@ -124,7 +124,7 @@ func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) ( return &api.Script{ ID: script.ID, Name: script.Name, - Hash: model.HashFormat(script.Hash), + Hash: model.HashFormat(uint64(script.Hash)), Source: script.Source, SubmissionID: script.SubmissionID, }, nil @@ -151,7 +151,7 @@ func (svc *Service) UpdateScript(ctx context.Context, req *api.ScriptUpdate, par } if source, ok := req.Source.Get(); ok { pmap.Add("source", source) - pmap.Add("hash", model.HashSource(source)) + pmap.Add("hash", int64(model.HashSource(source))) // No type safety! } if SubmissionID, ok := req.SubmissionID.Get(); ok { pmap.Add("submission_id", SubmissionID) diff --git a/pkg/service/submissions.go b/pkg/service/submissions.go index 5e2651a..8fd1f4d 100644 --- a/pkg/service/submissions.go +++ b/pkg/service/submissions.go @@ -21,11 +21,11 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio DisplayName: request.DisplayName, Creator: request.Creator, GameID: request.GameID, - Submitter: userInfo.UserID, - AssetID: uint64(request.AssetID), - AssetVersion: uint64(request.AssetVersion), + Submitter: int64(userInfo.UserID), + AssetID: request.AssetID, + AssetVersion: request.AssetVersion, Completed: false, - TargetAssetID: uint64(request.TargetAssetID.Value), + TargetAssetID: request.TargetAssetID.Value, StatusID: model.StatusUnderConstruction, }) if err != nil { @@ -149,7 +149,7 @@ func (svc *Service) UpdateSubmissionModel(ctx context.Context, params api.Update } // check if caller is the submitter - if !userInfo.IsSubmitter(submission.Submitter) { + if !userInfo.IsSubmitter(uint64(submission.Submitter)) { return ErrPermissionDenied } @@ -224,7 +224,7 @@ func (svc *Service) ActionSubmissionRevoke(ctx context.Context, params api.Actio } // check if caller is the submitter - if !userInfo.IsSubmitter(submission.Submitter) { + if !userInfo.IsSubmitter(uint64(submission.Submitter)) { return ErrPermissionDenied } @@ -252,7 +252,7 @@ func (svc *Service) ActionSubmissionSubmit(ctx context.Context, params api.Actio } // check if caller is the submitter - if !userInfo.IsSubmitter(submission.Submitter) { + if !userInfo.IsSubmitter(uint64(submission.Submitter)) { return ErrPermissionDenied } diff --git a/pkg/service_internal/script_policy.go b/pkg/service_internal/script_policy.go index f2a7160..6c97514 100644 --- a/pkg/service_internal/script_policy.go +++ b/pkg/service_internal/script_policy.go @@ -49,7 +49,7 @@ func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptP if err != nil { return nil, err } - filter.AddNotNil("from_script_hash", hash) + filter.AddNotNil("from_script_hash", int64(hash)) // No type safety! } if params.ToScriptID.IsSet(){ filter.AddNotNil("to_script_id", params.ToScriptID.Value) @@ -70,7 +70,7 @@ func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptP for i := 0; i < len(items); i++ { resp = append(resp, api.ScriptPolicy{ ID: items[i].ID, - FromScriptHash: model.HashFormat(items[i].FromScriptHash), + FromScriptHash: model.HashFormat(uint64(items[i].FromScriptHash)), ToScriptID: items[i].ToScriptID, Policy: int32(items[i].Policy), }) diff --git a/pkg/service_internal/scripts.go b/pkg/service_internal/scripts.go index 1680f57..44bb494 100644 --- a/pkg/service_internal/scripts.go +++ b/pkg/service_internal/scripts.go @@ -17,7 +17,7 @@ func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*a script, err := svc.DB.Scripts().Create(ctx, model.Script{ ID: 0, Name: req.Name, - Hash: model.HashSource(req.Source), + Hash: int64(model.HashSource(req.Source)), Source: req.Source, SubmissionID: req.SubmissionID.Or(0), }) @@ -43,7 +43,7 @@ func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParam if err != nil { return nil, err } - filter.AddNotNil("hash", hash) + filter.AddNotNil("hash", int64(hash)) // No type safety! } if params.Name.IsSet(){ filter.AddNotNil("name", params.Name.Value) @@ -67,7 +67,7 @@ func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParam for i := 0; i < len(items); i++ { resp = append(resp, api.Script{ ID: items[i].ID, - Hash: model.HashFormat(items[i].Hash), + Hash: model.HashFormat(uint64(items[i].Hash)), Source: items[i].Source, SubmissionID: items[i].SubmissionID, }) @@ -90,7 +90,7 @@ func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) ( return &api.Script{ ID: script.ID, Name: script.Name, - Hash: model.HashFormat(script.Hash), + Hash: model.HashFormat(uint64(script.Hash)), Source: script.Source, SubmissionID: script.SubmissionID, }, nil