feat: create generic paginated type and use it for collage search

This commit is contained in:
FrenchGithubUser
2025-11-01 12:31:32 +01:00
parent 83951e00a1
commit 150eb37a61
7 changed files with 27 additions and 109 deletions

View File

@@ -5,7 +5,10 @@ use actix_web::{
};
use arcadia_common::error::Result;
use arcadia_storage::{
models::collage::{CollageSearchResponse, SearchCollagesQuery},
models::{
collage::{CollageSearchResult, SearchCollagesQuery},
common::PaginatedResults,
},
redis::RedisPoolInterface,
};
@@ -17,7 +20,7 @@ use arcadia_storage::{
params (SearchCollagesQuery),
description = "Case insensitive",
responses(
(status = 200, description = "Successfully got the collages and some data about them", body=CollageSearchResponse),
(status = 200, description = "Successfully got the collages and some data about them", body=PaginatedResults<CollageSearchResult>),
)
)]
pub async fn exec<R: RedisPoolInterface + 'static>(

View File

@@ -0,0 +1,10 @@
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct PaginatedResults<T> {
pub results: Vec<T>,
pub page: u32,
pub page_size: u32,
pub total_items: i64,
}

View File

@@ -1,5 +1,6 @@
pub mod artist;
pub mod collage;
pub mod common;
pub mod conversation;
pub mod edition_group;
pub mod entity;

View File

@@ -1,8 +1,11 @@
use crate::{
connection_pool::ConnectionPool,
models::collage::{
Collage, CollageCategory, CollageEntry, CollageSearchResponse, CollageSearchResult,
CollageType, SearchCollagesQuery, UserCreatedCollage, UserCreatedCollageEntry,
models::{
collage::{
Collage, CollageCategory, CollageEntry, CollageSearchResult, CollageType,
SearchCollagesQuery, UserCreatedCollage, UserCreatedCollageEntry,
},
common::PaginatedResults,
},
};
use arcadia_common::error::{Error, Result};
@@ -157,7 +160,7 @@ impl ConnectionPool {
pub async fn search_collages(
&self,
form: &SearchCollagesQuery,
) -> Result<CollageSearchResponse> {
) -> Result<PaginatedResults<CollageSearchResult>> {
let offset = (form.page - 1) * form.page_size;
let total_items: i64 = query_scalar!(
@@ -211,9 +214,11 @@ impl ConnectionPool {
.fetch_all(self.borrow())
.await?;
Ok(CollageSearchResponse {
Ok(PaginatedResults {
results,
total_items,
page: form.page,
page_size: form.page_size,
})
}
}

View File

@@ -2651,11 +2651,7 @@ export interface operations {
parameters: {
query?: never;
header?: never;
path: {
limit: number | null;
page: number | null;
status: null | components["schemas"]["UserApplicationStatus"];
};
path?: never;
cookie?: never;
};
requestBody: {

View File

@@ -1 +0,0 @@
DATABASE_URL=postgresql://arcadia:password@localhost:4321/arcadia

View File

@@ -1,96 +0,0 @@
## Logging (docs: https://docs.rs/env_logger/latest/env_logger/)
# Possible options for RUST_LOG:
# "error" - Logs only error messages.
# "warn" - Logs warnings and errors.
# "info" - Logs informational messages, warnings, and errors.
# "debug" - Logs debug, informational messages, warnings, and errors.
# "trace" - Logs all messages including trace-level details.
# "off" - Disables logging entirely.
# You can also specify logging levels for specific modules, e.g.:
# - "debug,sqlx=info": Debug message for entire app, info for sqlx module.
# - "off": Disables logging entirely
RUST_LOG="debug,sqlx=info"
## Server Configuration
WEB_SERVER_HOST=0.0.0.0
WEB_SERVER_PORT=8081
## Tracker Configuration
# Used for the backend to make requests to the tracker
# and vice-versa. Must be the same as in arcadia's .env file
API_KEY=change_me
# Grace period for tracker announcements (in seconds).
ANNOUNCE_INTERVAL_GRACE_PERIOD=1800
# List of allowed torrent clients.
# The prefixed "-" should be removed.
ALLOWED_TORRENT_CLIENTS=BI3500,BI3600,BI3700,DE12,DE13,DE2,FL149,FL1490,HL04,KT21,KT23,KT24,KT5,LT,lt0D,lt0E,lt0F,qB2,qB3,qB40,qB41,qB42,qB43,qB44,qB45,qB46,qB50,qB51,TR2,TR3000,TR4010,TR4020,TR4030,TR4040,TR4050,TR4060
# The amount of peers that should be sent back if the peer does not
# include a numwant.
#
# Default: 15
NUMWANT_DEFAULT=15
# The max amount of peers that should be sent back if the peer's numwant
# is too high.
#
# Default: 15
NUMWANT_MAX=15
# A random amount of seconds between announce_min and announce_max will
# be returned to the peer for the next time they should announce.
#
# Default: 1800
ANNOUNCE_MIN=1800
# If a user announces before this many seconds after their previous
# announce, then they will receive a rate limit error.
#
# Default: 1740
ANNOUNCE_MIN_ENFORCED=1740
# A random amount of seconds between announce_min and announce_max will
# be returned to the peer for the next time they should announce.
#
# Default: 3600
ANNOUNCE_MAX=3600
# Max amount of active peers a user is allowed to have on a torrent.
# Prevents abuse from malicious users causing the server to run out of ram,
# as well as keeps the peer lists from being filled with too many clients
# of a single user.
#
# Default: 3
MAX_PEERS_PER_TORRENT_PER_USER=3
# The interval (in milliseconds) between when history, peers, torrents and
# users are flushed to the postgresql database.
#
# Default: 3000
FLUSH_INTERVAL_MILLISECONDS=3000
# Amount of seconds between scheduled batches where peers are marked as
# inactive or erased from memory.
#
# Default: 1800
PEER_EXPIRY_INTERVAL=1800
# Amount of seconds since the last announce before a peer is considered
# inactive.
#
# Default: 7200
ACTIVE_PEER_TTL=7200
# Amount of seconds since the last announce before a peer is erased from
# memory. This value should be long enough that users can suffer
# multi-day network outages without announcing, otherwise if their setup
# comes back online and the peer has been erased, then their new stats
# will be recorded incorrectly.
#
# Default: 1814400
INACTIVE_PEER_TTL=1814400
# The header provided by the reverse proxy that includes the bittorrent
# client's original ip address. The last address in the comma separated
# list will be selected. Leave empty to select the connecting ip address
# if not using a reverse proxy. A reverse proxy is required if listening
# on unix sockets.
#
# Default: <commented out>
# Example: "X-Real-IP"
# REVERSE_PROXY_CLIENT_IP_HEADER_NAME="X-Real-IP"
## Backend Configuration
ARCADIA_API_BASE_URL=http://localhost:8080
# connection string for the database.
DATABASE_URL=postgresql://arcadia:password@localhost:4321/arcadia