feat: initialize thoughts-frontend with Next.js, TypeScript, and ESLint
- Add ESLint configuration for Next.js and TypeScript support. - Create Next.js configuration file with standalone output option. - Initialize package.json with scripts for development, build, and linting. - Set up PostCSS configuration for Tailwind CSS. - Add SVG assets for UI components. - Create TypeScript configuration for strict type checking and module resolution.
This commit is contained in:
24
thoughts-backend/app/src/config.rs
Normal file
24
thoughts-backend/app/src/config.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
pub struct Config {
|
||||
pub db_url: String,
|
||||
pub host: String,
|
||||
pub port: u32,
|
||||
pub prefork: bool,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_env() -> Config {
|
||||
Config {
|
||||
db_url: std::env::var("DATABASE_URL").expect("DATABASE_URL is not set in .env file"),
|
||||
host: std::env::var("HOST").expect("HOST is not set in .env file"),
|
||||
port: std::env::var("PORT")
|
||||
.expect("PORT is not set in .env file")
|
||||
.parse()
|
||||
.expect("PORT is not a number"),
|
||||
prefork: std::env::var("PREFORK").is_ok_and(|v| v == "1"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_server_url(&self) -> String {
|
||||
format!("{}:{}", self.host, self.port)
|
||||
}
|
||||
}
|
3
thoughts-backend/app/src/error/mod.rs
Normal file
3
thoughts-backend/app/src/error/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
mod user;
|
||||
|
||||
pub use user::UserError;
|
14
thoughts-backend/app/src/error/user.rs
Normal file
14
thoughts-backend/app/src/error/user.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
#[derive(Debug)]
|
||||
pub enum UserError {
|
||||
NotFound,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for UserError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
UserError::NotFound => write!(f, "User not found"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for UserError {}
|
4
thoughts-backend/app/src/lib.rs
Normal file
4
thoughts-backend/app/src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod config;
|
||||
pub mod error;
|
||||
pub mod persistence;
|
||||
pub mod state;
|
24
thoughts-backend/app/src/persistence/blog.rs
Normal file
24
thoughts-backend/app/src/persistence/blog.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use sea_orm::{ActiveModelTrait, ColumnTrait, DbConn, DbErr, EntityTrait, QueryFilter, Set};
|
||||
|
||||
use models::{domains::blog, params::blog::CreateBlogParams, queries::blog::BlogQuery};
|
||||
|
||||
pub async fn search_blogs(db: &DbConn, query: BlogQuery) -> Result<Vec<blog::Model>, DbErr> {
|
||||
blog::Entity::find()
|
||||
.filter(blog::Column::Title.contains(query.title.unwrap_or_default()))
|
||||
.all(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn create_blog(
|
||||
db: &DbConn,
|
||||
params: CreateBlogParams,
|
||||
) -> Result<blog::ActiveModel, DbErr> {
|
||||
blog::ActiveModel {
|
||||
author_id: Set(params.author_id as i32),
|
||||
title: Set(params.title),
|
||||
content: Set(params.content),
|
||||
..Default::default()
|
||||
}
|
||||
.save(db)
|
||||
.await
|
||||
}
|
2
thoughts-backend/app/src/persistence/mod.rs
Normal file
2
thoughts-backend/app/src/persistence/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod blog;
|
||||
pub mod user;
|
28
thoughts-backend/app/src/persistence/user.rs
Normal file
28
thoughts-backend/app/src/persistence/user.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use sea_orm::{ActiveModelTrait, ColumnTrait, DbConn, DbErr, EntityTrait, QueryFilter, Set};
|
||||
|
||||
use models::domains::user;
|
||||
use models::params::user::CreateUserParams;
|
||||
use models::queries::user::UserQuery;
|
||||
|
||||
pub async fn create_user(
|
||||
db: &DbConn,
|
||||
params: CreateUserParams,
|
||||
) -> Result<user::ActiveModel, DbErr> {
|
||||
user::ActiveModel {
|
||||
username: Set(params.username),
|
||||
..Default::default()
|
||||
}
|
||||
.save(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn search_users(db: &DbConn, query: UserQuery) -> Result<Vec<user::Model>, DbErr> {
|
||||
user::Entity::find()
|
||||
.filter(user::Column::Username.contains(query.username.unwrap_or_default()))
|
||||
.all(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_user(db: &DbConn, id: i32) -> Result<Option<user::Model>, DbErr> {
|
||||
user::Entity::find_by_id(id).one(db).await
|
||||
}
|
6
thoughts-backend/app/src/state.rs
Normal file
6
thoughts-backend/app/src/state.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use sea_orm::DatabaseConnection;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub conn: DatabaseConnection,
|
||||
}
|
Reference in New Issue
Block a user