Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f48c7ee99c
|
||
|
|
64c6a7f6b5
|
||
|
|
4fdcd80db2
|
||
|
|
d249c34fb4
|
||
|
|
58682af84a
|
||
|
|
6ca17357dc
|
||
|
|
b668dc4abb
|
||
|
|
d2b9567c15
|
||
|
|
8a0e88c215
|
||
|
|
ed82e59a26
|
||
|
|
4ee0ba59fd
|
||
|
|
4403f3c7d2
|
||
|
|
980d2557a2
|
||
|
|
864447aa16
|
||
|
|
9b51442841
|
||
|
|
bad9efb026 | ||
|
|
23529e323a | ||
|
|
728948ebe4 | ||
|
|
4f9a51fcf0 |
No files matched your search
@@ -12,7 +12,7 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: Test Suite
|
name: Test Suite
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-26.04
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
@@ -31,7 +31,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.99
|
toolchain: 1.99.1
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- name: Verify Docker Environment
|
- name: Verify Docker Environment
|
||||||
run: |
|
run: |
|
||||||
@@ -49,7 +49,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
AWS_ACCESS_KEY_ID: "${{ secrets.GARAGE_KEY_ID }}"
|
AWS_ACCESS_KEY_ID: "${{ secrets.GARAGE_KEY_ID }}"
|
||||||
AWS_SECRET_ACCESS_KEY: "${{ secrets.GARAGE_SECRET }}"
|
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}}"
|
ENDPOINT_URL: "${{ secrets.S3_CI_ENDPOINT_URL}}"
|
||||||
run: |
|
run: |
|
||||||
sudo apt update
|
sudo apt update
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
@@ -16,7 +16,7 @@ jobs:
|
|||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.99
|
toolchain: 1.99.1
|
||||||
components: cargo
|
components: cargo
|
||||||
|
|
||||||
- name: Extract Version from Cargo.toml
|
- name: Extract Version from Cargo.toml
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
name: Check
|
name: Check
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.99
|
toolchain: 1.99.1
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
@@ -32,7 +32,7 @@ jobs:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
name: Test Suite
|
name: Test Suite
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-26.04
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
@@ -51,7 +51,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.99
|
toolchain: 1.99.1
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- name: Verify Docker Environment
|
- name: Verify Docker Environment
|
||||||
run: |
|
run: |
|
||||||
@@ -137,12 +137,12 @@ jobs:
|
|||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
name: Rustfmt
|
name: Rustfmt
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.99
|
toolchain: 1.99.1
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- run: |
|
- run: |
|
||||||
@@ -157,12 +157,12 @@ jobs:
|
|||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
name: Clippy
|
name: Clippy
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.99
|
toolchain: 1.99.1
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- run: |
|
- run: |
|
||||||
@@ -177,12 +177,12 @@ jobs:
|
|||||||
|
|
||||||
build:
|
build:
|
||||||
name: build
|
name: build
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.99
|
toolchain: 1.99.1
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
|
|||||||
Generated
+294
-470
File diff suppressed because it is too large.
Load diff
+10
-10
@@ -1,15 +1,15 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "soaricarus_api"
|
name = "soaricarus_api"
|
||||||
version = "0.5.11"
|
version = "0.5.13"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.95"
|
rust-version = "1.99.1"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
description = "Core API for interacting with soaricarus"
|
description = "Core API for interacting with soaricarus"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
axum = { version = "0.8.9", features = ["multipart"] }
|
axum = { version = "0.8.9", features = ["multipart"] }
|
||||||
axum-extra = { version = "0.12.6", features = ["cookie"] }
|
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 = { version = "1.0.229", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.154" }
|
serde_json = { version = "1.0.154" }
|
||||||
tokio = { version = "1.54.1", features = ["full"] }
|
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"
|
tracing-subscriber = "0.3.23"
|
||||||
futures = { version = "0.3.34" }
|
futures = { version = "0.3.34" }
|
||||||
mime_guess = { version = "2.0.5" }
|
mime_guess = { version = "2.0.5" }
|
||||||
uuid = { version = "1.29.0", features = ["v4", "serde"] }
|
uuid = { version = "1.29.3", features = ["v4", "serde"] }
|
||||||
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] }
|
sqlx = { version = "0.9.1", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] }
|
||||||
time = { version = "0.3.55", features = ["formatting", "macros", "parsing", "serde"] }
|
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" }
|
josekit = { version = "0.10.3" }
|
||||||
utoipa = { version = "6.0.0", features = ["axum_extras"] }
|
utoipa = { version = "6.0.0", features = ["axum_extras"] }
|
||||||
utoipa-swagger-ui = { version = "10.0.2", features = ["axum"] }
|
utoipa-swagger-ui = { version = "10.0.2", features = ["axum"] }
|
||||||
simeta = { git = "ssh://git@git.kundeng.us/phoenix/simeta.git", tag = "v0.6.3" }
|
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.7" }
|
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.2" }
|
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.6" }
|
labyrinth = { git = "ssh://git@git.kundeng.us/phoenix/labyrinth.git", tag = "v0.0.10" }
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|||||||
@@ -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
|
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.
|
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
|
### S3 Setup
|
||||||
Using the copied `.env.docker.sample`, ensure that the following has been properly populated.
|
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
|
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,
|
To view the OpenAPI spec, run the project and access `/swagger-ui`. If running through docker,
|
||||||
|
|||||||
+56
-7
@@ -18,6 +18,8 @@ services:
|
|||||||
condition: service_started
|
condition: service_started
|
||||||
auth_api:
|
auth_api:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
|
logledger_api:
|
||||||
|
condition: service_started
|
||||||
networks:
|
networks:
|
||||||
- soaricarus-network
|
- soaricarus-network
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -43,6 +45,25 @@ services:
|
|||||||
# volumes:
|
# volumes:
|
||||||
# - ./path/to/your/web-api-repo:/app
|
# - ./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 service ---
|
||||||
songparser:
|
songparser:
|
||||||
build:
|
build:
|
||||||
@@ -77,23 +98,23 @@ services:
|
|||||||
GARAGE_S3_API_ROOT_DOMAIN: "${GARAGE_ROOT_DOMAIN}"
|
GARAGE_S3_API_ROOT_DOMAIN: "${GARAGE_ROOT_DOMAIN}"
|
||||||
GARAGE_ADMIN_BIND_ADDR: "0.0.0.0:3902"
|
GARAGE_ADMIN_BIND_ADDR: "0.0.0.0:3902"
|
||||||
GARAGE_ADMIN_PUBLIC_BIND_ADDR: "0.0.0.0:3902"
|
GARAGE_ADMIN_PUBLIC_BIND_ADDR: "0.0.0.0:3902"
|
||||||
|
|
||||||
# Cluster configuration (single node for simplicity)
|
# Cluster configuration (single node for simplicity)
|
||||||
GARAGE_CLUSTER_REPLICATION_MODE: "none" # Single node
|
GARAGE_CLUSTER_REPLICATION_MODE: "none" # Single node
|
||||||
GARAGE_CLUSTER_PEER_REPLICATION_STRATEGY: "ring"
|
GARAGE_CLUSTER_PEER_REPLICATION_STRATEGY: "ring"
|
||||||
|
|
||||||
# Data storage
|
# Data storage
|
||||||
GARAGE_DATA_DIR: "/data"
|
GARAGE_DATA_DIR: "/data"
|
||||||
GARAGE_METADATA_DIR: "/data/meta"
|
GARAGE_METADATA_DIR: "/data/meta"
|
||||||
|
|
||||||
# RPC configuration
|
# RPC configuration
|
||||||
GARAGE_RPC_PUBLIC_ADDR: "http://maze:3901"
|
GARAGE_RPC_PUBLIC_ADDR: "http://maze:3901"
|
||||||
GARAGE_RPC_BIND_ADDR: "0.0.0.0:3901"
|
GARAGE_RPC_BIND_ADDR: "0.0.0.0:3901"
|
||||||
GARAGE_RPC_SECRET: "${GARAGE_RPC_SECRET}" # 32+ chars
|
GARAGE_RPC_SECRET: "${GARAGE_RPC_SECRET}" # 32+ chars
|
||||||
|
|
||||||
# Web Admin
|
# Web Admin
|
||||||
GARAGE_ADMIN_TOKEN: "${GARAGE_ADMIN_TOKEN}"
|
GARAGE_ADMIN_TOKEN: "${GARAGE_ADMIN_TOKEN}"
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
GARAGE_LOG_LEVEL: "info"
|
GARAGE_LOG_LEVEL: "info"
|
||||||
|
|
||||||
@@ -107,8 +128,8 @@ services:
|
|||||||
AWS_ACCESS_KEY_ID: "${GARAGE_DEFAULT_ACCESS_KEY}"
|
AWS_ACCESS_KEY_ID: "${GARAGE_DEFAULT_ACCESS_KEY}"
|
||||||
AWS_SECRET_ACCESS_KEY: "${GARAGE_DEFAULT_SECRET_KEY}"
|
AWS_SECRET_ACCESS_KEY: "${GARAGE_DEFAULT_SECRET_KEY}"
|
||||||
AWS_DEFAULT_REGION: "${GARAGE_DEFAULT_BUCKET}"
|
AWS_DEFAULT_REGION: "${GARAGE_DEFAULT_BUCKET}"
|
||||||
AWS_S3_FORCE_PATH_STYLE: "true"
|
AWS_S3_FORCE_PATH_STYLE: "true"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./garage.toml:/etc/garage.toml:ro # Mount config file
|
- ./garage.toml:/etc/garage.toml:ro # Mount config file
|
||||||
- shared_credentials:/data # Persist Garage data
|
- shared_credentials:/data # Persist Garage data
|
||||||
@@ -178,15 +199,43 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- soaricarus-network
|
- 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:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
driver: local # Use the default local driver
|
driver: local # Use the default local driver
|
||||||
postgres_data_auth:
|
postgres_data_auth:
|
||||||
driver: local # Use the default local driver
|
driver: local # Use the default local driver
|
||||||
|
postgres_data_logledger:
|
||||||
|
driver: local
|
||||||
object_data:
|
object_data:
|
||||||
driver: local # Use the default local driver
|
driver: local # Use the default local driver
|
||||||
shared_credentials: # New shared volume
|
shared_credentials: # New shared volume
|
||||||
driver: local
|
driver: local
|
||||||
|
logledger_data: # New shared volume
|
||||||
|
driver: local
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
soaricarus-network:
|
soaricarus-network:
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
|||||||
CREATE TABLE IF NOT EXISTS "songQueue" (
|
CREATE TABLE IF NOT EXISTS "songQueue" (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
filename TEXT NOT NULL,
|
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')),
|
status TEXT CHECK (status IN ('pending', 'ready', 'processing', 'done')),
|
||||||
user_id UUID NULL
|
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
@@ -42,7 +42,7 @@ pub async fn auth<B>(
|
|||||||
validation.set_audience(&["soaricarus"]);
|
validation.set_audience(&["soaricarus"]);
|
||||||
let _claims = decode::<simodels::token::UserClaims>(
|
let _claims = decode::<simodels::token::UserClaims>(
|
||||||
&token,
|
&token,
|
||||||
&DecodingKey::from_secret(secret_key.as_ref()),
|
&DecodingKey::from_secret(secret_key.as_ref()).unwrap(),
|
||||||
&validation,
|
&validation,
|
||||||
)
|
)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
|
|||||||
+26
-6
@@ -11,6 +11,7 @@ pub mod request {
|
|||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct Params {
|
pub struct Params {
|
||||||
pub id: Option<uuid::Uuid>,
|
pub id: Option<uuid::Uuid>,
|
||||||
|
pub song_id: Option<uuid::Uuid>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,7 +182,8 @@ pub mod endpoint {
|
|||||||
get,
|
get,
|
||||||
path = super::super::endpoints::GETCOVERART,
|
path = super::super::endpoints::GETCOVERART,
|
||||||
params(
|
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(
|
responses(
|
||||||
(status = 200, description = "Cover art retrieved", body = super::response::get_coverart::Response),
|
(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 {
|
Some(id) => match repo::coverart::get_coverart(&pool, &id).await {
|
||||||
Ok(coverart) => {
|
Ok(coverart) => {
|
||||||
response.data.push(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))
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -209,10 +211,28 @@ pub mod endpoint {
|
|||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => {
|
_ => match params.song_id {
|
||||||
response.message = String::from("Invalid parameters");
|
Some(song_id) => {
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
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 = "Invalid parameters".to_string();
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
pub mod coverart;
|
pub mod coverart;
|
||||||
|
pub mod playback;
|
||||||
pub mod queue;
|
pub mod queue;
|
||||||
pub mod song;
|
pub mod song;
|
||||||
|
|
||||||
@@ -14,10 +15,13 @@ pub mod endpoints {
|
|||||||
pub const CREATECOVERART: &str = "/api/v2/coverart";
|
pub const CREATECOVERART: &str = "/api/v2/coverart";
|
||||||
pub const GETCOVERART: &str = "/api/v2/coverart";
|
pub const GETCOVERART: &str = "/api/v2/coverart";
|
||||||
pub const DOWNLOADCOVERART: &str = "/api/v2/coverart/download/{id}";
|
pub const DOWNLOADCOVERART: &str = "/api/v2/coverart/download/{id}";
|
||||||
|
|
||||||
|
pub const CREATEPLAYBACKQUEUE: &str = "/api/v2/playback/queue";
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod response {
|
pub mod response {
|
||||||
pub const SUCCESSFUL: &str = "SUCCESSFUL";
|
pub const SUCCESSFUL: &str = "SUCCESSFUL";
|
||||||
|
pub const INVALID: &str = "INVALID";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Basic handler that responds with a static string
|
/// Basic handler that responds with a static string
|
||||||
|
|||||||
@@ -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
@@ -5,16 +5,20 @@ use tower_http::timeout::TimeoutLayer;
|
|||||||
use utoipa::OpenApi;
|
use utoipa::OpenApi;
|
||||||
|
|
||||||
use crate::callers::coverart as coverart_caller;
|
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::coverart as coverart_queue_callers;
|
||||||
use crate::callers::queue::metadata as metadata_queue_caller;
|
use crate::callers::queue::metadata as metadata_queue_caller;
|
||||||
use crate::callers::queue::song as song_queue_callers;
|
use crate::callers::queue::song as song_queue_callers;
|
||||||
use crate::callers::song as song_caller;
|
use crate::callers::song as song_caller;
|
||||||
|
|
||||||
use coverart_caller::endpoint as coverart_endpoints;
|
use coverart_caller::endpoint as coverart_endpoints;
|
||||||
use coverart_caller::response as coverart_responses;
|
use coverart_caller::response as coverart_responses;
|
||||||
use coverart_queue_callers::endpoint as coverart_queue_endpoints;
|
use coverart_queue_callers::endpoint as coverart_queue_endpoints;
|
||||||
use coverart_queue_callers::response as coverart_queue_responses;
|
use coverart_queue_callers::response as coverart_queue_responses;
|
||||||
use metadata_queue_caller::endpoint as metadata_queue_endpoints;
|
use metadata_queue_caller::endpoint as metadata_queue_endpoints;
|
||||||
use metadata_queue_caller::response as metadata_queue_responses;
|
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::endpoint as song_endpoints;
|
||||||
use song_caller::response as song_responses;
|
use song_caller::response as song_responses;
|
||||||
use song_queue_callers::endpoint as song_queue_endpoints;
|
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,
|
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_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,
|
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,
|
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_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,
|
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::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::fetch_coverart_with_data::Response, coverart_responses::create_coverart::Response,
|
||||||
coverart_queue_responses::wipe_data_from_coverart_queue::Response, coverart_responses::get_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(
|
tags(
|
||||||
(name = "soaricarus API", description = "Web API to manage music")
|
(name = "soaricarus API", description = "Web API to manage music")
|
||||||
)
|
)
|
||||||
@@ -227,6 +231,10 @@ pub async fn routes() -> axum::Router {
|
|||||||
crate::callers::endpoints::GETALLSONGS,
|
crate::callers::endpoints::GETALLSONGS,
|
||||||
get(crate::callers::song::endpoint::get_all_songs),
|
get(crate::callers::song::endpoint::get_all_songs),
|
||||||
)
|
)
|
||||||
|
.route(
|
||||||
|
crate::callers::endpoints::CREATEPLAYBACKQUEUE,
|
||||||
|
post(playback_endpoints::create_playback_queue),
|
||||||
|
)
|
||||||
.layer(cors::configure_cors().await)
|
.layer(cors::configure_cors().await)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+181
-42
@@ -117,13 +117,15 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod util {
|
mod util {
|
||||||
|
use axum::response;
|
||||||
|
|
||||||
pub async fn resp_to_bytes(
|
pub async fn resp_to_bytes(
|
||||||
response: axum::response::Response,
|
response: response::Response,
|
||||||
) -> Result<axum::body::Bytes, axum::Error> {
|
) -> Result<axum::body::Bytes, axum::Error> {
|
||||||
axum::body::to_bytes(response.into_body(), usize::MAX).await
|
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
|
where
|
||||||
Data: for<'a> serde::Deserialize<'a>,
|
Data: for<'a> serde::Deserialize<'a>,
|
||||||
{
|
{
|
||||||
@@ -137,35 +139,40 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn token_fields() -> (String, String, String) {
|
mod test_data {
|
||||||
(
|
pub const TEST_USER_ID: uuid::Uuid = uuid::uuid!("cc938368-615a-4694-b2ca-6e122fa31c52");
|
||||||
String::from("What a twist!"),
|
|
||||||
String::from("soaricarus_test"),
|
|
||||||
String::from("soaricarus"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
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> {
|
pub async fn test_token() -> Result<String, josekit::JoseError> {
|
||||||
let key: String = sienvy::environment::get_secret_main_key().value;
|
let key: String = sienvy::environment::get_secret_main_key().value;
|
||||||
let (message, issuer, audience) = token_fields();
|
let (message, issuer, audience) = token_fields();
|
||||||
|
|
||||||
let token_resource = simodels::token::TokenResource {
|
let token_resource = simodels::token::TokenResource {
|
||||||
message: message,
|
message: message,
|
||||||
issuer: issuer,
|
issuer: issuer,
|
||||||
audiences: vec![audience],
|
audiences: vec![audience],
|
||||||
id: TEST_USER_ID,
|
id: TEST_USER_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
match simodels::token::create_token(&key, &token_resource, time::Duration::hours(1)) {
|
match simodels::token::create_token(&key, &token_resource, time::Duration::hours(1)) {
|
||||||
Ok((access_token, _some_time)) => Ok(access_token),
|
Ok((access_token, _some_time)) => Ok(access_token),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
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,
|
Ok(access_token) => access_token,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
assert!(false, "Error: {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 {
|
pub enum ReqBody {
|
||||||
Json(serde_json::Value),
|
Json(serde_json::Value),
|
||||||
Multipart((String, String)),
|
Multipart((String, String)),
|
||||||
@@ -633,7 +665,7 @@ mod tests {
|
|||||||
let song_queue_id = resp.data[0];
|
let song_queue_id = resp.data[0];
|
||||||
assert_eq!(false, song_queue_id.is_nil(), "Should not be empty");
|
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
|
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 mod payload_data {
|
||||||
pub async fn queue_metadata(song_queue_id: &uuid::Uuid) -> serde_json::Value {
|
use serde_json::Value as JsonValue;
|
||||||
serde_json::json!(
|
use serde_json::json;
|
||||||
|
|
||||||
|
pub async fn queue_metadata(song_queue_id: &uuid::Uuid) -> JsonValue {
|
||||||
|
json!(
|
||||||
{
|
{
|
||||||
"song_queue_id": song_queue_id,
|
"song_queue_id": song_queue_id,
|
||||||
"album" : "I",
|
"album" : "I",
|
||||||
@@ -797,11 +832,8 @@ mod tests {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_song(
|
pub async fn create_song(song_queue_id: &uuid::Uuid, user_id: &uuid::Uuid) -> JsonValue {
|
||||||
song_queue_id: &uuid::Uuid,
|
json!({
|
||||||
user_id: &uuid::Uuid,
|
|
||||||
) -> serde_json::Value {
|
|
||||||
serde_json::json!({
|
|
||||||
"title" : "Hypocrite Like The Rest",
|
"title" : "Hypocrite Like The Rest",
|
||||||
"artist" : "Kuoth",
|
"artist" : "Kuoth",
|
||||||
"album_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(
|
pub async fn link_user_to_queued_song(
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
user_id: &uuid::Uuid,
|
user_id: &uuid::Uuid,
|
||||||
) -> serde_json::Value {
|
) -> JsonValue {
|
||||||
serde_json::json!({
|
json!({
|
||||||
"song_queue_id": song_queue_id,
|
"song_queue_id": song_queue_id,
|
||||||
"user_id": user_id
|
"user_id": user_id
|
||||||
})
|
})
|
||||||
@@ -832,8 +876,8 @@ mod tests {
|
|||||||
pub async fn link_queued_coverart_to_queued_song(
|
pub async fn link_queued_coverart_to_queued_song(
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
coverart_queue_id: &uuid::Uuid,
|
||||||
) -> serde_json::Value {
|
) -> JsonValue {
|
||||||
serde_json::json!({
|
json!({
|
||||||
"song_queue_id": song_queue_id,
|
"song_queue_id": song_queue_id,
|
||||||
"coverart_id": coverart_queue_id
|
"coverart_id": coverart_queue_id
|
||||||
})
|
})
|
||||||
@@ -842,17 +886,15 @@ mod tests {
|
|||||||
pub async fn create_coverart(
|
pub async fn create_coverart(
|
||||||
song_id: &uuid::Uuid,
|
song_id: &uuid::Uuid,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
coverart_queue_id: &uuid::Uuid,
|
||||||
) -> serde_json::Value {
|
) -> JsonValue {
|
||||||
serde_json::json!({
|
json!({
|
||||||
"song_id": song_id,
|
"song_id": song_id,
|
||||||
"coverart_queue_id": coverart_queue_id
|
"coverart_queue_id": coverart_queue_id
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_song_queue_status_to_ready(
|
pub async fn update_song_queue_status_to_ready(song_queue_id: &uuid::Uuid) -> JsonValue {
|
||||||
song_queue_id: &uuid::Uuid,
|
json!({
|
||||||
) -> serde_json::Value {
|
|
||||||
serde_json::json!({
|
|
||||||
"id": song_queue_id,
|
"id": song_queue_id,
|
||||||
"status": soaricarus_api::repo::queue::song::status::READY
|
"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");
|
assert_eq!(false, resp.data[0].is_nil(), "Should not be empty");
|
||||||
|
|
||||||
let song_queue_id = &resp.data[0];
|
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:?}");
|
println!("User Id: {user_id:?}");
|
||||||
|
|
||||||
match request::song_queue_link_req(&app, &song_queue_id, &user_id).await {
|
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;
|
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 {
|
pub mod zzz_after_song_queue {
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use tower::ServiceExt;
|
use tower::ServiceExt;
|
||||||
@@ -2143,6 +2187,62 @@ mod tests {
|
|||||||
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
|
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 mod test_data {
|
||||||
pub async fn song_id() -> Result<(uuid::Uuid, String, String, String), uuid::Error> {
|
pub async fn song_id() -> Result<(uuid::Uuid, String, String, String), uuid::Error> {
|
||||||
match uuid::Uuid::parse_str("44cf7940-34ff-489f-9124-d0ec90a55af9") {
|
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;
|
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,3 +1,4 @@
|
|||||||
pub mod coverart;
|
pub mod coverart;
|
||||||
|
pub mod playback;
|
||||||
pub mod queue;
|
pub mod queue;
|
||||||
pub mod song;
|
pub mod song;
|
||||||
@@ -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()
|
||||||
|
);
|
||||||
Reference in new issue
Block a user