From d4f206ebdbec23c76aaa3aa79da1c4b72b12adb1 Mon Sep 17 00:00:00 2001 From: Steven Pescheteau Date: Fri, 29 Nov 2024 19:28:12 +0100 Subject: [PATCH] City, orders, jobs linked to game to be registered with the right bot --- models/entities/books.go | 18 +++++++++++------- models/entities/cities.go | 5 ++++- models/entities/jobs.go | 5 ++++- models/entities/orders.go | 5 ++++- repositories/alignments/alignments.go | 9 +++++---- repositories/alignments/types.go | 5 +++-- repositories/jobs/jobs.go | 9 +++++---- repositories/jobs/types.go | 5 +++-- services/alignments/list.go | 4 ++-- services/alignments/set.go | 3 ++- services/alignments/types.go | 6 +++--- services/alignments/user.go | 4 ++-- services/books/books.go | 12 ++++++------ services/jobs/list.go | 4 ++-- services/jobs/set.go | 3 ++- services/jobs/types.go | 6 +++--- services/jobs/user.go | 4 ++-- 17 files changed, 63 insertions(+), 44 deletions(-) diff --git a/models/entities/books.go b/models/entities/books.go index e260053..f457a7b 100644 --- a/models/entities/books.go +++ b/models/entities/books.go @@ -1,19 +1,23 @@ package entities +import amqp "github.com/kaellybot/kaelly-amqp" + type JobBook struct { - UserID string `gorm:"primaryKey;type:varchar(100);"` - JobID string `gorm:"primaryKey;type:varchar(100);"` - ServerID string `gorm:"primaryKey;type:varchar(100);"` + UserID string `gorm:"primaryKey;type:varchar(100);"` + JobID string `gorm:"primaryKey;type:varchar(100);"` + ServerID string `gorm:"primaryKey;type:varchar(100);"` + Game amqp.Game `gorm:"primaryKey"` Level int64 Job Job `gorm:"foreignKey:JobID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` Server Server `gorm:"foreignKey:ServerID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` } type AlignmentBook struct { - UserID string `gorm:"primaryKey;type:varchar(100);"` - CityID string `gorm:"primaryKey;type:varchar(100);"` - OrderID string `gorm:"primaryKey;type:varchar(100);"` - ServerID string `gorm:"primaryKey;type:varchar(100);"` + UserID string `gorm:"primaryKey;type:varchar(100);"` + CityID string `gorm:"primaryKey;type:varchar(100);"` + OrderID string `gorm:"primaryKey;type:varchar(100);"` + ServerID string `gorm:"primaryKey;type:varchar(100);"` + Game amqp.Game `gorm:"primaryKey"` Level int64 City City `gorm:"foreignKey:CityID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` Order Order `gorm:"foreignKey:OrderID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` diff --git a/models/entities/cities.go b/models/entities/cities.go index c6a10c9..e0bf95a 100644 --- a/models/entities/cities.go +++ b/models/entities/cities.go @@ -1,5 +1,8 @@ package entities +import amqp "github.com/kaellybot/kaelly-amqp" + type City struct { - ID string `gorm:"primaryKey;type:varchar(100)"` + ID string `gorm:"primaryKey;type:varchar(100)"` + Game amqp.Game `gorm:"primaryKey"` } diff --git a/models/entities/jobs.go b/models/entities/jobs.go index 5cf8926..40b220d 100644 --- a/models/entities/jobs.go +++ b/models/entities/jobs.go @@ -1,5 +1,8 @@ package entities +import amqp "github.com/kaellybot/kaelly-amqp" + type Job struct { - ID string `gorm:"primaryKey;type:varchar(100)"` + ID string `gorm:"primaryKey;type:varchar(100)"` + Game amqp.Game `gorm:"primaryKey"` } diff --git a/models/entities/orders.go b/models/entities/orders.go index 383a965..fc20555 100644 --- a/models/entities/orders.go +++ b/models/entities/orders.go @@ -1,5 +1,8 @@ package entities +import amqp "github.com/kaellybot/kaelly-amqp" + type Order struct { - ID string `gorm:"primaryKey;type:varchar(100)"` + ID string `gorm:"primaryKey;type:varchar(100)"` + Game amqp.Game `gorm:"primaryKey"` } diff --git a/repositories/alignments/alignments.go b/repositories/alignments/alignments.go index 031db6e..ab5c49f 100644 --- a/repositories/alignments/alignments.go +++ b/repositories/alignments/alignments.go @@ -1,6 +1,7 @@ package alignments import ( + amqp "github.com/kaellybot/kaelly-amqp" "github.com/kaellybot/kaelly-books/models/entities" "github.com/kaellybot/kaelly-books/utils/databases" ) @@ -10,11 +11,11 @@ func New(db databases.MySQLConnection) *Impl { } func (repo *Impl) GetBooks(cityID, orderID, serverID string, userIDs []string, - offset, limit int) ([]entities.AlignmentBook, int64, error) { + game amqp.Game, offset, limit int) ([]entities.AlignmentBook, int64, error) { var total int64 var alignBooks []entities.AlignmentBook baseQuery := repo.db.GetDB(). - Where("server_id = ? AND user_id IN (?)", serverID, userIDs) + Where("server_id = ? AND game = ? AND user_id IN (?)", serverID, game, userIDs) if len(cityID) > 0 { baseQuery = baseQuery.Where("city_id = ?", cityID) @@ -36,10 +37,10 @@ func (repo *Impl) GetBooks(cityID, orderID, serverID string, userIDs []string, Find(&alignBooks).Error } -func (repo *Impl) GetUserBook(userID, serverID string) ([]entities.AlignmentBook, error) { +func (repo *Impl) GetUserBook(userID, serverID string, game amqp.Game) ([]entities.AlignmentBook, error) { var alignBooks []entities.AlignmentBook return alignBooks, repo.db.GetDB(). - Where("user_id = ? AND server_id = ?", userID, serverID). + Where("user_id = ? AND server_id = ? AND game = ?", userID, serverID, game). Find(&alignBooks).Error } diff --git a/repositories/alignments/types.go b/repositories/alignments/types.go index bfe17ab..f0ea8e9 100644 --- a/repositories/alignments/types.go +++ b/repositories/alignments/types.go @@ -1,14 +1,15 @@ package alignments import ( + amqp "github.com/kaellybot/kaelly-amqp" "github.com/kaellybot/kaelly-books/models/entities" "github.com/kaellybot/kaelly-books/utils/databases" ) type Repository interface { GetBooks(cityID, orderID, serverID string, userIDs []string, - offset, limit int) ([]entities.AlignmentBook, int64, error) - GetUserBook(userID, serverID string) ([]entities.AlignmentBook, error) + game amqp.Game, offset, limit int) ([]entities.AlignmentBook, int64, error) + GetUserBook(userID, serverID string, game amqp.Game) ([]entities.AlignmentBook, error) SaveUserBook(alignBook entities.AlignmentBook) error DeleteUserBook(alignBook entities.AlignmentBook) error } diff --git a/repositories/jobs/jobs.go b/repositories/jobs/jobs.go index 90e99ef..00b22b2 100644 --- a/repositories/jobs/jobs.go +++ b/repositories/jobs/jobs.go @@ -1,6 +1,7 @@ package jobs import ( + amqp "github.com/kaellybot/kaelly-amqp" "github.com/kaellybot/kaelly-books/models/entities" "github.com/kaellybot/kaelly-books/utils/databases" ) @@ -10,11 +11,11 @@ func New(db databases.MySQLConnection) *Impl { } func (repo *Impl) GetBooks(jobID, serverID string, userIDs []string, - offset, limit int) ([]entities.JobBook, int64, error) { + game amqp.Game, offset, limit int) ([]entities.JobBook, int64, error) { var total int64 var jobBooks []entities.JobBook baseQuery := repo.db.GetDB(). - Where("job_id = ? AND server_id = ? AND user_id IN (?)", jobID, serverID, userIDs) + Where("job_id = ? AND server_id = ? AND game = ? AND user_id IN (?)", jobID, serverID, game, userIDs) if errTotal := baseQuery.Model(&entities.JobBook{}). Count(&total).Error; errTotal != nil { @@ -28,10 +29,10 @@ func (repo *Impl) GetBooks(jobID, serverID string, userIDs []string, Find(&jobBooks).Error } -func (repo *Impl) GetUserBook(userID, serverID string) ([]entities.JobBook, error) { +func (repo *Impl) GetUserBook(userID, serverID string, game amqp.Game) ([]entities.JobBook, error) { var jobBooks []entities.JobBook return jobBooks, repo.db.GetDB(). - Where("user_id = ? AND server_id = ?", userID, serverID). + Where("user_id = ? AND server_id = ? AND game = ?", userID, serverID, game). Find(&jobBooks).Error } diff --git a/repositories/jobs/types.go b/repositories/jobs/types.go index 6bbdeb2..82da09f 100644 --- a/repositories/jobs/types.go +++ b/repositories/jobs/types.go @@ -1,14 +1,15 @@ package jobs import ( + amqp "github.com/kaellybot/kaelly-amqp" "github.com/kaellybot/kaelly-books/models/entities" "github.com/kaellybot/kaelly-books/utils/databases" ) type Repository interface { GetBooks(jobID, serverID string, userIDs []string, - offset, limit int) ([]entities.JobBook, int64, error) - GetUserBook(userID, serverID string) ([]entities.JobBook, error) + game amqp.Game, offset, limit int) ([]entities.JobBook, int64, error) + GetUserBook(userID, serverID string, game amqp.Game) ([]entities.JobBook, error) SaveUserBook(jobBook entities.JobBook) error DeleteUserBook(jobBook entities.JobBook) error } diff --git a/services/alignments/list.go b/services/alignments/list.go index 82a6c5d..b465df4 100644 --- a/services/alignments/list.go +++ b/services/alignments/list.go @@ -9,7 +9,7 @@ import ( ) func (service *Impl) GetBookRequest(ctx amqp.Context, request *amqp.AlignGetBookRequest, - lg amqp.Language) { + game amqp.Game, lg amqp.Language) { if !isValidAlignGetRequest(request) { replies.FailedAnswer(ctx, service.broker, amqp.RabbitMQMessage_ALIGN_GET_BOOK_ANSWER, lg) return @@ -22,7 +22,7 @@ func (service *Impl) GetBookRequest(ctx amqp.Context, request *amqp.AlignGetBook Msgf("Get align books request received") books, total, err := service.alignBookRepo.GetBooks(request.GetCityId(), request.GetOrderId(), - request.GetServerId(), request.GetUserIds(), int(request.GetOffset()), int(request.GetSize())) + request.GetServerId(), request.GetUserIds(), game, int(request.GetOffset()), int(request.GetSize())) if err != nil { replies.FailedAnswer(ctx, service.broker, amqp.RabbitMQMessage_ALIGN_GET_BOOK_ANSWER, lg) return diff --git a/services/alignments/set.go b/services/alignments/set.go index 8ee74b8..6f60ebc 100644 --- a/services/alignments/set.go +++ b/services/alignments/set.go @@ -10,7 +10,7 @@ import ( ) func (service *Impl) SetRequest(ctx amqp.Context, request *amqp.AlignSetRequest, - lg amqp.Language) { + game amqp.Game, lg amqp.Language) { if !isValidAlignSetRequest(request) { replies.FailedAnswer(ctx, service.broker, amqp.RabbitMQMessage_ALIGN_SET_ANSWER, lg) return @@ -28,6 +28,7 @@ func (service *Impl) SetRequest(ctx amqp.Context, request *amqp.AlignSetRequest, CityID: request.CityId, OrderID: request.OrderId, ServerID: request.ServerId, + Game: game, Level: request.Level, } diff --git a/services/alignments/types.go b/services/alignments/types.go index 7817055..cba4c4d 100644 --- a/services/alignments/types.go +++ b/services/alignments/types.go @@ -6,9 +6,9 @@ import ( ) type Service interface { - GetBookRequest(ctx amqp.Context, request *amqp.AlignGetBookRequest, lg amqp.Language) - SetRequest(ctx amqp.Context, request *amqp.AlignSetRequest, lg amqp.Language) - UserRequest(ctx amqp.Context, request *amqp.AlignGetUserRequest, lg amqp.Language) + GetBookRequest(ctx amqp.Context, request *amqp.AlignGetBookRequest, game amqp.Game, lg amqp.Language) + SetRequest(ctx amqp.Context, request *amqp.AlignSetRequest, game amqp.Game, lg amqp.Language) + UserRequest(ctx amqp.Context, request *amqp.AlignGetUserRequest, game amqp.Game, lg amqp.Language) } type Impl struct { diff --git a/services/alignments/user.go b/services/alignments/user.go index c258000..a10c415 100644 --- a/services/alignments/user.go +++ b/services/alignments/user.go @@ -9,7 +9,7 @@ import ( ) func (service *Impl) UserRequest(ctx amqp.Context, request *amqp.AlignGetUserRequest, - lg amqp.Language) { + game amqp.Game, lg amqp.Language) { if !isValidAlignGetUserRequest(request) { replies.FailedAnswer(ctx, service.broker, amqp.RabbitMQMessage_ALIGN_GET_USER_ANSWER, lg) return @@ -20,7 +20,7 @@ func (service *Impl) UserRequest(ctx amqp.Context, request *amqp.AlignGetUserReq Str(constants.LogServerID, request.ServerId). Msgf("Get job user request received") - books, err := service.alignBookRepo.GetUserBook(request.UserId, request.ServerId) + books, err := service.alignBookRepo.GetUserBook(request.UserId, request.ServerId, game) if err != nil { replies.FailedAnswer(ctx, service.broker, amqp.RabbitMQMessage_ALIGN_GET_USER_ANSWER, lg) return diff --git a/services/books/books.go b/services/books/books.go index 312545c..2784ec4 100644 --- a/services/books/books.go +++ b/services/books/books.go @@ -34,17 +34,17 @@ func (service *Impl) consume(ctx amqp.Context, message *amqp.RabbitMQMessage) { //exhaustive:ignore Don't need to be exhaustive here since they will be handled by default case switch message.Type { case amqp.RabbitMQMessage_JOB_GET_BOOK_REQUEST: - service.jobService.GetBookRequest(ctx, message.JobGetBookRequest, message.Language) + service.jobService.GetBookRequest(ctx, message.JobGetBookRequest, message.Game, message.Language) case amqp.RabbitMQMessage_JOB_GET_USER_REQUEST: - service.jobService.UserRequest(ctx, message.JobGetUserRequest, message.Language) + service.jobService.UserRequest(ctx, message.JobGetUserRequest, message.Game, message.Language) case amqp.RabbitMQMessage_JOB_SET_REQUEST: - service.jobService.SetRequest(ctx, message.JobSetRequest, message.Language) + service.jobService.SetRequest(ctx, message.JobSetRequest, message.Game, message.Language) case amqp.RabbitMQMessage_ALIGN_GET_BOOK_REQUEST: - service.alignService.GetBookRequest(ctx, message.AlignGetBookRequest, message.Language) + service.alignService.GetBookRequest(ctx, message.AlignGetBookRequest, message.Game, message.Language) case amqp.RabbitMQMessage_ALIGN_GET_USER_REQUEST: - service.alignService.UserRequest(ctx, message.AlignGetUserRequest, message.Language) + service.alignService.UserRequest(ctx, message.AlignGetUserRequest, message.Game, message.Language) case amqp.RabbitMQMessage_ALIGN_SET_REQUEST: - service.alignService.SetRequest(ctx, message.AlignSetRequest, message.Language) + service.alignService.SetRequest(ctx, message.AlignSetRequest, message.Game, message.Language) default: log.Warn(). Str(constants.LogCorrelationID, ctx.CorrelationID). diff --git a/services/jobs/list.go b/services/jobs/list.go index 0048cb0..8a5c434 100644 --- a/services/jobs/list.go +++ b/services/jobs/list.go @@ -9,7 +9,7 @@ import ( ) func (service *Impl) GetBookRequest(ctx amqp.Context, request *amqp.JobGetBookRequest, - lg amqp.Language) { + game amqp.Game, lg amqp.Language) { if !isValidJobGetRequest(request) { replies.FailedAnswer(ctx, service.broker, amqp.RabbitMQMessage_JOB_GET_BOOK_ANSWER, lg) return @@ -21,7 +21,7 @@ func (service *Impl) GetBookRequest(ctx amqp.Context, request *amqp.JobGetBookRe Msgf("Get job books request received") books, total, err := service.jobBookRepo.GetBooks(request.GetJobId(), request.GetServerId(), - request.GetUserIds(), int(request.GetOffset()), int(request.GetSize())) + request.GetUserIds(), game, int(request.GetOffset()), int(request.GetSize())) if err != nil { replies.FailedAnswer(ctx, service.broker, amqp.RabbitMQMessage_JOB_GET_BOOK_ANSWER, lg) return diff --git a/services/jobs/set.go b/services/jobs/set.go index 0a2ad86..17def23 100644 --- a/services/jobs/set.go +++ b/services/jobs/set.go @@ -10,7 +10,7 @@ import ( ) func (service *Impl) SetRequest(ctx amqp.Context, request *amqp.JobSetRequest, - lg amqp.Language) { + game amqp.Game, lg amqp.Language) { if !isValidJobSetRequest(request) { replies.FailedAnswer(ctx, service.broker, amqp.RabbitMQMessage_JOB_SET_ANSWER, lg) return @@ -26,6 +26,7 @@ func (service *Impl) SetRequest(ctx amqp.Context, request *amqp.JobSetRequest, UserID: request.UserId, JobID: request.JobId, ServerID: request.ServerId, + Game: game, Level: request.Level, } diff --git a/services/jobs/types.go b/services/jobs/types.go index d0258db..fbb6352 100644 --- a/services/jobs/types.go +++ b/services/jobs/types.go @@ -6,9 +6,9 @@ import ( ) type Service interface { - GetBookRequest(ctx amqp.Context, request *amqp.JobGetBookRequest, lg amqp.Language) - SetRequest(ctx amqp.Context, request *amqp.JobSetRequest, lg amqp.Language) - UserRequest(ctx amqp.Context, request *amqp.JobGetUserRequest, lg amqp.Language) + GetBookRequest(ctx amqp.Context, request *amqp.JobGetBookRequest, game amqp.Game, lg amqp.Language) + SetRequest(ctx amqp.Context, request *amqp.JobSetRequest, game amqp.Game, lg amqp.Language) + UserRequest(ctx amqp.Context, request *amqp.JobGetUserRequest, game amqp.Game, lg amqp.Language) } type Impl struct { diff --git a/services/jobs/user.go b/services/jobs/user.go index 46f9d73..e14bdac 100644 --- a/services/jobs/user.go +++ b/services/jobs/user.go @@ -9,7 +9,7 @@ import ( ) func (service *Impl) UserRequest(ctx amqp.Context, request *amqp.JobGetUserRequest, - lg amqp.Language) { + game amqp.Game, lg amqp.Language) { if !isValidJobGetUserRequest(request) { replies.FailedAnswer(ctx, service.broker, amqp.RabbitMQMessage_JOB_GET_USER_ANSWER, lg) return @@ -20,7 +20,7 @@ func (service *Impl) UserRequest(ctx amqp.Context, request *amqp.JobGetUserReque Str(constants.LogServerID, request.ServerId). Msgf("Get job user request received") - books, err := service.jobBookRepo.GetUserBook(request.UserId, request.ServerId) + books, err := service.jobBookRepo.GetUserBook(request.UserId, request.ServerId, game) if err != nil { replies.FailedAnswer(ctx, service.broker, amqp.RabbitMQMessage_JOB_GET_USER_ANSWER, lg) return