generated from VLADIMIR/template
add email
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user