renaming and fixing red underlines
This commit is contained in:
parent
7485729fd0
commit
a5009998a8
@ -10,21 +10,17 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Maps struct {
|
||||
*maps.UnimplementedMapsServiceServer
|
||||
type Submissions struct {
|
||||
Store datastore.Datastore
|
||||
}
|
||||
|
||||
func (m Maps) Get(ctx context.Context, params *api.GetSubmissionParams) (*api.Submission, error) {
|
||||
item, err := m.Store.Maps().Get(ctx, params.SubmissionID)
|
||||
func (m Submissions) Get(ctx context.Context, params *api.GetSubmissionParams) (*api.Submission, error) {
|
||||
item, err := m.Store.Submissions().Get(ctx, params.SubmissionID)
|
||||
if err != nil {
|
||||
if err == datastore.ErrNotExist {
|
||||
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 nil, err
|
||||
}
|
||||
|
||||
return &maps.MapResponse{
|
||||
return &api.Submission{
|
||||
ID: item.ID,
|
||||
DisplayName: item.DisplayName,
|
||||
Creator: item.Creator,
|
||||
@ -33,7 +29,7 @@ func (m Maps) Get(ctx context.Context, params *api.GetSubmissionParams) (*api.Su
|
||||
}, 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)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
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.AddNotNil("display_name", request.DisplayName)
|
||||
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
|
||||
}
|
||||
|
||||
func (m Maps) Create(ctx context.Context, request *maps.MapRequest) (*maps.IdMessage, error) {
|
||||
item, err := m.Store.Maps().Create(ctx, model.Map{
|
||||
func (m Submissions) Create(ctx context.Context, request *maps.MapRequest) (*maps.IdMessage, error) {
|
||||
item, err := m.Store.Maps().Create(ctx, model.Submission{
|
||||
ID: request.GetID(),
|
||||
DisplayName: request.GetDisplayName(),
|
||||
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
|
||||
}
|
||||
|
||||
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 == datastore.ErrNotExist {
|
||||
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
|
||||
}
|
||||
|
||||
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()
|
||||
fmt.Println(request)
|
||||
if request.Filter != nil {
|
||||
|
@ -3,7 +3,6 @@ package datastore
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.itzana.me/strafesnet/maps-service/internal/model"
|
||||
)
|
||||
@ -13,25 +12,10 @@ var (
|
||||
)
|
||||
|
||||
type Datastore interface {
|
||||
Times() Times
|
||||
Users() Users
|
||||
Bots() Bots
|
||||
Maps() Maps
|
||||
Events() Events
|
||||
Servers() Servers
|
||||
Transactions() Transactions
|
||||
Ranks() Ranks
|
||||
Submissions() Submissions
|
||||
}
|
||||
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
|
||||
type Bots interface {
|
||||
Get(ctx context.Context, id int64) (model.Bot, error)
|
||||
GetList(ctx context.Context, id []int64) ([]model.Bot, error)
|
||||
Create(ctx context.Context, bot model.Bot) (model.Bot, error)
|
||||
type Submissions interface {
|
||||
Get(ctx context.Context, id int64) (model.Submission, error)
|
||||
GetList(ctx context.Context, id []int64) ([]model.Submission, error)
|
||||
Create(ctx context.Context, time model.Submission) (model.Submission, 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.Bot, 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
|
||||
List(ctx context.Context, filters OptionalMap, page model.Page) ([]model.Submission, error)
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func New(migrate bool) (datastore.Datastore, error) {
|
||||
sqlDB.SetMaxOpenConns(25)
|
||||
|
||||
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")
|
||||
return nil, err
|
||||
}
|
||||
|
@ -11,34 +11,10 @@ type Gormstore struct {
|
||||
cache *cache.Cache[[]byte]
|
||||
}
|
||||
|
||||
func (g Gormstore) Times() datastore.Times {
|
||||
return &Times{db: g.db}
|
||||
}
|
||||
|
||||
func (g Gormstore) Users() datastore.Users {
|
||||
return &Users{db: g.db}
|
||||
}
|
||||
|
||||
func (g Gormstore) Bots() datastore.Bots {
|
||||
return &Bots{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}
|
||||
func (g Gormstore) Submissions() datastore.Submissions {
|
||||
return &Submissions{db: g.db}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Maps struct {
|
||||
type Submissions struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (m Maps) Get(ctx context.Context, id int64) (model.Map, error) {
|
||||
var smap model.Map
|
||||
func (m Submissions) Get(ctx context.Context, id int64) (model.Submission, error) {
|
||||
var smap model.Submission
|
||||
if err := m.db.WithContext(ctx).First(&smap, id).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return smap, datastore.ErrNotExist
|
||||
@ -23,8 +23,8 @@ func (m Maps) Get(ctx context.Context, id int64) (model.Map, error) {
|
||||
return smap, nil
|
||||
}
|
||||
|
||||
func (m Maps) GetList(ctx context.Context, id []int64) ([]model.Map, error) {
|
||||
var mapList []model.Map
|
||||
func (m Submissions) GetList(ctx context.Context, id []int64) ([]model.Submission, error) {
|
||||
var mapList []model.Submission
|
||||
if err := m.db.WithContext(ctx).Find(&mapList, "id IN ?", id).Error; err != nil {
|
||||
return mapList, err
|
||||
}
|
||||
@ -32,7 +32,7 @@ func (m Maps) GetList(ctx context.Context, id []int64) ([]model.Map, error) {
|
||||
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 {
|
||||
return smap, err
|
||||
}
|
||||
@ -40,8 +40,8 @@ func (m Maps) Create(ctx context.Context, smap model.Map) (model.Map, error) {
|
||||
return smap, nil
|
||||
}
|
||||
|
||||
func (m Maps) 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 {
|
||||
func (m Submissions) Update(ctx context.Context, id int64, values datastore.OptionalMap) error {
|
||||
if err := m.db.WithContext(ctx).Model(&model.Submission{}).Where("id = ?", id).Updates(values.Map()).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return datastore.ErrNotExist
|
||||
}
|
||||
@ -51,8 +51,8 @@ func (m Maps) Update(ctx context.Context, id int64, values datastore.OptionalMap
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m Maps) Delete(ctx context.Context, id int64) error {
|
||||
if err := m.db.WithContext(ctx).Delete(&model.Map{}, id).Error; err != nil {
|
||||
func (m Submissions) Delete(ctx context.Context, id int64) error {
|
||||
if err := m.db.WithContext(ctx).Delete(&model.Submission{}, id).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return datastore.ErrNotExist
|
||||
}
|
||||
@ -62,8 +62,8 @@ func (m Maps) Delete(ctx context.Context, id int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m Maps) List(ctx context.Context, filters datastore.OptionalMap, page model.Page) ([]model.Map, error) {
|
||||
var maps []model.Map
|
||||
func (m Submissions) List(ctx context.Context, filters datastore.OptionalMap, page model.Page) ([]model.Submission, error) {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2,10 +2,17 @@ package model
|
||||
|
||||
import "time"
|
||||
|
||||
type Map struct {
|
||||
ID int64
|
||||
DisplayName string
|
||||
Creator string
|
||||
GameID int32
|
||||
Date time.Time
|
||||
type Submission struct {
|
||||
ID int64
|
||||
DisplayName string
|
||||
Creator string
|
||||
GameID int32
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user