Skip to content

Commit

Permalink
add post_media with database impl
Browse files Browse the repository at this point in the history
  • Loading branch information
thebino committed Oct 10, 2023
1 parent 61ccdd8 commit 3d839d3
Show file tree
Hide file tree
Showing 35 changed files with 1,222 additions and 144 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions crates/accounts/src/api/routes/get_user_id_profile.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/* Photos.network · A privacy first photo storage and sharing service for fediverse.
* Copyright (C) 2020 Photos network developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use axum::http::StatusCode;

pub(crate) async fn get_user_id_profile() -> std::result::Result<String, StatusCode> {
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/config/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

//! This defines the app configuration
use std::{fmt, fs, path::PathBuf};
use std::{fmt, fs};

use serde::Deserialize;
use tracing::info;
Expand Down
45 changes: 45 additions & 0 deletions crates/common/src/database/details.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Photos.network · A privacy first photo storage and sharing service for fediverse.
* Copyright (C) 2020 Photos network developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use uuid::Uuid;

pub struct Details {
pub uuid: &'static Uuid,
pub camera_manufacturer: &'static str,
pub camera_model: &'static str,
pub camera_serial: &'static str,
pub lens_model: &'static str,
pub lens_serial: &'static str,
pub orientation: &'static str,
pub compression: &'static str,
pub resolution_x: &'static str,
pub resolution_y: &'static str,
pub resolution_unit: &'static str,
pub exposure_time: &'static str,
pub exposure_mode: &'static str,
pub exposure_program: &'static str,
pub exposure_bias: &'static str,
pub aperture: &'static f32,
pub iso: &'static i32,
pub color_space: &'static str,
pub pixel_x: &'static i64,
pub pixel_y: &'static i64,
pub user_comment: &'static str,
pub white_balance: &'static str,
pub flash: bool,
pub exif_version: &'static f32,
}
25 changes: 25 additions & 0 deletions crates/common/src/database/location.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Photos.network · A privacy first photo storage and sharing service for fediverse.
* Copyright (C) 2020 Photos network developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use uuid::Uuid;

pub struct Location {
pub uuid: &'static Uuid,
pub latitude: &'static f64,
pub longitude: &'static f64,
pub altitude: &'static Option<f64>,
}
31 changes: 31 additions & 0 deletions crates/common/src/database/media_item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Photos.network · A privacy first photo storage and sharing service for fediverse.
* Copyright (C) 2020 Photos network developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use std::time::Instant;

use super::{details::Details, location::Location, reference::Reference, tag::Tag};

pub struct MediaItem {
pub uuid: &'static str,
pub name: &'static str,
pub added_at: Instant,
pub taken_at: Option<Instant>,
pub details: Option<Details>,
pub tags: Option<Vec<Tag>>,
pub location: Option<Location>,
pub references: Option<Vec<Reference>>,
}
75 changes: 74 additions & 1 deletion crates/common/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,85 @@
/* Photos.network · A privacy first photo storage and sharing service for fediverse.
* Copyright (C) 2020 Photos network developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use async_trait::async_trait;
use std::error::Error;
use time::OffsetDateTime;

use crate::auth::user::User;

use self::{media_item::MediaItem, reference::Reference};

pub mod details;
pub mod location;
pub mod media_item;
pub mod reference;
pub mod tag;

#[async_trait]
pub trait Database {
/// Initialize the database and run required migrations
async fn setup(&mut self) -> Result<(), Box<dyn Error>>;

/// List registered user accounts
async fn get_users(&self) -> Result<Vec<User>, Box<dyn Error>>;

/// Create a new user account
async fn create_user(&self, user: &User) -> Result<(), Box<dyn Error>>;

/// Get user by user_id
async fn get_user(&self, user_id: &str) -> Result<User, Box<dyn Error>>;

/// Partial update a single user account
async fn update_email(&self, email: &str, user_id: &str) -> Result<(), Box<dyn Error>>;
async fn get_users(&self) -> Result<Vec<User>, Box<dyn Error>>;
async fn update_nickname(&self, nickname: &str) -> Result<(), Box<dyn Error>>;
async fn update_names(
&self,
firstname: &str,
lastname: &str,
user_id: &str,
) -> Result<(), Box<dyn Error>>;

async fn disable_user(&self, user_id: &str) -> Result<(), Box<dyn Error>>;
async fn enable_user(&self, user_id: &str) -> Result<(), Box<dyn Error>>;

async fn get_media_items(&self, user_id: &str) -> Result<Vec<MediaItem>, Box<dyn Error>>;
async fn create_media_item(
&self,
user_id: &str,
name: &str,
date_taken: OffsetDateTime,
) -> Result<String, Box<dyn Error>>;
async fn get_media_item(&self, media_id: &str) -> Result<MediaItem, Box<dyn Error>>;
async fn add_reference(
&self,
user_id: &str,
media_id: &str,
reference: &Reference,
) -> Result<String, Box<dyn Error>>;

async fn update_reference(
&self,
reference_id: &str,
reference: &Reference,
) -> Result<(), Box<dyn Error>>;

async fn remove_reference(
&self,
media_id: &str,
reference_id: &str,
) -> Result<(), Box<dyn Error>>;
}
28 changes: 28 additions & 0 deletions crates/common/src/database/reference.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Photos.network · A privacy first photo storage and sharing service for fediverse.
* Copyright (C) 2020 Photos network developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use time::OffsetDateTime;

pub struct Reference {
pub uuid: &'static str,
pub filepath: String,
pub filename: String,
pub size: u64,
pub description: &'static str,
pub last_modified: OffsetDateTime,
pub is_missing: bool,
}
24 changes: 24 additions & 0 deletions crates/common/src/database/tag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Photos.network · A privacy first photo storage and sharing service for fediverse.
* Copyright (C) 2020 Photos network developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use uuid::Uuid;

pub struct Tag {
pub uuid: &'static Uuid,
pub tag: &'static str,
pub origin: &'static str,
}
31 changes: 31 additions & 0 deletions crates/common/src/database/user.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Photos.network · A privacy first photo storage and sharing service for fediverse.
* Copyright (C) 2020 Photos network developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use std::time::Instant;

use super::{details::Details, location::Location, reference::Reference, tag::Tag};

pub struct MediaItem {
pub uuid: &'static str,
pub name: &'static str,
pub added_at: Instant,
pub taken_at: Option<Instant>,
pub details: Option<Details>,
pub tags: Option<Vec<Tag>>,
pub location: Option<Location>,
pub references: Option<Vec<Reference>>,
}
1 change: 1 addition & 0 deletions crates/database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ sqlx = { workspace = true, features = ["runtime-tokio", "tls-native-tls", "postg

[dev-dependencies]
testdir.workspace = true
time.workspace = true
45 changes: 0 additions & 45 deletions crates/database/data/init.sql

This file was deleted.

Loading

0 comments on commit 3d839d3

Please sign in to comment.