2026-02-27 20:26:25 +00:00
|
|
|
from datetime import UTC, datetime
|
|
|
|
|
|
2026-02-26 10:02:37 +00:00
|
|
|
from flask import request
|
|
|
|
|
from flask_jwt_extended import jwt_required
|
|
|
|
|
from flask_pydantic import validate
|
|
|
|
|
|
|
|
|
|
from app import db
|
|
|
|
|
from app.decorators import load_board_owned, load_list_owned
|
2026-02-27 20:26:25 +00:00
|
|
|
from app.models import Board, List
|
2026-02-26 10:02:37 +00:00
|
|
|
from app.schemas import ListCreateRequest
|
2026-02-27 20:26:25 +00:00
|
|
|
from app.services.list_position_service import ListPositionService
|
2026-02-26 10:02:37 +00:00
|
|
|
|
|
|
|
|
from . import kanban_bp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@kanban_bp.route("/boards/<int:board_id>/lists", methods=["POST"])
|
|
|
|
|
@jwt_required()
|
|
|
|
|
@load_board_owned
|
|
|
|
|
@validate(body=ListCreateRequest)
|
|
|
|
|
def create_list(board_id, board, body: ListCreateRequest):
|
|
|
|
|
"""Create a new list in a board"""
|
|
|
|
|
lst = List(
|
|
|
|
|
name=body.name,
|
|
|
|
|
board_id=board_id,
|
|
|
|
|
pos=body.pos,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
db.session.add(lst)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
return lst.to_dict(), 201
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@kanban_bp.route("/lists/<int:list_id>", methods=["PUT"])
|
|
|
|
|
@jwt_required()
|
|
|
|
|
@load_list_owned
|
|
|
|
|
@validate(body=ListCreateRequest)
|
|
|
|
|
def update_list(list_id, lst, body: ListCreateRequest):
|
|
|
|
|
"""Update a list"""
|
|
|
|
|
lst.name = body.name
|
|
|
|
|
if request.json.get("closed") is not None:
|
|
|
|
|
lst.closed = request.json.get("closed")
|
|
|
|
|
|
2026-02-27 20:26:25 +00:00
|
|
|
# Track if position is changing
|
|
|
|
|
old_position = lst.pos
|
|
|
|
|
new_position = body.pos
|
|
|
|
|
|
|
|
|
|
if old_position != new_position:
|
|
|
|
|
# Use ListPositionService to reorder lists
|
|
|
|
|
ListPositionService.reorder_lists(lst.board_id, list_id, new_position)
|
|
|
|
|
else:
|
|
|
|
|
lst.pos = new_position
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
# Update board activity timestamp
|
|
|
|
|
board = db.session.get(Board, lst.board_id)
|
|
|
|
|
board.date_last_activity = datetime.now(UTC)
|
2026-02-26 10:02:37 +00:00
|
|
|
|
|
|
|
|
return lst.to_dict(), 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@kanban_bp.route("/lists/<int:list_id>", methods=["DELETE"])
|
|
|
|
|
@jwt_required()
|
|
|
|
|
@load_list_owned
|
|
|
|
|
def delete_list(list_id, lst):
|
|
|
|
|
"""Delete a list"""
|
|
|
|
|
db.session.delete(lst)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
return {"message": "List deleted"}, 200
|