m1m02530125 Claude Sonnet 4.6 commited on
Commit
72fe206
·
1 Parent(s): e2c8c2a

fix: new employee appended to bottom of list

Browse files

Previously display_order was omitted from INSERT, defaulting to 0,
which placed new staff at or near the top of the list.

Now inserts with display_order = MAX(display_order) + 1 so new
staff always appear at the bottom, preserving the user-set order.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. db/repositories.py +5 -2
db/repositories.py CHANGED
@@ -68,9 +68,12 @@ def save_employee(emp: Employee) -> Employee:
68
  avail_b = int(emp.always_available_breakfast)
69
  avail_d = int(emp.always_available_dinner)
70
  if emp.id is None:
 
 
 
71
  emp.id = conn.execute_insert(
72
- "INSERT INTO employees (name, employment_type, hall_skill, kitchen_skill, primary_position, output_position, primary_timeslot, can_work_both_positions, can_open, can_cleanup, always_available_breakfast, always_available_dinner, is_active) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)",
73
- (emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, op, pt, both, opn, cln, avail_b, avail_d, 1)
74
  )
75
  else:
76
  conn.execute(
 
68
  avail_b = int(emp.always_available_breakfast)
69
  avail_d = int(emp.always_available_dinner)
70
  if emp.id is None:
71
+ # 末尾に追加されるよう MAX(display_order)+1 をセット
72
+ row = conn.execute("SELECT COALESCE(MAX(display_order), -1) FROM employees").fetchone()
73
+ next_order = (row[0] if row else -1) + 1
74
  emp.id = conn.execute_insert(
75
+ "INSERT INTO employees (name, employment_type, hall_skill, kitchen_skill, primary_position, output_position, primary_timeslot, can_work_both_positions, can_open, can_cleanup, always_available_breakfast, always_available_dinner, is_active, display_order) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
76
+ (emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, op, pt, both, opn, cln, avail_b, avail_d, 1, next_order)
77
  )
78
  else:
79
  conn.execute(