Gastansicht, Verbesserungen bei Planung

This commit is contained in:
concierge committed 2026-11-18 07:57:00 +01:00
1 parent b3afa3ef32
commit c08d43e7dd
38 files changed
+3845 -219

No files matched your search

+21 -14
View File
@@ -270,7 +270,8 @@ func (s *Store) DeleteGeneratedServices(ctx context.Context, tenantID string, r
// Assignments returns assignments whose service lies in the range.
func (s *Store) Assignments(ctx context.Context, tenantID string, r domain.DayRange) ([]domain.Assignment, error) {
rows, err := s.db.QueryContext(ctx, `
SELECT a.id, a.service_id, a.person_id, a.role, a.locked, a.note, a.created_at
SELECT a.id, a.service_id, a.person_id, a.role, a.locked, a.beyond_preferences,
a.note, a.created_at
FROM assignments a JOIN services s ON s.tenant_id=a.tenant_id AND s.id=a.service_id
WHERE a.tenant_id=? AND s.date >= ? AND s.date <= ?
ORDER BY s.date, s.time_minutes`, tenantID, domain.Key(r.Start), domain.Key(r.End))
@@ -292,7 +293,7 @@ func (s *Store) AssignmentsForServices(ctx context.Context, tenantID string, ser
for _, id := range serviceIDs {
args = append(args, id)
}
query := "SELECT id, service_id, person_id, role, locked, note, created_at FROM assignments " +
query := "SELECT id, service_id, person_id, role, locked, beyond_preferences, note, created_at FROM assignments " +
"WHERE tenant_id=? AND service_id IN (" + placeholders + ")"
rows, err := s.db.QueryContext(ctx, query, args...)
if err != nil {
@@ -305,7 +306,7 @@ func (s *Store) AssignmentsForServices(ctx context.Context, tenantID string, ser
// AssignmentsForPerson lists all assignments of a volunteer.
func (s *Store) AssignmentsForPerson(ctx context.Context, tenantID, personID string) ([]domain.Assignment, error) {
rows, err := s.db.QueryContext(ctx, `
SELECT id, service_id, person_id, role, locked, note, created_at
SELECT id, service_id, person_id, role, locked, beyond_preferences, note, created_at
FROM assignments WHERE tenant_id=? AND person_id=? ORDER BY created_at`, tenantID, personID)
if err != nil {
return nil, err
@@ -326,13 +327,14 @@ func scanAssignments(rows *sql.Rows) ([]domain.Assignment, error) {
for rows.Next() {
var assignment domain.Assignment
var role, created string
var locked int
var locked, beyond int
if err := rows.Scan(&assignment.ID, &assignment.ServiceID, &assignment.PersonID,
&role, &locked, &assignment.Note, &created); err != nil {
&role, &locked, &beyond, &assignment.Note, &created); err != nil {
return nil, err
}
assignment.Role = domain.Role(role)
assignment.Locked = locked != 0
assignment.BeyondPreferences = beyond != 0
assignment.CreatedAt = parseTime(created)
out = append(out, assignment)
}
@@ -351,14 +353,16 @@ func (s *Store) UpsertAssignment(ctx context.Context, tenantID string, assignmen
assignment.CreatedAt = time.Now().UTC()
}
_, err := s.db.ExecContext(ctx, `
INSERT INTO assignments(tenant_id, id, service_id, person_id, role, locked, note, created_at)
VALUES(?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO assignments(tenant_id, id, service_id, person_id, role, locked,
beyond_preferences, note, created_at)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(tenant_id, id) DO UPDATE SET
service_id=excluded.service_id, person_id=excluded.person_id,
role=excluded.role, locked=excluded.locked, note=excluded.note`,
role=excluded.role, locked=excluded.locked,
beyond_preferences=excluded.beyond_preferences, note=excluded.note`,
tenantID, assignment.ID, assignment.ServiceID, assignment.PersonID,
string(assignment.Role), boolInt(assignment.Locked), assignment.Note,
assignment.CreatedAt.Format(time.RFC3339))
string(assignment.Role), boolInt(assignment.Locked), boolInt(assignment.BeyondPreferences),
assignment.Note, assignment.CreatedAt.Format(time.RFC3339))
if err != nil && isUniqueViolation(err) {
return ErrConflict
}
@@ -399,13 +403,16 @@ func (s *Store) SavePlan(ctx context.Context, tenantID string, assignments []dom
assignment.CreatedAt = time.Now().UTC()
}
if _, err := tx.ExecContext(ctx, `
INSERT INTO assignments(tenant_id, id, service_id, person_id, role, locked, note, created_at)
VALUES(?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO assignments(tenant_id, id, service_id, person_id, role, locked,
beyond_preferences, note, created_at)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(tenant_id, id) DO UPDATE SET
service_id=excluded.service_id, person_id=excluded.person_id,
role=excluded.role, locked=excluded.locked, note=excluded.note`,
role=excluded.role, locked=excluded.locked,
beyond_preferences=excluded.beyond_preferences, note=excluded.note`,
tenantID, assignment.ID, assignment.ServiceID, assignment.PersonID,
string(assignment.Role), boolInt(assignment.Locked), assignment.Note,
string(assignment.Role), boolInt(assignment.Locked),
boolInt(assignment.BeyondPreferences), assignment.Note,
assignment.CreatedAt.Format(time.RFC3339)); err != nil {
return err
}