remove the notes model added by loco app template and everything related to it
This commit is contained in:
parent
c8e8dfae41
commit
652ead1c2b
20 changed files with 19 additions and 330 deletions
|
@ -3,7 +3,6 @@
|
|||
pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20220101_000001_users;
|
||||
mod m20231103_114510_notes;
|
||||
|
||||
mod m20241016_181828_servers;
|
||||
mod m20241021_121449_bundles;
|
||||
|
@ -16,7 +15,6 @@ impl MigratorTrait for Migrator {
|
|||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![
|
||||
Box::new(m20220101_000001_users::Migration),
|
||||
Box::new(m20231103_114510_notes::Migration),
|
||||
Box::new(m20241016_181828_servers::Migration),
|
||||
Box::new(m20241021_121449_bundles::Migration),
|
||||
Box::new(m20241021_121806_services::Migration),
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
use loco_rs::schema::table_auto_tz;
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
table_auto_tz(Notes::Table)
|
||||
.col(pk_auto(Notes::Id))
|
||||
.col(string_null(Notes::Title))
|
||||
.col(string_null(Notes::Content))
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Notes::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Notes {
|
||||
Table,
|
||||
Id,
|
||||
Title,
|
||||
Content,
|
||||
}
|
|
@ -16,7 +16,7 @@ use sea_orm::DatabaseConnection;
|
|||
|
||||
use crate::{
|
||||
controllers, initializers,
|
||||
models::_entities::{notes, users},
|
||||
models::_entities::{servers, bundles, services, bundles_services, users},
|
||||
tasks,
|
||||
workers::downloader::DownloadWorker,
|
||||
};
|
||||
|
@ -53,7 +53,6 @@ impl Hooks for App {
|
|||
.add_route(controllers::service::routes())
|
||||
.add_route(controllers::bundle::routes())
|
||||
.add_route(controllers::server::routes())
|
||||
.add_route(controllers::notes::routes())
|
||||
.add_route(controllers::auth::routes())
|
||||
.add_route(controllers::user::routes())
|
||||
}
|
||||
|
@ -69,13 +68,16 @@ impl Hooks for App {
|
|||
|
||||
async fn truncate(db: &DatabaseConnection) -> Result<()> {
|
||||
truncate_table(db, users::Entity).await?;
|
||||
truncate_table(db, notes::Entity).await?;
|
||||
truncate_table(db, bundles_services::Entity).await?;
|
||||
truncate_table(db, services::Entity).await?;
|
||||
truncate_table(db, bundles::Entity).await?;
|
||||
truncate_table(db, servers::Entity).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn seed(db: &DatabaseConnection, base: &Path) -> Result<()> {
|
||||
db::seed::<users::ActiveModel>(db, &base.join("users.yaml").display().to_string()).await?;
|
||||
db::seed::<notes::ActiveModel>(db, &base.join("notes.yaml").display().to_string()).await?;
|
||||
// ToDo: add seeds for other entities
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
pub mod auth;
|
||||
pub mod notes;
|
||||
pub mod user;
|
||||
|
||||
pub mod server;
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
#![allow(clippy::missing_errors_doc)]
|
||||
#![allow(clippy::unnecessary_struct_initialization)]
|
||||
#![allow(clippy::unused_async)]
|
||||
use axum::debug_handler;
|
||||
use loco_rs::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::models::_entities::notes::{ActiveModel, Entity, Model};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Params {
|
||||
pub title: Option<String>,
|
||||
pub content: Option<String>,
|
||||
}
|
||||
|
||||
impl Params {
|
||||
fn update(&self, item: &mut ActiveModel) {
|
||||
item.title = Set(self.title.clone());
|
||||
item.content = Set(self.content.clone());
|
||||
}
|
||||
}
|
||||
|
||||
async fn load_item(ctx: &AppContext, id: i32) -> Result<Model> {
|
||||
let item = Entity::find_by_id(id).one(&ctx.db).await?;
|
||||
item.ok_or_else(|| Error::NotFound)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn list(State(ctx): State<AppContext>) -> Result<Response> {
|
||||
format::json(Entity::find().all(&ctx.db).await?)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn add(State(ctx): State<AppContext>, Json(params): Json<Params>) -> Result<Response> {
|
||||
let mut item = ActiveModel {
|
||||
..Default::default()
|
||||
};
|
||||
params.update(&mut item);
|
||||
let item = item.insert(&ctx.db).await?;
|
||||
format::json(item)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn update(
|
||||
Path(id): Path<i32>,
|
||||
State(ctx): State<AppContext>,
|
||||
Json(params): Json<Params>,
|
||||
) -> Result<Response> {
|
||||
let item = load_item(&ctx, id).await?;
|
||||
let mut item = item.into_active_model();
|
||||
params.update(&mut item);
|
||||
let item = item.update(&ctx.db).await?;
|
||||
format::json(item)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn remove(Path(id): Path<i32>, State(ctx): State<AppContext>) -> Result<Response> {
|
||||
load_item(&ctx, id).await?.delete(&ctx.db).await?;
|
||||
format::empty()
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn get_one(Path(id): Path<i32>, State(ctx): State<AppContext>) -> Result<Response> {
|
||||
format::json(load_item(&ctx, id).await?)
|
||||
}
|
||||
|
||||
pub fn routes() -> Routes {
|
||||
Routes::new()
|
||||
.prefix("api/notes")
|
||||
.add("/", get(list))
|
||||
.add("/", post(add))
|
||||
.add("/:id", get(get_one))
|
||||
.add("/:id", delete(remove))
|
||||
.add("/:id", post(update))
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
---
|
||||
- id: 1
|
||||
title: Loco note 1
|
||||
content: Loco note 1 content
|
||||
created_at: "2023-11-12T12:34:56.789Z"
|
||||
updated_at: "2023-11-12T12:34:56.789Z"
|
||||
- id: 2
|
||||
title: Loco note 2
|
||||
content: Loco note 2 content
|
||||
created_at: "2023-11-12T12:34:56.789Z"
|
||||
updated_at: "2023-11-12T12:34:56.789Z"
|
|
@ -1,17 +1,10 @@
|
|||
---
|
||||
- id: 1
|
||||
pid: 11111111-1111-1111-1111-111111111111
|
||||
email: user1@example.com
|
||||
email: test@nixin.local.com
|
||||
password: "$argon2id$v=19$m=19456,t=2,p=1$ETQBx4rTgNAZhSaeYZKOZg$eYTdH26CRT6nUJtacLDEboP0li6xUwUF/q5nSlQ8uuc"
|
||||
api_key: lo-95ec80d7-cb60-4b70-9b4b-9ef74cb88758
|
||||
name: user1
|
||||
created_at: "2023-11-12T12:34:56.789Z"
|
||||
updated_at: "2023-11-12T12:34:56.789Z"
|
||||
- id: 2
|
||||
pid: 22222222-2222-2222-2222-222222222222
|
||||
email: user2@example.com
|
||||
password: "$argon2id$v=19$m=19456,t=2,p=1$ETQBx4rTgNAZhSaeYZKOZg$eYTdH26CRT6nUJtacLDEboP0li6xUwUF/q5nSlQ8uuc"
|
||||
api_key: lo-153561ca-fa84-4e1b-813a-c62526d0a77e
|
||||
name: user2
|
||||
name: test
|
||||
created_at: "2023-11-12T12:34:56.789Z"
|
||||
updated_at: "2023-11-12T12:34:56.789Z"
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ pub mod prelude;
|
|||
|
||||
pub mod bundles;
|
||||
pub mod bundles_services;
|
||||
pub mod notes;
|
||||
pub mod servers;
|
||||
pub mod services;
|
||||
pub mod users;
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "notes")]
|
||||
pub struct Model {
|
||||
pub created_at: DateTimeWithTimeZone,
|
||||
pub updated_at: DateTimeWithTimeZone,
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub title: Option<String>,
|
||||
pub content: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
pub use super::bundles::Entity as Bundles;
|
||||
pub use super::bundles_services::Entity as BundlesServices;
|
||||
pub use super::notes::Entity as Notes;
|
||||
pub use super::servers::Entity as Servers;
|
||||
pub use super::services::Entity as Services;
|
||||
pub use super::users::Entity as Users;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
pub mod _entities;
|
||||
pub mod notes;
|
||||
pub mod users;
|
||||
pub mod servers;
|
||||
pub mod bundles;
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
use sea_orm::entity::prelude::*;
|
||||
|
||||
use super::_entities::notes::ActiveModel;
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {
|
||||
// extend activemodel below (keep comment for generators)
|
||||
}
|
|
@ -23,9 +23,9 @@ async fn can_register() {
|
|||
configure_insta!();
|
||||
|
||||
testing::request::<App, _, _>(|request, ctx| async move {
|
||||
let email = "test@loco.com";
|
||||
let email = "test@nixin.local";
|
||||
let payload = serde_json::json!({
|
||||
"name": "loco",
|
||||
"name": "test",
|
||||
"email": email,
|
||||
"password": "12341234"
|
||||
});
|
||||
|
@ -57,9 +57,9 @@ async fn can_login_with_verify(#[case] test_name: &str, #[case] password: &str)
|
|||
configure_insta!();
|
||||
|
||||
testing::request::<App, _, _>(|request, ctx| async move {
|
||||
let email = "test@loco.com";
|
||||
let email = "test@nixin.local";
|
||||
let register_payload = serde_json::json!({
|
||||
"name": "loco",
|
||||
"name": "test",
|
||||
"email": email,
|
||||
"password": "12341234"
|
||||
});
|
||||
|
@ -107,10 +107,10 @@ async fn can_login_without_verify() {
|
|||
configure_insta!();
|
||||
|
||||
testing::request::<App, _, _>(|request, _ctx| async move {
|
||||
let email = "test@loco.com";
|
||||
let email = "test@nixin.local";
|
||||
let password = "12341234";
|
||||
let register_payload = serde_json::json!({
|
||||
"name": "loco",
|
||||
"name": "test",
|
||||
"email": email,
|
||||
"password": password
|
||||
});
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
mod auth;
|
||||
mod notes;
|
||||
mod prepare_data;
|
||||
mod user;
|
||||
|
|
|
@ -1,123 +0,0 @@
|
|||
use insta::{assert_debug_snapshot, with_settings};
|
||||
use loco_rs::testing;
|
||||
use nixin_farm_ssr::{app::App, models::_entities::notes::Entity};
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serial_test::serial;
|
||||
|
||||
// TODO: see how to dedup / extract this to app-local test utils
|
||||
// not to framework, because that would require a runtime dep on insta
|
||||
macro_rules! configure_insta {
|
||||
($($expr:expr),*) => {
|
||||
let mut settings = insta::Settings::clone_current();
|
||||
settings.set_prepend_module_to_snapshot(false);
|
||||
settings.set_snapshot_suffix("notes_request");
|
||||
let _guard = settings.bind_to_scope();
|
||||
};
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn can_get_notes() {
|
||||
configure_insta!();
|
||||
|
||||
testing::request::<App, _, _>(|request, ctx| async move {
|
||||
testing::seed::<App>(&ctx.db).await.unwrap();
|
||||
|
||||
let notes = request.get("/api/notes").await;
|
||||
|
||||
with_settings!({
|
||||
filters => {
|
||||
let mut combined_filters = testing::CLEANUP_DATE.to_vec();
|
||||
combined_filters.extend(vec![(r#"\"id\\":\d+"#, r#""id\":ID"#)]);
|
||||
combined_filters
|
||||
}
|
||||
}, {
|
||||
assert_debug_snapshot!(
|
||||
(notes.status_code(), notes.text())
|
||||
);
|
||||
});
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn can_add_note() {
|
||||
configure_insta!();
|
||||
|
||||
testing::request::<App, _, _>(|request, _ctx| async move {
|
||||
let payload = serde_json::json!({
|
||||
"title": "loco",
|
||||
"content": "loco note test",
|
||||
});
|
||||
|
||||
let add_note_request = request.post("/api/notes").json(&payload).await;
|
||||
|
||||
with_settings!({
|
||||
filters => {
|
||||
let mut combined_filters = testing::CLEANUP_DATE.to_vec();
|
||||
combined_filters.extend(vec![(r#"\"id\\":\d+"#, r#""id\":ID"#)]);
|
||||
combined_filters
|
||||
}
|
||||
}, {
|
||||
assert_debug_snapshot!(
|
||||
(add_note_request.status_code(), add_note_request.text())
|
||||
);
|
||||
});
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn can_get_note() {
|
||||
configure_insta!();
|
||||
|
||||
testing::request::<App, _, _>(|request, ctx| async move {
|
||||
testing::seed::<App>(&ctx.db).await.unwrap();
|
||||
|
||||
let add_note_request = request.get("/api/notes/1").await;
|
||||
|
||||
with_settings!({
|
||||
filters => {
|
||||
let mut combined_filters = testing::CLEANUP_DATE.to_vec();
|
||||
combined_filters.extend(vec![(r#"\"id\\":\d+"#, r#""id\":ID"#)]);
|
||||
combined_filters
|
||||
}
|
||||
}, {
|
||||
assert_debug_snapshot!(
|
||||
(add_note_request.status_code(), add_note_request.text())
|
||||
);
|
||||
});
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn can_delete_note() {
|
||||
configure_insta!();
|
||||
|
||||
testing::request::<App, _, _>(|request, ctx| async move {
|
||||
testing::seed::<App>(&ctx.db).await.unwrap();
|
||||
|
||||
let count_before_delete = Entity::find().all(&ctx.db).await.unwrap().len();
|
||||
let delete_note_request = request.delete("/api/notes/1").await;
|
||||
|
||||
with_settings!({
|
||||
filters => {
|
||||
let mut combined_filters = testing::CLEANUP_DATE.to_vec();
|
||||
combined_filters.extend(vec![(r#"\"id\\":\d+"#, r#""id\":ID"#)]);
|
||||
combined_filters
|
||||
}
|
||||
}, {
|
||||
assert_debug_snapshot!(
|
||||
(delete_note_request.status_code(), delete_note_request.text())
|
||||
);
|
||||
});
|
||||
|
||||
let count_after_delete = Entity::find().all(&ctx.db).await.unwrap().len();
|
||||
assert_eq!(count_after_delete, count_before_delete - 1);
|
||||
})
|
||||
.await;
|
||||
}
|
|
@ -2,8 +2,9 @@ use axum::http::{HeaderName, HeaderValue};
|
|||
use loco_rs::{app::AppContext, TestServer};
|
||||
use nixin_farm_ssr::{models::users, views::auth::LoginResponse};
|
||||
|
||||
const USER_EMAIL: &str = "test@loco.com";
|
||||
const USER_PASSWORD: &str = "1234";
|
||||
const USER_NAME: &str = "test";
|
||||
const USER_EMAIL: &str = "test@nixin.local";
|
||||
const USER_PASSWORD: &str = "Test";
|
||||
|
||||
pub struct LoggedInUser {
|
||||
pub user: users::Model,
|
||||
|
@ -12,7 +13,7 @@ pub struct LoggedInUser {
|
|||
|
||||
pub async fn init_user_login(request: &TestServer, ctx: &AppContext) -> LoggedInUser {
|
||||
let register_payload = serde_json::json!({
|
||||
"name": "loco",
|
||||
"name": USER_NAME,
|
||||
"email": USER_EMAIL,
|
||||
"password": USER_PASSWORD
|
||||
});
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
---
|
||||
source: tests/requests/notes.rs
|
||||
expression: "(add_note_request.status_code(), add_note_request.text())"
|
||||
---
|
||||
(
|
||||
200,
|
||||
"{\"created_at\":\"DATEZ\",\"updated_at\":\"DATEZ\",\"id\":ID,\"title\":\"loco\",\"content\":\"loco note test\"}",
|
||||
)
|
|
@ -1,8 +0,0 @@
|
|||
---
|
||||
source: tests/requests/notes.rs
|
||||
expression: "(delete_note_request.status_code(), delete_note_request.text())"
|
||||
---
|
||||
(
|
||||
200,
|
||||
"",
|
||||
)
|
|
@ -1,8 +0,0 @@
|
|||
---
|
||||
source: tests/requests/notes.rs
|
||||
expression: "(add_note_request.status_code(), add_note_request.text())"
|
||||
---
|
||||
(
|
||||
200,
|
||||
"{\"created_at\":\"DATEZ\",\"updated_at\":\"DATEZ\",\"id\":ID,\"title\":\"Loco note 1\",\"content\":\"Loco note 1 content\"}",
|
||||
)
|
|
@ -1,8 +0,0 @@
|
|||
---
|
||||
source: tests/requests/notes.rs
|
||||
expression: "(notes.status_code(), notes.text())"
|
||||
---
|
||||
(
|
||||
200,
|
||||
"[{\"created_at\":\"DATEZ\",\"updated_at\":\"DATEZ\",\"id\":ID,\"title\":\"Loco note 1\",\"content\":\"Loco note 1 content\"},{\"created_at\":\"DATEZ\",\"updated_at\":\"DATEZ\",\"id\":ID,\"title\":\"Loco note 2\",\"content\":\"Loco note 2 content\"}]",
|
||||
)
|
Loading…
Reference in a new issue