diff options
author | Michael Hunteman <michael@huntm.net> | 2024-10-20 18:52:16 -0700 |
---|---|---|
committer | Michael Hunteman <michael@huntm.net> | 2024-10-20 18:52:16 -0700 |
commit | 5a65b3a653eb4a9ca62332fa65c8d352e6dc782f (patch) | |
tree | 6f2fabb06936a7290a2f5e94a1b3aaf4534bf87c /server/guest/store.go | |
parent | 5c8f0ca091ff7f962260c75a0ffe4c99e7cdca3c (diff) |
Use UUID
Diffstat (limited to 'server/guest/store.go')
-rw-r--r-- | server/guest/store.go | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/server/guest/store.go b/server/guest/store.go index 16123e3..56a8c2c 100644 --- a/server/guest/store.go +++ b/server/guest/store.go @@ -48,7 +48,7 @@ func (store Store) Find(name Name) (Guest, error) { func createGuest(name Name, guestRows pgx.Rows) (Guest, bool) { var guest Guest for guestRows.Next() { - err := guestRows.Scan(&guest.ID, &guest.FirstName, &guest.LastName, + err := guestRows.Scan(&guest.Id, &guest.FirstName, &guest.LastName, &guest.Attendance, &guest.Email, &guest.Message, &guest.PartySize) if err != nil { return Guest{}, false @@ -64,13 +64,13 @@ func createGuest(name Name, guestRows pgx.Rows) (Guest, bool) { func addParty(guestWithoutParty Guest, partyRows pgx.Rows) (Guest, error) { guestWithParty := guestWithoutParty for partyRows.Next() { - var guestID int + var guestId string var partyMember Name - err := partyRows.Scan(&guestID, &partyMember.FirstName, &partyMember.LastName) + err := partyRows.Scan(&guestId, &partyMember.FirstName, &partyMember.LastName) if err != nil { return Guest{}, err } - if guestID == guestWithParty.ID { + if guestId == guestWithParty.Id { guestWithParty.PartyList = append(guestWithParty.PartyList, partyMember) } } @@ -108,7 +108,7 @@ func (store Store) createGuestSlice(guestRows pgx.Rows) ([]Guest, error) { guests := []Guest{} for guestRows.Next() { var guest Guest - err := guestRows.Scan(&guest.ID, &guest.FirstName, &guest.LastName, + err := guestRows.Scan(&guest.Id, &guest.FirstName, &guest.LastName, &guest.Attendance, &guest.Email, &guest.Message, &guest.PartySize) if err != nil { return []Guest{}, err @@ -122,14 +122,14 @@ func addPartySlice(guestsWithoutParty []Guest, partyRows pgx.Rows) ([]Guest, error) { guestsWithParty := guestsWithoutParty for partyRows.Next() { - var guestID int + var guestId string var partyMember Name - err := partyRows.Scan(&guestID, &partyMember.FirstName, &partyMember.LastName) + err := partyRows.Scan(&guestId, &partyMember.FirstName, &partyMember.LastName) if err != nil { return []Guest{}, err } for i, guest := range guestsWithParty { - if guestID == guest.ID { + if guestId == guest.Id { guestsWithParty[i].PartyList = append(guest.PartyList, partyMember) } } @@ -147,7 +147,7 @@ func (store Store) Add(guest Guest) error { func (store Store) insertGuest(guest Guest) error { statement := `insert into guest (id, first_name, last_name, attendance, email, message, party_size) values ($1, $2, $3, $4, $5, $6, $7)` - _, err := store.database.Exec(context.Background(), statement, guest.ID, + _, err := store.database.Exec(context.Background(), statement, guest.Id, guest.FirstName, guest.LastName, guest.Attendance, guest.Email, guest.Message, guest.PartySize) return err @@ -157,7 +157,7 @@ func (store Store) Update(guest Guest) error { if err := store.updateGuest(guest); err != nil { return err } - if err := store.deleteParty(guest.ID); err != nil { + if err := store.deleteParty(guest.Id); err != nil { return err } return store.insertParty(guest) @@ -167,13 +167,13 @@ func (store Store) updateGuest(guest Guest) error { statement := `update guest set attendance = $1, email = $2, message = $3, party_size = $4 where id = $5` _, err := store.database.Exec(context.Background(), statement, - guest.Attendance, guest.Email, guest.Message, guest.PartySize, guest.ID) + guest.Attendance, guest.Email, guest.Message, guest.PartySize, guest.Id) return err } -func (store Store) deleteParty(guestID int) error { +func (store Store) deleteParty(guestId string) error { statement := "delete from party where guest_id = $1" - _, err := store.database.Exec(context.Background(), statement, guestID) + _, err := store.database.Exec(context.Background(), statement, guestId) return err } @@ -181,7 +181,7 @@ func (store Store) insertParty(guest Guest) error { statement := `insert into party (guest_id, first_name, last_name) values ($1, $2, $3)` for _, pg := range guest.PartyList { - _, err := store.database.Exec(context.Background(), statement, guest.ID, + _, err := store.database.Exec(context.Background(), statement, guest.Id, pg.FirstName, pg.LastName) if err != nil { return err @@ -190,18 +190,18 @@ func (store Store) insertParty(guest Guest) error { return nil } -func (store Store) Delete(guestID int) error { - if err := store.deleteGuest(guestID); err != nil { +func (store Store) Delete(guestId string) error { + if err := store.deleteGuest(guestId); err != nil { return err } - if err := store.deleteParty(guestID); err != nil { + if err := store.deleteParty(guestId); err != nil { return err } return nil } -func (store Store) deleteGuest(guestID int) error { +func (store Store) deleteGuest(guestId string) error { statement := "delete from guest where id = $1" - _, err := store.database.Exec(context.Background(), statement, guestID) + _, err := store.database.Exec(context.Background(), statement, guestId) return err } |