feat: routes

This commit is contained in:
2026-06-06 12:59:52 +03:00
parent 63546c1fe3
commit 83abcd02dd
3 changed files with 71 additions and 11 deletions
+33 -8
View File
@@ -1,10 +1,11 @@
"""Admin user-management endpoints. Every route requires a superuser.
"""Admin endpoints: user management, services, sources, reindex, settings.
Registration is admin-only — this is a private instance, there is no public
sign-up (plan §6.4).
"""
import uuid
from typing import Any
from fastapi import APIRouter, Query, status
@@ -16,10 +17,10 @@ from app.api.schemas.user import (
UserResponse,
)
router = APIRouter(prefix="/admin/users", tags=["admin"])
router = APIRouter(prefix="/admin", tags=["admin"])
@router.get("", response_model=list[UserResponse])
@router.get("/users", response_model=list[UserResponse])
async def list_users(
_admin: SuperUser,
users: UserServiceDep,
@@ -30,7 +31,7 @@ async def list_users(
return [UserResponse.from_entity(u) for u in result]
@router.post("", response_model=UserResponse, status_code=status.HTTP_201_CREATED)
@router.post("/users", response_model=UserResponse, status_code=status.HTTP_201_CREATED)
async def create_user(
body: CreateUserRequest, _admin: SuperUser, users: UserServiceDep
) -> UserResponse:
@@ -42,12 +43,12 @@ async def create_user(
return UserResponse.from_entity(user)
@router.get("/{user_id}", response_model=UserResponse)
@router.get("/users/{user_id}", response_model=UserResponse)
async def get_user(user_id: uuid.UUID, _admin: SuperUser, users: UserServiceDep) -> UserResponse:
return UserResponse.from_entity(await users.get_user(user_id))
@router.patch("/{user_id}", response_model=UserResponse)
@router.patch("/users/{user_id}", response_model=UserResponse)
async def update_user(
user_id: uuid.UUID,
body: UpdateUserRequest,
@@ -62,7 +63,7 @@ async def update_user(
return UserResponse.from_entity(user)
@router.post("/{user_id}/reset-password", status_code=status.HTTP_204_NO_CONTENT)
@router.post("/users/{user_id}/reset-password", status_code=status.HTTP_204_NO_CONTENT)
async def reset_password(
user_id: uuid.UUID,
body: ResetPasswordRequest,
@@ -72,9 +73,33 @@ async def reset_password(
await users.reset_password(user_id, new_password=body.new_password)
@router.delete("/{user_id}", response_model=UserResponse)
@router.delete("/users/{user_id}", response_model=UserResponse)
async def deactivate_user(
user_id: uuid.UUID, _admin: SuperUser, users: UserServiceDep
) -> UserResponse:
"""Soft delete — deactivates the account and revokes its sessions."""
return UserResponse.from_entity(await users.deactivate(user_id))
@router.get("/services")
async def list_services(_admin: SuperUser) -> Any: ...
@router.get("/sources")
async def list_admin_sources(_admin: SuperUser) -> Any: ...
@router.patch("/sources/{source}")
async def update_admin_source(source: str, _admin: SuperUser) -> Any: ...
@router.post("/reindex")
async def trigger_reindex(_admin: SuperUser) -> Any: ...
@router.get("/settings")
async def get_admin_settings(_admin: SuperUser) -> Any: ...
@router.patch("/settings")
async def update_admin_settings(_admin: SuperUser) -> Any: ...