feat(ui): add content editor components for skills and thoughts
Some checks failed
CI / build-and-test (push) Failing after -31m24s

* Implement ContentEditorField for inline editing of content
* Create ContentEditorModal for editing content in a modal
* Introduce FormerShell for managing forms related to skills and thoughts
* Enhance SkillsPage and ThoughtsPage with new components for better content management
This commit is contained in:
2026-05-02 19:35:27 +02:00
parent 442cc3ef53
commit 9e6d05e055
59 changed files with 4727 additions and 3430 deletions

View File

@@ -1,206 +1,206 @@
package store
import (
"context"
"fmt"
"strings"
"time"
// import (
// "context"
// "fmt"
// "strings"
// "time"
"github.com/google/uuid"
// "github.com/google/uuid"
"git.warky.dev/wdevs/amcs/internal/generatedmodels"
ext "git.warky.dev/wdevs/amcs/internal/types"
)
// "git.warky.dev/wdevs/amcs/internal/generatedmodels"
// ext "git.warky.dev/wdevs/amcs/internal/types"
// )
func (db *DB) AddFamilyMember(ctx context.Context, m ext.FamilyMember) (ext.FamilyMember, error) {
row := db.pool.QueryRow(ctx, `
insert into family_members (name, relationship, birth_date, notes)
values ($1, $2, $3, $4)
returning id, created_at
`, m.Name, nullStr(m.Relationship), m.BirthDate, nullStr(m.Notes))
// func (db *DB) AddFamilyMember(ctx context.Context, m ext.FamilyMember) (ext.FamilyMember, error) {
// row := db.pool.QueryRow(ctx, `
// insert into family_members (name, relationship, birth_date, notes)
// values ($1, $2, $3, $4)
// returning id, created_at
// `, m.Name, nullStr(m.Relationship), m.BirthDate, nullStr(m.Notes))
created := m
var model generatedmodels.ModelPublicFamilyMembers
if err := row.Scan(&model.ID, &model.CreatedAt); err != nil {
return ext.FamilyMember{}, fmt.Errorf("insert family member: %w", err)
}
created.ID = model.ID.UUID()
created.CreatedAt = model.CreatedAt.Time()
return created, nil
}
// created := m
// var model generatedmodels.ModelPublicFamilyMembers
// if err := row.Scan(&model.ID, &model.CreatedAt); err != nil {
// return ext.FamilyMember{}, fmt.Errorf("insert family member: %w", err)
// }
// created.ID = model.ID.UUID()
// created.CreatedAt = model.CreatedAt.Time()
// return created, nil
// }
func (db *DB) ListFamilyMembers(ctx context.Context) ([]ext.FamilyMember, error) {
rows, err := db.pool.Query(ctx, `select id, name, relationship, birth_date, notes, created_at from family_members order by name`)
if err != nil {
return nil, fmt.Errorf("list family members: %w", err)
}
defer rows.Close()
// func (db *DB) ListFamilyMembers(ctx context.Context) ([]ext.FamilyMember, error) {
// rows, err := db.pool.Query(ctx, `select id, name, relationship, birth_date, notes, created_at from family_members order by name`)
// if err != nil {
// return nil, fmt.Errorf("list family members: %w", err)
// }
// defer rows.Close()
var members []ext.FamilyMember
for rows.Next() {
var model generatedmodels.ModelPublicFamilyMembers
if err := rows.Scan(&model.ID, &model.Name, &model.Relationship, &model.BirthDate, &model.Notes, &model.CreatedAt); err != nil {
return nil, fmt.Errorf("scan family member: %w", err)
}
members = append(members, familyMemberFromModel(model))
}
return members, rows.Err()
}
// var members []ext.FamilyMember
// for rows.Next() {
// var model generatedmodels.ModelPublicFamilyMembers
// if err := rows.Scan(&model.ID, &model.Name, &model.Relationship, &model.BirthDate, &model.Notes, &model.CreatedAt); err != nil {
// return nil, fmt.Errorf("scan family member: %w", err)
// }
// members = append(members, familyMemberFromModel(model))
// }
// return members, rows.Err()
// }
func (db *DB) AddActivity(ctx context.Context, a ext.Activity) (ext.Activity, error) {
row := db.pool.QueryRow(ctx, `
insert into activities (family_member_id, title, activity_type, day_of_week, start_time, end_time, start_date, end_date, location, notes)
values ($1, $2, $3, $4, $5::time, $6::time, $7, $8, $9, $10)
returning id, created_at
`, a.FamilyMemberID, a.Title, nullStr(a.ActivityType), nullStr(a.DayOfWeek),
nullStr(a.StartTime), nullStr(a.EndTime), a.StartDate, a.EndDate,
nullStr(a.Location), nullStr(a.Notes))
// func (db *DB) AddActivity(ctx context.Context, a ext.Activity) (ext.Activity, error) {
// row := db.pool.QueryRow(ctx, `
// insert into activities (family_member_id, title, activity_type, day_of_week, start_time, end_time, start_date, end_date, location, notes)
// values ($1, $2, $3, $4, $5::time, $6::time, $7, $8, $9, $10)
// returning id, created_at
// `, a.FamilyMemberID, a.Title, nullStr(a.ActivityType), nullStr(a.DayOfWeek),
// nullStr(a.StartTime), nullStr(a.EndTime), a.StartDate, a.EndDate,
// nullStr(a.Location), nullStr(a.Notes))
created := a
var model generatedmodels.ModelPublicActivities
if err := row.Scan(&model.ID, &model.CreatedAt); err != nil {
return ext.Activity{}, fmt.Errorf("insert activity: %w", err)
}
created.ID = model.ID.UUID()
created.CreatedAt = model.CreatedAt.Time()
return created, nil
}
// created := a
// var model generatedmodels.ModelPublicActivities
// if err := row.Scan(&model.ID, &model.CreatedAt); err != nil {
// return ext.Activity{}, fmt.Errorf("insert activity: %w", err)
// }
// created.ID = model.ID.UUID()
// created.CreatedAt = model.CreatedAt.Time()
// return created, nil
// }
func (db *DB) GetWeekSchedule(ctx context.Context, weekStart time.Time) ([]ext.Activity, error) {
weekEnd := weekStart.AddDate(0, 0, 7)
// func (db *DB) GetWeekSchedule(ctx context.Context, weekStart time.Time) ([]ext.Activity, error) {
// weekEnd := weekStart.AddDate(0, 0, 7)
rows, err := db.pool.Query(ctx, `
select a.id, a.family_member_id, fm.name, a.title, a.activity_type,
a.day_of_week, a.start_time::text, a.end_time::text,
a.start_date, a.end_date, a.location, a.notes, a.created_at
from activities a
left join family_members fm on fm.id = a.family_member_id
where (a.start_date >= $1 and a.start_date < $2)
or (a.day_of_week is not null and (a.end_date is null or a.end_date >= $1))
order by a.start_date, a.start_time
`, weekStart, weekEnd)
if err != nil {
return nil, fmt.Errorf("get week schedule: %w", err)
}
defer rows.Close()
// rows, err := db.pool.Query(ctx, `
// select a.id, a.family_member_id, fm.name, a.title, a.activity_type,
// a.day_of_week, a.start_time::text, a.end_time::text,
// a.start_date, a.end_date, a.location, a.notes, a.created_at
// from activities a
// left join family_members fm on fm.id = a.family_member_id
// where (a.start_date >= $1 and a.start_date < $2)
// or (a.day_of_week is not null and (a.end_date is null or a.end_date >= $1))
// order by a.start_date, a.start_time
// `, weekStart, weekEnd)
// if err != nil {
// return nil, fmt.Errorf("get week schedule: %w", err)
// }
// defer rows.Close()
return scanActivities(rows)
}
// return scanActivities(rows)
// }
func (db *DB) SearchActivities(ctx context.Context, query, activityType string, memberID *uuid.UUID) ([]ext.Activity, error) {
args := []any{}
conditions := []string{}
// func (db *DB) SearchActivities(ctx context.Context, query, activityType string, memberID *uuid.UUID) ([]ext.Activity, error) {
// args := []any{}
// conditions := []string{}
if q := strings.TrimSpace(query); q != "" {
args = append(args, "%"+q+"%")
conditions = append(conditions, fmt.Sprintf("(a.title ILIKE $%d OR a.notes ILIKE $%d)", len(args), len(args)))
}
if t := strings.TrimSpace(activityType); t != "" {
args = append(args, t)
conditions = append(conditions, fmt.Sprintf("a.activity_type = $%d", len(args)))
}
if memberID != nil {
args = append(args, *memberID)
conditions = append(conditions, fmt.Sprintf("a.family_member_id = $%d", len(args)))
}
// if q := strings.TrimSpace(query); q != "" {
// args = append(args, "%"+q+"%")
// conditions = append(conditions, fmt.Sprintf("(a.title ILIKE $%d OR a.notes ILIKE $%d)", len(args), len(args)))
// }
// if t := strings.TrimSpace(activityType); t != "" {
// args = append(args, t)
// conditions = append(conditions, fmt.Sprintf("a.activity_type = $%d", len(args)))
// }
// if memberID != nil {
// args = append(args, *memberID)
// conditions = append(conditions, fmt.Sprintf("a.family_member_id = $%d", len(args)))
// }
q := `
select a.id, a.family_member_id, fm.name, a.title, a.activity_type,
a.day_of_week, a.start_time::text, a.end_time::text,
a.start_date, a.end_date, a.location, a.notes, a.created_at
from activities a
left join family_members fm on fm.id = a.family_member_id
`
if len(conditions) > 0 {
q += " where " + strings.Join(conditions, " and ")
}
q += " order by a.start_date, a.start_time"
// q := `
// select a.id, a.family_member_id, fm.name, a.title, a.activity_type,
// a.day_of_week, a.start_time::text, a.end_time::text,
// a.start_date, a.end_date, a.location, a.notes, a.created_at
// from activities a
// left join family_members fm on fm.id = a.family_member_id
// `
// if len(conditions) > 0 {
// q += " where " + strings.Join(conditions, " and ")
// }
// q += " order by a.start_date, a.start_time"
rows, err := db.pool.Query(ctx, q, args...)
if err != nil {
return nil, fmt.Errorf("search activities: %w", err)
}
defer rows.Close()
// rows, err := db.pool.Query(ctx, q, args...)
// if err != nil {
// return nil, fmt.Errorf("search activities: %w", err)
// }
// defer rows.Close()
return scanActivities(rows)
}
// return scanActivities(rows)
// }
func (db *DB) AddImportantDate(ctx context.Context, d ext.ImportantDate) (ext.ImportantDate, error) {
row := db.pool.QueryRow(ctx, `
insert into important_dates (family_member_id, title, date_value, recurring_yearly, reminder_days_before, notes)
values ($1, $2, $3, $4, $5, $6)
returning id, created_at
`, d.FamilyMemberID, d.Title, d.DateValue, d.RecurringYearly, d.ReminderDaysBefore, nullStr(d.Notes))
// func (db *DB) AddImportantDate(ctx context.Context, d ext.ImportantDate) (ext.ImportantDate, error) {
// row := db.pool.QueryRow(ctx, `
// insert into important_dates (family_member_id, title, date_value, recurring_yearly, reminder_days_before, notes)
// values ($1, $2, $3, $4, $5, $6)
// returning id, created_at
// `, d.FamilyMemberID, d.Title, d.DateValue, d.RecurringYearly, d.ReminderDaysBefore, nullStr(d.Notes))
created := d
var model generatedmodels.ModelPublicImportantDates
if err := row.Scan(&model.ID, &model.CreatedAt); err != nil {
return ext.ImportantDate{}, fmt.Errorf("insert important date: %w", err)
}
created.ID = model.ID.UUID()
created.CreatedAt = model.CreatedAt.Time()
return created, nil
}
// created := d
// var model generatedmodels.ModelPublicImportantDates
// if err := row.Scan(&model.ID, &model.CreatedAt); err != nil {
// return ext.ImportantDate{}, fmt.Errorf("insert important date: %w", err)
// }
// created.ID = model.ID.UUID()
// created.CreatedAt = model.CreatedAt.Time()
// return created, nil
// }
func (db *DB) GetUpcomingDates(ctx context.Context, daysAhead int) ([]ext.ImportantDate, error) {
if daysAhead <= 0 {
daysAhead = 30
}
now := time.Now()
cutoff := now.AddDate(0, 0, daysAhead)
// func (db *DB) GetUpcomingDates(ctx context.Context, daysAhead int) ([]ext.ImportantDate, error) {
// if daysAhead <= 0 {
// daysAhead = 30
// }
// now := time.Now()
// cutoff := now.AddDate(0, 0, daysAhead)
// For yearly recurring events, check if this year's occurrence falls in range
rows, err := db.pool.Query(ctx, `
select d.id, d.family_member_id, fm.name, d.title, d.date_value,
d.recurring_yearly, d.reminder_days_before, d.notes, d.created_at
from important_dates d
left join family_members fm on fm.id = d.family_member_id
where (
(d.recurring_yearly = false and d.date_value between $1 and $2)
or
(d.recurring_yearly = true and
make_date(extract(year from now())::int, extract(month from d.date_value)::int, extract(day from d.date_value)::int)
between $1 and $2)
)
order by d.date_value
`, now, cutoff)
if err != nil {
return nil, fmt.Errorf("get upcoming dates: %w", err)
}
defer rows.Close()
// // For yearly recurring events, check if this year's occurrence falls in range
// rows, err := db.pool.Query(ctx, `
// select d.id, d.family_member_id, fm.name, d.title, d.date_value,
// d.recurring_yearly, d.reminder_days_before, d.notes, d.created_at
// from important_dates d
// left join family_members fm on fm.id = d.family_member_id
// where (
// (d.recurring_yearly = false and d.date_value between $1 and $2)
// or
// (d.recurring_yearly = true and
// make_date(extract(year from now())::int, extract(month from d.date_value)::int, extract(day from d.date_value)::int)
// between $1 and $2)
// )
// order by d.date_value
// `, now, cutoff)
// if err != nil {
// return nil, fmt.Errorf("get upcoming dates: %w", err)
// }
// defer rows.Close()
var dates []ext.ImportantDate
for rows.Next() {
var model generatedmodels.ModelPublicImportantDates
var memberName *string
if err := rows.Scan(&model.ID, &model.FamilyMemberID, &memberName, &model.Title, &model.DateValue,
&model.RecurringYearly, &model.ReminderDaysBefore, &model.Notes, &model.CreatedAt); err != nil {
return nil, fmt.Errorf("scan important date: %w", err)
}
dates = append(dates, importantDateFromModel(model, strVal(memberName)))
}
return dates, rows.Err()
}
// var dates []ext.ImportantDate
// for rows.Next() {
// var model generatedmodels.ModelPublicImportantDates
// var memberName *string
// if err := rows.Scan(&model.ID, &model.FamilyMemberID, &memberName, &model.Title, &model.DateValue,
// &model.RecurringYearly, &model.ReminderDaysBefore, &model.Notes, &model.CreatedAt); err != nil {
// return nil, fmt.Errorf("scan important date: %w", err)
// }
// dates = append(dates, importantDateFromModel(model, strVal(memberName)))
// }
// return dates, rows.Err()
// }
func scanActivities(rows interface {
Next() bool
Scan(...any) error
Err() error
Close()
}) ([]ext.Activity, error) {
defer rows.Close()
var activities []ext.Activity
for rows.Next() {
var model generatedmodels.ModelPublicActivities
var memberName *string
if err := rows.Scan(
&model.ID, &model.FamilyMemberID, &memberName, &model.Title, &model.ActivityType,
&model.DayOfWeek, &model.StartTime, &model.EndTime,
&model.StartDate, &model.EndDate, &model.Location, &model.Notes, &model.CreatedAt,
); err != nil {
return nil, fmt.Errorf("scan activity: %w", err)
}
activities = append(activities, activityFromModel(model, strVal(memberName)))
}
return activities, rows.Err()
}
// func scanActivities(rows interface {
// Next() bool
// Scan(...any) error
// Err() error
// Close()
// }) ([]ext.Activity, error) {
// defer rows.Close()
// var activities []ext.Activity
// for rows.Next() {
// var model generatedmodels.ModelPublicActivities
// var memberName *string
// if err := rows.Scan(
// &model.ID, &model.FamilyMemberID, &memberName, &model.Title, &model.ActivityType,
// &model.DayOfWeek, &model.StartTime, &model.EndTime,
// &model.StartDate, &model.EndDate, &model.Location, &model.Notes, &model.CreatedAt,
// ); err != nil {
// return nil, fmt.Errorf("scan activity: %w", err)
// }
// activities = append(activities, activityFromModel(model, strVal(memberName)))
// }
// return activities, rows.Err()
// }

View File

@@ -1,235 +1,235 @@
package store
import (
"context"
"fmt"
"strings"
"time"
// import (
// "context"
// "fmt"
// "strings"
// "time"
"github.com/google/uuid"
// "github.com/google/uuid"
"git.warky.dev/wdevs/amcs/internal/generatedmodels"
ext "git.warky.dev/wdevs/amcs/internal/types"
)
// "git.warky.dev/wdevs/amcs/internal/generatedmodels"
// ext "git.warky.dev/wdevs/amcs/internal/types"
// )
func (db *DB) AddProfessionalContact(ctx context.Context, c ext.ProfessionalContact) (ext.ProfessionalContact, error) {
if c.Tags == nil {
c.Tags = []string{}
}
// func (db *DB) AddProfessionalContact(ctx context.Context, c ext.ProfessionalContact) (ext.ProfessionalContact, error) {
// if c.Tags == nil {
// c.Tags = []string{}
// }
row := db.pool.QueryRow(ctx, `
insert into professional_contacts (name, company, title, email, phone, linkedin_url, how_we_met, tags, notes, follow_up_date)
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
returning id, created_at, updated_at
`, c.Name, nullStr(c.Company), nullStr(c.Title), nullStr(c.Email), nullStr(c.Phone),
nullStr(c.LinkedInURL), nullStr(c.HowWeMet), c.Tags, nullStr(c.Notes), c.FollowUpDate)
// row := db.pool.QueryRow(ctx, `
// insert into professional_contacts (name, company, title, email, phone, linkedin_url, how_we_met, tags, notes, follow_up_date)
// values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
// returning id, created_at, updated_at
// `, c.Name, nullStr(c.Company), nullStr(c.Title), nullStr(c.Email), nullStr(c.Phone),
// nullStr(c.LinkedInURL), nullStr(c.HowWeMet), c.Tags, nullStr(c.Notes), c.FollowUpDate)
created := c
var model generatedmodels.ModelPublicProfessionalContacts
if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil {
return ext.ProfessionalContact{}, fmt.Errorf("insert contact: %w", err)
}
created.ID = model.ID.UUID()
created.CreatedAt = model.CreatedAt.Time()
created.UpdatedAt = model.UpdatedAt.Time()
return created, nil
}
// created := c
// var model generatedmodels.ModelPublicProfessionalContacts
// if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil {
// return ext.ProfessionalContact{}, fmt.Errorf("insert contact: %w", err)
// }
// created.ID = model.ID.UUID()
// created.CreatedAt = model.CreatedAt.Time()
// created.UpdatedAt = model.UpdatedAt.Time()
// return created, nil
// }
func (db *DB) SearchContacts(ctx context.Context, query string, tags []string) ([]ext.ProfessionalContact, error) {
args := []any{}
conditions := []string{}
// func (db *DB) SearchContacts(ctx context.Context, query string, tags []string) ([]ext.ProfessionalContact, error) {
// args := []any{}
// conditions := []string{}
if q := strings.TrimSpace(query); q != "" {
args = append(args, "%"+q+"%")
idx := len(args)
conditions = append(conditions, fmt.Sprintf(
"(name ILIKE $%[1]d OR company ILIKE $%[1]d OR title ILIKE $%[1]d OR notes ILIKE $%[1]d)", idx))
}
if len(tags) > 0 {
args = append(args, tags)
conditions = append(conditions, fmt.Sprintf("tags @> $%d", len(args)))
}
// if q := strings.TrimSpace(query); q != "" {
// args = append(args, "%"+q+"%")
// idx := len(args)
// conditions = append(conditions, fmt.Sprintf(
// "(name ILIKE $%[1]d OR company ILIKE $%[1]d OR title ILIKE $%[1]d OR notes ILIKE $%[1]d)", idx))
// }
// if len(tags) > 0 {
// args = append(args, tags)
// conditions = append(conditions, fmt.Sprintf("tags @> $%d", len(args)))
// }
q := `select id, name, company, title, email, phone, linkedin_url, how_we_met, tags::text[], notes, last_contacted, follow_up_date, created_at, updated_at from professional_contacts`
if len(conditions) > 0 {
q += " where " + strings.Join(conditions, " and ")
}
q += " order by name"
// q := `select id, name, company, title, email, phone, linkedin_url, how_we_met, tags::text[], notes, last_contacted, follow_up_date, created_at, updated_at from professional_contacts`
// if len(conditions) > 0 {
// q += " where " + strings.Join(conditions, " and ")
// }
// q += " order by name"
rows, err := db.pool.Query(ctx, q, args...)
if err != nil {
return nil, fmt.Errorf("search contacts: %w", err)
}
defer rows.Close()
// rows, err := db.pool.Query(ctx, q, args...)
// if err != nil {
// return nil, fmt.Errorf("search contacts: %w", err)
// }
// defer rows.Close()
return scanContacts(rows)
}
// return scanContacts(rows)
// }
func (db *DB) GetContact(ctx context.Context, id uuid.UUID) (ext.ProfessionalContact, error) {
row := db.pool.QueryRow(ctx, `
select id, name, company, title, email, phone, linkedin_url, how_we_met, tags::text[], notes, last_contacted, follow_up_date, created_at, updated_at
from professional_contacts where id = $1
`, id)
// func (db *DB) GetContact(ctx context.Context, id uuid.UUID) (ext.ProfessionalContact, error) {
// row := db.pool.QueryRow(ctx, `
// select id, name, company, title, email, phone, linkedin_url, how_we_met, tags::text[], notes, last_contacted, follow_up_date, created_at, updated_at
// from professional_contacts where id = $1
// `, id)
var model generatedmodels.ModelPublicProfessionalContacts
var tags []string
if err := row.Scan(&model.ID, &model.Name, &model.Company, &model.Title, &model.Email, &model.Phone,
&model.LinkedinURL, &model.HowWeMet, &tags, &model.Notes, &model.LastContacted, &model.FollowUpDate,
&model.CreatedAt, &model.UpdatedAt); err != nil {
return ext.ProfessionalContact{}, fmt.Errorf("get contact: %w", err)
}
c := professionalContactFromModel(model, tags)
return c, nil
}
// var model generatedmodels.ModelPublicProfessionalContacts
// var tags []string
// if err := row.Scan(&model.ID, &model.Name, &model.Company, &model.Title, &model.Email, &model.Phone,
// &model.LinkedinURL, &model.HowWeMet, &tags, &model.Notes, &model.LastContacted, &model.FollowUpDate,
// &model.CreatedAt, &model.UpdatedAt); err != nil {
// return ext.ProfessionalContact{}, fmt.Errorf("get contact: %w", err)
// }
// c := professionalContactFromModel(model, tags)
// return c, nil
// }
func (db *DB) LogInteraction(ctx context.Context, interaction ext.ContactInteraction) (ext.ContactInteraction, error) {
occurredAt := interaction.OccurredAt
if occurredAt.IsZero() {
occurredAt = time.Now()
}
// func (db *DB) LogInteraction(ctx context.Context, interaction ext.ContactInteraction) (ext.ContactInteraction, error) {
// occurredAt := interaction.OccurredAt
// if occurredAt.IsZero() {
// occurredAt = time.Now()
// }
row := db.pool.QueryRow(ctx, `
insert into contact_interactions (contact_id, interaction_type, occurred_at, summary, follow_up_needed, follow_up_notes)
values ($1, $2, $3, $4, $5, $6)
returning id, created_at
`, interaction.ContactID, interaction.InteractionType, occurredAt, interaction.Summary,
interaction.FollowUpNeeded, nullStr(interaction.FollowUpNotes))
// row := db.pool.QueryRow(ctx, `
// insert into contact_interactions (contact_id, interaction_type, occurred_at, summary, follow_up_needed, follow_up_notes)
// values ($1, $2, $3, $4, $5, $6)
// returning id, created_at
// `, interaction.ContactID, interaction.InteractionType, occurredAt, interaction.Summary,
// interaction.FollowUpNeeded, nullStr(interaction.FollowUpNotes))
created := interaction
created.OccurredAt = occurredAt
var model generatedmodels.ModelPublicContactInteractions
if err := row.Scan(&model.ID, &model.CreatedAt); err != nil {
return ext.ContactInteraction{}, fmt.Errorf("insert interaction: %w", err)
}
created.ID = model.ID.UUID()
created.CreatedAt = model.CreatedAt.Time()
return created, nil
}
// created := interaction
// created.OccurredAt = occurredAt
// var model generatedmodels.ModelPublicContactInteractions
// if err := row.Scan(&model.ID, &model.CreatedAt); err != nil {
// return ext.ContactInteraction{}, fmt.Errorf("insert interaction: %w", err)
// }
// created.ID = model.ID.UUID()
// created.CreatedAt = model.CreatedAt.Time()
// return created, nil
// }
func (db *DB) GetContactHistory(ctx context.Context, contactID uuid.UUID) (ext.ContactHistory, error) {
contact, err := db.GetContact(ctx, contactID)
if err != nil {
return ext.ContactHistory{}, err
}
// func (db *DB) GetContactHistory(ctx context.Context, contactID uuid.UUID) (ext.ContactHistory, error) {
// contact, err := db.GetContact(ctx, contactID)
// if err != nil {
// return ext.ContactHistory{}, err
// }
rows, err := db.pool.Query(ctx, `
select id, contact_id, interaction_type, occurred_at, summary, follow_up_needed, follow_up_notes, created_at
from contact_interactions where contact_id = $1 order by occurred_at desc
`, contactID)
if err != nil {
return ext.ContactHistory{}, fmt.Errorf("get interactions: %w", err)
}
defer rows.Close()
// rows, err := db.pool.Query(ctx, `
// select id, contact_id, interaction_type, occurred_at, summary, follow_up_needed, follow_up_notes, created_at
// from contact_interactions where contact_id = $1 order by occurred_at desc
// `, contactID)
// if err != nil {
// return ext.ContactHistory{}, fmt.Errorf("get interactions: %w", err)
// }
// defer rows.Close()
var interactions []ext.ContactInteraction
for rows.Next() {
var model generatedmodels.ModelPublicContactInteractions
if err := rows.Scan(&model.ID, &model.ContactID, &model.InteractionType, &model.OccurredAt, &model.Summary,
&model.FollowUpNeeded, &model.FollowUpNotes, &model.CreatedAt); err != nil {
return ext.ContactHistory{}, fmt.Errorf("scan interaction: %w", err)
}
interactions = append(interactions, contactInteractionFromModel(model))
}
if err := rows.Err(); err != nil {
return ext.ContactHistory{}, err
}
// var interactions []ext.ContactInteraction
// for rows.Next() {
// var model generatedmodels.ModelPublicContactInteractions
// if err := rows.Scan(&model.ID, &model.ContactID, &model.InteractionType, &model.OccurredAt, &model.Summary,
// &model.FollowUpNeeded, &model.FollowUpNotes, &model.CreatedAt); err != nil {
// return ext.ContactHistory{}, fmt.Errorf("scan interaction: %w", err)
// }
// interactions = append(interactions, contactInteractionFromModel(model))
// }
// if err := rows.Err(); err != nil {
// return ext.ContactHistory{}, err
// }
oppRows, err := db.pool.Query(ctx, `
select id, contact_id, title, description, stage, value, expected_close_date, notes, created_at, updated_at
from opportunities where contact_id = $1 order by created_at desc
`, contactID)
if err != nil {
return ext.ContactHistory{}, fmt.Errorf("get opportunities: %w", err)
}
defer oppRows.Close()
// oppRows, err := db.pool.Query(ctx, `
// select id, contact_id, title, description, stage, value, expected_close_date, notes, created_at, updated_at
// from opportunities where contact_id = $1 order by created_at desc
// `, contactID)
// if err != nil {
// return ext.ContactHistory{}, fmt.Errorf("get opportunities: %w", err)
// }
// defer oppRows.Close()
var opportunities []ext.Opportunity
for oppRows.Next() {
var model generatedmodels.ModelPublicOpportunities
if err := oppRows.Scan(&model.ID, &model.ContactID, &model.Title, &model.Description, &model.Stage, &model.Value,
&model.ExpectedCloseDate, &model.Notes, &model.CreatedAt, &model.UpdatedAt); err != nil {
return ext.ContactHistory{}, fmt.Errorf("scan opportunity: %w", err)
}
opportunities = append(opportunities, opportunityFromModel(model))
}
if err := oppRows.Err(); err != nil {
return ext.ContactHistory{}, err
}
// var opportunities []ext.Opportunity
// for oppRows.Next() {
// var model generatedmodels.ModelPublicOpportunities
// if err := oppRows.Scan(&model.ID, &model.ContactID, &model.Title, &model.Description, &model.Stage, &model.Value,
// &model.ExpectedCloseDate, &model.Notes, &model.CreatedAt, &model.UpdatedAt); err != nil {
// return ext.ContactHistory{}, fmt.Errorf("scan opportunity: %w", err)
// }
// opportunities = append(opportunities, opportunityFromModel(model))
// }
// if err := oppRows.Err(); err != nil {
// return ext.ContactHistory{}, err
// }
return ext.ContactHistory{
Contact: contact,
Interactions: interactions,
Opportunities: opportunities,
}, nil
}
// return ext.ContactHistory{
// Contact: contact,
// Interactions: interactions,
// Opportunities: opportunities,
// }, nil
// }
func (db *DB) CreateOpportunity(ctx context.Context, o ext.Opportunity) (ext.Opportunity, error) {
row := db.pool.QueryRow(ctx, `
insert into opportunities (contact_id, title, description, stage, value, expected_close_date, notes)
values ($1, $2, $3, $4, $5, $6, $7)
returning id, created_at, updated_at
`, o.ContactID, o.Title, nullStr(o.Description), o.Stage, o.Value, o.ExpectedCloseDate, nullStr(o.Notes))
// func (db *DB) CreateOpportunity(ctx context.Context, o ext.Opportunity) (ext.Opportunity, error) {
// row := db.pool.QueryRow(ctx, `
// insert into opportunities (contact_id, title, description, stage, value, expected_close_date, notes)
// values ($1, $2, $3, $4, $5, $6, $7)
// returning id, created_at, updated_at
// `, o.ContactID, o.Title, nullStr(o.Description), o.Stage, o.Value, o.ExpectedCloseDate, nullStr(o.Notes))
created := o
var model generatedmodels.ModelPublicOpportunities
if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil {
return ext.Opportunity{}, fmt.Errorf("insert opportunity: %w", err)
}
created.ID = model.ID.UUID()
created.CreatedAt = model.CreatedAt.Time()
created.UpdatedAt = model.UpdatedAt.Time()
return created, nil
}
// created := o
// var model generatedmodels.ModelPublicOpportunities
// if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil {
// return ext.Opportunity{}, fmt.Errorf("insert opportunity: %w", err)
// }
// created.ID = model.ID.UUID()
// created.CreatedAt = model.CreatedAt.Time()
// created.UpdatedAt = model.UpdatedAt.Time()
// return created, nil
// }
func (db *DB) GetFollowUpsDue(ctx context.Context, daysAhead int) ([]ext.ProfessionalContact, error) {
if daysAhead <= 0 {
daysAhead = 7
}
cutoff := time.Now().AddDate(0, 0, daysAhead)
// func (db *DB) GetFollowUpsDue(ctx context.Context, daysAhead int) ([]ext.ProfessionalContact, error) {
// if daysAhead <= 0 {
// daysAhead = 7
// }
// cutoff := time.Now().AddDate(0, 0, daysAhead)
rows, err := db.pool.Query(ctx, `
select id, name, company, title, email, phone, linkedin_url, how_we_met, tags::text[], notes, last_contacted, follow_up_date, created_at, updated_at
from professional_contacts
where follow_up_date <= $1
order by follow_up_date asc
`, cutoff)
if err != nil {
return nil, fmt.Errorf("get follow-ups: %w", err)
}
defer rows.Close()
// rows, err := db.pool.Query(ctx, `
// select id, name, company, title, email, phone, linkedin_url, how_we_met, tags::text[], notes, last_contacted, follow_up_date, created_at, updated_at
// from professional_contacts
// where follow_up_date <= $1
// order by follow_up_date asc
// `, cutoff)
// if err != nil {
// return nil, fmt.Errorf("get follow-ups: %w", err)
// }
// defer rows.Close()
return scanContacts(rows)
}
// return scanContacts(rows)
// }
func (db *DB) AppendThoughtToContactNotes(ctx context.Context, contactID uuid.UUID, thoughtContent string) error {
_, err := db.pool.Exec(ctx, `
update professional_contacts
set notes = coalesce(notes, '') || $2
where id = $1
`, contactID, thoughtContent)
if err != nil {
return fmt.Errorf("append thought to contact: %w", err)
}
return nil
}
// func (db *DB) AppendThoughtToContactNotes(ctx context.Context, contactID uuid.UUID, thoughtContent string) error {
// _, err := db.pool.Exec(ctx, `
// update professional_contacts
// set notes = coalesce(notes, '') || $2
// where id = $1
// `, contactID, thoughtContent)
// if err != nil {
// return fmt.Errorf("append thought to contact: %w", err)
// }
// return nil
// }
func scanContacts(rows interface {
Next() bool
Scan(...any) error
Err() error
Close()
}) ([]ext.ProfessionalContact, error) {
defer rows.Close()
var contacts []ext.ProfessionalContact
for rows.Next() {
var model generatedmodels.ModelPublicProfessionalContacts
var tags []string
if err := rows.Scan(&model.ID, &model.Name, &model.Company, &model.Title, &model.Email, &model.Phone,
&model.LinkedinURL, &model.HowWeMet, &tags, &model.Notes, &model.LastContacted, &model.FollowUpDate,
&model.CreatedAt, &model.UpdatedAt); err != nil {
return nil, fmt.Errorf("scan contact: %w", err)
}
contacts = append(contacts, professionalContactFromModel(model, tags))
}
return contacts, rows.Err()
}
// func scanContacts(rows interface {
// Next() bool
// Scan(...any) error
// Err() error
// Close()
// }) ([]ext.ProfessionalContact, error) {
// defer rows.Close()
// var contacts []ext.ProfessionalContact
// for rows.Next() {
// var model generatedmodels.ModelPublicProfessionalContacts
// var tags []string
// if err := rows.Scan(&model.ID, &model.Name, &model.Company, &model.Title, &model.Email, &model.Phone,
// &model.LinkedinURL, &model.HowWeMet, &tags, &model.Notes, &model.LastContacted, &model.FollowUpDate,
// &model.CreatedAt, &model.UpdatedAt); err != nil {
// return nil, fmt.Errorf("scan contact: %w", err)
// }
// contacts = append(contacts, professionalContactFromModel(model, tags))
// }
// return contacts, rows.Err()
// }

View File

@@ -1,133 +1,133 @@
package store
import (
"context"
"encoding/json"
"fmt"
"strings"
// import (
// "context"
// "encoding/json"
// "fmt"
// "strings"
"github.com/google/uuid"
// "github.com/google/uuid"
"git.warky.dev/wdevs/amcs/internal/generatedmodels"
ext "git.warky.dev/wdevs/amcs/internal/types"
)
// "git.warky.dev/wdevs/amcs/internal/generatedmodels"
// ext "git.warky.dev/wdevs/amcs/internal/types"
// )
func (db *DB) AddHouseholdItem(ctx context.Context, item ext.HouseholdItem) (ext.HouseholdItem, error) {
details, err := json.Marshal(item.Details)
if err != nil {
return ext.HouseholdItem{}, fmt.Errorf("marshal details: %w", err)
}
// func (db *DB) AddHouseholdItem(ctx context.Context, item ext.HouseholdItem) (ext.HouseholdItem, error) {
// details, err := json.Marshal(item.Details)
// if err != nil {
// return ext.HouseholdItem{}, fmt.Errorf("marshal details: %w", err)
// }
row := db.pool.QueryRow(ctx, `
insert into household_items (name, category, location, details, notes)
values ($1, $2, $3, $4::jsonb, $5)
returning id, created_at, updated_at
`, item.Name, nullStr(item.Category), nullStr(item.Location), details, nullStr(item.Notes))
// row := db.pool.QueryRow(ctx, `
// insert into household_items (name, category, location, details, notes)
// values ($1, $2, $3, $4::jsonb, $5)
// returning id, created_at, updated_at
// `, item.Name, nullStr(item.Category), nullStr(item.Location), details, nullStr(item.Notes))
created := item
var model generatedmodels.ModelPublicHouseholdItems
if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil {
return ext.HouseholdItem{}, fmt.Errorf("insert household item: %w", err)
}
created.ID = model.ID.UUID()
created.CreatedAt = model.CreatedAt.Time()
created.UpdatedAt = model.UpdatedAt.Time()
return created, nil
}
// created := item
// var model generatedmodels.ModelPublicHouseholdItems
// if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil {
// return ext.HouseholdItem{}, fmt.Errorf("insert household item: %w", err)
// }
// created.ID = model.ID.UUID()
// created.CreatedAt = model.CreatedAt.Time()
// created.UpdatedAt = model.UpdatedAt.Time()
// return created, nil
// }
func (db *DB) SearchHouseholdItems(ctx context.Context, query, category, location string) ([]ext.HouseholdItem, error) {
args := []any{}
conditions := []string{}
// func (db *DB) SearchHouseholdItems(ctx context.Context, query, category, location string) ([]ext.HouseholdItem, error) {
// args := []any{}
// conditions := []string{}
if q := strings.TrimSpace(query); q != "" {
args = append(args, "%"+q+"%")
conditions = append(conditions, fmt.Sprintf("(name ILIKE $%d OR notes ILIKE $%d)", len(args), len(args)))
}
if c := strings.TrimSpace(category); c != "" {
args = append(args, c)
conditions = append(conditions, fmt.Sprintf("category = $%d", len(args)))
}
if l := strings.TrimSpace(location); l != "" {
args = append(args, "%"+l+"%")
conditions = append(conditions, fmt.Sprintf("location ILIKE $%d", len(args)))
}
// if q := strings.TrimSpace(query); q != "" {
// args = append(args, "%"+q+"%")
// conditions = append(conditions, fmt.Sprintf("(name ILIKE $%d OR notes ILIKE $%d)", len(args), len(args)))
// }
// if c := strings.TrimSpace(category); c != "" {
// args = append(args, c)
// conditions = append(conditions, fmt.Sprintf("category = $%d", len(args)))
// }
// if l := strings.TrimSpace(location); l != "" {
// args = append(args, "%"+l+"%")
// conditions = append(conditions, fmt.Sprintf("location ILIKE $%d", len(args)))
// }
q := `select id, name, category, location, details, notes, created_at, updated_at from household_items`
if len(conditions) > 0 {
q += " where " + strings.Join(conditions, " and ")
}
q += " order by name"
// q := `select id, name, category, location, details, notes, created_at, updated_at from household_items`
// if len(conditions) > 0 {
// q += " where " + strings.Join(conditions, " and ")
// }
// q += " order by name"
rows, err := db.pool.Query(ctx, q, args...)
if err != nil {
return nil, fmt.Errorf("search household items: %w", err)
}
defer rows.Close()
// rows, err := db.pool.Query(ctx, q, args...)
// if err != nil {
// return nil, fmt.Errorf("search household items: %w", err)
// }
// defer rows.Close()
var items []ext.HouseholdItem
for rows.Next() {
var model generatedmodels.ModelPublicHouseholdItems
if err := rows.Scan(&model.ID, &model.Name, &model.Category, &model.Location, &model.Details, &model.Notes, &model.CreatedAt, &model.UpdatedAt); err != nil {
return nil, fmt.Errorf("scan household item: %w", err)
}
items = append(items, householdItemFromModel(model))
}
return items, rows.Err()
}
// var items []ext.HouseholdItem
// for rows.Next() {
// var model generatedmodels.ModelPublicHouseholdItems
// if err := rows.Scan(&model.ID, &model.Name, &model.Category, &model.Location, &model.Details, &model.Notes, &model.CreatedAt, &model.UpdatedAt); err != nil {
// return nil, fmt.Errorf("scan household item: %w", err)
// }
// items = append(items, householdItemFromModel(model))
// }
// return items, rows.Err()
// }
func (db *DB) GetHouseholdItem(ctx context.Context, id uuid.UUID) (ext.HouseholdItem, error) {
row := db.pool.QueryRow(ctx, `
select id, name, category, location, details, notes, created_at, updated_at
from household_items where id = $1
`, id)
// func (db *DB) GetHouseholdItem(ctx context.Context, id uuid.UUID) (ext.HouseholdItem, error) {
// row := db.pool.QueryRow(ctx, `
// select id, name, category, location, details, notes, created_at, updated_at
// from household_items where id = $1
// `, id)
var model generatedmodels.ModelPublicHouseholdItems
if err := row.Scan(&model.ID, &model.Name, &model.Category, &model.Location, &model.Details, &model.Notes, &model.CreatedAt, &model.UpdatedAt); err != nil {
return ext.HouseholdItem{}, fmt.Errorf("get household item: %w", err)
}
return householdItemFromModel(model), nil
}
// var model generatedmodels.ModelPublicHouseholdItems
// if err := row.Scan(&model.ID, &model.Name, &model.Category, &model.Location, &model.Details, &model.Notes, &model.CreatedAt, &model.UpdatedAt); err != nil {
// return ext.HouseholdItem{}, fmt.Errorf("get household item: %w", err)
// }
// return householdItemFromModel(model), nil
// }
func (db *DB) AddVendor(ctx context.Context, v ext.HouseholdVendor) (ext.HouseholdVendor, error) {
row := db.pool.QueryRow(ctx, `
insert into household_vendors (name, service_type, phone, email, website, notes, rating, last_used)
values ($1, $2, $3, $4, $5, $6, $7, $8)
returning id, created_at
`, v.Name, nullStr(v.ServiceType), nullStr(v.Phone), nullStr(v.Email),
nullStr(v.Website), nullStr(v.Notes), v.Rating, v.LastUsed)
// func (db *DB) AddVendor(ctx context.Context, v ext.HouseholdVendor) (ext.HouseholdVendor, error) {
// row := db.pool.QueryRow(ctx, `
// insert into household_vendors (name, service_type, phone, email, website, notes, rating, last_used)
// values ($1, $2, $3, $4, $5, $6, $7, $8)
// returning id, created_at
// `, v.Name, nullStr(v.ServiceType), nullStr(v.Phone), nullStr(v.Email),
// nullStr(v.Website), nullStr(v.Notes), v.Rating, v.LastUsed)
created := v
var model generatedmodels.ModelPublicHouseholdVendors
if err := row.Scan(&model.ID, &model.CreatedAt); err != nil {
return ext.HouseholdVendor{}, fmt.Errorf("insert vendor: %w", err)
}
created.ID = model.ID.UUID()
created.CreatedAt = model.CreatedAt.Time()
return created, nil
}
// created := v
// var model generatedmodels.ModelPublicHouseholdVendors
// if err := row.Scan(&model.ID, &model.CreatedAt); err != nil {
// return ext.HouseholdVendor{}, fmt.Errorf("insert vendor: %w", err)
// }
// created.ID = model.ID.UUID()
// created.CreatedAt = model.CreatedAt.Time()
// return created, nil
// }
func (db *DB) ListVendors(ctx context.Context, serviceType string) ([]ext.HouseholdVendor, error) {
args := []any{}
q := `select id, name, service_type, phone, email, website, notes, rating, last_used, created_at from household_vendors`
if st := strings.TrimSpace(serviceType); st != "" {
args = append(args, st)
q += " where service_type = $1"
}
q += " order by name"
// func (db *DB) ListVendors(ctx context.Context, serviceType string) ([]ext.HouseholdVendor, error) {
// args := []any{}
// q := `select id, name, service_type, phone, email, website, notes, rating, last_used, created_at from household_vendors`
// if st := strings.TrimSpace(serviceType); st != "" {
// args = append(args, st)
// q += " where service_type = $1"
// }
// q += " order by name"
rows, err := db.pool.Query(ctx, q, args...)
if err != nil {
return nil, fmt.Errorf("list vendors: %w", err)
}
defer rows.Close()
// rows, err := db.pool.Query(ctx, q, args...)
// if err != nil {
// return nil, fmt.Errorf("list vendors: %w", err)
// }
// defer rows.Close()
var vendors []ext.HouseholdVendor
for rows.Next() {
var model generatedmodels.ModelPublicHouseholdVendors
if err := rows.Scan(&model.ID, &model.Name, &model.ServiceType, &model.Phone, &model.Email, &model.Website, &model.Notes, &model.Rating, &model.LastUsed, &model.CreatedAt); err != nil {
return nil, fmt.Errorf("scan vendor: %w", err)
}
vendors = append(vendors, householdVendorFromModel(model))
}
return vendors, rows.Err()
}
// var vendors []ext.HouseholdVendor
// for rows.Next() {
// var model generatedmodels.ModelPublicHouseholdVendors
// if err := rows.Scan(&model.ID, &model.Name, &model.ServiceType, &model.Phone, &model.Email, &model.Website, &model.Notes, &model.Rating, &model.LastUsed, &model.CreatedAt); err != nil {
// return nil, fmt.Errorf("scan vendor: %w", err)
// }
// vendors = append(vendors, householdVendorFromModel(model))
// }
// return vendors, rows.Err()
// }

View File

@@ -1,137 +1,137 @@
package store
import (
"context"
"fmt"
"strings"
"time"
// import (
// "context"
// "fmt"
// "strings"
// "time"
"git.warky.dev/wdevs/amcs/internal/generatedmodels"
ext "git.warky.dev/wdevs/amcs/internal/types"
)
// "git.warky.dev/wdevs/amcs/internal/generatedmodels"
// ext "git.warky.dev/wdevs/amcs/internal/types"
// )
func (db *DB) AddMaintenanceTask(ctx context.Context, t ext.MaintenanceTask) (ext.MaintenanceTask, error) {
row := db.pool.QueryRow(ctx, `
insert into maintenance_tasks (name, category, frequency_days, next_due, priority, notes)
values ($1, $2, $3, $4, $5, $6)
returning id, created_at, updated_at
`, t.Name, nullStr(t.Category), t.FrequencyDays, t.NextDue, t.Priority, nullStr(t.Notes))
// func (db *DB) AddMaintenanceTask(ctx context.Context, t ext.MaintenanceTask) (ext.MaintenanceTask, error) {
// row := db.pool.QueryRow(ctx, `
// insert into maintenance_tasks (name, category, frequency_days, next_due, priority, notes)
// values ($1, $2, $3, $4, $5, $6)
// returning id, created_at, updated_at
// `, t.Name, nullStr(t.Category), t.FrequencyDays, t.NextDue, t.Priority, nullStr(t.Notes))
created := t
var model generatedmodels.ModelPublicMaintenanceTasks
if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil {
return ext.MaintenanceTask{}, fmt.Errorf("insert maintenance task: %w", err)
}
created.ID = model.ID.UUID()
created.CreatedAt = model.CreatedAt.Time()
created.UpdatedAt = model.UpdatedAt.Time()
return created, nil
}
// created := t
// var model generatedmodels.ModelPublicMaintenanceTasks
// if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil {
// return ext.MaintenanceTask{}, fmt.Errorf("insert maintenance task: %w", err)
// }
// created.ID = model.ID.UUID()
// created.CreatedAt = model.CreatedAt.Time()
// created.UpdatedAt = model.UpdatedAt.Time()
// return created, nil
// }
func (db *DB) LogMaintenance(ctx context.Context, log ext.MaintenanceLog) (ext.MaintenanceLog, error) {
completedAt := log.CompletedAt
if completedAt.IsZero() {
completedAt = time.Now()
}
// func (db *DB) LogMaintenance(ctx context.Context, log ext.MaintenanceLog) (ext.MaintenanceLog, error) {
// completedAt := log.CompletedAt
// if completedAt.IsZero() {
// completedAt = time.Now()
// }
row := db.pool.QueryRow(ctx, `
insert into maintenance_logs (task_id, completed_at, performed_by, cost, notes, next_action)
values ($1, $2, $3, $4, $5, $6)
returning id
`, log.TaskID, completedAt, nullStr(log.PerformedBy), log.Cost, nullStr(log.Notes), nullStr(log.NextAction))
// row := db.pool.QueryRow(ctx, `
// insert into maintenance_logs (task_id, completed_at, performed_by, cost, notes, next_action)
// values ($1, $2, $3, $4, $5, $6)
// returning id
// `, log.TaskID, completedAt, nullStr(log.PerformedBy), log.Cost, nullStr(log.Notes), nullStr(log.NextAction))
created := log
created.CompletedAt = completedAt
var model generatedmodels.ModelPublicMaintenanceLogs
if err := row.Scan(&model.ID); err != nil {
return ext.MaintenanceLog{}, fmt.Errorf("insert maintenance log: %w", err)
}
created.ID = model.ID.UUID()
return created, nil
}
// created := log
// created.CompletedAt = completedAt
// var model generatedmodels.ModelPublicMaintenanceLogs
// if err := row.Scan(&model.ID); err != nil {
// return ext.MaintenanceLog{}, fmt.Errorf("insert maintenance log: %w", err)
// }
// created.ID = model.ID.UUID()
// return created, nil
// }
func (db *DB) GetUpcomingMaintenance(ctx context.Context, daysAhead int) ([]ext.MaintenanceTask, error) {
if daysAhead <= 0 {
daysAhead = 30
}
cutoff := time.Now().Add(time.Duration(daysAhead) * 24 * time.Hour)
// func (db *DB) GetUpcomingMaintenance(ctx context.Context, daysAhead int) ([]ext.MaintenanceTask, error) {
// if daysAhead <= 0 {
// daysAhead = 30
// }
// cutoff := time.Now().Add(time.Duration(daysAhead) * 24 * time.Hour)
rows, err := db.pool.Query(ctx, `
select id, name, category, frequency_days, last_completed, next_due, priority, notes, created_at, updated_at
from maintenance_tasks
where next_due <= $1 or next_due is null
order by next_due asc nulls last, priority desc
`, cutoff)
if err != nil {
return nil, fmt.Errorf("get upcoming maintenance: %w", err)
}
defer rows.Close()
// rows, err := db.pool.Query(ctx, `
// select id, name, category, frequency_days, last_completed, next_due, priority, notes, created_at, updated_at
// from maintenance_tasks
// where next_due <= $1 or next_due is null
// order by next_due asc nulls last, priority desc
// `, cutoff)
// if err != nil {
// return nil, fmt.Errorf("get upcoming maintenance: %w", err)
// }
// defer rows.Close()
tasks := make([]ext.MaintenanceTask, 0)
for rows.Next() {
var model generatedmodels.ModelPublicMaintenanceTasks
if err := rows.Scan(&model.ID, &model.Name, &model.Category, &model.FrequencyDays, &model.LastCompleted, &model.NextDue, &model.Priority, &model.Notes, &model.CreatedAt, &model.UpdatedAt); err != nil {
return nil, fmt.Errorf("scan maintenance task: %w", err)
}
tasks = append(tasks, maintenanceTaskFromModel(model))
}
return tasks, rows.Err()
}
// tasks := make([]ext.MaintenanceTask, 0)
// for rows.Next() {
// var model generatedmodels.ModelPublicMaintenanceTasks
// if err := rows.Scan(&model.ID, &model.Name, &model.Category, &model.FrequencyDays, &model.LastCompleted, &model.NextDue, &model.Priority, &model.Notes, &model.CreatedAt, &model.UpdatedAt); err != nil {
// return nil, fmt.Errorf("scan maintenance task: %w", err)
// }
// tasks = append(tasks, maintenanceTaskFromModel(model))
// }
// return tasks, rows.Err()
// }
func (db *DB) SearchMaintenanceHistory(ctx context.Context, query, category string, start, end *time.Time) ([]ext.MaintenanceLogWithTask, error) {
args := []any{}
conditions := []string{}
// func (db *DB) SearchMaintenanceHistory(ctx context.Context, query, category string, start, end *time.Time) ([]ext.MaintenanceLogWithTask, error) {
// args := []any{}
// conditions := []string{}
if q := strings.TrimSpace(query); q != "" {
args = append(args, "%"+q+"%")
conditions = append(conditions, fmt.Sprintf("(mt.name ILIKE $%d OR ml.notes ILIKE $%d)", len(args), len(args)))
}
if c := strings.TrimSpace(category); c != "" {
args = append(args, c)
conditions = append(conditions, fmt.Sprintf("mt.category = $%d", len(args)))
}
if start != nil {
args = append(args, *start)
conditions = append(conditions, fmt.Sprintf("ml.completed_at >= $%d", len(args)))
}
if end != nil {
args = append(args, *end)
conditions = append(conditions, fmt.Sprintf("ml.completed_at <= $%d", len(args)))
}
// if q := strings.TrimSpace(query); q != "" {
// args = append(args, "%"+q+"%")
// conditions = append(conditions, fmt.Sprintf("(mt.name ILIKE $%d OR ml.notes ILIKE $%d)", len(args), len(args)))
// }
// if c := strings.TrimSpace(category); c != "" {
// args = append(args, c)
// conditions = append(conditions, fmt.Sprintf("mt.category = $%d", len(args)))
// }
// if start != nil {
// args = append(args, *start)
// conditions = append(conditions, fmt.Sprintf("ml.completed_at >= $%d", len(args)))
// }
// if end != nil {
// args = append(args, *end)
// conditions = append(conditions, fmt.Sprintf("ml.completed_at <= $%d", len(args)))
// }
q := `
select ml.id, ml.task_id, ml.completed_at, ml.performed_by, ml.cost, ml.notes, ml.next_action,
mt.name, mt.category
from maintenance_logs ml
join maintenance_tasks mt on mt.id = ml.task_id
`
if len(conditions) > 0 {
q += " where " + strings.Join(conditions, " and ")
}
q += " order by ml.completed_at desc"
// q := `
// select ml.id, ml.task_id, ml.completed_at, ml.performed_by, ml.cost, ml.notes, ml.next_action,
// mt.name, mt.category
// from maintenance_logs ml
// join maintenance_tasks mt on mt.id = ml.task_id
// `
// if len(conditions) > 0 {
// q += " where " + strings.Join(conditions, " and ")
// }
// q += " order by ml.completed_at desc"
rows, err := db.pool.Query(ctx, q, args...)
if err != nil {
return nil, fmt.Errorf("search maintenance history: %w", err)
}
defer rows.Close()
// rows, err := db.pool.Query(ctx, q, args...)
// if err != nil {
// return nil, fmt.Errorf("search maintenance history: %w", err)
// }
// defer rows.Close()
var logs []ext.MaintenanceLogWithTask
for rows.Next() {
var model generatedmodels.ModelPublicMaintenanceLogs
var taskName, taskCategory string
if err := rows.Scan(
&model.ID, &model.TaskID, &model.CompletedAt, &model.PerformedBy, &model.Cost, &model.Notes, &model.NextAction,
&taskName, &taskCategory,
); err != nil {
return nil, fmt.Errorf("scan maintenance log: %w", err)
}
l := ext.MaintenanceLogWithTask{
MaintenanceLog: maintenanceLogFromModel(model),
TaskName: taskName,
TaskCategory: taskCategory,
}
logs = append(logs, l)
}
return logs, rows.Err()
}
// var logs []ext.MaintenanceLogWithTask
// for rows.Next() {
// var model generatedmodels.ModelPublicMaintenanceLogs
// var taskName, taskCategory string
// if err := rows.Scan(
// &model.ID, &model.TaskID, &model.CompletedAt, &model.PerformedBy, &model.Cost, &model.Notes, &model.NextAction,
// &taskName, &taskCategory,
// ); err != nil {
// return nil, fmt.Errorf("scan maintenance log: %w", err)
// }
// l := ext.MaintenanceLogWithTask{
// MaintenanceLog: maintenanceLogFromModel(model),
// TaskName: taskName,
// TaskCategory: taskCategory,
// }
// logs = append(logs, l)
// }
// return logs, rows.Err()
// }

View File

@@ -1,280 +1,280 @@
package store
import (
"context"
"encoding/json"
"fmt"
"strings"
"time"
// import (
// "context"
// "encoding/json"
// "fmt"
// "strings"
// "time"
"github.com/google/uuid"
// "github.com/google/uuid"
"git.warky.dev/wdevs/amcs/internal/generatedmodels"
ext "git.warky.dev/wdevs/amcs/internal/types"
)
// "git.warky.dev/wdevs/amcs/internal/generatedmodels"
// ext "git.warky.dev/wdevs/amcs/internal/types"
// )
func (db *DB) AddRecipe(ctx context.Context, r ext.Recipe) (ext.Recipe, error) {
ingredients, err := json.Marshal(r.Ingredients)
if err != nil {
return ext.Recipe{}, fmt.Errorf("marshal ingredients: %w", err)
}
instructions, err := json.Marshal(r.Instructions)
if err != nil {
return ext.Recipe{}, fmt.Errorf("marshal instructions: %w", err)
}
if r.Tags == nil {
r.Tags = []string{}
}
// func (db *DB) AddRecipe(ctx context.Context, r ext.Recipe) (ext.Recipe, error) {
// ingredients, err := json.Marshal(r.Ingredients)
// if err != nil {
// return ext.Recipe{}, fmt.Errorf("marshal ingredients: %w", err)
// }
// instructions, err := json.Marshal(r.Instructions)
// if err != nil {
// return ext.Recipe{}, fmt.Errorf("marshal instructions: %w", err)
// }
// if r.Tags == nil {
// r.Tags = []string{}
// }
row := db.pool.QueryRow(ctx, `
insert into recipes (name, cuisine, prep_time_minutes, cook_time_minutes, servings, ingredients, instructions, tags, rating, notes)
values ($1, $2, $3, $4, $5, $6::jsonb, $7::jsonb, $8, $9, $10)
returning id, created_at, updated_at
`, r.Name, nullStr(r.Cuisine), r.PrepTimeMinutes, r.CookTimeMinutes, r.Servings,
ingredients, instructions, r.Tags, r.Rating, nullStr(r.Notes))
// row := db.pool.QueryRow(ctx, `
// insert into recipes (name, cuisine, prep_time_minutes, cook_time_minutes, servings, ingredients, instructions, tags, rating, notes)
// values ($1, $2, $3, $4, $5, $6::jsonb, $7::jsonb, $8, $9, $10)
// returning id, created_at, updated_at
// `, r.Name, nullStr(r.Cuisine), r.PrepTimeMinutes, r.CookTimeMinutes, r.Servings,
// ingredients, instructions, r.Tags, r.Rating, nullStr(r.Notes))
created := r
var model generatedmodels.ModelPublicRecipes
if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil {
return ext.Recipe{}, fmt.Errorf("insert recipe: %w", err)
}
created.ID = model.ID.UUID()
created.CreatedAt = model.CreatedAt.Time()
created.UpdatedAt = model.UpdatedAt.Time()
return created, nil
}
// created := r
// var model generatedmodels.ModelPublicRecipes
// if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil {
// return ext.Recipe{}, fmt.Errorf("insert recipe: %w", err)
// }
// created.ID = model.ID.UUID()
// created.CreatedAt = model.CreatedAt.Time()
// created.UpdatedAt = model.UpdatedAt.Time()
// return created, nil
// }
func (db *DB) SearchRecipes(ctx context.Context, query, cuisine string, tags []string, ingredient string) ([]ext.Recipe, error) {
args := []any{}
conditions := []string{}
// func (db *DB) SearchRecipes(ctx context.Context, query, cuisine string, tags []string, ingredient string) ([]ext.Recipe, error) {
// args := []any{}
// conditions := []string{}
if q := strings.TrimSpace(query); q != "" {
args = append(args, "%"+q+"%")
conditions = append(conditions, fmt.Sprintf("name ILIKE $%d", len(args)))
}
if c := strings.TrimSpace(cuisine); c != "" {
args = append(args, c)
conditions = append(conditions, fmt.Sprintf("cuisine = $%d", len(args)))
}
if len(tags) > 0 {
args = append(args, tags)
conditions = append(conditions, fmt.Sprintf("tags @> $%d", len(args)))
}
if ing := strings.TrimSpace(ingredient); ing != "" {
args = append(args, "%"+ing+"%")
conditions = append(conditions, fmt.Sprintf("ingredients::text ILIKE $%d", len(args)))
}
// if q := strings.TrimSpace(query); q != "" {
// args = append(args, "%"+q+"%")
// conditions = append(conditions, fmt.Sprintf("name ILIKE $%d", len(args)))
// }
// if c := strings.TrimSpace(cuisine); c != "" {
// args = append(args, c)
// conditions = append(conditions, fmt.Sprintf("cuisine = $%d", len(args)))
// }
// if len(tags) > 0 {
// args = append(args, tags)
// conditions = append(conditions, fmt.Sprintf("tags @> $%d", len(args)))
// }
// if ing := strings.TrimSpace(ingredient); ing != "" {
// args = append(args, "%"+ing+"%")
// conditions = append(conditions, fmt.Sprintf("ingredients::text ILIKE $%d", len(args)))
// }
q := `select id, name, cuisine, prep_time_minutes, cook_time_minutes, servings, ingredients, instructions, tags::text[], rating, notes, created_at, updated_at from recipes`
if len(conditions) > 0 {
q += " where " + strings.Join(conditions, " and ")
}
q += " order by name"
// q := `select id, name, cuisine, prep_time_minutes, cook_time_minutes, servings, ingredients, instructions, tags::text[], rating, notes, created_at, updated_at from recipes`
// if len(conditions) > 0 {
// q += " where " + strings.Join(conditions, " and ")
// }
// q += " order by name"
rows, err := db.pool.Query(ctx, q, args...)
if err != nil {
return nil, fmt.Errorf("search recipes: %w", err)
}
defer rows.Close()
// rows, err := db.pool.Query(ctx, q, args...)
// if err != nil {
// return nil, fmt.Errorf("search recipes: %w", err)
// }
// defer rows.Close()
var recipes []ext.Recipe
for rows.Next() {
r, err := scanRecipeRow(rows)
if err != nil {
return nil, err
}
recipes = append(recipes, r)
}
return recipes, rows.Err()
}
// var recipes []ext.Recipe
// for rows.Next() {
// r, err := scanRecipeRow(rows)
// if err != nil {
// return nil, err
// }
// recipes = append(recipes, r)
// }
// return recipes, rows.Err()
// }
func (db *DB) GetRecipe(ctx context.Context, id uuid.UUID) (ext.Recipe, error) {
row := db.pool.QueryRow(ctx, `
select id, name, cuisine, prep_time_minutes, cook_time_minutes, servings, ingredients, instructions, tags::text[], rating, notes, created_at, updated_at
from recipes where id = $1
`, id)
// func (db *DB) GetRecipe(ctx context.Context, id uuid.UUID) (ext.Recipe, error) {
// row := db.pool.QueryRow(ctx, `
// select id, name, cuisine, prep_time_minutes, cook_time_minutes, servings, ingredients, instructions, tags::text[], rating, notes, created_at, updated_at
// from recipes where id = $1
// `, id)
var model generatedmodels.ModelPublicRecipes
var tags []string
if err := row.Scan(&model.ID, &model.Name, &model.Cuisine, &model.PrepTimeMinutes, &model.CookTimeMinutes, &model.Servings,
&model.Ingredients, &model.Instructions, &tags, &model.Rating, &model.Notes, &model.CreatedAt, &model.UpdatedAt); err != nil {
return ext.Recipe{}, fmt.Errorf("get recipe: %w", err)
}
if tags == nil {
tags = []string{}
}
return recipeFromModel(model, tags), nil
}
// var model generatedmodels.ModelPublicRecipes
// var tags []string
// if err := row.Scan(&model.ID, &model.Name, &model.Cuisine, &model.PrepTimeMinutes, &model.CookTimeMinutes, &model.Servings,
// &model.Ingredients, &model.Instructions, &tags, &model.Rating, &model.Notes, &model.CreatedAt, &model.UpdatedAt); err != nil {
// return ext.Recipe{}, fmt.Errorf("get recipe: %w", err)
// }
// if tags == nil {
// tags = []string{}
// }
// return recipeFromModel(model, tags), nil
// }
func (db *DB) UpdateRecipe(ctx context.Context, id uuid.UUID, r ext.Recipe) (ext.Recipe, error) {
ingredients, err := json.Marshal(r.Ingredients)
if err != nil {
return ext.Recipe{}, fmt.Errorf("marshal ingredients: %w", err)
}
instructions, err := json.Marshal(r.Instructions)
if err != nil {
return ext.Recipe{}, fmt.Errorf("marshal instructions: %w", err)
}
if r.Tags == nil {
r.Tags = []string{}
}
// func (db *DB) UpdateRecipe(ctx context.Context, id uuid.UUID, r ext.Recipe) (ext.Recipe, error) {
// ingredients, err := json.Marshal(r.Ingredients)
// if err != nil {
// return ext.Recipe{}, fmt.Errorf("marshal ingredients: %w", err)
// }
// instructions, err := json.Marshal(r.Instructions)
// if err != nil {
// return ext.Recipe{}, fmt.Errorf("marshal instructions: %w", err)
// }
// if r.Tags == nil {
// r.Tags = []string{}
// }
_, err = db.pool.Exec(ctx, `
update recipes set
name = $2, cuisine = $3, prep_time_minutes = $4, cook_time_minutes = $5,
servings = $6, ingredients = $7::jsonb, instructions = $8::jsonb,
tags = $9, rating = $10, notes = $11
where id = $1
`, id, r.Name, nullStr(r.Cuisine), r.PrepTimeMinutes, r.CookTimeMinutes, r.Servings,
ingredients, instructions, r.Tags, r.Rating, nullStr(r.Notes))
if err != nil {
return ext.Recipe{}, fmt.Errorf("update recipe: %w", err)
}
return db.GetRecipe(ctx, id)
}
// _, err = db.pool.Exec(ctx, `
// update recipes set
// name = $2, cuisine = $3, prep_time_minutes = $4, cook_time_minutes = $5,
// servings = $6, ingredients = $7::jsonb, instructions = $8::jsonb,
// tags = $9, rating = $10, notes = $11
// where id = $1
// `, id, r.Name, nullStr(r.Cuisine), r.PrepTimeMinutes, r.CookTimeMinutes, r.Servings,
// ingredients, instructions, r.Tags, r.Rating, nullStr(r.Notes))
// if err != nil {
// return ext.Recipe{}, fmt.Errorf("update recipe: %w", err)
// }
// return db.GetRecipe(ctx, id)
// }
func (db *DB) CreateMealPlan(ctx context.Context, weekStart time.Time, entries []ext.MealPlanInput) ([]ext.MealPlanEntry, error) {
if _, err := db.pool.Exec(ctx, `delete from meal_plans where week_start = $1`, weekStart); err != nil {
return nil, fmt.Errorf("clear meal plan: %w", err)
}
// func (db *DB) CreateMealPlan(ctx context.Context, weekStart time.Time, entries []ext.MealPlanInput) ([]ext.MealPlanEntry, error) {
// if _, err := db.pool.Exec(ctx, `delete from meal_plans where week_start = $1`, weekStart); err != nil {
// return nil, fmt.Errorf("clear meal plan: %w", err)
// }
var results []ext.MealPlanEntry
for _, e := range entries {
row := db.pool.QueryRow(ctx, `
insert into meal_plans (week_start, day_of_week, meal_type, recipe_id, custom_meal, servings, notes)
values ($1, $2, $3, $4, $5, $6, $7)
returning id, created_at
`, weekStart, e.DayOfWeek, e.MealType, e.RecipeID, nullStr(e.CustomMeal), e.Servings, nullStr(e.Notes))
// var results []ext.MealPlanEntry
// for _, e := range entries {
// row := db.pool.QueryRow(ctx, `
// insert into meal_plans (week_start, day_of_week, meal_type, recipe_id, custom_meal, servings, notes)
// values ($1, $2, $3, $4, $5, $6, $7)
// returning id, created_at
// `, weekStart, e.DayOfWeek, e.MealType, e.RecipeID, nullStr(e.CustomMeal), e.Servings, nullStr(e.Notes))
entry := ext.MealPlanEntry{
WeekStart: weekStart,
DayOfWeek: e.DayOfWeek,
MealType: e.MealType,
RecipeID: e.RecipeID,
CustomMeal: e.CustomMeal,
Servings: e.Servings,
Notes: e.Notes,
}
var model generatedmodels.ModelPublicMealPlans
if err := row.Scan(&model.ID, &model.CreatedAt); err != nil {
return nil, fmt.Errorf("insert meal plan entry: %w", err)
}
entry.ID = model.ID.UUID()
entry.CreatedAt = model.CreatedAt.Time()
results = append(results, entry)
}
return results, nil
}
// entry := ext.MealPlanEntry{
// WeekStart: weekStart,
// DayOfWeek: e.DayOfWeek,
// MealType: e.MealType,
// RecipeID: e.RecipeID,
// CustomMeal: e.CustomMeal,
// Servings: e.Servings,
// Notes: e.Notes,
// }
// var model generatedmodels.ModelPublicMealPlans
// if err := row.Scan(&model.ID, &model.CreatedAt); err != nil {
// return nil, fmt.Errorf("insert meal plan entry: %w", err)
// }
// entry.ID = model.ID.UUID()
// entry.CreatedAt = model.CreatedAt.Time()
// results = append(results, entry)
// }
// return results, nil
// }
func (db *DB) GetMealPlan(ctx context.Context, weekStart time.Time) ([]ext.MealPlanEntry, error) {
rows, err := db.pool.Query(ctx, `
select mp.id, mp.week_start, mp.day_of_week, mp.meal_type, mp.recipe_id, r.name, mp.custom_meal, mp.servings, mp.notes, mp.created_at
from meal_plans mp
left join recipes r on r.id = mp.recipe_id
where mp.week_start = $1
order by
case mp.day_of_week
when 'monday' then 1 when 'tuesday' then 2 when 'wednesday' then 3
when 'thursday' then 4 when 'friday' then 5 when 'saturday' then 6
when 'sunday' then 7 else 8
end,
case mp.meal_type
when 'breakfast' then 1 when 'lunch' then 2 when 'dinner' then 3
when 'snack' then 4 else 5
end
`, weekStart)
if err != nil {
return nil, fmt.Errorf("get meal plan: %w", err)
}
defer rows.Close()
// func (db *DB) GetMealPlan(ctx context.Context, weekStart time.Time) ([]ext.MealPlanEntry, error) {
// rows, err := db.pool.Query(ctx, `
// select mp.id, mp.week_start, mp.day_of_week, mp.meal_type, mp.recipe_id, r.name, mp.custom_meal, mp.servings, mp.notes, mp.created_at
// from meal_plans mp
// left join recipes r on r.id = mp.recipe_id
// where mp.week_start = $1
// order by
// case mp.day_of_week
// when 'monday' then 1 when 'tuesday' then 2 when 'wednesday' then 3
// when 'thursday' then 4 when 'friday' then 5 when 'saturday' then 6
// when 'sunday' then 7 else 8
// end,
// case mp.meal_type
// when 'breakfast' then 1 when 'lunch' then 2 when 'dinner' then 3
// when 'snack' then 4 else 5
// end
// `, weekStart)
// if err != nil {
// return nil, fmt.Errorf("get meal plan: %w", err)
// }
// defer rows.Close()
var entries []ext.MealPlanEntry
for rows.Next() {
var model generatedmodels.ModelPublicMealPlans
var recipeName *string
if err := rows.Scan(&model.ID, &model.WeekStart, &model.DayOfWeek, &model.MealType, &model.RecipeID, &recipeName, &model.CustomMeal, &model.Servings, &model.Notes, &model.CreatedAt); err != nil {
return nil, fmt.Errorf("scan meal plan entry: %w", err)
}
entries = append(entries, mealPlanEntryFromModel(model, strVal(recipeName)))
}
return entries, rows.Err()
}
// var entries []ext.MealPlanEntry
// for rows.Next() {
// var model generatedmodels.ModelPublicMealPlans
// var recipeName *string
// if err := rows.Scan(&model.ID, &model.WeekStart, &model.DayOfWeek, &model.MealType, &model.RecipeID, &recipeName, &model.CustomMeal, &model.Servings, &model.Notes, &model.CreatedAt); err != nil {
// return nil, fmt.Errorf("scan meal plan entry: %w", err)
// }
// entries = append(entries, mealPlanEntryFromModel(model, strVal(recipeName)))
// }
// return entries, rows.Err()
// }
func (db *DB) GenerateShoppingList(ctx context.Context, weekStart time.Time) (ext.ShoppingList, error) {
entries, err := db.GetMealPlan(ctx, weekStart)
if err != nil {
return ext.ShoppingList{}, err
}
// func (db *DB) GenerateShoppingList(ctx context.Context, weekStart time.Time) (ext.ShoppingList, error) {
// entries, err := db.GetMealPlan(ctx, weekStart)
// if err != nil {
// return ext.ShoppingList{}, err
// }
recipeIDs := map[uuid.UUID]bool{}
for _, e := range entries {
if e.RecipeID != nil {
recipeIDs[*e.RecipeID] = true
}
}
// recipeIDs := map[uuid.UUID]bool{}
// for _, e := range entries {
// if e.RecipeID != nil {
// recipeIDs[*e.RecipeID] = true
// }
// }
aggregated := map[string]*ext.ShoppingItem{}
for id := range recipeIDs {
recipe, err := db.GetRecipe(ctx, id)
if err != nil {
continue
}
for _, ing := range recipe.Ingredients {
key := strings.ToLower(ing.Name)
if existing, ok := aggregated[key]; ok {
if ing.Quantity != "" {
existing.Quantity += "+" + ing.Quantity
}
} else {
recipeIDCopy := id
aggregated[key] = &ext.ShoppingItem{
Name: ing.Name,
Quantity: ing.Quantity,
Unit: ing.Unit,
Purchased: false,
RecipeID: &recipeIDCopy,
}
}
}
}
// aggregated := map[string]*ext.ShoppingItem{}
// for id := range recipeIDs {
// recipe, err := db.GetRecipe(ctx, id)
// if err != nil {
// continue
// }
// for _, ing := range recipe.Ingredients {
// key := strings.ToLower(ing.Name)
// if existing, ok := aggregated[key]; ok {
// if ing.Quantity != "" {
// existing.Quantity += "+" + ing.Quantity
// }
// } else {
// recipeIDCopy := id
// aggregated[key] = &ext.ShoppingItem{
// Name: ing.Name,
// Quantity: ing.Quantity,
// Unit: ing.Unit,
// Purchased: false,
// RecipeID: &recipeIDCopy,
// }
// }
// }
// }
items := make([]ext.ShoppingItem, 0, len(aggregated))
for _, item := range aggregated {
items = append(items, *item)
}
// items := make([]ext.ShoppingItem, 0, len(aggregated))
// for _, item := range aggregated {
// items = append(items, *item)
// }
itemsJSON, err := json.Marshal(items)
if err != nil {
return ext.ShoppingList{}, fmt.Errorf("marshal shopping items: %w", err)
}
// itemsJSON, err := json.Marshal(items)
// if err != nil {
// return ext.ShoppingList{}, fmt.Errorf("marshal shopping items: %w", err)
// }
row := db.pool.QueryRow(ctx, `
insert into shopping_lists (week_start, items)
values ($1, $2::jsonb)
on conflict (week_start) do update set items = excluded.items, updated_at = now()
returning id, created_at, updated_at
`, weekStart, itemsJSON)
// row := db.pool.QueryRow(ctx, `
// insert into shopping_lists (week_start, items)
// values ($1, $2::jsonb)
// on conflict (week_start) do update set items = excluded.items, updated_at = now()
// returning id, created_at, updated_at
// `, weekStart, itemsJSON)
var model generatedmodels.ModelPublicShoppingLists
list := ext.ShoppingList{WeekStart: weekStart, Items: items}
if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil {
return ext.ShoppingList{}, fmt.Errorf("upsert shopping list: %w", err)
}
list.ID = model.ID.UUID()
list.CreatedAt = model.CreatedAt.Time()
list.UpdatedAt = model.UpdatedAt.Time()
return list, nil
}
// var model generatedmodels.ModelPublicShoppingLists
// list := ext.ShoppingList{WeekStart: weekStart, Items: items}
// if err := row.Scan(&model.ID, &model.CreatedAt, &model.UpdatedAt); err != nil {
// return ext.ShoppingList{}, fmt.Errorf("upsert shopping list: %w", err)
// }
// list.ID = model.ID.UUID()
// list.CreatedAt = model.CreatedAt.Time()
// list.UpdatedAt = model.UpdatedAt.Time()
// return list, nil
// }
func scanRecipeRow(rows interface{ Scan(...any) error }) (ext.Recipe, error) {
var model generatedmodels.ModelPublicRecipes
var tags []string
if err := rows.Scan(&model.ID, &model.Name, &model.Cuisine, &model.PrepTimeMinutes, &model.CookTimeMinutes, &model.Servings,
&model.Ingredients, &model.Instructions, &tags, &model.Rating, &model.Notes, &model.CreatedAt, &model.UpdatedAt); err != nil {
return ext.Recipe{}, fmt.Errorf("scan recipe: %w", err)
}
if tags == nil {
tags = []string{}
}
return recipeFromModel(model, tags), nil
}
// func scanRecipeRow(rows interface{ Scan(...any) error }) (ext.Recipe, error) {
// var model generatedmodels.ModelPublicRecipes
// var tags []string
// if err := rows.Scan(&model.ID, &model.Name, &model.Cuisine, &model.PrepTimeMinutes, &model.CookTimeMinutes, &model.Servings,
// &model.Ingredients, &model.Instructions, &tags, &model.Rating, &model.Notes, &model.CreatedAt, &model.UpdatedAt); err != nil {
// return ext.Recipe{}, fmt.Errorf("scan recipe: %w", err)
// }
// if tags == nil {
// tags = []string{}
// }
// return recipeFromModel(model, tags), nil
// }

View File

@@ -81,342 +81,342 @@ func storedFileFromModel(m generatedmodels.ModelPublicStoredFiles) ext.StoredFil
}
}
func maintenanceTaskFromModel(m generatedmodels.ModelPublicMaintenanceTasks) ext.MaintenanceTask {
var frequencyDays *int
if m.FrequencyDays.Valid {
n := int(m.FrequencyDays.Int64())
frequencyDays = &n
}
// func maintenanceTaskFromModel(m generatedmodels.ModelPublicMaintenanceTasks) ext.MaintenanceTask {
// var frequencyDays *int
// if m.FrequencyDays.Valid {
// n := int(m.FrequencyDays.Int64())
// frequencyDays = &n
// }
var lastCompleted *time.Time
if m.LastCompleted.Valid {
t := m.LastCompleted.Time()
lastCompleted = &t
}
// var lastCompleted *time.Time
// if m.LastCompleted.Valid {
// t := m.LastCompleted.Time()
// lastCompleted = &t
// }
var nextDue *time.Time
if m.NextDue.Valid {
t := m.NextDue.Time()
nextDue = &t
}
// var nextDue *time.Time
// if m.NextDue.Valid {
// t := m.NextDue.Time()
// nextDue = &t
// }
return ext.MaintenanceTask{
ID: m.ID.UUID(),
Name: m.Name.String(),
Category: m.Category.String(),
FrequencyDays: frequencyDays,
LastCompleted: lastCompleted,
NextDue: nextDue,
Priority: m.Priority.String(),
Notes: m.Notes.String(),
CreatedAt: m.CreatedAt.Time(),
UpdatedAt: m.UpdatedAt.Time(),
}
}
// return ext.MaintenanceTask{
// ID: m.ID.UUID(),
// Name: m.Name.String(),
// Category: m.Category.String(),
// FrequencyDays: frequencyDays,
// LastCompleted: lastCompleted,
// NextDue: nextDue,
// Priority: m.Priority.String(),
// Notes: m.Notes.String(),
// CreatedAt: m.CreatedAt.Time(),
// UpdatedAt: m.UpdatedAt.Time(),
// }
// }
func maintenanceLogFromModel(m generatedmodels.ModelPublicMaintenanceLogs) ext.MaintenanceLog {
var cost *float64
if m.Cost.Valid {
v := m.Cost.Float64()
cost = &v
}
// func maintenanceLogFromModel(m generatedmodels.ModelPublicMaintenanceLogs) ext.MaintenanceLog {
// var cost *float64
// if m.Cost.Valid {
// v := m.Cost.Float64()
// cost = &v
// }
return ext.MaintenanceLog{
ID: m.ID.UUID(),
TaskID: m.TaskID.UUID(),
CompletedAt: m.CompletedAt.Time(),
PerformedBy: m.PerformedBy.String(),
Cost: cost,
Notes: m.Notes.String(),
NextAction: m.NextAction.String(),
}
}
// return ext.MaintenanceLog{
// ID: m.ID.UUID(),
// TaskID: m.TaskID.UUID(),
// CompletedAt: m.CompletedAt.Time(),
// PerformedBy: m.PerformedBy.String(),
// Cost: cost,
// Notes: m.Notes.String(),
// NextAction: m.NextAction.String(),
// }
// }
func householdItemFromModel(m generatedmodels.ModelPublicHouseholdItems) ext.HouseholdItem {
details := map[string]any{}
if len(m.Details) > 0 {
if err := json.Unmarshal(m.Details, &details); err != nil {
details = map[string]any{}
}
}
// func householdItemFromModel(m generatedmodels.ModelPublicHouseholdItems) ext.HouseholdItem {
// details := map[string]any{}
// if len(m.Details) > 0 {
// if err := json.Unmarshal(m.Details, &details); err != nil {
// details = map[string]any{}
// }
// }
return ext.HouseholdItem{
ID: m.ID.UUID(),
Name: m.Name.String(),
Category: m.Category.String(),
Location: m.Location.String(),
Details: details,
Notes: m.Notes.String(),
CreatedAt: m.CreatedAt.Time(),
UpdatedAt: m.UpdatedAt.Time(),
}
}
// return ext.HouseholdItem{
// ID: m.ID.UUID(),
// Name: m.Name.String(),
// Category: m.Category.String(),
// Location: m.Location.String(),
// Details: details,
// Notes: m.Notes.String(),
// CreatedAt: m.CreatedAt.Time(),
// UpdatedAt: m.UpdatedAt.Time(),
// }
// }
func householdVendorFromModel(m generatedmodels.ModelPublicHouseholdVendors) ext.HouseholdVendor {
var rating *int
if m.Rating.Valid {
v := int(m.Rating.Int64())
rating = &v
}
// func householdVendorFromModel(m generatedmodels.ModelPublicHouseholdVendors) ext.HouseholdVendor {
// var rating *int
// if m.Rating.Valid {
// v := int(m.Rating.Int64())
// rating = &v
// }
var lastUsed *time.Time
if m.LastUsed.Valid {
t := m.LastUsed.Time()
lastUsed = &t
}
// var lastUsed *time.Time
// if m.LastUsed.Valid {
// t := m.LastUsed.Time()
// lastUsed = &t
// }
return ext.HouseholdVendor{
ID: m.ID.UUID(),
Name: m.Name.String(),
ServiceType: m.ServiceType.String(),
Phone: m.Phone.String(),
Email: m.Email.String(),
Website: m.Website.String(),
Notes: m.Notes.String(),
Rating: rating,
LastUsed: lastUsed,
CreatedAt: m.CreatedAt.Time(),
}
}
// return ext.HouseholdVendor{
// ID: m.ID.UUID(),
// Name: m.Name.String(),
// ServiceType: m.ServiceType.String(),
// Phone: m.Phone.String(),
// Email: m.Email.String(),
// Website: m.Website.String(),
// Notes: m.Notes.String(),
// Rating: rating,
// LastUsed: lastUsed,
// CreatedAt: m.CreatedAt.Time(),
// }
// }
func familyMemberFromModel(m generatedmodels.ModelPublicFamilyMembers) ext.FamilyMember {
var birthDate *time.Time
if m.BirthDate.Valid {
t := m.BirthDate.Time()
birthDate = &t
}
// func familyMemberFromModel(m generatedmodels.ModelPublicFamilyMembers) ext.FamilyMember {
// var birthDate *time.Time
// if m.BirthDate.Valid {
// t := m.BirthDate.Time()
// birthDate = &t
// }
return ext.FamilyMember{
ID: m.ID.UUID(),
Name: m.Name.String(),
Relationship: m.Relationship.String(),
BirthDate: birthDate,
Notes: m.Notes.String(),
CreatedAt: m.CreatedAt.Time(),
}
}
// return ext.FamilyMember{
// ID: m.ID.UUID(),
// Name: m.Name.String(),
// Relationship: m.Relationship.String(),
// BirthDate: birthDate,
// Notes: m.Notes.String(),
// CreatedAt: m.CreatedAt.Time(),
// }
// }
func activityFromModel(m generatedmodels.ModelPublicActivities, memberName string) ext.Activity {
var familyMemberID *uuid.UUID
if m.FamilyMemberID.Valid {
id := m.FamilyMemberID.UUID()
familyMemberID = &id
}
// func activityFromModel(m generatedmodels.ModelPublicActivities, memberName string) ext.Activity {
// var familyMemberID *uuid.UUID
// if m.FamilyMemberID.Valid {
// id := m.FamilyMemberID.UUID()
// familyMemberID = &id
// }
var startDate *time.Time
if m.StartDate.Valid {
t := m.StartDate.Time()
startDate = &t
}
// var startDate *time.Time
// if m.StartDate.Valid {
// t := m.StartDate.Time()
// startDate = &t
// }
var endDate *time.Time
if m.EndDate.Valid {
t := m.EndDate.Time()
endDate = &t
}
// var endDate *time.Time
// if m.EndDate.Valid {
// t := m.EndDate.Time()
// endDate = &t
// }
return ext.Activity{
ID: m.ID.UUID(),
FamilyMemberID: familyMemberID,
MemberName: memberName,
Title: m.Title.String(),
ActivityType: m.ActivityType.String(),
DayOfWeek: m.DayOfWeek.String(),
StartTime: m.StartTime.String(),
EndTime: m.EndTime.String(),
StartDate: startDate,
EndDate: endDate,
Location: m.Location.String(),
Notes: m.Notes.String(),
CreatedAt: m.CreatedAt.Time(),
}
}
// return ext.Activity{
// ID: m.ID.UUID(),
// FamilyMemberID: familyMemberID,
// MemberName: memberName,
// Title: m.Title.String(),
// ActivityType: m.ActivityType.String(),
// DayOfWeek: m.DayOfWeek.String(),
// StartTime: m.StartTime.String(),
// EndTime: m.EndTime.String(),
// StartDate: startDate,
// EndDate: endDate,
// Location: m.Location.String(),
// Notes: m.Notes.String(),
// CreatedAt: m.CreatedAt.Time(),
// }
// }
func importantDateFromModel(m generatedmodels.ModelPublicImportantDates, memberName string) ext.ImportantDate {
var familyMemberID *uuid.UUID
if m.FamilyMemberID.Valid {
id := m.FamilyMemberID.UUID()
familyMemberID = &id
}
// func importantDateFromModel(m generatedmodels.ModelPublicImportantDates, memberName string) ext.ImportantDate {
// var familyMemberID *uuid.UUID
// if m.FamilyMemberID.Valid {
// id := m.FamilyMemberID.UUID()
// familyMemberID = &id
// }
return ext.ImportantDate{
ID: m.ID.UUID(),
FamilyMemberID: familyMemberID,
MemberName: memberName,
Title: m.Title.String(),
DateValue: m.DateValue.Time(),
RecurringYearly: m.RecurringYearly,
ReminderDaysBefore: int(m.ReminderDaysBefore),
Notes: m.Notes.String(),
CreatedAt: m.CreatedAt.Time(),
}
}
// return ext.ImportantDate{
// ID: m.ID.UUID(),
// FamilyMemberID: familyMemberID,
// MemberName: memberName,
// Title: m.Title.String(),
// DateValue: m.DateValue.Time(),
// RecurringYearly: m.RecurringYearly,
// ReminderDaysBefore: int(m.ReminderDaysBefore),
// Notes: m.Notes.String(),
// CreatedAt: m.CreatedAt.Time(),
// }
// }
func professionalContactFromModel(m generatedmodels.ModelPublicProfessionalContacts, tags []string) ext.ProfessionalContact {
var lastContacted *time.Time
if m.LastContacted.Valid {
t := m.LastContacted.Time()
lastContacted = &t
}
// func professionalContactFromModel(m generatedmodels.ModelPublicProfessionalContacts, tags []string) ext.ProfessionalContact {
// var lastContacted *time.Time
// if m.LastContacted.Valid {
// t := m.LastContacted.Time()
// lastContacted = &t
// }
var followUpDate *time.Time
if m.FollowUpDate.Valid {
t := m.FollowUpDate.Time()
followUpDate = &t
}
// var followUpDate *time.Time
// if m.FollowUpDate.Valid {
// t := m.FollowUpDate.Time()
// followUpDate = &t
// }
return ext.ProfessionalContact{
ID: m.ID.UUID(),
Name: m.Name.String(),
Company: m.Company.String(),
Title: m.Title.String(),
Email: m.Email.String(),
Phone: m.Phone.String(),
LinkedInURL: m.LinkedinURL.String(),
HowWeMet: m.HowWeMet.String(),
Tags: tags,
Notes: m.Notes.String(),
LastContacted: lastContacted,
FollowUpDate: followUpDate,
CreatedAt: m.CreatedAt.Time(),
UpdatedAt: m.UpdatedAt.Time(),
}
}
// return ext.ProfessionalContact{
// ID: m.ID.UUID(),
// Name: m.Name.String(),
// Company: m.Company.String(),
// Title: m.Title.String(),
// Email: m.Email.String(),
// Phone: m.Phone.String(),
// LinkedInURL: m.LinkedinURL.String(),
// HowWeMet: m.HowWeMet.String(),
// Tags: tags,
// Notes: m.Notes.String(),
// LastContacted: lastContacted,
// FollowUpDate: followUpDate,
// CreatedAt: m.CreatedAt.Time(),
// UpdatedAt: m.UpdatedAt.Time(),
// }
// }
func contactInteractionFromModel(m generatedmodels.ModelPublicContactInteractions) ext.ContactInteraction {
return ext.ContactInteraction{
ID: m.ID.UUID(),
ContactID: m.ContactID.UUID(),
InteractionType: m.InteractionType.String(),
OccurredAt: m.OccurredAt.Time(),
Summary: m.Summary.String(),
FollowUpNeeded: m.FollowUpNeeded,
FollowUpNotes: m.FollowUpNotes.String(),
CreatedAt: m.CreatedAt.Time(),
}
}
// func contactInteractionFromModel(m generatedmodels.ModelPublicContactInteractions) ext.ContactInteraction {
// return ext.ContactInteraction{
// ID: m.ID.UUID(),
// ContactID: m.ContactID.UUID(),
// InteractionType: m.InteractionType.String(),
// OccurredAt: m.OccurredAt.Time(),
// Summary: m.Summary.String(),
// FollowUpNeeded: m.FollowUpNeeded,
// FollowUpNotes: m.FollowUpNotes.String(),
// CreatedAt: m.CreatedAt.Time(),
// }
// }
func opportunityFromModel(m generatedmodels.ModelPublicOpportunities) ext.Opportunity {
var contactID *uuid.UUID
if m.ContactID.Valid {
id := m.ContactID.UUID()
contactID = &id
}
// func opportunityFromModel(m generatedmodels.ModelPublicOpportunities) ext.Opportunity {
// var contactID *uuid.UUID
// if m.ContactID.Valid {
// id := m.ContactID.UUID()
// contactID = &id
// }
var value *float64
if m.Value.Valid {
v := m.Value.Float64()
value = &v
}
// var value *float64
// if m.Value.Valid {
// v := m.Value.Float64()
// value = &v
// }
var expectedCloseDate *time.Time
if m.ExpectedCloseDate.Valid {
t := m.ExpectedCloseDate.Time()
expectedCloseDate = &t
}
// var expectedCloseDate *time.Time
// if m.ExpectedCloseDate.Valid {
// t := m.ExpectedCloseDate.Time()
// expectedCloseDate = &t
// }
return ext.Opportunity{
ID: m.ID.UUID(),
ContactID: contactID,
Title: m.Title.String(),
Description: m.Description.String(),
Stage: m.Stage.String(),
Value: value,
ExpectedCloseDate: expectedCloseDate,
Notes: m.Notes.String(),
CreatedAt: m.CreatedAt.Time(),
UpdatedAt: m.UpdatedAt.Time(),
}
}
// return ext.Opportunity{
// ID: m.ID.UUID(),
// ContactID: contactID,
// Title: m.Title.String(),
// Description: m.Description.String(),
// Stage: m.Stage.String(),
// Value: value,
// ExpectedCloseDate: expectedCloseDate,
// Notes: m.Notes.String(),
// CreatedAt: m.CreatedAt.Time(),
// UpdatedAt: m.UpdatedAt.Time(),
// }
// }
func recipeFromModel(m generatedmodels.ModelPublicRecipes, tags []string) ext.Recipe {
var prepTimeMinutes *int
if m.PrepTimeMinutes.Valid {
v := int(m.PrepTimeMinutes.Int64())
prepTimeMinutes = &v
}
// func recipeFromModel(m generatedmodels.ModelPublicRecipes, tags []string) ext.Recipe {
// var prepTimeMinutes *int
// if m.PrepTimeMinutes.Valid {
// v := int(m.PrepTimeMinutes.Int64())
// prepTimeMinutes = &v
// }
var cookTimeMinutes *int
if m.CookTimeMinutes.Valid {
v := int(m.CookTimeMinutes.Int64())
cookTimeMinutes = &v
}
// var cookTimeMinutes *int
// if m.CookTimeMinutes.Valid {
// v := int(m.CookTimeMinutes.Int64())
// cookTimeMinutes = &v
// }
var servings *int
if m.Servings.Valid {
v := int(m.Servings.Int64())
servings = &v
}
// var servings *int
// if m.Servings.Valid {
// v := int(m.Servings.Int64())
// servings = &v
// }
var rating *int
if m.Rating.Valid {
v := int(m.Rating.Int64())
rating = &v
}
// var rating *int
// if m.Rating.Valid {
// v := int(m.Rating.Int64())
// rating = &v
// }
recipe := ext.Recipe{
ID: m.ID.UUID(),
Name: m.Name.String(),
Cuisine: m.Cuisine.String(),
PrepTimeMinutes: prepTimeMinutes,
CookTimeMinutes: cookTimeMinutes,
Servings: servings,
Tags: tags,
Rating: rating,
Notes: m.Notes.String(),
CreatedAt: m.CreatedAt.Time(),
UpdatedAt: m.UpdatedAt.Time(),
}
// recipe := ext.Recipe{
// ID: m.ID.UUID(),
// Name: m.Name.String(),
// Cuisine: m.Cuisine.String(),
// PrepTimeMinutes: prepTimeMinutes,
// CookTimeMinutes: cookTimeMinutes,
// Servings: servings,
// Tags: tags,
// Rating: rating,
// Notes: m.Notes.String(),
// CreatedAt: m.CreatedAt.Time(),
// UpdatedAt: m.UpdatedAt.Time(),
// }
if err := json.Unmarshal(m.Ingredients, &recipe.Ingredients); err != nil {
recipe.Ingredients = []ext.Ingredient{}
}
if err := json.Unmarshal(m.Instructions, &recipe.Instructions); err != nil {
recipe.Instructions = []string{}
}
return recipe
}
// if err := json.Unmarshal(m.Ingredients, &recipe.Ingredients); err != nil {
// recipe.Ingredients = []ext.Ingredient{}
// }
// if err := json.Unmarshal(m.Instructions, &recipe.Instructions); err != nil {
// recipe.Instructions = []string{}
// }
// return recipe
// }
func mealPlanEntryFromModel(m generatedmodels.ModelPublicMealPlans, recipeName string) ext.MealPlanEntry {
var recipeID *uuid.UUID
if m.RecipeID.Valid {
id := m.RecipeID.UUID()
recipeID = &id
}
// func mealPlanEntryFromModel(m generatedmodels.ModelPublicMealPlans, recipeName string) ext.MealPlanEntry {
// var recipeID *uuid.UUID
// if m.RecipeID.Valid {
// id := m.RecipeID.UUID()
// recipeID = &id
// }
var servings *int
if m.Servings.Valid {
v := int(m.Servings.Int64())
servings = &v
}
// var servings *int
// if m.Servings.Valid {
// v := int(m.Servings.Int64())
// servings = &v
// }
return ext.MealPlanEntry{
ID: m.ID.UUID(),
WeekStart: m.WeekStart.Time(),
DayOfWeek: m.DayOfWeek.String(),
MealType: m.MealType.String(),
RecipeID: recipeID,
RecipeName: recipeName,
CustomMeal: m.CustomMeal.String(),
Servings: servings,
Notes: m.Notes.String(),
CreatedAt: m.CreatedAt.Time(),
}
}
// return ext.MealPlanEntry{
// ID: m.ID.UUID(),
// WeekStart: m.WeekStart.Time(),
// DayOfWeek: m.DayOfWeek.String(),
// MealType: m.MealType.String(),
// RecipeID: recipeID,
// RecipeName: recipeName,
// CustomMeal: m.CustomMeal.String(),
// Servings: servings,
// Notes: m.Notes.String(),
// CreatedAt: m.CreatedAt.Time(),
// }
// }
func shoppingListFromModel(m generatedmodels.ModelPublicShoppingLists) ext.ShoppingList {
list := ext.ShoppingList{
ID: m.ID.UUID(),
WeekStart: m.WeekStart.Time(),
Notes: m.Notes.String(),
CreatedAt: m.CreatedAt.Time(),
UpdatedAt: m.UpdatedAt.Time(),
}
if err := json.Unmarshal(m.Items, &list.Items); err != nil {
list.Items = []ext.ShoppingItem{}
}
return list
}
// func shoppingListFromModel(m generatedmodels.ModelPublicShoppingLists) ext.ShoppingList {
// list := ext.ShoppingList{
// ID: m.ID.UUID(),
// WeekStart: m.WeekStart.Time(),
// Notes: m.Notes.String(),
// CreatedAt: m.CreatedAt.Time(),
// UpdatedAt: m.UpdatedAt.Time(),
// }
// if err := json.Unmarshal(m.Items, &list.Items); err != nil {
// list.Items = []ext.ShoppingItem{}
// }
// return list
// }
func planFromModel(m generatedmodels.ModelPublicPlans, tags []string) ext.Plan {
var projectID *uuid.UUID