Skip to content

Commit

Permalink
rename media endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
thebino committed Jul 18, 2023
1 parent 212fcaa commit da3ec35
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 39 deletions.
1 change: 1 addition & 0 deletions crates/accounts/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl AccountsApi {
// 401 Unauthorized - Requesting user is unauthenticated
// 404 Not Found - The requested resource does not exist.
.route("/users/:user_id/profile", get(list_photos_handler))

// Update a single account when `admin.users:write` scope is present
// 200 - OK
// 400 Bad Request - The request body was malformed or a field violated its constraints.
Expand Down
8 changes: 8 additions & 0 deletions crates/media/src/api/handler/create_media_item_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Returns a list of media items owned or shared with the user
//!

use axum::http::StatusCode;

pub(crate) async fn create_media_item_handler() -> std::result::Result<String, StatusCode> {
Err(StatusCode::NOT_IMPLEMENTED)
}
8 changes: 8 additions & 0 deletions crates/media/src/api/handler/list_media_items_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Returns a list of media items owned or shared with the user
//!

use axum::http::StatusCode;

pub(crate) async fn list_media_items_handler() -> std::result::Result<String, StatusCode> {
Err(StatusCode::NOT_IMPLEMENTED)
}
7 changes: 0 additions & 7 deletions crates/media/src/api/handler/list_photos_handler.rs

This file was deleted.

40 changes: 32 additions & 8 deletions crates/media/src/api/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use crate::api::handler::list_media_items_handler::list_media_items_handler;
use crate::api::handler::create_media_item_handler::create_media_item_handler;
use crate::api::handler::file_handler::file_handler;
use axum::routing::{get, patch, post};
use axum::routing::{get, patch, post, delete};
use axum::Router;

pub struct MediaApi {}
Expand All @@ -27,14 +29,35 @@ impl MediaApi {
S: Send + Sync + 'static + Clone,
{
Router::new()
// list owned and shared items
.route("/photos", get(file_handler))
// Returns a list of owned and shared photos for current user
// 200 Ok
// 401 Unauthorized - Requesting user is unauthenticated
// 403 Forbidden
// 500 Internal Server Error
.route("/media", get(list_media_items_handler))

// Creates one or multiple items
// 201 - Created
// 400 Bad Request - The request body was malformed or a field violated its constraints.
// 401 Unauthorized - You are unauthenticated
// 403 Forbidden - You are authenticated but have no permission to manage the target user.
// 500 Internal Server Error
.route("/media", post(create_media_item_handler))

// get metadata of a specific item
.route("/photos/:entity_id", get(file_handler))
// update the given media item owned by the user
.route("/photos/:entity_id", patch(file_handler))
// creates one or multiple media items
.route("/photos", post(file_handler))
// 200 - Ok
// 400 Bad Request - The request body was malformed or a field violated its constraints.
// 401 Unauthorized - You are unauthenticated
// 403 Forbidden - You are authenticated but have no permission to manage the target user.
// 500 Internal Server Error
.route("/media/:media_id", get(file_handler))

// update the given item owned by the user
.route("/media/:media_id", patch(file_handler))

// delete the given item owned by the user
.route("/media/:media_id", delete(file_handler))

// list owned and shared albums
.route("/albums", get(file_handler))
// create new album
Expand All @@ -47,6 +70,7 @@ impl MediaApi {
.route("/albums/:entity_id/share", patch(file_handler))
// unshares the given album
.route("/albums/:entity_id/unshare", patch(file_handler))

.layer(tower_http::trace::TraceLayer::new_for_http())
}
}
26 changes: 26 additions & 0 deletions crates/media/src/data/file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* 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;

pub struct File {
pub uuid: &'static str,
pub filename: &'static str,
pub filesize: f64,
pub last_modified: Option<Instant>,
pub is_missing: bool,
}
21 changes: 21 additions & 0 deletions crates/media/src/data/location.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* 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/>.
*/

pub struct Location {
pub latitude: f64,
pub longitude: f64
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,30 @@

use std::time::Instant;

#[derive(Default, Serialize)]
#[cfg_attr(test, derive(Deserialize, Eq, PartialEq, Debug, Copy, Clone, Default))]
pub struct Photo {
use serde::Serialize;
use serde::Deserialize;


#[derive(Serialize, Deserialize)]

Check failure on line 24 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Test Suite

the trait bound `Instant: Serialize` is not satisfied

Check failure on line 24 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Check

the trait bound `Instant: Serialize` is not satisfied
pub struct MediaItem {
pub uuid: &'static str,
pub path: &'static str,
pub filename: &'static str,
pub name: &'static str,
pub date_added: Instant,

Check failure on line 28 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Test Suite

the trait bound `Instant: Deserialize<'_>` is not satisfied

Check failure on line 28 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Test Suite

the trait bound `Instant: Deserialize<'_>` is not satisfied

Check failure on line 28 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Check

the trait bound `Instant: Deserialize<'_>` is not satisfied

Check failure on line 28 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Check

the trait bound `Instant: Deserialize<'_>` is not satisfied
pub date_taken: Option<Instant>,

Check failure on line 29 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Test Suite

the trait bound `Instant: Deserialize<'_>` is not satisfied

Check failure on line 29 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Test Suite

the trait bound `Instant: Deserialize<'_>` is not satisfied

Check failure on line 29 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Check

the trait bound `Instant: Deserialize<'_>` is not satisfied

Check failure on line 29 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Check

the trait bound `Instant: Deserialize<'_>` is not satisfied
pub date_modified: Option<Instant>,
pub file_is_missing: bool,
pub owner: &'static str,
pub details: Option<ExifInformation>,

Check failure on line 30 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Test Suite

cannot find type `ExifInformation` in this scope

Check failure on line 30 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Test Suite

cannot find type `ExifInformation` in this scope

Check failure on line 30 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find type `ExifInformation` in this scope

Check failure on line 30 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find type `ExifInformation` in this scope
pub tags: Option<Vec<String>>,
pub location: Option<Location>,

Check failure on line 32 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Test Suite

cannot find type `Location` in this scope

Check failure on line 32 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find type `Location` in this scope
pub references: Option<Vec<File>>

Check failure on line 33 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Test Suite

cannot find type `File` in this scope

Check failure on line 33 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find type `File` in this scope
}

impl Photo {
fn new() -> Self {
Photo {
file_is_missing: true
impl MediaItem {
fn new(name: &'static str) -> Self {
MediaItem {
uuid: ,

Check failure on line 39 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Lints

expected expression, found `,`

Check failure on line 39 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Test Suite

expected expression, found `,`

Check failure on line 39 in crates/media/src/data/media_item.rs

View workflow job for this annotation

GitHub Actions / Check

expected expression, found `,`
name: name,
date_added: Instant::now(),

}
}
}

5 changes: 4 additions & 1 deletion crates/media/src/data/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pub mod DataAccessError;
pub mod error;
pub mod file;
pub mod location;
pub mod media_item;
6 changes: 3 additions & 3 deletions crates/media/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

pub mod data {
pub mod error;
}
pub mod data;

pub mod api {
pub mod handler {
pub mod file_handler;
pub mod list_media_items_handler;
pub mod create_media_item_handler;
}
pub mod router;
}
14 changes: 7 additions & 7 deletions crates/media/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
/// MockPhotosRepositoryTrait is created by automock macro
#[cfg_attr(test, automock)]
#[async_trait]
trait PhotosRepositoryTrait {
/// Gets a list of heroes from the DB filted by name
async fn get_photos_for_user(&self, user_id: &str) -> Result<Vec<Photo>, DataAccessError>;
trait MediaRepositoryTrait {
/// Gets a list of media items from the DB filted by user_id
async fn get_media_items_for_user(&self, user_id: &str) -> Result<Vec<MediaItem>, DataAccessError>;
}

struct PhotosRepository();
struct MediaRepository();

#[async_trait]
impl PhotosRepositoryTrait for PhotosRepository {
async fn get_photos_for_user(&self, user_id: &str) -> Result<Vec<Photo>, DataAccessError> {
impl MediaRepositoryTrait for MediaRepository {
async fn get_media_items_for_user(&self, user_id: &str) -> Result<Vec<MediaItem>, DataAccessError> {
}
}

Expand All @@ -36,5 +36,5 @@ impl PhotosRepositoryTrait for PhotosRepository {
mod tests {
use super::*;

async fn get_photos_for_user_success(#[case] uri: &'static str, #[case] expected_filter: &'static str);
async fn get_media_items_for_user_success(#[case] uri: &'static str, #[case] expected_filter: &'static str);
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub async fn start_server() -> Result<()> {

// authorization server
.nest("/", AuthorizationServerManager::routes(server))
.nest("/api", MediaApi::routes())
.nest("/", MediaApi::routes())
// oauth 2
// .nest("/oauth", api::authentication::AutenticationManager::routes())
.layer(TraceLayer::new_for_http())
Expand Down

0 comments on commit da3ec35

Please sign in to comment.