diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2025-08-23 22:29:28 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2025-08-23 22:29:28 +0100 |
| commit | ecc6a55aba7bb35fc778e7a53848396b88214151 (patch) | |
| tree | 1b37a2dc5f4594155114da1ae0c4529d20a4c548 /pkg/database/sqlc | |
| parent | 8f7dec8ba6b2f9bde01afd0a110596ebbd43e0ed (diff) | |
Add multiple conferences feature
Diffstat (limited to 'pkg/database/sqlc')
| -rw-r--r-- | pkg/database/sqlc/conferences.sql.go | 119 | ||||
| -rw-r--r-- | pkg/database/sqlc/favourites.sql.go | 76 | ||||
| -rw-r--r-- | pkg/database/sqlc/models.go | 18 | ||||
| -rw-r--r-- | pkg/database/sqlc/users.sql.go | 36 |
4 files changed, 224 insertions, 25 deletions
diff --git a/pkg/database/sqlc/conferences.sql.go b/pkg/database/sqlc/conferences.sql.go new file mode 100644 index 0000000..1345185 --- /dev/null +++ b/pkg/database/sqlc/conferences.sql.go @@ -0,0 +1,119 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.29.0 +// source: conferences.sql + +package sqlc + +import ( + "context" + + "github.com/jackc/pgx/v5/pgtype" +) + +const createConference = `-- name: CreateConference :one +INSERT INTO conferences ( + url, title, venue, city +) VALUES ( + $1, $2, $3, $4 +) +RETURNING id, url, title, venue, city +` + +type CreateConferenceParams struct { + Url string `json:"url"` + Title pgtype.Text `json:"title"` + Venue pgtype.Text `json:"venue"` + City pgtype.Text `json:"city"` +} + +func (q *Queries) CreateConference(ctx context.Context, arg CreateConferenceParams) (Conference, error) { + row := q.db.QueryRow(ctx, createConference, + arg.Url, + arg.Title, + arg.Venue, + arg.City, + ) + var i Conference + err := row.Scan( + &i.ID, + &i.Url, + &i.Title, + &i.Venue, + &i.City, + ) + return i, err +} + +const deleteConference = `-- name: DeleteConference :exec +DELETE FROM conferences +WHERE id = $1 +` + +func (q *Queries) DeleteConference(ctx context.Context, id int32) error { + _, err := q.db.Exec(ctx, deleteConference, id) + return err +} + +const getConferences = `-- name: GetConferences :many +SELECT id, url, title, venue, city FROM conferences +` + +func (q *Queries) GetConferences(ctx context.Context) ([]Conference, error) { + rows, err := q.db.Query(ctx, getConferences) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Conference + for rows.Next() { + var i Conference + if err := rows.Scan( + &i.ID, + &i.Url, + &i.Title, + &i.Venue, + &i.City, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateConferenceDetails = `-- name: UpdateConferenceDetails :one +UPDATE conferences SET ( + title, venue, city +) = ($2, $3, $4) +WHERE id = $1 +RETURNING id, url, title, venue, city +` + +type UpdateConferenceDetailsParams struct { + ID int32 `json:"id"` + Title pgtype.Text `json:"title"` + Venue pgtype.Text `json:"venue"` + City pgtype.Text `json:"city"` +} + +func (q *Queries) UpdateConferenceDetails(ctx context.Context, arg UpdateConferenceDetailsParams) (Conference, error) { + row := q.db.QueryRow(ctx, updateConferenceDetails, + arg.ID, + arg.Title, + arg.Venue, + arg.City, + ) + var i Conference + err := row.Scan( + &i.ID, + &i.Url, + &i.Title, + &i.Venue, + &i.City, + ) + return i, err +} diff --git a/pkg/database/sqlc/favourites.sql.go b/pkg/database/sqlc/favourites.sql.go index b13261f..d28470d 100644 --- a/pkg/database/sqlc/favourites.sql.go +++ b/pkg/database/sqlc/favourites.sql.go @@ -13,27 +13,34 @@ import ( const createFavourite = `-- name: CreateFavourite :one INSERT INTO favourites ( - user_id, event_guid, event_id + user_id, event_guid, event_id, conference_id ) VALUES ( - $1, $2, $3 + $1, $2, $3, $4 ) -RETURNING id, user_id, event_guid, event_id +RETURNING id, user_id, event_guid, event_id, conference_id ` type CreateFavouriteParams struct { - UserID int32 `json:"user_id"` - EventGuid pgtype.UUID `json:"event_guid"` - EventID pgtype.Int4 `json:"event_id"` + UserID int32 `json:"user_id"` + EventGuid pgtype.UUID `json:"event_guid"` + EventID pgtype.Int4 `json:"event_id"` + ConferenceID int32 `json:"conference_id"` } func (q *Queries) CreateFavourite(ctx context.Context, arg CreateFavouriteParams) (Favourite, error) { - row := q.db.QueryRow(ctx, createFavourite, arg.UserID, arg.EventGuid, arg.EventID) + row := q.db.QueryRow(ctx, createFavourite, + arg.UserID, + arg.EventGuid, + arg.EventID, + arg.ConferenceID, + ) var i Favourite err := row.Scan( &i.ID, &i.UserID, &i.EventGuid, &i.EventID, + &i.ConferenceID, ) return i, err } @@ -50,17 +57,23 @@ func (q *Queries) DeleteFavourite(ctx context.Context, id int32) error { const deleteFavouriteByEventDetails = `-- name: DeleteFavouriteByEventDetails :execrows DELETE FROM favourites -WHERE (event_guid = $1 OR event_id = $2) AND user_id = $3 +WHERE (event_guid = $1 OR event_id = $2) AND user_id = $3 AND conference_id = $4 ` type DeleteFavouriteByEventDetailsParams struct { - EventGuid pgtype.UUID `json:"event_guid"` - EventID pgtype.Int4 `json:"event_id"` - UserID int32 `json:"user_id"` + EventGuid pgtype.UUID `json:"event_guid"` + EventID pgtype.Int4 `json:"event_id"` + UserID int32 `json:"user_id"` + ConferenceID int32 `json:"conference_id"` } func (q *Queries) DeleteFavouriteByEventDetails(ctx context.Context, arg DeleteFavouriteByEventDetailsParams) (int64, error) { - result, err := q.db.Exec(ctx, deleteFavouriteByEventDetails, arg.EventGuid, arg.EventID, arg.UserID) + result, err := q.db.Exec(ctx, deleteFavouriteByEventDetails, + arg.EventGuid, + arg.EventID, + arg.UserID, + arg.ConferenceID, + ) if err != nil { return 0, err } @@ -68,7 +81,7 @@ func (q *Queries) DeleteFavouriteByEventDetails(ctx context.Context, arg DeleteF } const getFavouritesForUser = `-- name: GetFavouritesForUser :many -SELECT id, user_id, event_guid, event_id FROM favourites +SELECT id, user_id, event_guid, event_id, conference_id FROM favourites WHERE user_id = $1 ` @@ -86,6 +99,43 @@ func (q *Queries) GetFavouritesForUser(ctx context.Context, userID int32) ([]Fav &i.UserID, &i.EventGuid, &i.EventID, + &i.ConferenceID, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getFavouritesForUserConference = `-- name: GetFavouritesForUserConference :many +SELECT id, user_id, event_guid, event_id, conference_id FROM favourites +WHERE user_id = $1 AND conference_id = $2 +` + +type GetFavouritesForUserConferenceParams struct { + UserID int32 `json:"user_id"` + ConferenceID int32 `json:"conference_id"` +} + +func (q *Queries) GetFavouritesForUserConference(ctx context.Context, arg GetFavouritesForUserConferenceParams) ([]Favourite, error) { + rows, err := q.db.Query(ctx, getFavouritesForUserConference, arg.UserID, arg.ConferenceID) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Favourite + for rows.Next() { + var i Favourite + if err := rows.Scan( + &i.ID, + &i.UserID, + &i.EventGuid, + &i.EventID, + &i.ConferenceID, ); err != nil { return nil, err } diff --git a/pkg/database/sqlc/models.go b/pkg/database/sqlc/models.go index 57fd082..b7dfc19 100644 --- a/pkg/database/sqlc/models.go +++ b/pkg/database/sqlc/models.go @@ -15,15 +15,25 @@ type Calendar struct { Key string `json:"key"` } +type Conference struct { + ID int32 `json:"id"` + Url string `json:"url"` + Title pgtype.Text `json:"title"` + Venue pgtype.Text `json:"venue"` + City pgtype.Text `json:"city"` +} + type Favourite struct { - ID int32 `json:"id"` - UserID int32 `json:"user_id"` - EventGuid pgtype.UUID `json:"event_guid"` - EventID pgtype.Int4 `json:"event_id"` + ID int32 `json:"id"` + UserID int32 `json:"user_id"` + EventGuid pgtype.UUID `json:"event_guid"` + EventID pgtype.Int4 `json:"event_id"` + ConferenceID int32 `json:"conference_id"` } type User struct { ID int32 `json:"id"` Username string `json:"username"` Password pgtype.Text `json:"password"` + Admin bool `json:"admin"` } diff --git a/pkg/database/sqlc/users.sql.go b/pkg/database/sqlc/users.sql.go index cf0aeb9..45ae019 100644 --- a/pkg/database/sqlc/users.sql.go +++ b/pkg/database/sqlc/users.sql.go @@ -17,7 +17,7 @@ INSERT INTO users ( ) VALUES ( $1, $2 ) -RETURNING id, username, password +RETURNING id, username, password, admin ` type CreateUserParams struct { @@ -28,7 +28,12 @@ type CreateUserParams struct { func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) { row := q.db.QueryRow(ctx, createUser, arg.Username, arg.Password) var i User - err := row.Scan(&i.ID, &i.Username, &i.Password) + err := row.Scan( + &i.ID, + &i.Username, + &i.Password, + &i.Admin, + ) return i, err } @@ -43,31 +48,41 @@ func (q *Queries) DeleteUser(ctx context.Context, id int32) error { } const getUserByID = `-- name: GetUserByID :one -SELECT id, username, password FROM users +SELECT id, username, password, admin FROM users WHERE id = $1 LIMIT 1 ` func (q *Queries) GetUserByID(ctx context.Context, id int32) (User, error) { row := q.db.QueryRow(ctx, getUserByID, id) var i User - err := row.Scan(&i.ID, &i.Username, &i.Password) + err := row.Scan( + &i.ID, + &i.Username, + &i.Password, + &i.Admin, + ) return i, err } const getUserByName = `-- name: GetUserByName :one -SELECT id, username, password FROM users +SELECT id, username, password, admin FROM users WHERE username = $1 LIMIT 1 ` func (q *Queries) GetUserByName(ctx context.Context, username string) (User, error) { row := q.db.QueryRow(ctx, getUserByName, username) var i User - err := row.Scan(&i.ID, &i.Username, &i.Password) + err := row.Scan( + &i.ID, + &i.Username, + &i.Password, + &i.Admin, + ) return i, err } const listUsers = `-- name: ListUsers :many -SELECT id, username, password FROM users +SELECT id, username, password, admin FROM users ORDER BY username ` @@ -80,7 +95,12 @@ func (q *Queries) ListUsers(ctx context.Context) ([]User, error) { var items []User for rows.Next() { var i User - if err := rows.Scan(&i.ID, &i.Username, &i.Password); err != nil { + if err := rows.Scan( + &i.ID, + &i.Username, + &i.Password, + &i.Admin, + ); err != nil { return nil, err } items = append(items, i) |
