Compare commits

...
19 Commits
Author SHA1 Message Date
phoenix f48c7ee99c tsk-271: One down
pr CI / Test Suite (pull_request) Successful in 2m2s
2026-11-20 16:38:54 -05:00
phoenix 64c6a7f6b5 tsk-271: Warning fix 2026-11-20 16:31:08 -05:00
phoenix 4fdcd80db2 tsk-271: Warning fix
pr CI / Test Suite (pull_request) Successful in 2m0s
2026-11-20 16:29:31 -05:00
phoenix d249c34fb4 tsk-271: Test refactor 2026-11-20 16:29:10 -05:00
phoenix 58682af84a tsk-271: Adding test to create playback queue
pr CI / Test Suite (pull_request) Successful in 2m2s
2026-11-20 16:25:00 -05:00
phoenix 6ca17357dc tsk-271: Making migration available in test
pr CI / Test Suite (pull_request) Successful in 2m1s
2026-11-20 16:04:52 -05:00
phoenix b668dc4abb tsk-271: Code formatting
pr CI / Test Suite (pull_request) Successful in 2m9s
2026-11-20 15:53:19 -05:00
phoenix d2b9567c15 tsk-271: Migration syntax fix 2026-11-20 15:53:12 -05:00
phoenix 8a0e88c215 tsk-271: Got it to build 2026-11-20 15:41:18 -05:00
phoenix ed82e59a26 tsk-271: More code 2026-11-20 15:21:32 -05:00
phoenix 4ee0ba59fd tsk-271: Adding more code
pr CI / Test Suite (pull_request) Failing after 1m16s
2026-11-20 15:08:43 -05:00
phoenix 4403f3c7d2 tsk-271: Updated migration 2026-11-20 14:36:53 -05:00
phoenix 980d2557a2 tsk-271: Fixed syntax issue
pr CI / Test Suite (pull_request) Successful in 2m6s
2026-11-20 14:17:26 -05:00
phoenix 864447aa16 tsk-271: Added TODO to migrations. Will eventually remove them
pr CI / Test Suite (pull_request) Failing after 1m23s
2026-11-20 14:09:04 -05:00
phoenix 9b51442841 tsk-271: Added migrations for playbackQueue 2026-11-20 14:08:39 -05:00
phoenix bad9efb026 Update rust (#270)
soaricarus_api CI / Rustfmt (push) Successful in 2m52s
soaricarus_api CI / Check (push) Successful in 6m25s
soaricarus_api CI / Clippy (push) Successful in 7m23s
soaricarus_api CI / build (push) Successful in 8m56s
soaricarus_api CI / Test Suite (push) Successful in 9m1s
pr CI / Test Suite (pull_request) Successful in 2m10s
Reviewed-on: #270
2026-11-19 17:43:14 -05:00
phoenix 23529e323a tsk-268: Extend get cover art (#269)
soaricarus_api CI / Check (push) Successful in 4m59s
soaricarus_api CI / Rustfmt (push) Successful in 2m26s
soaricarus_api CI / Clippy (push) Successful in 4m18s
soaricarus_api CI / build (push) Successful in 5m1s
soaricarus_api CI / Test Suite (push) Failing after 2m26s
pr CI / Test Suite (pull_request) Failing after 2m45s
Closes #268

Reviewed-on: http://git.kundeng.us/phoenix/soaricarus_api/pulls/269
2026-11-07 13:35:52 -05:00
phoenix 728948ebe4 docker: logledger_api (#267)
soaricarus_api CI / Check (push) Successful in 10m2s
soaricarus_api CI / Rustfmt (push) Successful in 9m48s
soaricarus_api CI / Clippy (push) Successful in 10m9s
soaricarus_api CI / build (push) Successful in 10m53s
soaricarus_api CI / Test Suite (push) Failing after 1m26s
pr CI / Test Suite (pull_request) Failing after 1m26s
Reviewed-on: http://git.kundeng.us/phoenix/soaricarus_api/pulls/267
2026-11-06 15:34:32 -05:00
phoenix 4f9a51fcf0 Update soaricarus dependencies (#266)
soaricarus_api CI / Rustfmt (push) Successful in 2m30s
soaricarus_api CI / Check (push) Successful in 4m28s
soaricarus_api CI / Clippy (push) Successful in 4m30s
soaricarus_api CI / Test Suite (push) Successful in 6m12s
soaricarus_api CI / build (push) Successful in 7m14s
Reviewed-on: http://git.kundeng.us/phoenix/soaricarus_api/pulls/266
2026-11-05 16:23:06 -05:00
18 changed files with 830 additions and 532 deletions

No files matched your search

+3 -3
View File
@@ -12,7 +12,7 @@ concurrency:
jobs:
test:
name: Test Suite
runs-on: ubuntu-24.04
runs-on: ubuntu-26.04
timeout-minutes: 20
services:
postgres:
@@ -31,7 +31,7 @@ jobs:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.99
toolchain: 1.99.1
- uses: Swatinem/rust-cache@v2
- name: Verify Docker Environment
run: |
@@ -49,7 +49,7 @@ jobs:
env:
AWS_ACCESS_KEY_ID: "${{ secrets.GARAGE_KEY_ID }}"
AWS_SECRET_ACCESS_KEY: "${{ secrets.GARAGE_SECRET }}"
AWS_DEFAULT_REGION: us-east-1
AWS_DEFAULT_REGION: "${{ secrets.GARAGE_REGION }}"
ENDPOINT_URL: "${{ secrets.S3_CI_ENDPOINT_URL}}"
run: |
sudo apt update
+2 -2
View File
@@ -6,7 +6,7 @@ on:
jobs:
release:
runs-on: ubuntu-24.04
runs-on: ubuntu-26.04
steps:
- name: Checkout code
uses: actions/checkout@v6
@@ -16,7 +16,7 @@ jobs:
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.99
toolchain: 1.99.1
components: cargo
- name: Extract Version from Cargo.toml
+10 -10
View File
@@ -12,12 +12,12 @@ concurrency:
jobs:
check:
name: Check
runs-on: ubuntu-24.04
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.99
toolchain: 1.99.1
- uses: Swatinem/rust-cache@v2
- run: |
mkdir -p ~/.ssh
@@ -32,7 +32,7 @@ jobs:
test:
name: Test Suite
runs-on: ubuntu-24.04
runs-on: ubuntu-26.04
timeout-minutes: 20
services:
postgres:
@@ -51,7 +51,7 @@ jobs:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.99
toolchain: 1.99.1
- uses: Swatinem/rust-cache@v2
- name: Verify Docker Environment
run: |
@@ -137,12 +137,12 @@ jobs:
fmt:
name: Rustfmt
runs-on: ubuntu-24.04
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.99
toolchain: 1.99.1
- uses: Swatinem/rust-cache@v2
- run: rustup component add rustfmt
- run: |
@@ -157,12 +157,12 @@ jobs:
clippy:
name: Clippy
runs-on: ubuntu-24.04
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.99
toolchain: 1.99.1
- uses: Swatinem/rust-cache@v2
- run: rustup component add clippy
- run: |
@@ -177,12 +177,12 @@ jobs:
build:
name: build
runs-on: ubuntu-24.04
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.99
toolchain: 1.99.1
- uses: Swatinem/rust-cache@v2
- run: |
mkdir -p ~/.ssh
Generated
+294 -470
View File
File diff suppressed because it is too large. Load diff
+10 -10
View File
@@ -1,15 +1,15 @@
[package]
name = "soaricarus_api"
version = "0.5.11"
version = "0.5.13"
edition = "2024"
rust-version = "1.95"
rust-version = "1.99.1"
license = "MIT"
description = "Core API for interacting with soaricarus"
[dependencies]
axum = { version = "0.8.9", features = ["multipart"] }
axum-extra = { version = "0.12.6", features = ["cookie"] }
openssl = { version = "0.10.81", features = ["vendored"] }
openssl = { version = "0.10.82", features = ["vendored"] }
serde = { version = "1.0.229", features = ["derive"] }
serde_json = { version = "1.0.154" }
tokio = { version = "1.54.1", features = ["full"] }
@@ -19,17 +19,17 @@ tower-http = { version = "0.7.1", features = ["cors", "timeout"] }
tracing-subscriber = "0.3.23"
futures = { version = "0.3.34" }
mime_guess = { version = "2.0.5" }
uuid = { version = "1.29.0", features = ["v4", "serde"] }
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] }
uuid = { version = "1.29.3", features = ["v4", "serde"] }
sqlx = { version = "0.9.1", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] }
time = { version = "0.3.55", features = ["formatting", "macros", "parsing", "serde"] }
jsonwebtoken = { version = "11.0.0", features = ["rust_crypto"] }
jsonwebtoken = { version = "12.0.0", features = ["rust_crypto"] }
josekit = { version = "0.10.3" }
utoipa = { version = "6.0.0", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "10.0.2", features = ["axum"] }
simeta = { git = "ssh://git@git.kundeng.us/phoenix/simeta.git", tag = "v0.6.3" }
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.7" }
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.2" }
labyrinth = { git = "ssh://git@git.kundeng.us/phoenix/labyrinth.git", tag = "v0.0.6" }
simeta = { git = "ssh://git@git.kundeng.us/phoenix/simeta.git", tag = "v0.6.5" }
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.20" }
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.4" }
labyrinth = { git = "ssh://git@git.kundeng.us/phoenix/labyrinth.git", tag = "v0.0.10" }
[dev-dependencies]
+6 -1
View File
@@ -19,6 +19,11 @@ Copy the `.env.docker.sample` file to `.env`. Ensure that the `ROOT_DIRECTORY` v
and exists on the docker image's filesystem. The credentials for the database doesn't need to be
changed for development, but if deploying it, it should be modified.
### Authentication setup
Make sure the `SECRET_MAIN_KEY` variable in the `.env` file is at least **24** characters long
and it should match the same value as the `SECRET_KEY` variable from `soaricarus_auth`.
### S3 Setup
Using the copied `.env.docker.sample`, ensure that the following has been properly populated.
```
@@ -41,7 +46,7 @@ docker compose build --ssh default
Bring it up
```
docker compose up -d --force-recreate
docker compose up
```
To view the OpenAPI spec, run the project and access `/swagger-ui`. If running through docker,
+49
View File
@@ -18,6 +18,8 @@ services:
condition: service_started
auth_api:
condition: service_started
logledger_api:
condition: service_started
networks:
- soaricarus-network
restart: unless-stopped
@@ -43,6 +45,25 @@ services:
# volumes:
# - ./path/to/your/web-api-repo:/app
logledger_api:
build:
context: ../logledger_api
ssh: ["default"]
dockerfile: Dockerfile
container_name: logledger_api
ports:
- "8200:8200"
env_file:
- ../logledger_api/.env
depends_on:
logledger_db:
condition: service_healthy
volumes:
- logledger_data:/shared:ro # Mount as read-only
networks:
- soaricarus-network
restart: unless-stopped
# --- songparser service ---
songparser:
build:
@@ -178,15 +199,43 @@ services:
networks:
- soaricarus-network
logledger_db:
image: postgres:18.6-alpine
container_name: logledger_db
environment:
POSTGRES_USER: ${POSTGRES_LOG_USER:-logledger}
POSTGRES_PASSWORD: ${POSTGRES_LOG_PASSWORD:-password}
POSTGRES_DB: ${POSTGRES_LOG_DB:-logledger_db}
volumes:
# Persist database data using a named volume
- postgres_data_logledger:/var/lib/postgresql
ports:
- "5434:5432"
healthcheck:
# Checks if Postgres is ready to accept connections
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
restart: always
networks:
- soaricarus-network
volumes:
postgres_data:
driver: local # Use the default local driver
postgres_data_auth:
driver: local # Use the default local driver
postgres_data_logledger:
driver: local
object_data:
driver: local # Use the default local driver
shared_credentials: # New shared volume
driver: local
logledger_data: # New shared volume
driver: local
networks:
soaricarus-network:
@@ -5,6 +5,8 @@ CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE IF NOT EXISTS "songQueue" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
filename TEXT NOT NULL,
-- TODO: Make it uppercase and check other areas of soaricarus to make
-- sure it is consistent
status TEXT CHECK (status IN ('pending', 'ready', 'processing', 'done')),
user_id UUID NULL
);
@@ -0,0 +1,16 @@
-- Add migration script here
CREATE TABLE IF NOT EXISTS "playbackQueue" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
device_type TEXT CHECK (device_type IN ('BROWSER', 'MOBILE')),
user_id UUID NOT NULL,
date_created timestamptz DEFAULT now()
);
CREATE TABLE IF NOT EXISTS "playbackQueueItem" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
queue_index INT NOT NULL,
song_id UUID NOT NULL,
playback_queue_id UUID NOT NULL,
date_created timestamptz DEFAULT now()
);
+1 -1
View File
@@ -42,7 +42,7 @@ pub async fn auth<B>(
validation.set_audience(&["soaricarus"]);
let _claims = decode::<simodels::token::UserClaims>(
&token,
&DecodingKey::from_secret(secret_key.as_ref()),
&DecodingKey::from_secret(secret_key.as_ref()).unwrap(),
&validation,
)
.map_err(|err| {
+23 -3
View File
@@ -11,6 +11,7 @@ pub mod request {
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct Params {
pub id: Option<uuid::Uuid>,
pub song_id: Option<uuid::Uuid>,
}
}
}
@@ -181,7 +182,8 @@ pub mod endpoint {
get,
path = super::super::endpoints::GETCOVERART,
params(
("id" = uuid::Uuid, Path, description = "Cover art Id")
("id" = uuid::Uuid, Path, description = "Cover art Id"),
("song_id" = uuid::Uuid, Path, description = "Song Id")
),
responses(
(status = 200, description = "Cover art retrieved", body = super::response::get_coverart::Response),
@@ -201,7 +203,7 @@ pub mod endpoint {
Some(id) => match repo::coverart::get_coverart(&pool, &id).await {
Ok(coverart) => {
response.data.push(coverart);
response.message = String::from(super::super::response::SUCCESSFUL);
response.message = super::super::response::SUCCESSFUL.to_string();
(axum::http::StatusCode::OK, axum::Json(response))
}
Err(err) => {
@@ -209,10 +211,28 @@ pub mod endpoint {
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
},
_ => match params.song_id {
Some(song_id) => {
match repo::coverart::get_coverart_with_song_id(&pool, &song_id).await {
Ok(coverart) => {
response.data.push(coverart);
response.message = super::super::response::SUCCESSFUL.to_string();
(axum::http::StatusCode::OK, axum::Json(response))
}
Err(err) => {
response.message = err.to_string();
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
}
}
}
None => {
response.message = String::from("Invalid parameters");
response.message = "Invalid parameters".to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
},
}
}
+4
View File
@@ -1,4 +1,5 @@
pub mod coverart;
pub mod playback;
pub mod queue;
pub mod song;
@@ -14,10 +15,13 @@ pub mod endpoints {
pub const CREATECOVERART: &str = "/api/v2/coverart";
pub const GETCOVERART: &str = "/api/v2/coverart";
pub const DOWNLOADCOVERART: &str = "/api/v2/coverart/download/{id}";
pub const CREATEPLAYBACKQUEUE: &str = "/api/v2/playback/queue";
}
pub mod response {
pub const SUCCESSFUL: &str = "SUCCESSFUL";
pub const INVALID: &str = "INVALID";
}
/// Basic handler that responds with a static string
+138
View File
@@ -0,0 +1,138 @@
pub mod queue {
const PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER: &str = "BROWSER";
const PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE: &str = "MOBILE";
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct PlaybackQueue {
pub id: uuid::Uuid,
pub name: String,
pub device_type: String,
pub user_id: uuid::Uuid,
#[serde(with = "time::serde::rfc3339::option")]
pub date_created: Option<time::OffsetDateTime>,
}
pub mod request {
pub mod create_playback_queue {
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
pub struct CreatePlaybackQueueRequest {
pub name: String,
pub device_type: String,
pub user_id: uuid::Uuid,
}
impl CreatePlaybackQueueRequest {
pub fn is_valid(&self) -> bool {
let pre_check =
!self.user_id.is_nil() && !self.name.is_empty() && !self.user_id.is_nil();
pre_check && self.valid_device_type()
}
fn valid_device_type(&self) -> bool {
matches!(
self.device_type.as_str(),
super::super::PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER
| super::super::PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE
)
}
}
}
}
pub mod response {
pub mod create_playback_queue {
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
pub struct CreatePlaybackQueueResponse {
pub message: String,
pub data: Vec<super::super::PlaybackQueue>,
}
}
}
pub mod endpoint {
use axum::{Extension, Json, http};
use http::StatusCode;
use crate::repo::playback::queue as playback_repo;
#[utoipa::path(
post,
path = super::super::super::endpoints::CREATEPLAYBACKQUEUE,
request_body(
content = super::request::create_playback_queue::CreatePlaybackQueueRequest,
description = "Create playback queue for a user",
content_type = "application/json"
),
responses(
(status = 200, description = "Queue already exists", body = super::response::create_playback_queue::CreatePlaybackQueueResponse),
(status = 201, description = "Playback queue created", body = super::response::create_playback_queue::CreatePlaybackQueueResponse),
(status = 400, description = "Bad request", body = super::response::create_playback_queue::CreatePlaybackQueueResponse),
(status = 505, description = "Something went wrong", body = super::response::create_playback_queue::CreatePlaybackQueueResponse)
)
)]
pub async fn create_playback_queue(
Extension(pool): Extension<sqlx::PgPool>,
Json(payload): Json<super::request::create_playback_queue::CreatePlaybackQueueRequest>,
) -> (
axum::http::StatusCode,
axum::Json<super::response::create_playback_queue::CreatePlaybackQueueResponse>,
) {
let mut response =
super::response::create_playback_queue::CreatePlaybackQueueResponse::default();
if !payload.is_valid() {
response.message = super::super::super::response::INVALID.to_string();
(StatusCode::BAD_REQUEST, Json(response))
} else {
let res = match playback_repo::queue_existence_search(
&pool,
&payload.device_type,
&payload.user_id,
)
.await
{
Ok(result) => result,
Err(err) => {
eprintln!("Error: {err:?}");
response.message = err.to_string();
return (StatusCode::INTERNAL_SERVER_ERROR, Json(response));
}
};
if res {
// Do not create plaback queue
response.message = "Already created".to_string();
(StatusCode::OK, Json(response))
} else {
let mut playback_queue = super::PlaybackQueue {
name: payload.name,
device_type: payload.device_type,
user_id: payload.user_id,
..Default::default()
};
match playback_repo::create_queue(&pool, &playback_queue).await {
Ok((id, date_created)) => {
playback_queue.id = id;
playback_queue.date_created = Some(date_created);
response.data.push(playback_queue);
response.message =
super::super::super::response::SUCCESSFUL.to_string();
(StatusCode::CREATED, Json(response))
}
Err(err) => {
eprintln!("Error: {err:?}");
(StatusCode::INTERNAL_SERVER_ERROR, Json(response))
}
}
}
}
}
}
}
+10 -2
View File
@@ -5,16 +5,20 @@ use tower_http::timeout::TimeoutLayer;
use utoipa::OpenApi;
use crate::callers::coverart as coverart_caller;
use crate::callers::playback::queue as playback_caller;
use crate::callers::queue::coverart as coverart_queue_callers;
use crate::callers::queue::metadata as metadata_queue_caller;
use crate::callers::queue::song as song_queue_callers;
use crate::callers::song as song_caller;
use coverart_caller::endpoint as coverart_endpoints;
use coverart_caller::response as coverart_responses;
use coverart_queue_callers::endpoint as coverart_queue_endpoints;
use coverart_queue_callers::response as coverart_queue_responses;
use metadata_queue_caller::endpoint as metadata_queue_endpoints;
use metadata_queue_caller::response as metadata_queue_responses;
use playback_caller::endpoint as playback_endpoints;
use playback_caller::response as playback_responses;
use song_caller::endpoint as song_endpoints;
use song_caller::response as song_responses;
use song_queue_callers::endpoint as song_queue_endpoints;
@@ -73,14 +77,14 @@ mod cors {
song_endpoints::delete_song, coverart_queue_endpoints::queue, coverart_queue_endpoints::link, coverart_queue_endpoints::fetch_coverart_no_data,
coverart_queue_endpoints::fetch_coverart_with_data, coverart_endpoints::create_coverart, coverart_queue_endpoints::wipe_data_from_coverart_queue,
coverart_endpoints::get_coverart, coverart_endpoints::download_coverart,
metadata_queue_endpoints::queue_metadata, metadata_queue_endpoints::fetch_metadata),
metadata_queue_endpoints::queue_metadata, metadata_queue_endpoints::fetch_metadata, playback_endpoints::create_playback_queue),
components(schemas(song_queue_callers::response::song_queue::Response, song_queue_callers::response::link_user_id::Response, song_queue_callers::response::fetch_queue_song::Response,
song_queue_responses::update_status::Response, song_queue_callers::response::update_song_queue::Response, song_responses::create_metadata::Response,
song_queue_callers::response::wipe_data_from_song_queue::Response, song_responses::get_songs::Response, song_responses::delete_song::Response,
coverart_queue_responses::queue::Response, coverart_queue_responses::link::Response, coverart_queue_responses::fetch_coverart_no_data::Response,
coverart_queue_responses::fetch_coverart_with_data::Response, coverart_responses::create_coverart::Response,
coverart_queue_responses::wipe_data_from_coverart_queue::Response, coverart_responses::get_coverart::Response,
metadata_queue_responses::queue_metadata::Response, metadata_queue_responses::fetch_metadata::Response)),
metadata_queue_responses::queue_metadata::Response, metadata_queue_responses::fetch_metadata::Response, playback_responses::create_playback_queue::CreatePlaybackQueueResponse)),
tags(
(name = "soaricarus API", description = "Web API to manage music")
)
@@ -227,6 +231,10 @@ pub async fn routes() -> axum::Router {
crate::callers::endpoints::GETALLSONGS,
get(crate::callers::song::endpoint::get_all_songs),
)
.route(
crate::callers::endpoints::CREATEPLAYBACKQUEUE,
post(playback_endpoints::create_playback_queue),
)
.layer(cors::configure_cors().await)
}
+169 -30
View File
@@ -117,13 +117,15 @@ mod tests {
}
mod util {
use axum::response;
pub async fn resp_to_bytes(
response: axum::response::Response,
response: response::Response,
) -> Result<axum::body::Bytes, axum::Error> {
axum::body::to_bytes(response.into_body(), usize::MAX).await
}
pub async fn get_resp_data<Data>(response: axum::response::Response) -> Data
pub async fn get_resp_data<Data>(response: response::Response) -> Data
where
Data: for<'a> serde::Deserialize<'a>,
{
@@ -137,16 +139,12 @@ mod tests {
}
}
pub fn token_fields() -> (String, String, String) {
(
String::from("What a twist!"),
String::from("soaricarus_test"),
String::from("soaricarus"),
)
}
mod test_data {
pub const TEST_USER_ID: uuid::Uuid = uuid::uuid!("cc938368-615a-4694-b2ca-6e122fa31c52");
pub const DEVICE_TYPE: &str = "BROWSER";
pub const NAME: &str = "DougDimmaDome Browser Queue";
pub async fn test_token() -> Result<String, josekit::JoseError> {
let key: String = sienvy::environment::get_secret_main_key().value;
let (message, issuer, audience) = token_fields();
@@ -164,8 +162,17 @@ mod tests {
}
}
pub fn token_fields() -> (String, String, String) {
(
"What a twist!".to_string(),
"soaricarus_test".to_string(),
"soaricarus".to_string(),
)
}
}
pub async fn bearer_auth() -> String {
let token = match test_token().await {
let token = match test_data::test_token().await {
Ok(access_token) => access_token,
Err(err) => {
assert!(false, "Error: {err:?}");
@@ -444,6 +451,31 @@ mod tests {
}
}
pub async fn create_playback_queue(
app: &axum::Router,
name: &str,
device_type: &str,
user_id: &uuid::Uuid,
) -> Result<axum::response::Response, axum::http::Error> {
let uri = soaricarus_api::callers::endpoints::CREATEPLAYBACKQUEUE;
let payload =
super::payload_data::create_playback_queue(name, device_type, user_id).await;
match run_post(
Some(ReqBody::Json(payload)),
uri,
axum::http::Method::POST,
true,
)
.await
{
Ok(request) => match app.clone().oneshot(request).await {
Ok(response) => Ok(response),
Err(err) => Err(axum::http::Error::from(err)),
},
Err(err) => Err(err),
}
}
pub enum ReqBody {
Json(serde_json::Value),
Multipart((String, String)),
@@ -633,7 +665,7 @@ mod tests {
let song_queue_id = resp.data[0];
assert_eq!(false, song_queue_id.is_nil(), "Should not be empty");
let user_id = super::TEST_USER_ID;
let user_id = super::test_data::TEST_USER_ID;
match super::request::song_queue_link_req(&app, &song_queue_id, &user_id).await
{
@@ -779,8 +811,11 @@ mod tests {
}
pub mod payload_data {
pub async fn queue_metadata(song_queue_id: &uuid::Uuid) -> serde_json::Value {
serde_json::json!(
use serde_json::Value as JsonValue;
use serde_json::json;
pub async fn queue_metadata(song_queue_id: &uuid::Uuid) -> JsonValue {
json!(
{
"song_queue_id": song_queue_id,
"album" : "I",
@@ -797,11 +832,8 @@ mod tests {
})
}
pub async fn create_song(
song_queue_id: &uuid::Uuid,
user_id: &uuid::Uuid,
) -> serde_json::Value {
serde_json::json!({
pub async fn create_song(song_queue_id: &uuid::Uuid, user_id: &uuid::Uuid) -> JsonValue {
json!({
"title" : "Hypocrite Like The Rest",
"artist" : "Kuoth",
"album_artist": "Kuoth",
@@ -819,11 +851,23 @@ mod tests {
})
}
pub async fn create_playback_queue(
name: &str,
device_type: &str,
user_id: &uuid::Uuid,
) -> JsonValue {
json!({
"name": name,
"device_type": device_type,
"user_id": user_id
})
}
pub async fn link_user_to_queued_song(
song_queue_id: &uuid::Uuid,
user_id: &uuid::Uuid,
) -> serde_json::Value {
serde_json::json!({
) -> JsonValue {
json!({
"song_queue_id": song_queue_id,
"user_id": user_id
})
@@ -832,8 +876,8 @@ mod tests {
pub async fn link_queued_coverart_to_queued_song(
song_queue_id: &uuid::Uuid,
coverart_queue_id: &uuid::Uuid,
) -> serde_json::Value {
serde_json::json!({
) -> JsonValue {
json!({
"song_queue_id": song_queue_id,
"coverart_id": coverart_queue_id
})
@@ -842,17 +886,15 @@ mod tests {
pub async fn create_coverart(
song_id: &uuid::Uuid,
coverart_queue_id: &uuid::Uuid,
) -> serde_json::Value {
serde_json::json!({
) -> JsonValue {
json!({
"song_id": song_id,
"coverart_queue_id": coverart_queue_id
})
}
pub async fn update_song_queue_status_to_ready(
song_queue_id: &uuid::Uuid,
) -> serde_json::Value {
serde_json::json!({
pub async fn update_song_queue_status_to_ready(song_queue_id: &uuid::Uuid) -> JsonValue {
json!({
"id": song_queue_id,
"status": soaricarus_api::repo::queue::song::status::READY
})
@@ -926,7 +968,7 @@ mod tests {
assert_eq!(false, resp.data[0].is_nil(), "Should not be empty");
let song_queue_id = &resp.data[0];
let user_id = TEST_USER_ID;
let user_id = test_data::TEST_USER_ID;
println!("User Id: {user_id:?}");
match request::song_queue_link_req(&app, &song_queue_id, &user_id).await {
@@ -2036,6 +2078,8 @@ mod tests {
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
}
// NOTE: This was probably done so the tests in this module run after
// all the other tests finished
pub mod zzz_after_song_queue {
use futures::StreamExt;
use tower::ServiceExt;
@@ -2143,6 +2187,62 @@ mod tests {
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
}
#[tokio::test]
async fn test_get_coverart_with_song_id() {
let tm_pool = super::db_mgr::get_pool().await.unwrap();
let db_name = super::db_mgr::generate_db_name().await;
match super::db_mgr::create_database(&tm_pool, &db_name).await {
Ok(_) => {
println!("Success");
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
}
let pool = super::db_mgr::connect_to_db(&db_name).await.unwrap();
super::db_mgr::migrations(&pool).await;
let app = super::init::app(pool).await;
let (song_id, _, _, _) = test_data::song_id().await.unwrap();
let uri = format!(
"{}?song_id={song_id}",
soaricarus_api::callers::endpoints::GETCOVERART
);
match app
.clone()
.oneshot(
super::request::run_post(None, &uri, axum::http::Method::GET, false)
.await
.unwrap(),
)
.await
{
Ok(response) => {
let resp = super::util::get_resp_data::<
soaricarus_api::callers::coverart::response::get_coverart::Response,
>(response)
.await;
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
let coverart = resp.data[0].clone();
assert_eq!(
song_id, coverart.song_id,
"Song Id does not match {coverart:?}"
);
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
}
pub mod test_data {
pub async fn song_id() -> Result<(uuid::Uuid, String, String, String), uuid::Error> {
match uuid::Uuid::parse_str("44cf7940-34ff-489f-9124-d0ec90a55af9") {
@@ -2536,5 +2636,44 @@ mod tests {
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
}
#[tokio::test]
async fn test_create_playback_queue() {
let tm_pool = super::db_mgr::get_pool().await.unwrap();
let db_name = super::db_mgr::generate_db_name().await;
match super::db_mgr::create_database(&tm_pool, &db_name).await {
Ok(_) => {
println!("Success");
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
}
let pool = super::db_mgr::connect_to_db(&db_name).await.unwrap();
super::db_mgr::migrations(&pool).await;
let app = super::init::app(pool).await;
let user_id = super::test_data::TEST_USER_ID;
let device_type = super::test_data::DEVICE_TYPE;
let name = super::test_data::NAME;
match super::request::create_playback_queue(&app, name, device_type, &user_id).await {
Ok(response) => {
let resp = super::util::get_resp_data::<
soaricarus_api::callers::playback::queue::response::create_playback_queue::CreatePlaybackQueueResponse
>(response)
.await;
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
}
Err(err) => {
eprintln!("Error: {err:?}");
assert!(false, "Error: {err:?}");
}
}
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
}
}
}
+1
View File
@@ -1,3 +1,4 @@
pub mod coverart;
pub mod playback;
pub mod queue;
pub mod song;
+76
View File
@@ -0,0 +1,76 @@
pub mod queue {
use sqlx::{PgPool, Row};
// use sqlx::postgres::PgRow;
use crate::callers::playback::queue::PlaybackQueue;
use sqlx::Error as SqlxError;
pub async fn create_queue(
pool: &PgPool,
playback_queue: &PlaybackQueue,
) -> Result<(uuid::Uuid, time::OffsetDateTime), SqlxError> {
let query = r#"
INSERT INTO "playbackQueue" (name, device_type, user_id)
VALUES ($1, $2, $3)
RETURNING date_created, id;
"#;
match sqlx::query(query)
.bind(&playback_queue.name)
.bind(&playback_queue.device_type)
.bind(playback_queue.user_id)
.fetch_one(pool)
.await
{
Ok(row) => {
let id = row
.try_get("id")
.map_err(|_e| SqlxError::RowNotFound)
.unwrap();
let date_created = row
.try_get("date_created")
.map_err(|_e| SqlxError::RowNotFound)
.unwrap();
Ok((id, date_created))
}
Err(err) => Err(err),
}
}
pub async fn queue_existence_search(
pool: &PgPool,
device_type: &str,
user_id: &uuid::Uuid,
) -> Result<bool, SqlxError> {
let query = r#"
SELECT id FROM "playbackQueue"
WHERE device_type = $1 AND user_id = $2;
"#;
match sqlx::query(query)
.bind(device_type)
.bind(user_id)
.execute(pool)
.await
{
Ok(row) => {
let rows_affected = row.rows_affected();
Ok(rows_affected > 0)
}
Err(err) => Err(err),
}
}
// TODO: For later
/*
async fn parse_row(row: &PgRow) -> Result<PlaybackQueue, SqlxError> {
Ok(PlayBackQueue {
id: row.try_get("id").map_err(|_e| SqlxError::RowNotFound).unwrap(),
name: row.try_get("name").map_err(|_e| SqlxError::RowNotFound).unwrap(),
device_type: row.try_get("device_type").map_err(|_e| SqlxError::RowNotFound).unwrap(),
user_id: row.try_get("user_id").map_err(|_e| SqlxError::RowNotFound).unwrap(),
date_created: row.try_get("date_created").map_err(|_e| SqlxError::RowNotFound).unwrap()
})
}
*/
}
@@ -0,0 +1,16 @@
-- Add migration script here
CREATE TABLE IF NOT EXISTS "playbackQueue" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
device_type TEXT CHECK (device_type IN ('BROWSER', 'MOBILE')),
user_id UUID NOT NULL,
date_created timestamptz DEFAULT now()
);
CREATE TABLE IF NOT EXISTS "playbackQueueItem" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
queue_index INT NOT NULL,
song_id UUID NOT NULL,
playback_queue_id UUID NOT NULL,
date_created timestamptz DEFAULT now()
);