From 150eb37a61b39d245f0fddafded841b2e96572d2 Mon Sep 17 00:00:00 2001 From: FrenchGithubUser Date: Sat, 1 Nov 2025 12:31:32 +0100 Subject: [PATCH] feat: create generic paginated type and use it for collage search --- .../src/handlers/search/search_collages.rs | 7 +- backend/storage/src/models/common.rs | 10 ++ backend/storage/src/models/mod.rs | 1 + .../src/repositories/collage_repository.rs | 15 ++- frontend/src/api-schema/schema.d.ts | 6 +- shared/.env.ci | 1 - tracker/arcadia_tracker/.env.ci | 96 ------------------- 7 files changed, 27 insertions(+), 109 deletions(-) create mode 100644 backend/storage/src/models/common.rs delete mode 100644 shared/.env.ci delete mode 100644 tracker/arcadia_tracker/.env.ci diff --git a/backend/api/src/handlers/search/search_collages.rs b/backend/api/src/handlers/search/search_collages.rs index 55109ea7..626869ca 100644 --- a/backend/api/src/handlers/search/search_collages.rs +++ b/backend/api/src/handlers/search/search_collages.rs @@ -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), ) )] pub async fn exec( diff --git a/backend/storage/src/models/common.rs b/backend/storage/src/models/common.rs new file mode 100644 index 00000000..e42a1bbc --- /dev/null +++ b/backend/storage/src/models/common.rs @@ -0,0 +1,10 @@ +use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; + +#[derive(Debug, Serialize, Deserialize, ToSchema)] +pub struct PaginatedResults { + pub results: Vec, + pub page: u32, + pub page_size: u32, + pub total_items: i64, +} diff --git a/backend/storage/src/models/mod.rs b/backend/storage/src/models/mod.rs index 32bc3ddb..4191a8b9 100644 --- a/backend/storage/src/models/mod.rs +++ b/backend/storage/src/models/mod.rs @@ -1,5 +1,6 @@ pub mod artist; pub mod collage; +pub mod common; pub mod conversation; pub mod edition_group; pub mod entity; diff --git a/backend/storage/src/repositories/collage_repository.rs b/backend/storage/src/repositories/collage_repository.rs index 66800aa1..02d8173f 100644 --- a/backend/storage/src/repositories/collage_repository.rs +++ b/backend/storage/src/repositories/collage_repository.rs @@ -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 { + ) -> Result> { 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, }) } } diff --git a/frontend/src/api-schema/schema.d.ts b/frontend/src/api-schema/schema.d.ts index 0de53493..721a6756 100644 --- a/frontend/src/api-schema/schema.d.ts +++ b/frontend/src/api-schema/schema.d.ts @@ -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: { diff --git a/shared/.env.ci b/shared/.env.ci deleted file mode 100644 index 716b7b38..00000000 --- a/shared/.env.ci +++ /dev/null @@ -1 +0,0 @@ -DATABASE_URL=postgresql://arcadia:password@localhost:4321/arcadia diff --git a/tracker/arcadia_tracker/.env.ci b/tracker/arcadia_tracker/.env.ci deleted file mode 100644 index 31f32597..00000000 --- a/tracker/arcadia_tracker/.env.ci +++ /dev/null @@ -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: -# 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