diff --git a/api/project.go b/api/project.go index ac412b2..61c0647 100644 --- a/api/project.go +++ b/api/project.go @@ -23,6 +23,10 @@ func Project(g *gin.RouterGroup, db database.Database) { if setting := c.Query("expiring"); setting != "" { filter.Expiring = setting == "true" } + if setting := c.Query("favorite"); setting != "" { + favorite := setting == "true" + filter.Favorite = &favorite + } return l.ListProjects(c, filter) })) diff --git a/database/postgres/project.go b/database/postgres/project.go index 7ba1a93..ae02e24 100644 --- a/database/postgres/project.go +++ b/database/postgres/project.go @@ -39,6 +39,9 @@ func (r *projectRepository) List(ctx context.Context, filter models.ProjectFilte if filter.Expiring { sq = sq.Where("end_time IS NOT NULL") } + if filter.Favorite != nil { + sq = sq.Where(squirrel.Eq{"favorite": *filter.Favorite}) + } sq = sq.OrderBy("active", "created_time DESC") @@ -62,9 +65,9 @@ func (r *projectRepository) List(ctx context.Context, filter models.ProjectFilte func (r *projectRepository) Insert(ctx context.Context, project models.Project) error { _, err := r.db.NamedExecContext(ctx, ` INSERT INTO project( - project_id, user_id, name, description, icon, active, created_time, end_time, status_tag + project_id, user_id, name, description, icon, active, created_time, end_time, status_tag, favorite ) VALUES ( - :project_id, :user_id, :name, :description, :icon, :active, :created_time, :end_time, :status_tag + :project_id, :user_id, :name, :description, :icon, :active, :created_time, :end_time, :status_tag, :favorite ) `, &project) if err != nil { @@ -82,7 +85,8 @@ func (r *projectRepository) Update(ctx context.Context, project models.Project) icon = :icon, active = :active, end_time = :end_time, - status_tag = :status_tag + status_tag = :status_tag, + favorite = :favorite WHERE project_id=:project_id `, &project) if err != nil { diff --git a/migrations/postgres/20210227154406_add_project_column_favorite.sql b/migrations/postgres/20210227154406_add_project_column_favorite.sql new file mode 100644 index 0000000..7928450 --- /dev/null +++ b/migrations/postgres/20210227154406_add_project_column_favorite.sql @@ -0,0 +1,11 @@ +-- +goose Up +-- +goose StatementBegin +ALTER TABLE project + ADD COLUMN favorite BOOLEAN NOT NULL DEFAULT false; +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +ALTER TABLE project + DROP COLUMN favorite; +-- +goose StatementEnd diff --git a/models/project.go b/models/project.go index b8fdd76..0e398df 100644 --- a/models/project.go +++ b/models/project.go @@ -15,6 +15,7 @@ type Project struct { CreatedTime time.Time `json:"createdTime" db:"created_time"` EndTime *time.Time `json:"endTime" db:"end_time"` StatusTag *string `json:"statusTag" db:"status_tag"` + Favorite bool `json:"favorite" db:"favorite"` } func (project *Project) Update(update ProjectUpdate) { @@ -43,6 +44,9 @@ func (project *Project) Update(update ProjectUpdate) { if update.ClearStatusTag { project.StatusTag = nil } + if update.Favorite != nil { + project.Favorite = *update.Favorite + } } type ProjectUpdate struct { @@ -54,6 +58,7 @@ type ProjectUpdate struct { ClearEndTime bool `json:"clearEndTime"` StatusTag *string `json:"statusTag"` ClearStatusTag bool `json:"clearStatusTag"` + Favorite *bool `json:"favorite"` } type ProjectResult struct { @@ -64,6 +69,7 @@ type ProjectResult struct { type ProjectFilter struct { UserID string Active *bool + Favorite *bool Expiring bool IDs []string } diff --git a/svelte-ui/src/clients/stufflog.ts b/svelte-ui/src/clients/stufflog.ts index 5f868e8..6645520 100644 --- a/svelte-ui/src/clients/stufflog.ts +++ b/svelte-ui/src/clients/stufflog.ts @@ -60,7 +60,7 @@ export class StufflogClient { return data.project; } - async listProjects({active, expiring}: ProjectFilter): Promise { + async listProjects({active, expiring, favorite}: ProjectFilter): Promise { let queries = []; if (active != null) { queries.push(`active=${active}`); @@ -68,6 +68,9 @@ export class StufflogClient { if (expiring != null) { queries.push(`expiring=${expiring}`); } + if (favorite != null) { + queries.push(`favorite=${favorite}`) + } const query = queries.length > 0 ? `?${queries.join("&")}` : ""; diff --git a/svelte-ui/src/components/Boi.svelte b/svelte-ui/src/components/Boi.svelte index 6bd78eb..7f2b117 100644 --- a/svelte-ui/src/components/Boi.svelte +++ b/svelte-ui/src/components/Boi.svelte @@ -6,6 +6,7 @@ export let open: ModalData = {name: "none"}; export let disabled: boolean = false; export let compact: boolean = false; + export let compacter: boolean = false; export let tiny: boolean = false; const dispatch = createEventDispatcher(); @@ -19,7 +20,7 @@ } -
+
\ No newline at end of file diff --git a/svelte-ui/src/components/ProjectSelect.svelte b/svelte-ui/src/components/ProjectSelect.svelte index abde2ff..85fb3e5 100644 --- a/svelte-ui/src/components/ProjectSelect.svelte +++ b/svelte-ui/src/components/ProjectSelect.svelte @@ -1,7 +1,5 @@