diff --git a/backend/db/views.go b/backend/db/views.go index 210d9da..b5dfe64 100644 --- a/backend/db/views.go +++ b/backend/db/views.go @@ -16,20 +16,26 @@ func CreateView(v types.View) (int, error) { return int(id), nil } -func GetProjectViews(projectID int) ([]types.View, error) { +func GetProjectViews(projectID int) ([]types.FullView, error) { rows, err := db.Query("SELECT * FROM views WHERE project_id = ?", projectID) if err != nil { return nil, err } defer rows.Close() - var views []types.View + var views []types.FullView for rows.Next() { - var v types.View + var v types.FullView if err := rows.Scan(&v.ID, &v.ProjectID, &v.PrimaryTagID, &v.SecondaryTagID, &v.Title, &v.SortTagID, &v.SortDirection); err != nil { return nil, err } + filters, err := GetViewFilters(v.ID) + if err != nil { + return nil, err + } + v.Filters = filters + views = append(views, v) } @@ -40,7 +46,7 @@ func GetProjectViews(projectID int) ([]types.View, error) { return views, nil } -func GetView(id int) (*types.View, error) { +func GetView(id int) (*types.FullView, error) { rows, err := db.Query("SELECT * FROM views WHERE id = ?", id) if err != nil { return nil, err @@ -51,9 +57,15 @@ func GetView(id int) (*types.View, error) { return nil, nil } - var v types.View + var v types.FullView rows.Scan(&v.ID, &v.ProjectID, v.PrimaryTagID, v.SecondaryTagID, v.Title, v.SortTagID, v.SortDirection) + filters, err := GetViewFilters(id) + if(err != nil) { + return nil, err + } + v.Filters = filters + return &v, nil } diff --git a/backend/types/view.go b/backend/types/view.go index cf8b1a4..04014c4 100644 --- a/backend/types/view.go +++ b/backend/types/view.go @@ -9,3 +9,14 @@ type View struct { SortTagID *int `json:"sort_tag_id"` SortDirection *int `json:"sort_direction"` } + +type FullView struct { + ID int `json:"id"` + ProjectID int `json:"project_id"` + Title string `json:"title"` + PrimaryTagID *int `json:"primary_tag_id"` + SecondaryTagID *int `json:"secondary_tag_id"` + SortTagID *int `json:"sort_tag_id"` + SortDirection *int `json:"sort_direction"` + Filters []Filter `json:"filters"` +} \ No newline at end of file