Skip to content

Commit

Permalink
wip: remove flag_gen
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed Jun 9, 2024
1 parent eb260dc commit aaba51c
Show file tree
Hide file tree
Showing 24 changed files with 160 additions and 123 deletions.
1 change: 0 additions & 1 deletion internal/app/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func migrate() {
&model.GameChallenge{},
&model.GameTeam{},
&model.Flag{},
&model.FlagGen{},
&model.Port{},
&model.Nat{},
&model.Env{},
Expand Down
11 changes: 9 additions & 2 deletions internal/files/i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
not_found: "team not found"
join:
invalid_token: "invalid token"

pod:
not_found: "pod not found"
create:
invalid_image: "invalid image"
11 changes: 9 additions & 2 deletions internal/files/i18n/zh-Hans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ welcome: "欢迎"
user:
not_found: "用户不存在"
login:
password_incorrect: "密码错误"
invalid_password: "密码错误"

team:
not_found: "团队不存在"
not_found: "团队不存在"
join:
invalid_token: "邀请码无效"

pod:
not_found: "实例不存在"
create:
invalid_image: "无效镜像"
10 changes: 0 additions & 10 deletions internal/model/flag_gen.go

This file was deleted.

4 changes: 3 additions & 1 deletion internal/model/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ 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()
}
}

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
}
32 changes: 0 additions & 32 deletions internal/repository/flag_gen.go

This file was deleted.

2 changes: 0 additions & 2 deletions internal/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type Repository struct {
PortRepository IPortRepository
NatRepository INatRepository
EnvRepository IEnvRepository
FlagGenRepository IFlagGenRepository
GameTeamRepository IGameTeamRepository
NoticeRepository INoticeRepository
}
Expand Down Expand Up @@ -55,7 +54,6 @@ func InitRepository() {
PortRepository: NewPortRepository(d),
NatRepository: NewNatRepository(d),
EnvRepository: NewEnvRepository(d),
FlagGenRepository: NewFlagGenRepository(d),
GameTeamRepository: NewGameTeamRepository(d),
NoticeRepository: NewNoticeRepository(d),
}
Expand Down
4 changes: 2 additions & 2 deletions internal/repository/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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).
Expand Down
3 changes: 3 additions & 0 deletions internal/service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
23 changes: 15 additions & 8 deletions internal/service/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
7 changes: 7 additions & 0 deletions internal/service/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions internal/service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

type IConfigService interface {
// Update will update the config with the given request.
Update(req request.ConfigUpdateRequest) error
}

Expand Down
5 changes: 5 additions & 0 deletions internal/service/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
27 changes: 17 additions & 10 deletions internal/service/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand All @@ -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
}
7 changes: 7 additions & 0 deletions internal/service/game_challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 7 additions & 0 deletions internal/service/game_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions internal/service/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 7 additions & 0 deletions internal/service/notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading

0 comments on commit aaba51c

Please sign in to comment.