renaming and fixing red underlines

This commit is contained in:
Quaternions 2024-11-26 14:37:18 -08:00
parent 7485729fd0
commit a5009998a8
6 changed files with 45 additions and 124 deletions

View File

@ -10,21 +10,17 @@ import (
"time" "time"
) )
type Maps struct { type Submissions struct {
*maps.UnimplementedMapsServiceServer
Store datastore.Datastore Store datastore.Datastore
} }
func (m Maps) Get(ctx context.Context, params *api.GetSubmissionParams) (*api.Submission, error) { func (m Submissions) Get(ctx context.Context, params *api.GetSubmissionParams) (*api.Submission, error) {
item, err := m.Store.Maps().Get(ctx, params.SubmissionID) item, err := m.Store.Submissions().Get(ctx, params.SubmissionID)
if err != nil { if err != nil {
if err == datastore.ErrNotExist { return nil, err
return nil, status.Error(codes.NotFound, "map does not exit")
}
return nil, status.Error(codes.Internal, errors.Wrap(err, "failed to get map:").Error())
} }
return &maps.MapResponse{ return &api.Submission{
ID: item.ID, ID: item.ID,
DisplayName: item.DisplayName, DisplayName: item.DisplayName,
Creator: item.Creator, Creator: item.Creator,
@ -33,7 +29,7 @@ func (m Maps) Get(ctx context.Context, params *api.GetSubmissionParams) (*api.Su
}, nil }, nil
} }
func (m Maps) GetList(ctx context.Context, list *maps.IdList) (*maps.MapList, error) { func (m Submissions) GetList(ctx context.Context, list *maps.IdList) (*maps.MapList, error) {
items, err := m.Store.Maps().GetList(ctx, list.ID) items, err := m.Store.Maps().GetList(ctx, list.ID)
if err != nil { if err != nil {
return nil, status.Error(codes.Internal, errors.Wrap(err, "failed to get maps").Error()) return nil, status.Error(codes.Internal, errors.Wrap(err, "failed to get maps").Error())
@ -53,7 +49,7 @@ func (m Maps) GetList(ctx context.Context, list *maps.IdList) (*maps.MapList, er
return &resp, nil return &resp, nil
} }
func (m Maps) Update(ctx context.Context, request *maps.MapRequest) (*maps.NullResponse, error) { func (m Submissions) Update(ctx context.Context, request *maps.MapRequest) (*maps.NullResponse, error) {
updates := datastore.Optional() updates := datastore.Optional()
updates.AddNotNil("display_name", request.DisplayName) updates.AddNotNil("display_name", request.DisplayName)
updates.AddNotNil("creator", request.Creator) updates.AddNotNil("creator", request.Creator)
@ -72,8 +68,8 @@ func (m Maps) Update(ctx context.Context, request *maps.MapRequest) (*maps.NullR
return &maps.NullResponse{}, nil return &maps.NullResponse{}, nil
} }
func (m Maps) Create(ctx context.Context, request *maps.MapRequest) (*maps.IdMessage, error) { func (m Submissions) Create(ctx context.Context, request *maps.MapRequest) (*maps.IdMessage, error) {
item, err := m.Store.Maps().Create(ctx, model.Map{ item, err := m.Store.Maps().Create(ctx, model.Submission{
ID: request.GetID(), ID: request.GetID(),
DisplayName: request.GetDisplayName(), DisplayName: request.GetDisplayName(),
Creator: request.GetCreator(), Creator: request.GetCreator(),
@ -87,7 +83,7 @@ func (m Maps) Create(ctx context.Context, request *maps.MapRequest) (*maps.IdMes
return &maps.IdMessage{ID: item.ID}, nil return &maps.IdMessage{ID: item.ID}, nil
} }
func (m Maps) Delete(ctx context.Context, message *maps.IdMessage) (*maps.NullResponse, error) { func (m Submissions) Delete(ctx context.Context, message *maps.IdMessage) (*maps.NullResponse, error) {
if err := m.Store.Maps().Delete(ctx, message.GetID()); err != nil { if err := m.Store.Maps().Delete(ctx, message.GetID()); err != nil {
if err == datastore.ErrNotExist { if err == datastore.ErrNotExist {
return nil, status.Error(codes.NotFound, "map does not exit") return nil, status.Error(codes.NotFound, "map does not exit")
@ -98,7 +94,7 @@ func (m Maps) Delete(ctx context.Context, message *maps.IdMessage) (*maps.NullRe
return &maps.NullResponse{}, nil return &maps.NullResponse{}, nil
} }
func (m Maps) List(ctx context.Context, request *maps.ListRequest) (*maps.MapList, error) { func (m Submissions) List(ctx context.Context, request *maps.ListRequest) (*maps.MapList, error) {
filter := datastore.Optional() filter := datastore.Optional()
fmt.Println(request) fmt.Println(request)
if request.Filter != nil { if request.Filter != nil {

View File

@ -3,7 +3,6 @@ package datastore
import ( import (
"context" "context"
"errors" "errors"
"time"
"git.itzana.me/strafesnet/maps-service/internal/model" "git.itzana.me/strafesnet/maps-service/internal/model"
) )
@ -13,25 +12,10 @@ var (
) )
type Datastore interface { type Datastore interface {
Times() Times
Users() Users Users() Users
Bots() Bots Submissions() Submissions
Maps() Maps
Events() Events
Servers() Servers
Transactions() Transactions
Ranks() Ranks
} }
type Times interface {
Get(ctx context.Context, id int64) (model.Time, error)
Create(ctx context.Context, time model.Time) (model.Time, error)
Update(ctx context.Context, id int64, values OptionalMap) error
Delete(ctx context.Context, id int64) error
List(ctx context.Context, filters OptionalMap, blacklisted bool, page model.Page, sort uint32) (int64, []model.Time, error)
Rank(ctx context.Context, id int64) (int64, error)
DistinctStylePairs(ctx context.Context) ([]model.Time, error)
}
type Users interface { type Users interface {
Get(ctx context.Context, id int64) (model.User, error) Get(ctx context.Context, id int64) (model.User, error)
@ -42,53 +26,11 @@ type Users interface {
List(ctx context.Context, filters OptionalMap, page model.Page) ([]model.User, error) List(ctx context.Context, filters OptionalMap, page model.Page) ([]model.User, error)
} }
type Bots interface { type Submissions interface {
Get(ctx context.Context, id int64) (model.Bot, error) Get(ctx context.Context, id int64) (model.Submission, error)
GetList(ctx context.Context, id []int64) ([]model.Bot, error) GetList(ctx context.Context, id []int64) ([]model.Submission, error)
Create(ctx context.Context, bot model.Bot) (model.Bot, error) Create(ctx context.Context, time model.Submission) (model.Submission, error)
Update(ctx context.Context, id int64, values OptionalMap) error Update(ctx context.Context, id int64, values OptionalMap) error
Delete(ctx context.Context, id int64) error Delete(ctx context.Context, id int64) error
List(ctx context.Context, filters OptionalMap, page model.Page) ([]model.Bot, error) List(ctx context.Context, filters OptionalMap, page model.Page) ([]model.Submission, error)
}
type Maps interface {
Get(ctx context.Context, id int64) (model.Map, error)
GetList(ctx context.Context, id []int64) ([]model.Map, error)
Create(ctx context.Context, time model.Map) (model.Map, error)
Update(ctx context.Context, id int64, values OptionalMap) error
Delete(ctx context.Context, id int64) error
List(ctx context.Context, filters OptionalMap, page model.Page) ([]model.Map, error)
}
type Events interface {
Latest(ctx context.Context, date int64, page model.Page) ([]model.Event, error)
Create(ctx context.Context, event model.Event) (model.Event, error)
Clean(ctx context.Context) error
}
type Servers interface {
Get(ctx context.Context, id string) (model.Server, error)
Create(ctx context.Context, server model.Server) (model.Server, error)
Update(ctx context.Context, id string, values OptionalMap) error
Delete(ctx context.Context, id string) error
DeleteByLastUpdated(ctx context.Context, date time.Time) error
List(ctx context.Context, filters OptionalMap, page model.Page) ([]model.Server, error)
}
type Transactions interface {
Balance(ctx context.Context, user int64) (int64, error)
Get(ctx context.Context, id string) (model.Transaction, error)
Create(ctx context.Context, transaction model.Transaction) (model.Transaction, error)
Update(ctx context.Context, id string, values OptionalMap) error
Delete(ctx context.Context, id string) error
List(ctx context.Context, filters OptionalMap, page model.Page) ([]model.Transaction, error)
}
type Ranks interface {
Delete(ctx context.Context, id int64) error
Get(ctx context.Context, user int64, style, game, mode int32, state []int32) (model.Rank, error)
List(ctx context.Context, style, game, mode int32, sort int64, state []int32, page model.Page) ([]model.Rank, error)
UpdateRankCalc(ctx context.Context) error
UpdateAll(ctx context.Context, style, game, mode int32) error
UpdateUsers(ctx context.Context, style, game, mode int32, users []int) error
} }

View File

@ -38,7 +38,7 @@ func New(migrate bool) (datastore.Datastore, error) {
sqlDB.SetMaxOpenConns(25) sqlDB.SetMaxOpenConns(25)
if migrate { if migrate {
if err := db.AutoMigrate(&model.Time{}, &model.User{}, &model.Bot{}, &model.Map{}, &model.Event{}, &model.Server{}, &model.Transaction{}, &model.Rank{}, &model.RankCalc{}); err != nil { if err := db.AutoMigrate(&model.Time{}, &model.User{}, &model.Bot{}, &model.Submission{}, &model.Event{}, &model.Server{}, &model.Transaction{}, &model.Rank{}, &model.RankCalc{}); err != nil {
log.WithField("error", err).Errorln("database migration failed") log.WithField("error", err).Errorln("database migration failed")
return nil, err return nil, err
} }

View File

@ -11,34 +11,10 @@ type Gormstore struct {
cache *cache.Cache[[]byte] cache *cache.Cache[[]byte]
} }
func (g Gormstore) Times() datastore.Times {
return &Times{db: g.db}
}
func (g Gormstore) Users() datastore.Users { func (g Gormstore) Users() datastore.Users {
return &Users{db: g.db} return &Users{db: g.db}
} }
func (g Gormstore) Bots() datastore.Bots { func (g Gormstore) Submissions() datastore.Submissions {
return &Bots{db: g.db} return &Submissions{db: g.db}
}
func (g Gormstore) Maps() datastore.Maps {
return &Maps{db: g.db}
}
func (g Gormstore) Events() datastore.Events {
return &Events{db: g.db}
}
func (g Gormstore) Servers() datastore.Servers {
return &Servers{db: g.db}
}
func (g Gormstore) Transactions() datastore.Transactions {
return &Transactions{db: g.db}
}
func (g Gormstore) Ranks() datastore.Ranks {
return &Ranks{db: g.db, cache: g.cache}
} }

View File

@ -7,12 +7,12 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
type Maps struct { type Submissions struct {
db *gorm.DB db *gorm.DB
} }
func (m Maps) Get(ctx context.Context, id int64) (model.Map, error) { func (m Submissions) Get(ctx context.Context, id int64) (model.Submission, error) {
var smap model.Map var smap model.Submission
if err := m.db.WithContext(ctx).First(&smap, id).Error; err != nil { if err := m.db.WithContext(ctx).First(&smap, id).Error; err != nil {
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return smap, datastore.ErrNotExist return smap, datastore.ErrNotExist
@ -23,8 +23,8 @@ func (m Maps) Get(ctx context.Context, id int64) (model.Map, error) {
return smap, nil return smap, nil
} }
func (m Maps) GetList(ctx context.Context, id []int64) ([]model.Map, error) { func (m Submissions) GetList(ctx context.Context, id []int64) ([]model.Submission, error) {
var mapList []model.Map var mapList []model.Submission
if err := m.db.WithContext(ctx).Find(&mapList, "id IN ?", id).Error; err != nil { if err := m.db.WithContext(ctx).Find(&mapList, "id IN ?", id).Error; err != nil {
return mapList, err return mapList, err
} }
@ -32,7 +32,7 @@ func (m Maps) GetList(ctx context.Context, id []int64) ([]model.Map, error) {
return mapList, nil return mapList, nil
} }
func (m Maps) Create(ctx context.Context, smap model.Map) (model.Map, error) { func (m Submissions) Create(ctx context.Context, smap model.Submission) (model.Submission, error) {
if err := m.db.WithContext(ctx).Create(&smap).Error; err != nil { if err := m.db.WithContext(ctx).Create(&smap).Error; err != nil {
return smap, err return smap, err
} }
@ -40,8 +40,8 @@ func (m Maps) Create(ctx context.Context, smap model.Map) (model.Map, error) {
return smap, nil return smap, nil
} }
func (m Maps) Update(ctx context.Context, id int64, values datastore.OptionalMap) error { func (m Submissions) Update(ctx context.Context, id int64, values datastore.OptionalMap) error {
if err := m.db.WithContext(ctx).Model(&model.Map{}).Where("id = ?", id).Updates(values.Map()).Error; err != nil { if err := m.db.WithContext(ctx).Model(&model.Submission{}).Where("id = ?", id).Updates(values.Map()).Error; err != nil {
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return datastore.ErrNotExist return datastore.ErrNotExist
} }
@ -51,8 +51,8 @@ func (m Maps) Update(ctx context.Context, id int64, values datastore.OptionalMap
return nil return nil
} }
func (m Maps) Delete(ctx context.Context, id int64) error { func (m Submissions) Delete(ctx context.Context, id int64) error {
if err := m.db.WithContext(ctx).Delete(&model.Map{}, id).Error; err != nil { if err := m.db.WithContext(ctx).Delete(&model.Submission{}, id).Error; err != nil {
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return datastore.ErrNotExist return datastore.ErrNotExist
} }
@ -62,8 +62,8 @@ func (m Maps) Delete(ctx context.Context, id int64) error {
return nil return nil
} }
func (m Maps) List(ctx context.Context, filters datastore.OptionalMap, page model.Page) ([]model.Map, error) { func (m Submissions) List(ctx context.Context, filters datastore.OptionalMap, page model.Page) ([]model.Submission, error) {
var maps []model.Map var maps []model.Submission
if err := m.db.WithContext(ctx).Where(filters.Map()).Offset(int((page.Number - 1) * page.Size)).Limit(int(page.Size)).Find(&maps).Error; err != nil { if err := m.db.WithContext(ctx).Where(filters.Map()).Offset(int((page.Number - 1) * page.Size)).Limit(int(page.Size)).Find(&maps).Error; err != nil {
return nil, err return nil, err
} }

View File

@ -2,10 +2,17 @@ package model
import "time" import "time"
type Map struct { type Submission struct {
ID int64 ID int64
DisplayName string DisplayName string
Creator string Creator string
GameID int32 GameID int32
Date time.Time Date time.Time
Submitter int64 // UserID
AssetID int64
AssetVersion int64
Completed bool
Type int32 // 1=New 2=Fix
TargetAssetID int64 // where to upload map fix
StatusID int32
} }