package store import "context" func (s *Store) Services(ctx context.Context, activeOnly bool) ([]Service, error) { query := `select id, title, summary, details, position, active, created_at from services` if activeOnly { query += ` where active = 1` } query += ` order by position asc, id asc` rows, err := s.db.QueryContext(ctx, query) if err != nil { return nil, err } defer rows.Close() var services []Service for rows.Next() { var service Service var active int if err := rows.Scan(&service.ID, &service.Title, &service.Summary, &service.Details, &service.Position, &active, &service.CreatedAt); err != nil { return nil, err } service.Active = active == 1 services = append(services, service) } return services, rows.Err() } func (s *Store) CreateService(ctx context.Context, service Service) error { _, err := s.db.ExecContext(ctx, `insert into services (title, summary, details, position, active) values (?, ?, ?, ?, ?)`, service.Title, service.Summary, service.Details, service.Position, boolInt(service.Active)) return err } func (s *Store) UpdateService(ctx context.Context, service Service) error { _, err := s.db.ExecContext(ctx, `update services set title=?, summary=?, details=?, position=?, active=? where id=?`, service.Title, service.Summary, service.Details, service.Position, boolInt(service.Active), service.ID) return err } func (s *Store) DeleteService(ctx context.Context, id int64) error { _, err := s.db.ExecContext(ctx, `delete from services where id = ?`, id) return err } func (s *Store) FAQs(ctx context.Context, activeOnly bool) ([]FAQ, error) { query := `select id, question, answer, position, active, created_at from faqs` if activeOnly { query += ` where active = 1` } query += ` order by position asc, id asc` rows, err := s.db.QueryContext(ctx, query) if err != nil { return nil, err } defer rows.Close() var faqs []FAQ for rows.Next() { var faq FAQ var active int if err := rows.Scan(&faq.ID, &faq.Question, &faq.Answer, &faq.Position, &active, &faq.CreatedAt); err != nil { return nil, err } faq.Active = active == 1 faqs = append(faqs, faq) } return faqs, rows.Err() } func (s *Store) CreateFAQ(ctx context.Context, faq FAQ) error { _, err := s.db.ExecContext(ctx, `insert into faqs (question, answer, position, active) values (?, ?, ?, ?)`, faq.Question, faq.Answer, faq.Position, boolInt(faq.Active)) return err } func (s *Store) UpdateFAQ(ctx context.Context, faq FAQ) error { _, err := s.db.ExecContext(ctx, `update faqs set question=?, answer=?, position=?, active=? where id=?`, faq.Question, faq.Answer, faq.Position, boolInt(faq.Active), faq.ID) return err } func (s *Store) DeleteFAQ(ctx context.Context, id int64) error { _, err := s.db.ExecContext(ctx, `delete from faqs where id = ?`, id) return err }