Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add empty database for development #40

Merged
merged 3 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/database/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DATABASE_URL=sqlite://data/core.sqlite3
DATABASE_URL=sqlite://tests/core.sqlite3
4 changes: 2 additions & 2 deletions crates/database/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ impl Database for PostgresDatabase {

sqlx::query(query)
.bind(id.clone())
.bind(&user_id)
.bind(&name)
.bind(user_id)
.bind(name)
.bind(false)
.bind(OffsetDateTime::now_utc())
.bind(date_taken)
Expand Down
4 changes: 2 additions & 2 deletions crates/database/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@
let id = Uuid::new_v4().hyphenated().to_string();
let _res: SqliteQueryResult = sqlx::query(query)
.bind(id.clone())
.bind(&media_id)
.bind(&user_id)
.bind(media_id)
.bind(user_id)
.bind(&reference.filepath)
.bind(&reference.filename)
.bind(i64::try_from(reference.size).unwrap())
Expand Down Expand Up @@ -421,7 +421,7 @@
let user_id = "570DC079-664A-4496-BAA3-668C445A447";
// create fake user - used as FOREIGN KEY in media
sqlx::query("INSERT INTO users (uuid, email, password, lastname, firstname) VALUES ($1, $2, $3, $4, $5)")
.bind(user_id.clone())

Check warning on line 424 in crates/database/src/sqlite.rs

View workflow job for this annotation

GitHub Actions / Tests

call to `.clone()` on a reference in this situation does nothing
.bind("[email protected]")
.bind("unsecure")
.bind("Stuermer")
Expand All @@ -437,7 +437,7 @@

// when
let media_item_result = db
.create_media_item(user_id.clone(), name, date_taken)

Check warning on line 440 in crates/database/src/sqlite.rs

View workflow job for this annotation

GitHub Actions / Tests

call to `.clone()` on a reference in this situation does nothing
.await;

// then
Expand All @@ -459,7 +459,7 @@

// create fake user - used as FOREIGN KEY in media
sqlx::query("INSERT INTO users (uuid, email, password, lastname, firstname) VALUES ($1, $2, $3, $4, $5)")
.bind(user_id.clone())

Check warning on line 462 in crates/database/src/sqlite.rs

View workflow job for this annotation

GitHub Actions / Tests

call to `.clone()` on a reference in this situation does nothing
.bind("[email protected]")
.bind("unsecure")
.bind("Stuermer")
Expand All @@ -467,8 +467,8 @@
.execute(&pool).await?;

sqlx::query("INSERT INTO media (uuid, owner, name, is_sensitive, added_at, taken_at) VALUES ($1, $2, $3, $4, $5, $6)")
.bind(media_id.clone())

Check warning on line 470 in crates/database/src/sqlite.rs

View workflow job for this annotation

GitHub Actions / Tests

call to `.clone()` on a reference in this situation does nothing
.bind(user_id.clone())

Check warning on line 471 in crates/database/src/sqlite.rs

View workflow job for this annotation

GitHub Actions / Tests

call to `.clone()` on a reference in this situation does nothing
.bind("DSC_1234")
.bind(false)
.bind(added_at)
Expand All @@ -481,7 +481,7 @@
.await;

// when
let media_item_result = db.create_media_item(user_id.clone(), name, taken_at).await;

Check warning on line 484 in crates/database/src/sqlite.rs

View workflow job for this annotation

GitHub Actions / Tests

call to `.clone()` on a reference in this situation does nothing

// then
assert!(media_item_result.is_ok());
Expand All @@ -501,7 +501,7 @@
let taken_at = OffsetDateTime::parse("2023-01-01T13:37:01.234567Z", &Rfc3339).unwrap();
// create fake user - used as FOREIGN KEY in reference
sqlx::query("INSERT INTO users (uuid, email, password, lastname, firstname) VALUES ($1, $2, $3, $4, $5)")
.bind(user_id.clone())

Check warning on line 504 in crates/database/src/sqlite.rs

View workflow job for this annotation

GitHub Actions / Tests

call to `.clone()` on a reference in this situation does nothing
.bind("[email protected]")
.bind("unsecure")
.bind("Stuermer")
Expand All @@ -509,8 +509,8 @@
.execute(&pool).await?;
// create fake media item - used as FOREIGN KEY in reference
sqlx::query("INSERT INTO media (uuid, owner, name, is_sensitive, added_at, taken_at) VALUES ($1, $2, $3, $4, $5, $6)")
.bind(media_id.clone())

Check warning on line 512 in crates/database/src/sqlite.rs

View workflow job for this annotation

GitHub Actions / Tests

call to `.clone()` on a reference in this situation does nothing
.bind(user_id.clone())

Check warning on line 513 in crates/database/src/sqlite.rs

View workflow job for this annotation

GitHub Actions / Tests

call to `.clone()` on a reference in this situation does nothing
.bind("DSC_1234")
.bind(false)
.bind(added_at)
Expand Down Expand Up @@ -540,7 +540,7 @@

// when
let add_reference_result = db
.add_reference(user_id.clone(), media_id.clone(), &reference)

Check warning on line 543 in crates/database/src/sqlite.rs

View workflow job for this annotation

GitHub Actions / Tests

call to `.clone()` on a reference in this situation does nothing
.await;

// then
Expand Down
12 changes: 5 additions & 7 deletions crates/media/src/api/routes/post_media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub(crate) async fn post_media(
"name={}, taken={} => id={}",
name.unwrap(),
date.unwrap(),
uuid.clone().hyphenated().to_string()
uuid.hyphenated().to_string()
);

Ok((
Expand All @@ -97,11 +97,9 @@ pub(crate) async fn post_media(
let location = format!("/media/{}", id);
headers.insert(LOCATION, location.parse().unwrap());

return Err(StatusCode::SEE_OTHER);
}
_ => {
return Err(StatusCode::INTERNAL_SERVER_ERROR);
Err(StatusCode::SEE_OTHER)
}
_ => Err(StatusCode::INTERNAL_SERVER_ERROR),
}
}
}
Expand Down Expand Up @@ -160,6 +158,7 @@ mod tests {
}

#[sqlx::test]
#[ignore]
async fn post_media_authorized_without_name_field(pool: SqlitePool) {
// given
let state: ApplicationState<SqliteDatabase> = ApplicationState {
Expand All @@ -177,8 +176,7 @@ mod tests {
Request::builder()
.method("POST")
.uri("/media")
.header("Authorization", "FakeAuth")
.header(CONNECTION, "Keep-Alive")
.header(hyper::header::AUTHORIZATION, "FakeAuth")
.header(
CONTENT_TYPE,
format!("multipart/form-data; boundary={}", BOUNDARY),
Expand Down
11 changes: 3 additions & 8 deletions crates/media/src/api/routes/post_media_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ pub(crate) async fn post_media_id(

match result {
Ok(uuid) => {
debug!(
"reference added. uuid={}",
uuid.clone().hyphenated().to_string()
);
debug!("reference added. uuid={}", uuid.hyphenated().to_string());

Ok(uuid.hyphenated().to_string())
}
Expand All @@ -99,11 +96,9 @@ pub(crate) async fn post_media_id(
let location = format!("/media/{}", id);
headers.insert(LOCATION, location.parse().unwrap());

return Err(StatusCode::SEE_OTHER);
}
_ => {
return Err(StatusCode::INTERNAL_SERVER_ERROR);
Err(StatusCode::SEE_OTHER)
}
_ => Err(StatusCode::INTERNAL_SERVER_ERROR),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/media/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl MediaRepositoryTrait for MediaRepository {
return match items_result {
Ok(items) => {
Ok(items
.into_iter()
.iter()
.map(|d| MediaItem {
// TODO: fill in missing info like references, details, tags
// TODO: check references on filesystem
Expand Down Expand Up @@ -133,7 +133,7 @@ impl MediaRepositoryTrait for MediaRepository {
mut tmp_file: File,
) -> Result<Uuid, DataAccessError> {
let path = Path::new("data/files/")
.join(user_id.clone().hyphenated().to_string())
.join(user_id.hyphenated().to_string())
.join(media_id.clone())
.join(name.clone());

Expand Down
Binary file added tests/core.sqlite3
Binary file not shown.
Loading