Add filters to views requests

This commit is contained in:
Brieuc Dubois 2024-01-10 16:21:07 +01:00
parent 7404aed139
commit bb479c45ef
2 changed files with 28 additions and 5 deletions

View File

@ -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
}

View File

@ -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"`
}