use crate::{ApiResponse, error::ApiError};
use actix_web::{HttpResponse, Result, web};
use service::AppService;
use service::user::user_activity::UserActivityQuery;
use session::Session;

#[utoipa::path(
    get,
    path = "/api/users/{username}/activity",
    params(
        ("username" = String, Path),
        ("page" = Option<u64>, Query),
        ("per_page" = Option<u64>, Query),
    ),
    responses(
        (status = 200, description = "Get user activity", body = ApiResponse<service::user::user_activity::UserActivityResponse>),
        (status = 401, description = "Unauthorized"),
        (status = 404, description = "Not found"),
),
    tag = "User"
)]
pub async fn get_user_activity(
    service: web::Data<AppService>,
    session: Session,
    path: web::Path<String>,
    query: web::Query<UserActivityQuery>,
) -> Result<HttpResponse, ApiError> {
    let username = path.into_inner();
    let resp = service
        .get_user_activity(session, username, query.into_inner())
        .await?;
    Ok(ApiResponse::ok(resp).to_response())
}
