Skip to content

Commit

Permalink
feat: dto team
Browse files Browse the repository at this point in the history
  • Loading branch information
brizzinck committed Jan 9, 2025
1 parent 3861bfc commit 83a3179
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/api/admin/get.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions src/api/admin/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod get;
pub mod post;
1 change: 1 addition & 0 deletions src/api/admin/post.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

9 changes: 3 additions & 6 deletions src/api/hackathon_2024/team/post.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use crate::diesel::models::hackathon_2024::team::HackathonTeam2024Insertable;
use crate::dto::request::hackathon_2024::team::TeamCreateData;
use crate::utils::prelude_api::*;
use crate::utils::security::hashing_data;
use rocket::post;

#[post("/hackathon_2024/team/create", data = "<data>")]
pub async fn create(
db_pool: &DbState,
data: Json<HackathonTeam2024Insertable>,
) -> Result<(), ApiError> {
let mut team = data.into_inner();
pub async fn create(db_pool: &DbState, data: Json<TeamCreateData>) -> Result<(), ApiError> {
let mut team = data.into_inner().0;

crate::utils::validation::data::hackathon_2024::team::field(&team)?;
team.password_registration = hashing_data(team.password_registration)?;
Expand Down
1 change: 1 addition & 0 deletions src/api/hackathon_2024/user/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::utils::prelude_api::*;
use crate::utils::security::decoded_data;
use rocket::get;

#[allow(dead_code)]
#[get("/hackathon_2024/user/confirm_new_user?<jwt_token>")]
pub async fn confirm_new_user(db_pool: &DbState, jwt_token: String) -> Result<(), ApiError> {
create_user_by_jwt(db_pool, decoded_data(&jwt_token)?.claims)
Expand Down
1 change: 1 addition & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod admin;
pub mod banner;
pub mod hackathon_2024;
pub mod news;
Expand Down
3 changes: 3 additions & 0 deletions src/dto/request/hackathon_2024/team.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::diesel::models::hackathon_2024::category::HackathonCategory2024Enum;
use crate::diesel::models::hackathon_2024::team::HackathonTeam2024Insertable;
use serde::Deserialize;

#[derive(Deserialize)]
Expand All @@ -14,3 +15,5 @@ pub struct TeamUpdateData {
pub category: HackathonCategory2024Enum,
pub nickname_tg: String,
}
#[derive(Debug, Deserialize)]
pub struct TeamCreateData(pub HackathonTeam2024Insertable);
1 change: 1 addition & 0 deletions src/dto/response/hackathon_2024/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod team;
pub mod university;
pub mod user;
7 changes: 7 additions & 0 deletions src/dto/response/hackathon_2024/team.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[derive(serde::Serialize)]
pub struct Team(pub crate::diesel::models::hackathon_2024::team::HackathonTeam2024Queryable);

#[derive(serde::Serialize)]
pub struct VecTeam(
pub Vec<crate::diesel::models::hackathon_2024::team::HackathonTeam2024Queryable>,
);
3 changes: 1 addition & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Server {
}

fn configure_cors() -> Cors {
let exact = &[&format!("https://{}", "your_main_url.com")];
let exact = &[&format!("https://{}", EnvConfiguration::get().main_url)];
CorsOptions {
allowed_origins: AllowedOrigins::some_exact(exact),
allowed_methods: vec!["GET", "POST", "PUT", "DELETE"]
Expand All @@ -68,7 +68,6 @@ impl Server {
api::test::get::ping,
// /hackathon_2024/user/*
api::hackathon_2024::user::post::registration_by_tg,
api::hackathon_2024::user::get::confirm_new_user,
api::hackathon_2024::user::get::all,
api::hackathon_2024::user::put::by_id,
api::hackathon_2024::user::delete::by_id,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/env_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl EnvConfiguration {
.parse()
.expect("Invalid DATABASE_PORT"),
main_url: EnvConfiguration::unwrap_env(
"DATABASE_PASSWORD",
"MAIN_URL",
Some("http://localhost:3000".to_owned()),
),
server_port: EnvConfiguration::unwrap_env("SERVER_PORT", Some(8080.to_string()))
Expand Down
2 changes: 2 additions & 0 deletions src/utils/prelude_api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub use crate::diesel::prelude::DbState;
pub use crate::error::api_error::ApiError;
#[allow(unused_imports)]
pub use crate::utils::env_configuration::EnvConfiguration;
pub use log::info;
pub use rocket::serde::json::Json;
2 changes: 1 addition & 1 deletion src/utils/validation/validation_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<T: AsRef<str>> Validate for T {
}

fn is_nickname_tg(&self) -> bool {
match Regex::new(r"(?i)^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$") {
match Regex::new(r"^[a-zA-Z0-9](?:[a-zA-Z0-9_]{3,30}[a-zA-Z0-9])?$") {
Ok(nickname_regex) => nickname_regex.is_match(self.as_ref()),
Err(_) => false,
}
Expand Down

0 comments on commit 83a3179

Please sign in to comment.