generated from VLADIMIR/template
add teams tests
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"evening_detective/internal/models"
|
||||
"evening_detective/internal/services/story_service"
|
||||
"evening_detective/proto"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func mapTeamsToTeamAdvanced(team *models.Team) *proto.TeamAdvanced {
|
||||
@@ -24,7 +25,7 @@ func mapTeamsToTeamFull(team *models.Team) *proto.TeamFull {
|
||||
|
||||
func mapProtoTeamsToTeam(team *proto.Team) *models.Team {
|
||||
return &models.Team{
|
||||
Name: team.Name,
|
||||
Name: clearTeamName(team.Name),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,3 +86,7 @@ func mapProtoApplicationToApplication(items *proto.Application) *models.Applicat
|
||||
ID: items.Id,
|
||||
}
|
||||
}
|
||||
|
||||
func clearTeamName(code string) string {
|
||||
return strings.TrimSpace(code)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func NewRepository(filepath string) (*Repository, error) {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("load db from: %s", filepath)
|
||||
_, err = db.Exec("CREATE TABLE IF NOT EXISTS teams (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, password TEXT);")
|
||||
_, err = db.Exec("CREATE TABLE IF NOT EXISTS teams (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE NOT NULL CHECK(length(trim(name)) > 0), password TEXT);")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -39,6 +39,10 @@ func NewRepository(filepath string) (*Repository, error) {
|
||||
return &Repository{db: db}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) Close() {
|
||||
r.db.Close()
|
||||
}
|
||||
|
||||
func (r *Repository) GetTeams(ctx context.Context) ([]*models.Team, error) {
|
||||
rows, err := r.db.Query("select id, name, password from teams")
|
||||
if err != nil {
|
||||
@@ -192,3 +196,8 @@ func (r *Repository) GameUpdateState(ctx context.Context, state string) error {
|
||||
_, err := r.db.Exec("update games set state = $1", state)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *Repository) DeleteAllTeams(ctx context.Context) error {
|
||||
_, err := r.db.Exec("delete from teams where 1")
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user