Skip to content

Commit

Permalink
setup intermediate tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Francia committed Apr 25, 2024
1 parent e1ef685 commit 888a83c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/api/tournament-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/google/uuid"
"net/http"
"strconv"
"time"
)

func (app *application) createNewTournament(c *gin.Context) {
Expand Down Expand Up @@ -141,6 +142,8 @@ func (app *application) modifyPlayers(c *gin.Context) {
func (app *application) updateTournament(c *gin.Context) {
var ut map[string]interface{}
t := c.MustGet("input").(data.Tournament)
now := time.Now()
fmt.Println("now: ", now.Format(time.RFC3339))

_, err := uuid.Parse(*t.Code)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/data/many-2-many-rels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package data
6 changes: 6 additions & 0 deletions internal/data/tournaments.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ func (m TournamentModel) Update(nt map[string]interface{}) (Tournament, error) {
continue
}

if key == "dates" {
qs = qs.Set(key, pq.Array(value))
continue
}

qs = qs.Set(key, value)
}
qs = qs.Set("updated_at", now)
Expand All @@ -374,6 +379,7 @@ func (m TournamentModel) Update(nt map[string]interface{}) (Tournament, error) {
qs = qs.Suffix("RETURNING code, created_at")

query, args, err := qs.ToSql()
fmt.Println("query: ", query)
if err != nil {
return t, err
}
Expand Down
1 change: 1 addition & 0 deletions migrations/000009_create_date_tournament_table.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS date_tournament;
5 changes: 5 additions & 0 deletions migrations/000009_create_date_tournament_table.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS date_tournament (
date_id INT REFERENCES dates(id) ON DELETE NO ACTION,
tournament_id INT REFERENCES tournaments(id) ON DELETE NO ACTION,
CONSTRAINT date_tournament_pk PRIMARY KEY (date_id, tournament_id)
);

0 comments on commit 888a83c

Please sign in to comment.