diff --git a/go.mod b/go.mod index 06b5998..12662b3 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/acmcsufoss/api.acmcsuf.com -go 1.21.3 +go 1.23 require ( github.com/swaggest/openapi-go v0.2.45 diff --git a/internal/db/sqlite/db.go b/internal/db/sqlite/db.go index bf52be0..df564d1 100644 --- a/internal/db/sqlite/db.go +++ b/internal/db/sqlite/db.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.23.0 +// sqlc v1.25.0 package sqlite diff --git a/internal/db/sqlite/queries.sql b/internal/db/sqlite/queries.sql index 812ffbb..6a39b21 100644 --- a/internal/db/sqlite/queries.sql +++ b/internal/db/sqlite/queries.sql @@ -76,7 +76,7 @@ VALUES -- name: DeleteResource :exec DELETE FROM resource WHERE - id = ?; + uuid = ?; -- name: GetResource :exec SELECT @@ -153,6 +153,6 @@ SELECT discord_channel_id, discord_message_id from - announcements + announcement where uuid = ?; \ No newline at end of file diff --git a/internal/db/sqlite/queries.sql.go b/internal/db/sqlite/queries.sql.go index 40128cc..c132b3b 100644 --- a/internal/db/sqlite/queries.sql.go +++ b/internal/db/sqlite/queries.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.23.0 +// sqlc v1.25.0 // source: queries.sql package sqlite @@ -10,48 +10,36 @@ import ( "database/sql" ) -const addResource = `-- name: AddResource :exec -INSERT INTO resource_references (resource_id, resource_list_id, index_in_list, created_at, updated_at) VALUES (?, ?, ?, ?, ?) -` - -type AddResourceParams struct { - ResourceID string `json:"resource_id"` - ResourceListID string `json:"resource_list_id"` - IndexInList int64 `json:"index_in_list"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` -} - -func (q *Queries) AddResource(ctx context.Context, arg AddResourceParams) error { - _, err := q.db.ExecContext(ctx, addResource, - arg.ResourceID, - arg.ResourceListID, - arg.IndexInList, - arg.CreatedAt, - arg.UpdatedAt, - ) - return err -} - const createAnnouncement = `-- name: CreateAnnouncement :exec -INSERT INTO announcements (id, event_list_id, approved_by_list_id, visibility, announce_at, discord_channel_id, discord_message_id) VALUES (?, ?, ?, ?, ?, ?, ?) +INSERT INTO + announcement ( + uuid, + event_groups_group_uuid, + approved_by_list_uuid, + visibility, + announce_at, + discord_channel_id, + discord_message_id + ) +VALUES + (?, ?, ?, ?, ?, ?, ?) ` type CreateAnnouncementParams struct { - ID string `json:"id"` - EventListID sql.NullString `json:"event_list_id"` - ApprovedByListID sql.NullString `json:"approved_by_list_id"` - Visibility string `json:"visibility"` - AnnounceAt int64 `json:"announce_at"` - DiscordChannelID sql.NullString `json:"discord_channel_id"` - DiscordMessageID sql.NullString `json:"discord_message_id"` + Uuid string `json:"uuid"` + EventGroupsGroupUuid sql.NullString `json:"event_groups_group_uuid"` + ApprovedByListUuid sql.NullString `json:"approved_by_list_uuid"` + Visibility string `json:"visibility"` + AnnounceAt int64 `json:"announce_at"` + DiscordChannelID sql.NullString `json:"discord_channel_id"` + DiscordMessageID sql.NullString `json:"discord_message_id"` } func (q *Queries) CreateAnnouncement(ctx context.Context, arg CreateAnnouncementParams) error { _, err := q.db.ExecContext(ctx, createAnnouncement, - arg.ID, - arg.EventListID, - arg.ApprovedByListID, + arg.Uuid, + arg.EventGroupsGroupUuid, + arg.ApprovedByListUuid, arg.Visibility, arg.AnnounceAt, arg.DiscordChannelID, @@ -61,14 +49,25 @@ func (q *Queries) CreateAnnouncement(ctx context.Context, arg CreateAnnouncement } const createEvent = `-- name: CreateEvent :exec -INSERT INTO events (id, location, start_at, duration_ms, is_all_day, host, visibility) VALUES (?, ?, ?, ?, ?, ?, ?) +INSERT INTO + event ( + uuid, + location, + start_at, + end_at, + is_all_day, + host, + visibility + ) +VALUES + (?, ?, ?, ?, ?, ?, ?) ` type CreateEventParams struct { - ID string `json:"id"` + Uuid string `json:"uuid"` Location string `json:"location"` StartAt interface{} `json:"start_at"` - DurationMs interface{} `json:"duration_ms"` + EndAt interface{} `json:"end_at"` IsAllDay bool `json:"is_all_day"` Host string `json:"host"` Visibility string `json:"visibility"` @@ -76,10 +75,10 @@ type CreateEventParams struct { func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) error { _, err := q.db.ExecContext(ctx, createEvent, - arg.ID, + arg.Uuid, arg.Location, arg.StartAt, - arg.DurationMs, + arg.EndAt, arg.IsAllDay, arg.Host, arg.Visibility, @@ -87,240 +86,257 @@ func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) error return err } +const createGroupResourceMapping = `-- name: CreateGroupResourceMapping :exec +INSERT INTO + group_id_resource_list_mapping ( + group_uuid, + resource_uuid, + index_in_list, + created_at, + updated_at, + deleted_at + ) +VALUES + (?, ?, ?, ?, ?, ?) +` + +type CreateGroupResourceMappingParams struct { + GroupUuid sql.NullString `json:"group_uuid"` + ResourceUuid string `json:"resource_uuid"` + IndexInList int64 `json:"index_in_list"` + CreatedAt sql.NullTime `json:"created_at"` + UpdatedAt sql.NullTime `json:"updated_at"` + DeletedAt sql.NullTime `json:"deleted_at"` +} + +func (q *Queries) CreateGroupResourceMapping(ctx context.Context, arg CreateGroupResourceMappingParams) error { + _, err := q.db.ExecContext(ctx, createGroupResourceMapping, + arg.GroupUuid, + arg.ResourceUuid, + arg.IndexInList, + arg.CreatedAt, + arg.UpdatedAt, + arg.DeletedAt, + ) + return err +} + +const createPerson = `-- name: CreatePerson :exec +INSERT INTO + person (uuid, name, preferred_pronoun) +VALUES + (?, ?, ?) +` + +type CreatePersonParams struct { + Uuid sql.NullString `json:"uuid"` + Name sql.NullString `json:"name"` + PreferredPronoun sql.NullString `json:"preferred_pronoun"` +} + +func (q *Queries) CreatePerson(ctx context.Context, arg CreatePersonParams) error { + _, err := q.db.ExecContext(ctx, createPerson, arg.Uuid, arg.Name, arg.PreferredPronoun) + return err +} + const createResource = `-- name: CreateResource :exec -INSERT INTO resources (id, title, content_md, image_url, resource_type, resource_list_id, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?) +INSERT INTO + resource ( + uuid, + title, + content_md, + image_url, + resource_type, + created_at, + updated_at, + deleted_at + ) +VALUES + (?, ?, ?, ?, ?, ?, ?, ?) ` type CreateResourceParams struct { - ID string `json:"id"` - Title string `json:"title"` - ContentMd string `json:"content_md"` - ImageUrl sql.NullString `json:"image_url"` - ResourceType string `json:"resource_type"` - ResourceListID sql.NullString `json:"resource_list_id"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` + Uuid string `json:"uuid"` + Title string `json:"title"` + ContentMd string `json:"content_md"` + ImageUrl sql.NullString `json:"image_url"` + ResourceType string `json:"resource_type"` + CreatedAt sql.NullTime `json:"created_at"` + UpdatedAt sql.NullTime `json:"updated_at"` + DeletedAt sql.NullTime `json:"deleted_at"` } func (q *Queries) CreateResource(ctx context.Context, arg CreateResourceParams) error { _, err := q.db.ExecContext(ctx, createResource, - arg.ID, + arg.Uuid, arg.Title, arg.ContentMd, arg.ImageUrl, arg.ResourceType, - arg.ResourceListID, arg.CreatedAt, arg.UpdatedAt, + arg.DeletedAt, ) return err } -const createResourceList = `-- name: CreateResourceList :exec -INSERT INTO resource_lists (title, created_at, updated_at) VALUES (?, ?, ?) -` - -type CreateResourceListParams struct { - Title string `json:"title"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` -} - -func (q *Queries) CreateResourceList(ctx context.Context, arg CreateResourceListParams) error { - _, err := q.db.ExecContext(ctx, createResourceList, arg.Title, arg.CreatedAt, arg.UpdatedAt) - return err -} - -const createResourceReference = `-- name: CreateResourceReference :exec -INSERT INTO resource_references (resource_id, resource_list_id, created_at, updated_at) VALUES (?, ?, ?, ?) +const createResourceGroupMapping = `-- name: CreateResourceGroupMapping :exec +INSERT INTO + resource_id_group_id_mapping ( + resource_uuid, + group_uuid, + type, + created_at, + updated_at, + deleted_at + ) +VALUES + (?, ?, ?, ?, ?, ?) ` -type CreateResourceReferenceParams struct { - ResourceID string `json:"resource_id"` - ResourceListID string `json:"resource_list_id"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` +type CreateResourceGroupMappingParams struct { + ResourceUuid sql.NullString `json:"resource_uuid"` + GroupUuid string `json:"group_uuid"` + Type sql.NullString `json:"type"` + CreatedAt sql.NullTime `json:"created_at"` + UpdatedAt sql.NullTime `json:"updated_at"` + DeletedAt sql.NullTime `json:"deleted_at"` } -func (q *Queries) CreateResourceReference(ctx context.Context, arg CreateResourceReferenceParams) error { - _, err := q.db.ExecContext(ctx, createResourceReference, - arg.ResourceID, - arg.ResourceListID, +func (q *Queries) CreateResourceGroupMapping(ctx context.Context, arg CreateResourceGroupMappingParams) error { + _, err := q.db.ExecContext(ctx, createResourceGroupMapping, + arg.ResourceUuid, + arg.GroupUuid, + arg.Type, arg.CreatedAt, arg.UpdatedAt, + arg.DeletedAt, ) return err } const deleteResource = `-- name: DeleteResource :exec -DELETE FROM resources WHERE id = ? +DELETE FROM resource +WHERE + uuid = ? ` -func (q *Queries) DeleteResource(ctx context.Context, id string) error { - _, err := q.db.ExecContext(ctx, deleteResource, id) +func (q *Queries) DeleteResource(ctx context.Context, uuid string) error { + _, err := q.db.ExecContext(ctx, deleteResource, uuid) return err } -const getAnnouncement = `-- name: GetAnnouncement :one +const getAnnouncement = `-- name: GetAnnouncement :exec SELECT - r.id, - r.title, - r.content_md, - r.image_url, - r.resource_type, - r.resource_list_id, - r.created_at, - r.updated_at, - a.event_list_id, - a.approved_by_list_id, - a.visibility, - a.announce_at, - a.discord_channel_id, - a.discord_message_id -FROM resources r -INNER JOIN announcements a ON r.id = a.id -WHERE r.id = ? + uuid, + event_groups_group_uuid, + approved_by_list_uuid, + visibility, + announce_at, + discord_channel_id, + discord_message_id +from + announcement +where + uuid = ? ` -type GetAnnouncementRow struct { - ID string `json:"id"` - Title string `json:"title"` - ContentMd string `json:"content_md"` - ImageUrl sql.NullString `json:"image_url"` - ResourceType string `json:"resource_type"` - ResourceListID sql.NullString `json:"resource_list_id"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` - EventListID sql.NullString `json:"event_list_id"` - ApprovedByListID sql.NullString `json:"approved_by_list_id"` - Visibility string `json:"visibility"` - AnnounceAt int64 `json:"announce_at"` - DiscordChannelID sql.NullString `json:"discord_channel_id"` - DiscordMessageID sql.NullString `json:"discord_message_id"` +func (q *Queries) GetAnnouncement(ctx context.Context, uuid string) error { + _, err := q.db.ExecContext(ctx, getAnnouncement, uuid) + return err } -func (q *Queries) GetAnnouncement(ctx context.Context, id string) (GetAnnouncementRow, error) { - row := q.db.QueryRowContext(ctx, getAnnouncement, id) - var i GetAnnouncementRow - err := row.Scan( - &i.ID, - &i.Title, - &i.ContentMd, - &i.ImageUrl, - &i.ResourceType, - &i.ResourceListID, - &i.CreatedAt, - &i.UpdatedAt, - &i.EventListID, - &i.ApprovedByListID, - &i.Visibility, - &i.AnnounceAt, - &i.DiscordChannelID, - &i.DiscordMessageID, - ) - return i, err +const getEvent = `-- name: GetEvent :exec +SELECT + uuid, + location, + start_at, + end_at, + is_all_day, + host, + visibility +from + event +where + uuid = ? +` + +func (q *Queries) GetEvent(ctx context.Context, uuid string) error { + _, err := q.db.ExecContext(ctx, getEvent, uuid) + return err } -const getEvent = `-- name: GetEvent :one +const getGroupResourceMapping = `-- name: GetGroupResourceMapping :exec SELECT - r.id, - r.title, - r.content_md, - r.image_url, - r.resource_type, - r.resource_list_id, - r.created_at, - r.updated_at, - e.location, - e.start_at, - e.duration_ms, - e.is_all_day, - e.host, - e.visibility -FROM resources r -INNER JOIN events e ON r.id = e.id -WHERE r.id = ? + group_uuid, + resource_uuid, + index_in_list, + created_at, + updated_at, + deleted_at +from + group_id_resource_list_mapping +where + group_uuid = ? ` -type GetEventRow struct { - ID string `json:"id"` - Title string `json:"title"` - ContentMd string `json:"content_md"` - ImageUrl sql.NullString `json:"image_url"` - ResourceType string `json:"resource_type"` - ResourceListID sql.NullString `json:"resource_list_id"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` - Location string `json:"location"` - StartAt interface{} `json:"start_at"` - DurationMs interface{} `json:"duration_ms"` - IsAllDay bool `json:"is_all_day"` - Host string `json:"host"` - Visibility string `json:"visibility"` +func (q *Queries) GetGroupResourceMapping(ctx context.Context, groupUuid sql.NullString) error { + _, err := q.db.ExecContext(ctx, getGroupResourceMapping, groupUuid) + return err } -func (q *Queries) GetEvent(ctx context.Context, id string) (GetEventRow, error) { - row := q.db.QueryRowContext(ctx, getEvent, id) - var i GetEventRow - err := row.Scan( - &i.ID, - &i.Title, - &i.ContentMd, - &i.ImageUrl, - &i.ResourceType, - &i.ResourceListID, - &i.CreatedAt, - &i.UpdatedAt, - &i.Location, - &i.StartAt, - &i.DurationMs, - &i.IsAllDay, - &i.Host, - &i.Visibility, - ) - return i, err +const getPerson = `-- name: GetPerson :exec +SELECT + uuid, + name, + preferred_pronoun +from + person +where + uuid = ? +` + +func (q *Queries) GetPerson(ctx context.Context, uuid sql.NullString) error { + _, err := q.db.ExecContext(ctx, getPerson, uuid) + return err } -const getResourceList = `-- name: GetResourceList :many -SELECT rr.resource_id, rr.resource_list_id, rr.created_at, rr.updated_at -FROM resource_references rr -JOIN resources r ON rr.resource_id = r.id -JOIN resource_lists rl ON rr.resource_list_id = rl.id -WHERE rl.id = ? -ORDER BY rr.index_in_list ASC +const getResource = `-- name: GetResource :exec +SELECT + uuid, + title, + content_md, + image_url, + resource_type, + created_at, + updated_at, + deleted_at +from + resource +where + uuid = ? ` -type GetResourceListRow struct { - ResourceID string `json:"resource_id"` - ResourceListID string `json:"resource_list_id"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` +func (q *Queries) GetResource(ctx context.Context, uuid string) error { + _, err := q.db.ExecContext(ctx, getResource, uuid) + return err } -func (q *Queries) GetResourceList(ctx context.Context, id string) ([]GetResourceListRow, error) { - rows, err := q.db.QueryContext(ctx, getResourceList, id) - if err != nil { - return nil, err - } - defer rows.Close() - var items []GetResourceListRow - for rows.Next() { - var i GetResourceListRow - if err := rows.Scan( - &i.ResourceID, - &i.ResourceListID, - &i.CreatedAt, - &i.UpdatedAt, - ); err != nil { - return nil, err - } - items = append(items, i) - } - if err := rows.Close(); err != nil { - return nil, err - } - if err := rows.Err(); err != nil { - return nil, err - } - return items, nil +const getResourceGroupMapping = `-- name: GetResourceGroupMapping :exec +SELECT + resource_uuid, + group_uuid, + type, + created_at, + updated_at, + deleted_at +from + resource_id_group_id_mapping +where + resource_uuid = ? +` + +func (q *Queries) GetResourceGroupMapping(ctx context.Context, resourceUuid sql.NullString) error { + _, err := q.db.ExecContext(ctx, getResourceGroupMapping, resourceUuid) + return err } diff --git a/internal/db/sqlite/schema.go b/internal/db/sqlite/schema.go index 3a000dc..ef2d2e5 100644 --- a/internal/db/sqlite/schema.go +++ b/internal/db/sqlite/schema.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.23.0 +// sqlc v1.25.0 package sqlite @@ -9,47 +9,56 @@ import ( ) type Announcement struct { - ID string `json:"id"` - EventListID sql.NullString `json:"event_list_id"` - ApprovedByListID sql.NullString `json:"approved_by_list_id"` - Visibility string `json:"visibility"` - AnnounceAt int64 `json:"announce_at"` - DiscordChannelID sql.NullString `json:"discord_channel_id"` - DiscordMessageID sql.NullString `json:"discord_message_id"` + Uuid string `json:"uuid"` + EventGroupsGroupUuid sql.NullString `json:"event_groups_group_uuid"` + ApprovedByListUuid sql.NullString `json:"approved_by_list_uuid"` + Visibility string `json:"visibility"` + AnnounceAt int64 `json:"announce_at"` + DiscordChannelID sql.NullString `json:"discord_channel_id"` + DiscordMessageID sql.NullString `json:"discord_message_id"` } type Event struct { - ID string `json:"id"` + Uuid string `json:"uuid"` Location string `json:"location"` StartAt interface{} `json:"start_at"` - DurationMs interface{} `json:"duration_ms"` + EndAt interface{} `json:"end_at"` IsAllDay bool `json:"is_all_day"` Host string `json:"host"` Visibility string `json:"visibility"` } -type Resource struct { - ID string `json:"id"` - Title string `json:"title"` - ContentMd string `json:"content_md"` - ImageUrl sql.NullString `json:"image_url"` - ResourceType string `json:"resource_type"` - ResourceListID sql.NullString `json:"resource_list_id"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` +type GroupIDResourceListMapping struct { + GroupUuid sql.NullString `json:"group_uuid"` + ResourceUuid string `json:"resource_uuid"` + IndexInList int64 `json:"index_in_list"` + CreatedAt sql.NullTime `json:"created_at"` + UpdatedAt sql.NullTime `json:"updated_at"` + DeletedAt sql.NullTime `json:"deleted_at"` +} + +type Person struct { + Uuid sql.NullString `json:"uuid"` + Name sql.NullString `json:"name"` + PreferredPronoun sql.NullString `json:"preferred_pronoun"` } -type ResourceList struct { - ID string `json:"id"` - Title string `json:"title"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` +type Resource struct { + Uuid string `json:"uuid"` + Title string `json:"title"` + ContentMd string `json:"content_md"` + ImageUrl sql.NullString `json:"image_url"` + ResourceType string `json:"resource_type"` + CreatedAt sql.NullTime `json:"created_at"` + UpdatedAt sql.NullTime `json:"updated_at"` + DeletedAt sql.NullTime `json:"deleted_at"` } -type ResourceReference struct { - ResourceID string `json:"resource_id"` - ResourceListID string `json:"resource_list_id"` - IndexInList int64 `json:"index_in_list"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` +type ResourceIDGroupIDMapping struct { + ResourceUuid sql.NullString `json:"resource_uuid"` + GroupUuid string `json:"group_uuid"` + Type sql.NullString `json:"type"` + CreatedAt sql.NullTime `json:"created_at"` + UpdatedAt sql.NullTime `json:"updated_at"` + DeletedAt sql.NullTime `json:"deleted_at"` } diff --git a/internal/db/sqlite/schema.sql b/internal/db/sqlite/schema.sql index 2108afc..7b10e70 100644 --- a/internal/db/sqlite/schema.sql +++ b/internal/db/sqlite/schema.sql @@ -7,7 +7,7 @@ CREATE TABLE type TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - deleted_at TIMESTAMP DEFAULT NULL, + deleted_at TIMESTAMP DEFAULT NULL ); CREATE TABLE @@ -17,7 +17,7 @@ CREATE TABLE index_in_list INTEGER NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - deleted_at TIMESTAMP DEFAULT NULL, + deleted_at TIMESTAMP DEFAULT NULL ); -- Create the 'resource' table. @@ -30,7 +30,7 @@ CREATE TABLE resource_type TEXT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - deleted_at TIMESTAMP DEFAULT NULL, + deleted_at TIMESTAMP DEFAULT NULL ); -- Create the 'events' table which is a table of event resources. @@ -42,7 +42,7 @@ CREATE TABLE end_at NUMBER NOT NULL, is_all_day BOOLEAN NOT NULL, host TEXT NOT NULL, -- Accepts team ID or plain text. - visibility TEXT NOT NULL, -- Accepts 'public' or 'private'. + visibility TEXT NOT NULL -- Accepts 'public' or 'private'. ) -- Create the 'person' table which is a table of person resources. CREATE TABLE