diff --git a/internal/app/db/db.go b/internal/app/db/db.go index 98a0440f..92dcb05f 100644 --- a/internal/app/db/db.go +++ b/internal/app/db/db.go @@ -92,7 +92,6 @@ func migrate() { &model.GameChallenge{}, &model.GameTeam{}, &model.Flag{}, - &model.FlagGen{}, &model.Port{}, &model.Nat{}, &model.Env{}, diff --git a/internal/files/i18n/en.yaml b/internal/files/i18n/en.yaml index 8c4abca3..1252d413 100644 --- a/internal/files/i18n/en.yaml +++ b/internal/files/i18n/en.yaml @@ -3,7 +3,14 @@ welcome: "welcome" user: not_found: "user not found" login: - password_incorrect: "password incorrect" + invalid_password: "password incorrect" team: - not_found: "team not found" \ No newline at end of file + not_found: "team not found" + join: + invalid_token: "invalid token" + +pod: + not_found: "pod not found" + create: + invalid_image: "invalid image" \ No newline at end of file diff --git a/internal/files/i18n/zh-Hans.yaml b/internal/files/i18n/zh-Hans.yaml index 53d720f9..84dbe47e 100644 --- a/internal/files/i18n/zh-Hans.yaml +++ b/internal/files/i18n/zh-Hans.yaml @@ -3,7 +3,14 @@ welcome: "欢迎" user: not_found: "用户不存在" login: - password_incorrect: "密码错误" + invalid_password: "密码错误" team: - not_found: "团队不存在" \ No newline at end of file + not_found: "团队不存在" + join: + invalid_token: "邀请码无效" + +pod: + not_found: "实例不存在" + create: + invalid_image: "无效镜像" \ No newline at end of file diff --git a/internal/model/flag_gen.go b/internal/model/flag_gen.go deleted file mode 100644 index fca72e4e..00000000 --- a/internal/model/flag_gen.go +++ /dev/null @@ -1,10 +0,0 @@ -package model - -// FlagGen is the generated flag which is injected into the container. -// It will be generated when Flag's type is "dynamic". -type FlagGen struct { - ID uint `json:"id"` - Flag string `gorm:"type:varchar(128);" json:"flag"` - PodID uint `gorm:"not null;" json:"pod_id"` - Pod *Pod `json:"pod"` -} diff --git a/internal/model/pod.go b/internal/model/pod.go index b21f617c..2a053f7c 100644 --- a/internal/model/pod.go +++ b/internal/model/pod.go @@ -12,11 +12,14 @@ type Pod struct { Team *Team `gorm:"foreignkey:TeamID;association_foreignkey:ID" json:"team,omitempty"` ChallengeID *uint `gorm:"index;null;default:null" json:"challenge_id"` Challenge *Challenge `gorm:"foreignkey:ChallengeID;association_foreignkey:ID" json:"challenge,omitempty"` + Flag string `json:"flag,omitempty"` // The generated flag, which will be injected into the container. RemovedAt int64 `json:"removed_at"` + CreatedAt int64 `gorm:"autoUpdateTime:milli" json:"created_at,omitempty"` Nats []*Nat `json:"nats,omitempty"` } func (p *Pod) Simplify() { + p.Flag = "" if p.Challenge != nil { p.Challenge.Simplify() } @@ -24,6 +27,5 @@ func (p *Pod) Simplify() { func (p *Pod) BeforeDelete(db *gorm.DB) (err error) { db.Table("nats").Where("pod_id = ?", p.ID).Delete(&Nat{}) - db.Table("flag_gens").Where("pod_id = ?", p.ID).Delete(&FlagGen{}) return nil } diff --git a/internal/repository/flag_gen.go b/internal/repository/flag_gen.go deleted file mode 100644 index 1085ca54..00000000 --- a/internal/repository/flag_gen.go +++ /dev/null @@ -1,32 +0,0 @@ -package repository - -import ( - "github.com/elabosak233/cloudsdale/internal/model" - "gorm.io/gorm" -) - -type IFlagGenRepository interface { - Create(flag model.FlagGen) (model.FlagGen, error) - FindByPodID(podIDs []uint) ([]model.FlagGen, error) -} - -type FlagGenRepository struct { - db *gorm.DB -} - -func NewFlagGenRepository(db *gorm.DB) IFlagGenRepository { - return &FlagGenRepository{db: db} -} - -func (t *FlagGenRepository) Create(flag model.FlagGen) (model.FlagGen, error) { - result := t.db.Table("flag_gens").Create(&flag) - return flag, result.Error -} - -func (t *FlagGenRepository) FindByPodID(podIDs []uint) ([]model.FlagGen, error) { - var flags []model.FlagGen - result := t.db.Table("flag_gens"). - Where("pod_id IN ?", podIDs). - Find(&flags) - return flags, result.Error -} diff --git a/internal/repository/repository.go b/internal/repository/repository.go index c6e67d91..97d459fd 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -25,7 +25,6 @@ type Repository struct { PortRepository IPortRepository NatRepository INatRepository EnvRepository IEnvRepository - FlagGenRepository IFlagGenRepository GameTeamRepository IGameTeamRepository NoticeRepository INoticeRepository } @@ -55,7 +54,6 @@ func InitRepository() { PortRepository: NewPortRepository(d), NatRepository: NewNatRepository(d), EnvRepository: NewEnvRepository(d), - FlagGenRepository: NewFlagGenRepository(d), GameTeamRepository: NewGameTeamRepository(d), NoticeRepository: NewNoticeRepository(d), } diff --git a/internal/repository/team.go b/internal/repository/team.go index 618ee5f6..1dd484e1 100644 --- a/internal/repository/team.go +++ b/internal/repository/team.go @@ -11,7 +11,7 @@ type ITeamRepository interface { Update(team model.Team) error Delete(id uint) error Find(req request.TeamFindRequest) ([]model.Team, int64, error) - FindById(id uint) (model.Team, error) + FindByID(id uint) (model.Team, error) } type TeamRepository struct { @@ -85,7 +85,7 @@ func (t *TeamRepository) Find(req request.TeamFindRequest) ([]model.Team, int64, return teams, total, result.Error } -func (t *TeamRepository) FindById(id uint) (model.Team, error) { +func (t *TeamRepository) FindByID(id uint) (model.Team, error) { var team model.Team result := t.db.Table("teams").Where("id = ?", id).First(&team) return team, result.Error diff --git a/internal/repository/user.go b/internal/repository/user.go index 480f04fa..ed2c0945 100644 --- a/internal/repository/user.go +++ b/internal/repository/user.go @@ -10,7 +10,7 @@ type IUserRepository interface { Create(user model.User) error Update(user model.User) error Delete(id uint) error - FindById(id uint) (model.User, error) + FindByID(id uint) (model.User, error) FindByUsername(username string) (model.User, error) Find(req request.UserFindRequest) ([]model.User, int64, error) } @@ -78,7 +78,7 @@ func (t *UserRepository) Find(req request.UserFindRequest) ([]model.User, int64, return users, total, result.Error } -func (t *UserRepository) FindById(id uint) (model.User, error) { +func (t *UserRepository) FindByID(id uint) (model.User, error) { var user model.User result := t.db.Table("users"). Where("id = ?", id). diff --git a/internal/service/auth.go b/internal/service/auth.go index 2d766f49..9de8b40a 100644 --- a/internal/service/auth.go +++ b/internal/service/auth.go @@ -6,7 +6,10 @@ import ( ) type IAuthService interface { + // CanModifyUser will check if the user can modify the target user. CanModifyUser(user *model.User, targetUserID uint) bool + + // CanModifyTeam will check if the user can modify the target team. CanModifyTeam(user *model.User, targetTeamID uint) bool } diff --git a/internal/service/category.go b/internal/service/category.go index 7007d927..83737a5d 100644 --- a/internal/service/category.go +++ b/internal/service/category.go @@ -7,10 +7,17 @@ import ( ) type ICategoryService interface { - Create(req model.Category) (err error) - Update(req model.Category) (err error) - Find(req request.CategoryFindRequest) (categories []model.Category, err error) - Delete(req request.CategoryDeleteRequest) (err error) + // Create will create a new category with the given request. + Create(req model.Category) error + + // Update will update the category with the given request. + Update(req model.Category) error + + // Find will find the category with the given request, and return the categories. + Find(req request.CategoryFindRequest) ([]model.Category, error) + + // Delete will delete the category with the given request. + Delete(req request.CategoryDeleteRequest) error } type CategoryService struct { @@ -23,18 +30,18 @@ func NewCategoryService(r *repository.Repository) ICategoryService { } } -func (c *CategoryService) Create(req model.Category) (err error) { +func (c *CategoryService) Create(req model.Category) error { return c.categoryRepository.Create(req) } -func (c *CategoryService) Update(req model.Category) (err error) { +func (c *CategoryService) Update(req model.Category) error { return c.categoryRepository.Update(req) } -func (c *CategoryService) Find(req request.CategoryFindRequest) (categories []model.Category, err error) { +func (c *CategoryService) Find(req request.CategoryFindRequest) ([]model.Category, error) { return c.categoryRepository.Find(req) } -func (c *CategoryService) Delete(req request.CategoryDeleteRequest) (err error) { +func (c *CategoryService) Delete(req request.CategoryDeleteRequest) error { return c.categoryRepository.Delete(req.ID) } diff --git a/internal/service/challenge.go b/internal/service/challenge.go index 3ecbe5e3..48bf3484 100644 --- a/internal/service/challenge.go +++ b/internal/service/challenge.go @@ -8,9 +8,16 @@ import ( ) type IChallengeService interface { + // Find will find the challenge with the given request, and return the challenges and the total number of challenges. Find(req request.ChallengeFindRequest) ([]model.Challenge, int64, error) + + // Create will create a new challenge with the given request. Create(req request.ChallengeCreateRequest) error + + // Update will update the challenge with the given request. Update(req request.ChallengeUpdateRequest) error + + // Delete will delete the challenge with the given request. Delete(id uint) error } diff --git a/internal/service/config.go b/internal/service/config.go index 28334092..daa7a1c3 100644 --- a/internal/service/config.go +++ b/internal/service/config.go @@ -6,6 +6,7 @@ import ( ) type IConfigService interface { + // Update will update the config with the given request. Update(req request.ConfigUpdateRequest) error } diff --git a/internal/service/flag.go b/internal/service/flag.go index 5725c328..5ae0eb97 100644 --- a/internal/service/flag.go +++ b/internal/service/flag.go @@ -8,8 +8,13 @@ import ( ) type IFlagService interface { + // Create will create a new flag with the given request. Create(req request.FlagCreateRequest) error + + // Update will update the flag with the given request. Update(req request.FlagUpdateRequest) error + + // Delete will delete the flag with the given request. Delete(req request.FlagDeleteRequest) error } diff --git a/internal/service/game.go b/internal/service/game.go index 090cc3c6..5b22aaf8 100644 --- a/internal/service/game.go +++ b/internal/service/game.go @@ -11,10 +11,17 @@ import ( ) type IGameService interface { - Find(req request.GameFindRequest) (games []model.Game, total int64, err error) - Create(req request.GameCreateRequest) (err error) - Update(req request.GameUpdateRequest) (err error) - Delete(req request.GameDeleteRequest) (err error) + // Find will find games with the given request, and return the games and total count. + Find(req request.GameFindRequest) ([]model.Game, int64, error) + + // Create will create a new game with the given request. + Create(req request.GameCreateRequest) error + + // Update will update the game with the given request. + Update(req request.GameUpdateRequest) error + + // Delete will delete the game with the given request. + Delete(req request.GameDeleteRequest) error } type GameService struct { @@ -39,7 +46,7 @@ func NewGameService(r *repository.Repository) IGameService { } } -func (g *GameService) Create(req request.GameCreateRequest) (err error) { +func (g *GameService) Create(req request.GameCreateRequest) error { publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader) game := model.Game{ PublicKey: base64.StdEncoding.EncodeToString(publicKey), @@ -50,20 +57,20 @@ func (g *GameService) Create(req request.GameCreateRequest) (err error) { return err } -func (g *GameService) Update(req request.GameUpdateRequest) (err error) { +func (g *GameService) Update(req request.GameUpdateRequest) error { game := model.Game{} - err = mapstructure.Decode(req, &game) + err := mapstructure.Decode(req, &game) err = g.gameRepository.Update(game) return err } -func (g *GameService) Delete(req request.GameDeleteRequest) (err error) { +func (g *GameService) Delete(req request.GameDeleteRequest) error { return g.gameRepository.Delete(model.Game{ ID: req.ID, }) } -func (g *GameService) Find(req request.GameFindRequest) (games []model.Game, total int64, err error) { - games, total, err = g.gameRepository.Find(req) +func (g *GameService) Find(req request.GameFindRequest) ([]model.Game, int64, error) { + games, total, err := g.gameRepository.Find(req) return games, total, err } diff --git a/internal/service/game_challenge.go b/internal/service/game_challenge.go index ef545310..d0e5e03e 100644 --- a/internal/service/game_challenge.go +++ b/internal/service/game_challenge.go @@ -9,9 +9,16 @@ import ( ) type IGameChallengeService interface { + // Find will find the challenges in game with the given request. Find(req request.GameChallengeFindRequest) ([]model.GameChallenge, error) + + // Create will create a new game challenge with the given request. Create(req request.GameChallengeCreateRequest) error + + // Update will update the game challenge with the given request. Update(req request.GameChallengeUpdateRequest) error + + // Delete will delete the game challenge with the given request. Delete(req request.GameChallengeDeleteRequest) error } diff --git a/internal/service/game_team.go b/internal/service/game_team.go index 1a242d4c..ea200019 100644 --- a/internal/service/game_team.go +++ b/internal/service/game_team.go @@ -12,9 +12,16 @@ import ( ) type IGameTeamService interface { + // Find will find the game team with the given request. Find(req request.GameTeamFindRequest) ([]model.GameTeam, int64, error) + + // Create will create a new game team with the given request. Create(req request.GameTeamCreateRequest) error + + // Update will update the game team with the given request. Update(req request.GameTeamUpdateRequest) error + + // Delete will delete the game team with the given request. Delete(req request.GameTeamDeleteRequest) error } diff --git a/internal/service/media.go b/internal/service/media.go index f6368999..18d4b971 100644 --- a/internal/service/media.go +++ b/internal/service/media.go @@ -10,13 +10,28 @@ import ( ) type IMediaService interface { + // SaveGamePoster will save the game poster to the media folder with the game id as the folder name. SaveGamePoster(id uint, fileHeader *multipart.FileHeader) error + + // DeleteGamePoster will delete the game poster from the media folder with the game id as the folder name. DeleteGamePoster(id uint) error + + // SaveUserAvatar will save the user avatar to the media folder with the user id as the folder name. SaveUserAvatar(id uint, fileHeader *multipart.FileHeader) error + + // DeleteUserAvatar will delete the user avatar from the media folder with the user id as the folder name. DeleteUserAvatar(id uint) error + + // SaveTeamAvatar will save the team avatar to the media folder with the team id as the folder name. SaveTeamAvatar(id uint, fileHeader *multipart.FileHeader) error + + // DeleteTeamAvatar will delete the team avatar from the media folder with the team id as the folder name. DeleteTeamAvatar(id uint) error + + // SaveChallengeAttachment will save the challenge attachment to the media folder with the challenge id as the folder name. SaveChallengeAttachment(id uint, fileHeader *multipart.FileHeader) error + + // DeleteChallengeAttachment will delete the challenge attachment from the media folder with the challenge id as the folder name. DeleteChallengeAttachment(id uint) error } diff --git a/internal/service/notice.go b/internal/service/notice.go index f8c57a71..6762c25c 100644 --- a/internal/service/notice.go +++ b/internal/service/notice.go @@ -8,9 +8,16 @@ import ( ) type INoticeService interface { + // Find will find the notice with the given request. Find(req request.NoticeFindRequest) ([]model.Notice, int64, error) + + // Create will create a new notice with the given request. Create(req request.NoticeCreateRequest) error + + // Update will update the notice with the given request. Update(req request.NoticeUpdateRequest) error + + // Delete will delete the notice with the given request. Delete(req request.NoticeDeleteRequest) error } diff --git a/internal/service/pod.go b/internal/service/pod.go index 58d2f1cf..841056af 100644 --- a/internal/service/pod.go +++ b/internal/service/pod.go @@ -50,20 +50,19 @@ type PodService struct { challengeRepository repository.IChallengeRepository podRepository repository.IPodRepository natRepository repository.INatRepository - flagGenRepository repository.IFlagGenRepository } func NewPodService(r *repository.Repository) IPodService { return &PodService{ challengeRepository: r.ChallengeRepository, - flagGenRepository: r.FlagGenRepository, podRepository: r.PodRepository, natRepository: r.NatRepository, } } -func GenerateFlag(flagFmt string) (flag string) { - flag = strings.Replace(flagFmt, "[UUID]", utils.HyphenlessUUID(), -1) +func GenerateFlag(flag string) string { + flag = strings.Replace(flag, "[UUID]", utils.HyphenlessUUID(), -1) + flag = strings.Replace(flag, "[uuid]", utils.HyphenlessUUID(), -1) return flag } @@ -130,24 +129,22 @@ func (t *PodService) Create(req request.PodCreateRequest) (model.Pod, error) { removedAt := time.Now().Add(time.Duration(challenge.Duration) * time.Second).Unix() - // Select the first one as the target flag which will be injected - var flag model.Flag - for _, f := range challenge.Flags { - if f.Type == "dynamic" { - flag = *f - flag.Value = GenerateFlag(flag.Value) - } else { - if f.Env == "" { - f.Env = "FLAG" - } - flag = *f + // Select the first one as the target flag which will be injected into the container. + generatedFlag := model.Flag{} + for _, flag := range challenge.Flags { + generatedFlag = *flag + if flag.Type == "dynamic" { + generatedFlag.Value = GenerateFlag(flag.Value) + } + if flag.Env == "" { + generatedFlag.Env = "FLAG" } break } ctnManager := manager.NewContainerManager( challenge, - flag, + generatedFlag, time.Duration(challenge.Duration)*time.Second, ) @@ -161,15 +158,11 @@ func (t *PodService) Create(req request.PodCreateRequest) (model.Pod, error) { TeamID: req.TeamID, RemovedAt: removedAt, Nats: nats, + Flag: generatedFlag.Value, }) ctnManager.SetPodID(pod.ID) - _, _ = t.flagGenRepository.Create(model.FlagGen{ - Flag: flag.Value, - PodID: pod.ID, - }) - go func() { if ctnManager.RemoveAfterDuration() { delete(PodManagers, pod.ID) @@ -193,12 +186,12 @@ func (t *PodService) Renew(req request.PodRenewRequest) error { ID: req.ID, }) if total == 0 { - return errors.New("实例不存在") + return errors.New("pod.not_found") } pod := pods[0] ctn, ok := PodManagers[req.ID] if !ok { - return errors.New("实例不存在") + return errors.New("pod.not_found") } ctn.Renew(ctn.Duration()) pod.RemovedAt = time.Now().Add(ctn.Duration()).Unix() diff --git a/internal/service/submission.go b/internal/service/submission.go index 58ea1a6c..6231a510 100644 --- a/internal/service/submission.go +++ b/internal/service/submission.go @@ -11,8 +11,13 @@ import ( ) type ISubmissionService interface { + // Create will create a new submission with the given request, and return the status and rank. Create(req request.SubmissionCreateRequest) (status int, rank int64, err error) - Delete(id uint) (err error) + + // Delete will delete the submission with the given id. + Delete(id uint) error + + // Find will find the submissions with the given request. Find(req request.SubmissionFindRequest) ([]model.Submission, int64, error) } @@ -23,7 +28,6 @@ type SubmissionService struct { teamRepository repository.ITeamRepository userRepository repository.IUserRepository gameChallengeRepository repository.IGameChallengeRepository - flagGenRepository repository.IFlagGenRepository gameRepository repository.IGameRepository noticeRepository repository.INoticeRepository } @@ -36,7 +40,6 @@ func NewSubmissionService(r *repository.Repository) ISubmissionService { teamRepository: r.TeamRepository, userRepository: r.UserRepository, gameChallengeRepository: r.GameChallengeRepository, - flagGenRepository: r.FlagGenRepository, gameRepository: r.GameRepository, noticeRepository: r.NoticeRepository, } @@ -53,13 +56,8 @@ func (t *SubmissionService) JudgeDynamicChallenge(req request.SubmissionCreateRe for _, pod := range perhapsPods { podIDs = append(podIDs, pod.ID) } - flags, err := t.flagGenRepository.FindByPodID(podIDs) - flagMap := make(map[uint]string) - for _, flag := range flags { - flagMap[flag.PodID] = flag.Flag - } for _, pod := range perhapsPods { - if req.Flag == flagMap[pod.ID] { + if req.Flag == pod.Flag { if (pod.UserID != nil && req.UserID == *(pod.UserID) && req.UserID != 0) || (pod.TeamID != nil && req.TeamID != nil && *(req.TeamID) == *(pod.TeamID)) { status = 2 } else { diff --git a/internal/service/team.go b/internal/service/team.go index 93e84f5f..1fd76592 100644 --- a/internal/service/team.go +++ b/internal/service/team.go @@ -43,7 +43,7 @@ func NewTeamService(r *repository.Repository) ITeamService { } func (t *TeamService) Create(req request.TeamCreateRequest) error { - user, err := t.userRepository.FindById(req.CaptainId) + user, err := t.userRepository.FindByID(req.CaptainId) if err != nil || user.ID == 0 { return errors.New("user.not_found") } @@ -61,7 +61,7 @@ func (t *TeamService) Create(req request.TeamCreateRequest) error { } func (t *TeamService) Update(req request.TeamUpdateRequest) error { - team, err := t.teamRepository.FindById(req.ID) + team, err := t.teamRepository.FindByID(req.ID) if err != nil || team.ID == 0 { return errors.New("team.not_found") } @@ -77,7 +77,7 @@ func (t *TeamService) Update(req request.TeamUpdateRequest) error { } func (t *TeamService) Delete(id uint) error { - team, err := t.teamRepository.FindById(id) + team, err := t.teamRepository.FindByID(id) if err != nil || team.ID == 0 { return errors.New("team.not_found") } @@ -95,7 +95,7 @@ func (t *TeamService) Find(req request.TeamFindRequest) ([]model.Team, int64, er } func (t *TeamService) GetInviteToken(req request.TeamGetInviteTokenRequest) (token string, err error) { - team, err := t.teamRepository.FindById(req.ID) + team, err := t.teamRepository.FindByID(req.ID) if err != nil || team.ID == 0 { return "", errors.New("team.not_found") } @@ -103,7 +103,7 @@ func (t *TeamService) GetInviteToken(req request.TeamGetInviteTokenRequest) (tok } func (t *TeamService) UpdateInviteToken(req request.TeamUpdateInviteTokenRequest) (token string, err error) { - team, err := t.teamRepository.FindById(req.ID) + team, err := t.teamRepository.FindByID(req.ID) if err != nil || team.ID == 0 { return "", errors.New("team.not_found") } diff --git a/internal/service/user.go b/internal/service/user.go index 95562173..787ec044 100644 --- a/internal/service/user.go +++ b/internal/service/user.go @@ -145,7 +145,7 @@ func (t *UserService) Login(req request.UserLoginRequest) (model.User, string, e } err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(req.Password)) if err != nil { - return user, "", errors.New("user.login.password_incorrect") + return user, "", errors.New("user.login.invalid_password") } token, err := t.GetJwtTokenByID(user) return user, token, err diff --git a/internal/service/user_team.go b/internal/service/user_team.go index 040f3505..4b957479 100644 --- a/internal/service/user_team.go +++ b/internal/service/user_team.go @@ -28,13 +28,16 @@ func NewUserTeamService(r *repository.Repository) IUserTeamService { } func (t *UserTeamService) Join(req request.TeamUserJoinRequest) error { - user, err := t.userRepository.FindById(req.UserID) - team, err := t.teamRepository.FindById(req.TeamID) - if err != nil || user.ID == 0 || team.ID == 0 { - return errors.New("user_or_team_not_found") + user, err := t.userRepository.FindByID(req.UserID) + if err != nil || user.ID == 0 { + return errors.New("user.not_found") + } + team, err := t.teamRepository.FindByID(req.TeamID) + if err != nil || team.ID == 0 { + return errors.New("team.not_found") } if team.InviteToken != req.InviteToken { - return errors.New("invalid_invite_token") + return errors.New("team.join.invalid_token") } err = t.userTeamRepository.Create(model.UserTeam{ TeamID: team.ID, @@ -44,10 +47,13 @@ func (t *UserTeamService) Join(req request.TeamUserJoinRequest) error { } func (t *UserTeamService) Create(req request.TeamUserCreateRequest) error { - user, err := t.userRepository.FindById(req.UserID) - team, err := t.teamRepository.FindById(req.TeamID) - if err != nil || user.ID == 0 || team.ID == 0 { - return errors.New("user_or_team_not_found") + user, err := t.userRepository.FindByID(req.UserID) + if err != nil || user.ID == 0 { + return errors.New("user.not_found") + } + team, err := t.teamRepository.FindByID(req.TeamID) + if err != nil || team.ID == 0 { + return errors.New("team.not_found") } err = t.userTeamRepository.Create(model.UserTeam{ TeamID: team.ID, @@ -57,10 +63,13 @@ func (t *UserTeamService) Create(req request.TeamUserCreateRequest) error { } func (t *UserTeamService) Delete(req request.TeamUserDeleteRequest) error { - user, err := t.userRepository.FindById(req.UserID) - team, err := t.teamRepository.FindById(req.TeamID) - if err != nil || user.ID == 0 || team.ID == 0 { - return errors.New("user_or_team_not_found") + user, err := t.userRepository.FindByID(req.UserID) + if err != nil || user.ID == 0 { + return errors.New("user.not_found") + } + team, err := t.teamRepository.FindByID(req.TeamID) + if err != nil || team.ID == 0 { + return errors.New("team.not_found") } err = t.userTeamRepository.Delete(model.UserTeam{ TeamID: team.ID,