Skip to content

Commit

Permalink
Merge pull request #467 from senchabot-opensource/dev
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
senchabot-github committed May 14, 2024
2 parents c9ad1a3 + 2a37a0d commit 283bff6
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 89 deletions.
4 changes: 2 additions & 2 deletions apps/discord-bot/internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/senchabot-opensource/monorepo/apps/discord-bot/internal/service/webhook"
"github.com/senchabot-opensource/monorepo/db"
"github.com/senchabot-opensource/monorepo/db/mysql"
"github.com/senchabot-opensource/monorepo/db/postgresql"
"github.com/senchabot-opensource/monorepo/packages/gosenchabot/models"
"github.com/senchabot-opensource/monorepo/packages/gosenchabot/platform"
)
Expand Down Expand Up @@ -65,7 +65,7 @@ type service struct {
}

func New() Service {
dbService := mysql.NewMySQL()
dbService := postgresql.New()
whService := webhook.NewWebhook(dbService)

return &service{
Expand Down
4 changes: 2 additions & 2 deletions apps/twitch-bot/internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/senchabot-opensource/monorepo/apps/twitch-bot/internal/service/timer"
"github.com/senchabot-opensource/monorepo/apps/twitch-bot/internal/service/webhook"
"github.com/senchabot-opensource/monorepo/db"
"github.com/senchabot-opensource/monorepo/db/mysql"
"github.com/senchabot-opensource/monorepo/db/postgresql"
"github.com/senchabot-opensource/monorepo/packages/gosenchabot/models"
"github.com/senchabot-opensource/monorepo/packages/gosenchabot/platform"
)
Expand Down Expand Up @@ -64,7 +64,7 @@ type services struct {
}

func NewServices() Service {
dbService := mysql.NewMySQL()
dbService := postgresql.New()
whService := webhook.NewWebhook(dbService)
timerService := timer.NewTimer()

Expand Down
42 changes: 21 additions & 21 deletions db/mysql/common.go → db/postgresql/common.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mysql
package postgresql

import (
"context"
Expand All @@ -12,7 +12,7 @@ import (
"gorm.io/gorm/clause"
)

func (m *MySQL) CreateBotCommand(ctx context.Context, botPlatform platform.Platform, commandName string, commandContent string, botPlatformId string, createdBy string) (*string, error) {
func (m *postgresql) CreateBotCommand(ctx context.Context, botPlatform platform.Platform, commandName string, commandContent string, botPlatformId string, createdBy string) (*string, error) {
var botCommand []models.BotCommand
var infoText string
var twitchChannelId, discordServerId string
Expand Down Expand Up @@ -59,7 +59,7 @@ func (m *MySQL) CreateBotCommand(ctx context.Context, botPlatform platform.Platf
return nil, nil
}

func (m *MySQL) UpdateBotCommand(ctx context.Context, botPlatform platform.Platform, commandName string, commandContent string, botPlatformId string, updatedBy string) (*string, *string, error) {
func (m *postgresql) UpdateBotCommand(ctx context.Context, botPlatform platform.Platform, commandName string, commandContent string, botPlatformId string, updatedBy string) (*string, *string, error) {
var botCommand *models.BotCommand
var result *gorm.DB

Expand Down Expand Up @@ -98,7 +98,7 @@ func (m *MySQL) UpdateBotCommand(ctx context.Context, botPlatform platform.Platf
return &commandName, nil, nil
}

func (m *MySQL) DeleteBotCommand(ctx context.Context, botPlatform platform.Platform, commandName string, botPlatformId string) (*string, *string, error) {
func (m *postgresql) DeleteBotCommand(ctx context.Context, botPlatform platform.Platform, commandName string, botPlatformId string) (*string, *string, error) {
var botCommand *models.BotCommand
var botCommandAlias *models.BotCommandAlias
var result *gorm.DB
Expand Down Expand Up @@ -148,7 +148,7 @@ func (m *MySQL) DeleteBotCommand(ctx context.Context, botPlatform platform.Platf
return &commandName, nil, nil
}

func (m *MySQL) CheckCommandExists(ctx context.Context, botPlatform platform.Platform, commandName string, botPlatformId string) (*string, error) {
func (m *postgresql) CheckCommandExists(ctx context.Context, botPlatform platform.Platform, commandName string, botPlatformId string) (*string, error) {
var infoText string
existGlobalCommandName, err := m.CheckGlobalCommandExists(ctx, commandName)
if err != nil {
Expand Down Expand Up @@ -183,7 +183,7 @@ func (m *MySQL) CheckCommandExists(ctx context.Context, botPlatform platform.Pla
return nil, nil
}

func (m *MySQL) CheckGlobalCommandExists(ctx context.Context, commandName string) (*string, error) {
func (m *postgresql) CheckGlobalCommandExists(ctx context.Context, commandName string) (*string, error) {
var botCommand []models.BotCommand

result := m.DB.Where("command_name = ?", commandName).Where("command_type", 0).Find(&botCommand)
Expand All @@ -197,7 +197,7 @@ func (m *MySQL) CheckGlobalCommandExists(ctx context.Context, commandName string
return nil, nil
}

func (m *MySQL) CheckUserCommandExists(ctx context.Context, botPlatform platform.Platform, commandName string, botPlatformId string) (*string, error) {
func (m *postgresql) CheckUserCommandExists(ctx context.Context, botPlatform platform.Platform, commandName string, botPlatformId string) (*string, error) {
var botCommand []models.BotCommand
var result *gorm.DB

Expand All @@ -217,7 +217,7 @@ func (m *MySQL) CheckUserCommandExists(ctx context.Context, botPlatform platform
return nil, nil
}

func (m *MySQL) GetCommandAlias(ctx context.Context, botPlatform platform.Platform, command string, botPlatformId string) (*string, error) {
func (m *postgresql) GetCommandAlias(ctx context.Context, botPlatform platform.Platform, command string, botPlatformId string) (*string, error) {
var commandAlias models.BotCommandAlias
var err error

Expand All @@ -234,7 +234,7 @@ func (m *MySQL) GetCommandAlias(ctx context.Context, botPlatform platform.Platfo
return &commandAlias.CommandName, nil
}

func (m *MySQL) CheckCommandAliasExist(ctx context.Context, botPlatform platform.Platform, commandAlias string, botPlatformId string) (*string, error) {
func (m *postgresql) CheckCommandAliasExist(ctx context.Context, botPlatform platform.Platform, commandAlias string, botPlatformId string) (*string, error) {
var commandAliasModel []models.BotCommandAlias
var result *gorm.DB

Expand All @@ -255,7 +255,7 @@ func (m *MySQL) CheckCommandAliasExist(ctx context.Context, botPlatform platform
return nil, nil
}

func (m *MySQL) CreateCommandAlias(ctx context.Context, botPlatform platform.Platform, commandName string, aliases []string, botPlatformId string, createdBy string) (*string, error) {
func (m *postgresql) CreateCommandAlias(ctx context.Context, botPlatform platform.Platform, commandName string, aliases []string, botPlatformId string, createdBy string) (*string, error) {
commandAliases := []models.BotCommandAlias{}
var infoText string
var twitchChannelId, discordServerId string
Expand Down Expand Up @@ -311,7 +311,7 @@ func (m *MySQL) CreateCommandAlias(ctx context.Context, botPlatform platform.Pla
return nil, nil
}

func (m *MySQL) DeleteCommandAlias(ctx context.Context, botPlatform platform.Platform, commandAlias string, botPlatformId string) (*string, error) {
func (m *postgresql) DeleteCommandAlias(ctx context.Context, botPlatform platform.Platform, commandAlias string, botPlatformId string) (*string, error) {
var commandAliasModel *models.BotCommandAlias
var result *gorm.DB

Expand Down Expand Up @@ -343,7 +343,7 @@ func (m *MySQL) DeleteCommandAlias(ctx context.Context, botPlatform platform.Pla
return nil, nil
}

func (m *MySQL) CreateBotActionActivity(ctx context.Context, botPlatform platform.Platform, botActivity string, botPlatformId string, activityAuthor, activityAuthorId string) error {
func (m *postgresql) CreateBotActionActivity(ctx context.Context, botPlatform platform.Platform, botActivity string, botPlatformId string, activityAuthor, activityAuthorId string) error {
botActionActivity := models.BotActionActivity{
BotPlatformType: botPlatform,
BotPlatformID: &botPlatformId,
Expand All @@ -361,7 +361,7 @@ func (m *MySQL) CreateBotActionActivity(ctx context.Context, botPlatform platfor
return nil
}

func (m *MySQL) GetGlobalBotCommand(ctx context.Context, commandName string) (*models.BotCommand, error) {
func (m *postgresql) GetGlobalBotCommand(ctx context.Context, commandName string) (*models.BotCommand, error) {
var botCommand models.BotCommand

result := m.DB.Where("command_name = ?", commandName).Where("command_type = ?", 0).Where("status = ?", 1).First(&botCommand)
Expand All @@ -372,7 +372,7 @@ func (m *MySQL) GetGlobalBotCommand(ctx context.Context, commandName string) (*m
return &botCommand, nil
}

func (m *MySQL) GetUserBotCommand(ctx context.Context, botPlatform platform.Platform, commandName string, botPlatformId string) (*models.BotCommand, error) {
func (m *postgresql) GetUserBotCommand(ctx context.Context, botPlatform platform.Platform, commandName string, botPlatformId string) (*models.BotCommand, error) {
var botCommand models.BotCommand
var result *gorm.DB

Expand All @@ -389,7 +389,7 @@ func (m *MySQL) GetUserBotCommand(ctx context.Context, botPlatform platform.Plat
return &botCommand, nil
}

func (m *MySQL) GetCommandList(ctx context.Context, botPlatform platform.Platform, botPlatformId string) ([]*models.BotCommand, error) {
func (m *postgresql) GetCommandList(ctx context.Context, botPlatform platform.Platform, botPlatformId string) ([]*models.BotCommand, error) {
var botCommandList []*models.BotCommand
var result *gorm.DB

Expand All @@ -406,7 +406,7 @@ func (m *MySQL) GetCommandList(ctx context.Context, botPlatform platform.Platfor
return botCommandList, nil
}

func (m *MySQL) AddBotCommandStatistic(ctx context.Context, botPlatform platform.Platform, commandName string) error {
func (m *postgresql) AddBotCommandStatistic(ctx context.Context, botPlatform platform.Platform, commandName string) error {
botCommandStatistic := models.BotCommandStatistic{CommandName: commandName, BotPlatformType: botPlatform, Count: 1}

result := m.DB.Clauses(clause.OnConflict{
Expand All @@ -422,7 +422,7 @@ func (m *MySQL) AddBotCommandStatistic(ctx context.Context, botPlatform platform
return nil
}

func (m *MySQL) GetCommandTimers(ctx context.Context, botPlatform platform.Platform, botPlatformId string) ([]*models.CommandTimer, error) {
func (m *postgresql) GetCommandTimers(ctx context.Context, botPlatform platform.Platform, botPlatformId string) ([]*models.CommandTimer, error) {
var commandTimers []*models.CommandTimer
result := m.DB.Where("bot_platform = ?", botPlatform).Where("bot_platform_id = ?", botPlatformId).Find(&commandTimers)

Expand All @@ -433,7 +433,7 @@ func (m *MySQL) GetCommandTimers(ctx context.Context, botPlatform platform.Platf
return commandTimers, nil
}

func (m *MySQL) CreateCommandTimer(ctx context.Context, botPlatform platform.Platform, botPlatformId string, commandName string, interval int) (bool, error) {
func (m *postgresql) CreateCommandTimer(ctx context.Context, botPlatform platform.Platform, botPlatformId string, commandName string, interval int) (bool, error) {
exist := m.GetCommandTimer(ctx, botPlatform, botPlatformId, commandName)
if exist != nil {
return true, fmt.Errorf("the command '%v' is already in use for timer", commandName)
Expand All @@ -453,7 +453,7 @@ func (m *MySQL) CreateCommandTimer(ctx context.Context, botPlatform platform.Pla
return true, nil
}

func (m *MySQL) GetCommandTimer(ctx context.Context, botPlatform platform.Platform, botPlatformId string, commandName string) *models.CommandTimer {
func (m *postgresql) GetCommandTimer(ctx context.Context, botPlatform platform.Platform, botPlatformId string, commandName string) *models.CommandTimer {
var commandTimer []models.CommandTimer

result := m.DB.Where("bot_platform = ?", botPlatform).Where("bot_platform_id = ?", botPlatformId).Where("command_name = ?", commandName).Find(&commandTimer)
Expand All @@ -467,7 +467,7 @@ func (m *MySQL) GetCommandTimer(ctx context.Context, botPlatform platform.Platfo
return &commandTimer[0]
}

func (m *MySQL) UpdateCommandTimer(ctx context.Context, botPlatform platform.Platform, botPlatformId string, commandName string, interval int, status int) error {
func (m *postgresql) UpdateCommandTimer(ctx context.Context, botPlatform platform.Platform, botPlatformId string, commandName string, interval int, status int) error {
var commandTimer *models.CommandTimer

result := m.DB.Where("bot_platform = ?", botPlatform).Where("bot_platform_id = ?", botPlatformId).Where("command_name = ?", commandName).First(&commandTimer)
Expand All @@ -490,7 +490,7 @@ func (m *MySQL) UpdateCommandTimer(ctx context.Context, botPlatform platform.Pla

return nil
}
func (m *MySQL) DeleteCommandTimer(ctx context.Context, botPlatform platform.Platform, botPlatformId string, commandName string) error {
func (m *postgresql) DeleteCommandTimer(ctx context.Context, botPlatform platform.Platform, botPlatformId string, commandName string) error {
var commandTimer *models.CommandTimer

result := m.DB.Where("bot_platform = ?", botPlatform).Where("bot_platform_id = ?", botPlatformId).Where("command_name = ?", commandName).First(&commandTimer)
Expand Down
Loading

0 comments on commit 283bff6

Please sign in to comment.