feat(users): Enhance user schema and DTOs with additional fields for website, social links, location, skills, experience, and education

This commit is contained in:
MythEclipse
2025-08-13 20:40:02 +07:00
parent 277cf0770d
commit f6232832af
17 changed files with 327 additions and 55 deletions
@@ -1,5 +1,5 @@
use crate::{
AppState, GachaItemDto, GachaItemRequestDto, GachaItemService, MessageResponseDto,
AppState, GachaItemDto, GachaItemRequestDto, GachaItemUpdateRequestDto, GachaItemService, MessageResponseDto,
MetaRequestDto, ResponseListSuccessDto, ResponseSuccessDto,
};
use axum::{
@@ -111,7 +111,7 @@ pub async fn post_create_gacha_item(
security(
("Bearer" = [])
),
request_body = GachaItemRequestDto,
request_body = GachaItemUpdateRequestDto,
responses(
(status = 200, description = "Update gacha item", body = MessageResponseDto)
),
@@ -121,7 +121,7 @@ pub async fn put_update_gacha_item(
headers: HeaderMap,
Extension(state): Extension<AppState>,
Path(id): Path<String>,
Json(payload): Json<GachaItemRequestDto>,
Json(payload): Json<GachaItemUpdateRequestDto>,
) -> impl IntoResponse {
match permissions_guard(
&headers,
@@ -11,6 +11,16 @@ pub struct GachaItemRequestDto {
pub image_url: String,
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
pub struct GachaItemUpdateRequestDto {
#[validate(length(min = 1, message = "Item name must not be empty"))]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[validate(length(min = 1, message = "Image URL must not be empty"))]
#[serde(skip_serializing_if = "Option::is_none")]
pub image_url: Option<String>,
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct GachaItemDto {
pub id: String,
@@ -43,4 +43,8 @@ impl GachaItemSchema {
..Default::default()
}
}
pub fn from_existing(existing: GachaItemSchema) -> Self {
existing
}
}
@@ -1,11 +1,12 @@
use crate::{
AppState, GachaItemDto, GachaItemRepository, GachaItemRequestDto, GachaItemSchema,
AppState, GachaItemDto, GachaItemRepository, GachaItemRequestDto, GachaItemUpdateRequestDto, GachaItemSchema,
MetaRequestDto, ResourceEnum, ResponseListSuccessDto, ResponseSuccessDto,
common_response, make_thing, success_list_response, success_response,
validate_request,
};
use axum::http::StatusCode;
use axum::response::Response;
use imphnen_utils::get_iso_date;
pub struct GachaItemService;
@@ -59,20 +60,33 @@ impl GachaItemService {
pub async fn update_gacha_item(
state: &AppState,
payload: GachaItemRequestDto,
payload: GachaItemUpdateRequestDto,
id: String,
) -> Response {
if let Err((status, message)) = validate_request(&payload) {
return common_response(status, &message);
}
let repo = GachaItemRepository::new(state);
let schema = GachaItemSchema {
id: make_thing(&ResourceEnum::GachaItems.to_string(), &id),
name: payload.name,
image_url: payload.image_url,
..Default::default()
// Get current gacha item data first
let _thing_id = make_thing(&ResourceEnum::GachaItems.to_string(), &id);
let current_item = match repo.query_gacha_item_by_id(id.clone()).await {
Ok(item) => item,
Err(_) => return common_response(StatusCode::NOT_FOUND, "Gacha Item not found"),
};
match repo.query_update_gacha_item(schema).await {
let mut updated_item = current_item;
updated_item.updated_at = Some(get_iso_date());
// Only update fields that are provided
if let Some(name) = payload.name {
updated_item.name = name;
}
if let Some(image_url) = payload.image_url {
updated_item.image_url = image_url;
}
match repo.query_update_gacha_item(updated_item).await {
Ok(msg) => common_response(StatusCode::OK, &msg),
Err(e) => {
if e.to_string().contains("not found") {