fix: has_more overflow, magic constant, remove dead get_index handler
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
const DEFAULT_PAGE_LIMIT: u32 = 20;
|
||||||
|
|
||||||
pub mod html {
|
pub mod html {
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, Query, State},
|
extract::{Path, Query, State},
|
||||||
@@ -11,13 +13,12 @@ pub mod html {
|
|||||||
use application::{
|
use application::{
|
||||||
commands::{DeleteReviewCommand, LoginCommand, RegisterCommand},
|
commands::{DeleteReviewCommand, LoginCommand, RegisterCommand},
|
||||||
ports::{HtmlPageContext, LoginPageData, NewReviewPageData, RegisterPageData},
|
ports::{HtmlPageContext, LoginPageData, NewReviewPageData, RegisterPageData},
|
||||||
use_cases::{delete_review, get_diary, log_review, login as login_uc, register as register_uc},
|
use_cases::{delete_review, log_review, login as login_uc, register as register_uc},
|
||||||
};
|
};
|
||||||
use domain::{errors::DomainError, value_objects::UserId};
|
use domain::{errors::DomainError, value_objects::UserId};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dtos::{DiaryQueryParams, ErrorQuery, LoginForm, LogReviewData, LogReviewForm, RegisterForm},
|
dtos::{DiaryQueryParams, ErrorQuery, LoginForm, LogReviewData, LogReviewForm, RegisterForm},
|
||||||
errors::ApiError,
|
|
||||||
extractors::{OptionalCookieUser, RequiredCookieUser},
|
extractors::{OptionalCookieUser, RequiredCookieUser},
|
||||||
state::AppState,
|
state::AppState,
|
||||||
};
|
};
|
||||||
@@ -58,21 +59,6 @@ pub mod html {
|
|||||||
(SET_COOKIE, HeaderValue::from_str(&val).expect("valid cookie"))
|
(SET_COOKIE, HeaderValue::from_str(&val).expect("valid cookie"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_index(
|
|
||||||
OptionalCookieUser(user_id): OptionalCookieUser,
|
|
||||||
State(state): State<AppState>,
|
|
||||||
Query(params): Query<DiaryQueryParams>,
|
|
||||||
) -> Result<impl IntoResponse, ApiError> {
|
|
||||||
let query = params.into();
|
|
||||||
let ctx = build_page_context(&state, user_id).await;
|
|
||||||
let page = get_diary::execute(&state.app_ctx, query).await?;
|
|
||||||
let html = state
|
|
||||||
.html_renderer
|
|
||||||
.render_diary_page(&page, ctx)
|
|
||||||
.map_err(|e| ApiError(DomainError::InfrastructureError(e)))?;
|
|
||||||
Ok(Html(html))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_login_page(
|
pub async fn get_login_page(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Query(params): Query<ErrorQuery>,
|
Query(params): Query<ErrorQuery>,
|
||||||
@@ -250,7 +236,7 @@ pub mod html {
|
|||||||
Ok(entries) => {
|
Ok(entries) => {
|
||||||
let limit = entries.limit;
|
let limit = entries.limit;
|
||||||
let offset = entries.offset;
|
let offset = entries.offset;
|
||||||
let has_more = (offset + limit) < entries.total_count as u32;
|
let has_more = (offset as u64).saturating_add(limit as u64) < entries.total_count;
|
||||||
let data = application::ports::ActivityFeedPageData {
|
let data = application::ports::ActivityFeedPageData {
|
||||||
ctx,
|
ctx,
|
||||||
current_offset: offset,
|
current_offset: offset,
|
||||||
@@ -291,7 +277,7 @@ pub mod html {
|
|||||||
Query(params): Query<crate::dtos::ProfileQueryParams>,
|
Query(params): Query<crate::dtos::ProfileQueryParams>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let ctx = build_page_context(&state, user_id).await;
|
let ctx = build_page_context(&state, user_id).await;
|
||||||
let view = params.view.clone().unwrap_or_else(|| "recent".to_string());
|
let view = params.view.unwrap_or_else(|| "recent".to_string());
|
||||||
|
|
||||||
let profile_user = match state.app_ctx.user_repository
|
let profile_user = match state.app_ctx.user_repository
|
||||||
.find_by_id(&domain::value_objects::UserId::from_uuid(profile_user_uuid))
|
.find_by_id(&domain::value_objects::UserId::from_uuid(profile_user_uuid))
|
||||||
@@ -313,10 +299,10 @@ pub mod html {
|
|||||||
Ok(profile) => {
|
Ok(profile) => {
|
||||||
let (offset, has_more, limit) = profile.entries.as_ref()
|
let (offset, has_more, limit) = profile.entries.as_ref()
|
||||||
.map(|e| {
|
.map(|e| {
|
||||||
let has_more = (e.offset + e.limit) < e.total_count as u32;
|
let has_more = (e.offset as u64).saturating_add(e.limit as u64) < e.total_count;
|
||||||
(e.offset, has_more, e.limit)
|
(e.offset, has_more, e.limit)
|
||||||
})
|
})
|
||||||
.unwrap_or((0, false, 20));
|
.unwrap_or((0, false, super::DEFAULT_PAGE_LIMIT));
|
||||||
let data = application::ports::ProfilePageData {
|
let data = application::ports::ProfilePageData {
|
||||||
ctx,
|
ctx,
|
||||||
profile_user_id: profile_user_uuid,
|
profile_user_id: profile_user_uuid,
|
||||||
|
|||||||
Reference in New Issue
Block a user