add email

This commit is contained in:
2026-09-16 04:07:34 +07:00
parent b9afada40a
commit 99724058eb
10 changed files with 71 additions and 11 deletions
@@ -118,4 +118,18 @@ func TestRegistrationPostgres(t *testing.T) {
if otherID, err := repo.RegisterTeam(ctx, 2, "delivery", "Team", "captain@example.org", 5, "abcdefgh"); err != nil || otherID == id {
t.Fatalf("other game: %d %v", otherID, err)
}
for _, email := range []string{"", "manual@example.org"} {
manualID, err := repo.AddTeamWithParticipation(ctx, 1, 2, "Manual", "password", email, false)
if err != nil {
t.Fatal(err)
}
manual, err := repo.GetTeamByID(ctx, manualID)
if err != nil {
t.Fatal(err)
}
if manual.CaptainEmail != email || manual.ParticipationStatus != "pending" {
t.Fatalf("incorrect manual team: %+v", manual)
}
}
}
+5 -4
View File
@@ -115,10 +115,10 @@ func (r *TeamsRepo) AddTeam(
name string,
password string,
) (int, error) {
return r.AddTeamWithParticipation(ctx, creatorId, gameId, name, password, false)
return r.AddTeamWithParticipation(ctx, creatorId, gameId, name, password, "", false)
}
func (r *TeamsRepo) AddTeamWithParticipation(ctx context.Context, creatorId, gameId int, name, password string, autoConfirm bool) (int, error) {
func (r *TeamsRepo) AddTeamWithParticipation(ctx context.Context, creatorId, gameId int, name, password, captainEmail string, autoConfirm bool) (int, error) {
id := 0
status, source := "pending", ""
if autoConfirm {
@@ -126,8 +126,8 @@ func (r *TeamsRepo) AddTeamWithParticipation(ctx context.Context, creatorId, gam
}
err := r.pool.QueryRow(
ctx,
`INSERT INTO teams (name, creator_id, game_id, password, participation_status, participation_source, participation_answered_at)
VALUES ($1, $2, $3, $4, $5, $6, CASE WHEN $5 = 'confirmed' THEN NOW() ELSE NULL END)
`INSERT INTO teams (name, creator_id, game_id, password, participation_status, participation_source, participation_answered_at, captain_email)
VALUES ($1, $2, $3, $4, $5, $6, CASE WHEN $5 = 'confirmed' THEN NOW() ELSE NULL END, $7)
RETURNING id`,
name,
creatorId,
@@ -135,6 +135,7 @@ func (r *TeamsRepo) AddTeamWithParticipation(ctx context.Context, creatorId, gam
password,
status,
source,
captainEmail,
).Scan(&id)
if err != nil {