feat: new AI generated lists
I think this could be how we generate other lists Problems: - Knowing it's a location is good because you can do nice stuff on the frontend. - Same for contacts & events. So a good alternative, is to still use this type, but perhaps change the database such that all lists live within the new tables (lists, image_lists). But have special tags. This would also make it easier on the AI I think.
This commit is contained in:
49
backend/models/lists.go
Normal file
49
backend/models/lists.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
"screenmark/screenmark/.gen/haystack/haystack/model"
|
||||
. "screenmark/screenmark/.gen/haystack/haystack/table"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type ListModel struct {
|
||||
dbPool *sql.DB
|
||||
}
|
||||
|
||||
func (m ListModel) Save(ctx context.Context, userId uuid.UUID, name string, description string) (model.Lists, error) {
|
||||
stmt := Lists.INSERT(Lists.UserID, Lists.Name, Lists.Description).
|
||||
VALUES(userId, name, description).
|
||||
RETURNING(Lists.ID, Lists.Name, Lists.Description)
|
||||
|
||||
newList := model.Lists{}
|
||||
err := stmt.QueryContext(ctx, m.dbPool, &newList)
|
||||
|
||||
return newList, err
|
||||
}
|
||||
|
||||
func (m ListModel) List(ctx context.Context, userId uuid.UUID) ([]model.Lists, error) {
|
||||
stmt := Lists.SELECT(Lists.AllColumns).
|
||||
WHERE(Lists.UserID.EQ(UUID(userId)))
|
||||
|
||||
lists := []model.Lists{}
|
||||
err := stmt.QueryContext(ctx, m.dbPool, &lists)
|
||||
|
||||
return lists, err
|
||||
}
|
||||
|
||||
func (m ListModel) SaveInto(ctx context.Context, listId uuid.UUID, imageId uuid.UUID) error {
|
||||
stmt := ImageLists.INSERT(ImageLists.ListID, ImageLists.ImageID).
|
||||
VALUES(listId, imageId)
|
||||
|
||||
_, err := stmt.ExecContext(ctx, m.dbPool)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func NewListModel(db *sql.DB) ListModel {
|
||||
return ListModel{dbPool: db}
|
||||
}
|
||||
Reference in New Issue
Block a user