Compare commits
5 Commits
a123c0b8cc
...
eebdbeaaf2
| Author | SHA1 | Date | |
|---|---|---|---|
| eebdbeaaf2 | |||
| f387be43fb | |||
| 1a1ba3da63 | |||
| 9757ebdabf | |||
| 344bcf34af |
@@ -29,7 +29,7 @@ services:
|
|||||||
PORT: 8000
|
PORT: 8000
|
||||||
JWT_SECRET: ${JWT_SECRET}
|
JWT_SECRET: ${JWT_SECRET}
|
||||||
BASE_URL: ${BASE_URL}
|
BASE_URL: ${BASE_URL}
|
||||||
NATS_URL: ${NATS_URL}
|
NATS_URL: nats://k_nats:4222
|
||||||
CORS_ORIGINS: ${CORS_ORIGINS:-*}
|
CORS_ORIGINS: ${CORS_ORIGINS:-*}
|
||||||
ALLOW_REGISTRATION: ${ALLOW_REGISTRATION:-false}
|
ALLOW_REGISTRATION: ${ALLOW_REGISTRATION:-false}
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -42,7 +42,16 @@ services:
|
|||||||
retries: 5
|
retries: 5
|
||||||
networks:
|
networks:
|
||||||
- internal
|
- internal
|
||||||
- nats
|
- shared-services
|
||||||
|
- traefik
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.docker.network=traefik"
|
||||||
|
- "traefik.http.routers.thoughts-api.rule=Host(`api.thoughts.gabrielkaszewski.dev`)"
|
||||||
|
- "traefik.http.routers.thoughts-api.entrypoints=web,websecure"
|
||||||
|
- "traefik.http.routers.thoughts-api.tls.certresolver=letsencrypt"
|
||||||
|
- "traefik.http.routers.thoughts-api.service=thoughts-api"
|
||||||
|
- "traefik.http.services.thoughts-api.loadbalancer.server.port=8000"
|
||||||
|
|
||||||
worker:
|
worker:
|
||||||
container_name: thoughts-worker
|
container_name: thoughts-worker
|
||||||
@@ -53,13 +62,13 @@ services:
|
|||||||
RUST_LOG: info
|
RUST_LOG: info
|
||||||
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database/${POSTGRES_DB}
|
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database/${POSTGRES_DB}
|
||||||
BASE_URL: ${BASE_URL}
|
BASE_URL: ${BASE_URL}
|
||||||
NATS_URL: ${NATS_URL}
|
NATS_URL: nats://k_nats:4222
|
||||||
depends_on:
|
depends_on:
|
||||||
database:
|
database:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
networks:
|
networks:
|
||||||
- internal
|
- internal
|
||||||
- nats
|
- shared-services
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
container_name: thoughts-frontend
|
container_name: thoughts-frontend
|
||||||
@@ -67,6 +76,7 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
NEXT_PUBLIC_SERVER_SIDE_API_URL: http://api:8000
|
NEXT_PUBLIC_SERVER_SIDE_API_URL: http://api:8000
|
||||||
|
NEXT_PUBLIC_API_URL: https://api.thoughts.gabrielkaszewski.dev
|
||||||
PORT: 3000
|
PORT: 3000
|
||||||
HOSTNAME: 0.0.0.0
|
HOSTNAME: 0.0.0.0
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -79,18 +89,6 @@ services:
|
|||||||
retries: 5
|
retries: 5
|
||||||
networks:
|
networks:
|
||||||
- internal
|
- internal
|
||||||
|
|
||||||
proxy:
|
|
||||||
container_name: thoughts-proxy
|
|
||||||
image: custom-proxy:latest
|
|
||||||
restart: unless-stopped
|
|
||||||
depends_on:
|
|
||||||
frontend:
|
|
||||||
condition: service_healthy
|
|
||||||
api:
|
|
||||||
condition: service_healthy
|
|
||||||
networks:
|
|
||||||
- internal
|
|
||||||
- traefik
|
- traefik
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
@@ -99,20 +97,16 @@ services:
|
|||||||
- "traefik.http.routers.thoughts.entrypoints=web,websecure"
|
- "traefik.http.routers.thoughts.entrypoints=web,websecure"
|
||||||
- "traefik.http.routers.thoughts.tls.certresolver=letsencrypt"
|
- "traefik.http.routers.thoughts.tls.certresolver=letsencrypt"
|
||||||
- "traefik.http.routers.thoughts.service=thoughts"
|
- "traefik.http.routers.thoughts.service=thoughts"
|
||||||
- "traefik.http.services.thoughts.loadbalancer.server.port=80"
|
- "traefik.http.services.thoughts.loadbalancer.server.port=3000"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
driver: local
|
driver: local
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
# Shared NATS network — must already exist on the host (external: true).
|
shared-services:
|
||||||
# Set NATS_NETWORK env var to match your shared network name (default: nats).
|
|
||||||
nats:
|
|
||||||
name: ${NATS_NETWORK:-nats}
|
|
||||||
external: true
|
external: true
|
||||||
traefik:
|
traefik:
|
||||||
name: traefik
|
|
||||||
external: true
|
external: true
|
||||||
internal:
|
internal:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use domain::models::thought::Visibility;
|
|
||||||
|
fn visibility_from_str(s: &str) -> domain::models::thought::Visibility {
|
||||||
|
use domain::models::thought::Visibility;
|
||||||
|
match s {
|
||||||
|
"followers" => Visibility::Followers,
|
||||||
|
"unlisted" => Visibility::Unlisted,
|
||||||
|
"direct" => Visibility::Direct,
|
||||||
|
_ => Visibility::Public,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
use domain::{
|
use domain::{
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
models::{
|
models::{
|
||||||
@@ -48,8 +58,6 @@ struct FeedRow {
|
|||||||
author_local: bool,
|
author_local: bool,
|
||||||
u_ap_id: Option<String>,
|
u_ap_id: Option<String>,
|
||||||
inbox_url: Option<String>,
|
inbox_url: Option<String>,
|
||||||
public_key: Option<String>,
|
|
||||||
private_key: Option<String>,
|
|
||||||
author_created_at: DateTime<Utc>,
|
author_created_at: DateTime<Utc>,
|
||||||
author_updated_at: DateTime<Utc>,
|
author_updated_at: DateTime<Utc>,
|
||||||
like_count: i64,
|
like_count: i64,
|
||||||
@@ -66,7 +74,6 @@ const FEED_SELECT: &str = "
|
|||||||
u.id AS author_id, u.username, u.email, u.password_hash,
|
u.id AS author_id, u.username, u.email, u.password_hash,
|
||||||
u.display_name, u.bio, u.avatar_url, u.header_url, u.custom_css,
|
u.display_name, u.bio, u.avatar_url, u.header_url, u.custom_css,
|
||||||
u.local AS author_local, u.ap_id AS u_ap_id, u.inbox_url,
|
u.local AS author_local, u.ap_id AS u_ap_id, u.inbox_url,
|
||||||
u.public_key, u.private_key,
|
|
||||||
u.created_at AS author_created_at, u.updated_at AS author_updated_at,
|
u.created_at AS author_created_at, u.updated_at AS author_updated_at,
|
||||||
(SELECT COUNT(*) FROM likes l WHERE l.thought_id=t.id) AS like_count,
|
(SELECT COUNT(*) FROM likes l WHERE l.thought_id=t.id) AS like_count,
|
||||||
(SELECT COUNT(*) FROM boosts b WHERE b.thought_id=t.id) AS boost_count,
|
(SELECT COUNT(*) FROM boosts b WHERE b.thought_id=t.id) AS boost_count,
|
||||||
@@ -81,7 +88,7 @@ fn row_to_entry(r: FeedRow) -> FeedEntry {
|
|||||||
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||||
in_reply_to_url: r.in_reply_to_url,
|
in_reply_to_url: r.in_reply_to_url,
|
||||||
ap_id: r.t_ap_id,
|
ap_id: r.t_ap_id,
|
||||||
visibility: Visibility::from_db_str(&r.visibility),
|
visibility: visibility_from_str(&r.visibility),
|
||||||
content_warning: r.content_warning,
|
content_warning: r.content_warning,
|
||||||
sensitive: r.sensitive,
|
sensitive: r.sensitive,
|
||||||
local: r.t_local,
|
local: r.t_local,
|
||||||
@@ -101,8 +108,6 @@ fn row_to_entry(r: FeedRow) -> FeedEntry {
|
|||||||
local: r.author_local,
|
local: r.author_local,
|
||||||
ap_id: r.u_ap_id,
|
ap_id: r.u_ap_id,
|
||||||
inbox_url: r.inbox_url,
|
inbox_url: r.inbox_url,
|
||||||
public_key: r.public_key,
|
|
||||||
private_key: r.private_key,
|
|
||||||
created_at: r.author_created_at,
|
created_at: r.author_created_at,
|
||||||
updated_at: r.author_updated_at,
|
updated_at: r.author_updated_at,
|
||||||
};
|
};
|
||||||
@@ -131,8 +136,6 @@ struct UserRow {
|
|||||||
local: bool,
|
local: bool,
|
||||||
ap_id: Option<String>,
|
ap_id: Option<String>,
|
||||||
inbox_url: Option<String>,
|
inbox_url: Option<String>,
|
||||||
public_key: Option<String>,
|
|
||||||
private_key: Option<String>,
|
|
||||||
created_at: DateTime<Utc>,
|
created_at: DateTime<Utc>,
|
||||||
updated_at: DateTime<Utc>,
|
updated_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
@@ -152,8 +155,6 @@ impl From<UserRow> for User {
|
|||||||
local: r.local,
|
local: r.local,
|
||||||
ap_id: r.ap_id,
|
ap_id: r.ap_id,
|
||||||
inbox_url: r.inbox_url,
|
inbox_url: r.inbox_url,
|
||||||
public_key: r.public_key,
|
|
||||||
private_key: r.private_key,
|
|
||||||
created_at: r.created_at,
|
created_at: r.created_at,
|
||||||
updated_at: r.updated_at,
|
updated_at: r.updated_at,
|
||||||
}
|
}
|
||||||
@@ -162,7 +163,7 @@ impl From<UserRow> for User {
|
|||||||
|
|
||||||
const USER_SELECT: &str =
|
const USER_SELECT: &str =
|
||||||
"SELECT id,username,email,password_hash,display_name,bio,avatar_url,header_url,\
|
"SELECT id,username,email,password_hash,display_name,bio,avatar_url,header_url,\
|
||||||
custom_css,local,ap_id,inbox_url,public_key,private_key,created_at,updated_at FROM users";
|
custom_css,local,ap_id,inbox_url,created_at,updated_at FROM users";
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl SearchPort for PgSearchRepository {
|
impl SearchPort for PgSearchRepository {
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use domain::models::thought::Visibility;
|
|
||||||
|
fn visibility_from_str(s: &str) -> domain::models::thought::Visibility {
|
||||||
|
use domain::models::thought::Visibility;
|
||||||
|
match s {
|
||||||
|
"followers" => Visibility::Followers,
|
||||||
|
"unlisted" => Visibility::Unlisted,
|
||||||
|
"direct" => Visibility::Direct,
|
||||||
|
_ => Visibility::Public,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
use domain::{
|
use domain::{
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
models::{
|
models::{
|
||||||
@@ -48,8 +58,6 @@ struct FeedRow {
|
|||||||
author_local: bool,
|
author_local: bool,
|
||||||
u_ap_id: Option<String>,
|
u_ap_id: Option<String>,
|
||||||
inbox_url: Option<String>,
|
inbox_url: Option<String>,
|
||||||
public_key: Option<String>,
|
|
||||||
private_key: Option<String>,
|
|
||||||
author_created_at: DateTime<Utc>,
|
author_created_at: DateTime<Utc>,
|
||||||
author_updated_at: DateTime<Utc>,
|
author_updated_at: DateTime<Utc>,
|
||||||
like_count: i64,
|
like_count: i64,
|
||||||
@@ -77,7 +85,6 @@ fn feed_select(viewer: Option<uuid::Uuid>) -> String {
|
|||||||
u.id AS author_id, u.username, u.email, u.password_hash,
|
u.id AS author_id, u.username, u.email, u.password_hash,
|
||||||
u.display_name, u.bio, u.avatar_url, u.header_url, u.custom_css,
|
u.display_name, u.bio, u.avatar_url, u.header_url, u.custom_css,
|
||||||
u.local AS author_local, u.ap_id AS u_ap_id, u.inbox_url,
|
u.local AS author_local, u.ap_id AS u_ap_id, u.inbox_url,
|
||||||
u.public_key, u.private_key,
|
|
||||||
u.created_at AS author_created_at, u.updated_at AS author_updated_at,
|
u.created_at AS author_created_at, u.updated_at AS author_updated_at,
|
||||||
(SELECT COUNT(*) FROM likes l WHERE l.thought_id=t.id) AS like_count,
|
(SELECT COUNT(*) FROM likes l WHERE l.thought_id=t.id) AS like_count,
|
||||||
(SELECT COUNT(*) FROM boosts b WHERE b.thought_id=t.id) AS boost_count,
|
(SELECT COUNT(*) FROM boosts b WHERE b.thought_id=t.id) AS boost_count,
|
||||||
@@ -95,7 +102,7 @@ fn row_to_entry(r: FeedRow) -> FeedEntry {
|
|||||||
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||||
in_reply_to_url: r.in_reply_to_url,
|
in_reply_to_url: r.in_reply_to_url,
|
||||||
ap_id: r.t_ap_id,
|
ap_id: r.t_ap_id,
|
||||||
visibility: Visibility::from_db_str(&r.visibility),
|
visibility: visibility_from_str(&r.visibility),
|
||||||
content_warning: r.content_warning,
|
content_warning: r.content_warning,
|
||||||
sensitive: r.sensitive,
|
sensitive: r.sensitive,
|
||||||
local: r.t_local,
|
local: r.t_local,
|
||||||
@@ -115,8 +122,6 @@ fn row_to_entry(r: FeedRow) -> FeedEntry {
|
|||||||
local: r.author_local,
|
local: r.author_local,
|
||||||
ap_id: r.u_ap_id,
|
ap_id: r.u_ap_id,
|
||||||
inbox_url: r.inbox_url,
|
inbox_url: r.inbox_url,
|
||||||
public_key: r.public_key,
|
|
||||||
private_key: r.private_key,
|
|
||||||
created_at: r.author_created_at,
|
created_at: r.author_created_at,
|
||||||
updated_at: r.author_updated_at,
|
updated_at: r.author_updated_at,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,24 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
|
fn follow_state_from_str(s: &str) -> domain::models::social::FollowState {
|
||||||
|
use domain::models::social::FollowState;
|
||||||
|
match s {
|
||||||
|
"pending" => FollowState::Pending,
|
||||||
|
"rejected" => FollowState::Rejected,
|
||||||
|
_ => FollowState::Accepted,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn follow_state_as_str(state: &domain::models::social::FollowState) -> &'static str {
|
||||||
|
use domain::models::social::FollowState;
|
||||||
|
match state {
|
||||||
|
FollowState::Pending => "pending",
|
||||||
|
FollowState::Accepted => "accepted",
|
||||||
|
FollowState::Rejected => "rejected",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
use domain::{
|
use domain::{
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
models::{
|
models::{
|
||||||
@@ -31,7 +50,7 @@ impl FollowRepository for PgFollowRepository {
|
|||||||
)
|
)
|
||||||
.bind(f.follower_id.as_uuid())
|
.bind(f.follower_id.as_uuid())
|
||||||
.bind(f.following_id.as_uuid())
|
.bind(f.following_id.as_uuid())
|
||||||
.bind(f.state.as_str())
|
.bind(follow_state_as_str(&f.state))
|
||||||
.bind(&f.ap_id)
|
.bind(&f.ap_id)
|
||||||
.bind(f.created_at)
|
.bind(f.created_at)
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
@@ -77,7 +96,7 @@ impl FollowRepository for PgFollowRepository {
|
|||||||
.map(|o| o.map(|r| Follow {
|
.map(|o| o.map(|r| Follow {
|
||||||
follower_id: UserId::from_uuid(r.follower_id),
|
follower_id: UserId::from_uuid(r.follower_id),
|
||||||
following_id: UserId::from_uuid(r.following_id),
|
following_id: UserId::from_uuid(r.following_id),
|
||||||
state: FollowState::from_db_str(&r.state),
|
state: follow_state_from_str(&r.state),
|
||||||
ap_id: r.ap_id,
|
ap_id: r.ap_id,
|
||||||
created_at: r.created_at,
|
created_at: r.created_at,
|
||||||
}))
|
}))
|
||||||
@@ -92,7 +111,7 @@ impl FollowRepository for PgFollowRepository {
|
|||||||
sqlx::query("UPDATE follows SET state=$3 WHERE follower_id=$1 AND following_id=$2")
|
sqlx::query("UPDATE follows SET state=$3 WHERE follower_id=$1 AND following_id=$2")
|
||||||
.bind(follower_id.as_uuid())
|
.bind(follower_id.as_uuid())
|
||||||
.bind(following_id.as_uuid())
|
.bind(following_id.as_uuid())
|
||||||
.bind(state.as_str())
|
.bind(follow_state_as_str(state))
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| DomainError::Internal(e.to_string()))
|
.map_err(|e| DomainError::Internal(e.to_string()))
|
||||||
@@ -113,7 +132,7 @@ impl FollowRepository for PgFollowRepository {
|
|||||||
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
||||||
|
|
||||||
let rows = sqlx::query_as::<_, crate::user::UserRow>(
|
let rows = sqlx::query_as::<_, crate::user::UserRow>(
|
||||||
"SELECT u.id,u.username,u.email,u.password_hash,u.display_name,u.bio,u.avatar_url,u.header_url,u.custom_css,u.local,u.ap_id,u.inbox_url,u.public_key,u.private_key,u.created_at,u.updated_at
|
"SELECT u.id,u.username,u.email,u.password_hash,u.display_name,u.bio,u.avatar_url,u.header_url,u.custom_css,u.local,u.ap_id,u.inbox_url,u.created_at,u.updated_at
|
||||||
FROM users u JOIN follows f ON f.follower_id=u.id
|
FROM users u JOIN follows f ON f.follower_id=u.id
|
||||||
WHERE f.following_id=$1 AND f.state='accepted'
|
WHERE f.following_id=$1 AND f.state='accepted'
|
||||||
ORDER BY f.created_at DESC LIMIT $2 OFFSET $3"
|
ORDER BY f.created_at DESC LIMIT $2 OFFSET $3"
|
||||||
@@ -147,7 +166,7 @@ impl FollowRepository for PgFollowRepository {
|
|||||||
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
||||||
|
|
||||||
let rows = sqlx::query_as::<_, crate::user::UserRow>(
|
let rows = sqlx::query_as::<_, crate::user::UserRow>(
|
||||||
"SELECT u.id,u.username,u.email,u.password_hash,u.display_name,u.bio,u.avatar_url,u.header_url,u.custom_css,u.local,u.ap_id,u.inbox_url,u.public_key,u.private_key,u.created_at,u.updated_at
|
"SELECT u.id,u.username,u.email,u.password_hash,u.display_name,u.bio,u.avatar_url,u.header_url,u.custom_css,u.local,u.ap_id,u.inbox_url,u.created_at,u.updated_at
|
||||||
FROM users u JOIN follows f ON f.following_id=u.id
|
FROM users u JOIN follows f ON f.following_id=u.id
|
||||||
WHERE f.follower_id=$1 AND f.state='accepted'
|
WHERE f.follower_id=$1 AND f.state='accepted'
|
||||||
ORDER BY f.created_at DESC LIMIT $2 OFFSET $3"
|
ORDER BY f.created_at DESC LIMIT $2 OFFSET $3"
|
||||||
|
|||||||
@@ -1,10 +1,33 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
|
fn notif_type_from_str(s: &str) -> domain::models::notification::NotificationType {
|
||||||
|
use domain::models::notification::NotificationType;
|
||||||
|
match s {
|
||||||
|
"like" => NotificationType::Like,
|
||||||
|
"boost" => NotificationType::Boost,
|
||||||
|
"follow" => NotificationType::Follow,
|
||||||
|
"mention" => NotificationType::Mention,
|
||||||
|
_ => NotificationType::Reply,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn notif_type_as_str(t: &domain::models::notification::NotificationType) -> &'static str {
|
||||||
|
use domain::models::notification::NotificationType;
|
||||||
|
match t {
|
||||||
|
NotificationType::Like => "like",
|
||||||
|
NotificationType::Boost => "boost",
|
||||||
|
NotificationType::Follow => "follow",
|
||||||
|
NotificationType::Mention => "mention",
|
||||||
|
NotificationType::Reply => "reply",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
use domain::{
|
use domain::{
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
models::{
|
models::{
|
||||||
feed::{PageParams, Paginated},
|
feed::{PageParams, Paginated},
|
||||||
notification::{Notification, NotificationType},
|
notification::Notification,
|
||||||
},
|
},
|
||||||
ports::NotificationRepository,
|
ports::NotificationRepository,
|
||||||
value_objects::{NotificationId, ThoughtId, UserId},
|
value_objects::{NotificationId, ThoughtId, UserId},
|
||||||
@@ -26,7 +49,7 @@ impl NotificationRepository for PgNotificationRepository {
|
|||||||
sqlx::query(
|
sqlx::query(
|
||||||
"INSERT INTO notifications(id,user_id,type,from_user_id,thought_id,read,created_at) VALUES($1,$2,$3,$4,$5,$6,$7)"
|
"INSERT INTO notifications(id,user_id,type,from_user_id,thought_id,read,created_at) VALUES($1,$2,$3,$4,$5,$6,$7)"
|
||||||
)
|
)
|
||||||
.bind(n.id.as_uuid()).bind(n.user_id.as_uuid()).bind(n.notification_type.as_str())
|
.bind(n.id.as_uuid()).bind(n.user_id.as_uuid()).bind(notif_type_as_str(&n.notification_type))
|
||||||
.bind(n.from_user_id.as_ref().map(|u| u.as_uuid()))
|
.bind(n.from_user_id.as_ref().map(|u| u.as_uuid()))
|
||||||
.bind(n.thought_id.as_ref().map(|t| t.as_uuid()))
|
.bind(n.thought_id.as_ref().map(|t| t.as_uuid()))
|
||||||
.bind(n.read).bind(n.created_at)
|
.bind(n.read).bind(n.created_at)
|
||||||
@@ -62,7 +85,7 @@ impl NotificationRepository for PgNotificationRepository {
|
|||||||
.map(|r| Notification {
|
.map(|r| Notification {
|
||||||
id: NotificationId::from_uuid(r.id),
|
id: NotificationId::from_uuid(r.id),
|
||||||
user_id: UserId::from_uuid(r.user_id),
|
user_id: UserId::from_uuid(r.user_id),
|
||||||
notification_type: NotificationType::from_db_str(&r.r#type),
|
notification_type: notif_type_from_str(&r.r#type),
|
||||||
from_user_id: r.from_user_id.map(UserId::from_uuid),
|
from_user_id: r.from_user_id.map(UserId::from_uuid),
|
||||||
thought_id: r.thought_id.map(ThoughtId::from_uuid),
|
thought_id: r.thought_id.map(ThoughtId::from_uuid),
|
||||||
read: r.read,
|
read: r.read,
|
||||||
|
|||||||
@@ -1,10 +1,31 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
|
fn visibility_from_str(s: &str) -> domain::models::thought::Visibility {
|
||||||
|
use domain::models::thought::Visibility;
|
||||||
|
match s {
|
||||||
|
"followers" => Visibility::Followers,
|
||||||
|
"unlisted" => Visibility::Unlisted,
|
||||||
|
"direct" => Visibility::Direct,
|
||||||
|
_ => Visibility::Public,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visibility_as_str(v: &domain::models::thought::Visibility) -> &'static str {
|
||||||
|
use domain::models::thought::Visibility;
|
||||||
|
match v {
|
||||||
|
Visibility::Public => "public",
|
||||||
|
Visibility::Followers => "followers",
|
||||||
|
Visibility::Unlisted => "unlisted",
|
||||||
|
Visibility::Direct => "direct",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
use domain::{
|
use domain::{
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
models::{
|
models::{
|
||||||
feed::{PageParams, Paginated},
|
feed::{PageParams, Paginated},
|
||||||
thought::{Thought, Visibility},
|
thought::Thought,
|
||||||
},
|
},
|
||||||
ports::ThoughtRepository,
|
ports::ThoughtRepository,
|
||||||
value_objects::{Content, ThoughtId, UserId},
|
value_objects::{Content, ThoughtId, UserId},
|
||||||
@@ -45,7 +66,7 @@ impl From<ThoughtRow> for Thought {
|
|||||||
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||||
in_reply_to_url: r.in_reply_to_url,
|
in_reply_to_url: r.in_reply_to_url,
|
||||||
ap_id: r.ap_id,
|
ap_id: r.ap_id,
|
||||||
visibility: Visibility::from_db_str(&r.visibility),
|
visibility: visibility_from_str(&r.visibility),
|
||||||
content_warning: r.content_warning,
|
content_warning: r.content_warning,
|
||||||
sensitive: r.sensitive,
|
sensitive: r.sensitive,
|
||||||
local: r.local,
|
local: r.local,
|
||||||
@@ -72,7 +93,7 @@ impl ThoughtRepository for PgThoughtRepository {
|
|||||||
.bind(t.in_reply_to_id.as_ref().map(|x| x.as_uuid()))
|
.bind(t.in_reply_to_id.as_ref().map(|x| x.as_uuid()))
|
||||||
.bind(&t.in_reply_to_url)
|
.bind(&t.in_reply_to_url)
|
||||||
.bind(&t.ap_id)
|
.bind(&t.ap_id)
|
||||||
.bind(t.visibility.as_str())
|
.bind(visibility_as_str(&t.visibility))
|
||||||
.bind(&t.content_warning)
|
.bind(&t.content_warning)
|
||||||
.bind(t.sensitive)
|
.bind(t.sensitive)
|
||||||
.bind(t.local)
|
.bind(t.local)
|
||||||
|
|||||||
@@ -65,8 +65,6 @@ impl TopFriendRepository for PgTopFriendRepository {
|
|||||||
local: bool,
|
local: bool,
|
||||||
ap_id: Option<String>,
|
ap_id: Option<String>,
|
||||||
inbox_url: Option<String>,
|
inbox_url: Option<String>,
|
||||||
public_key: Option<String>,
|
|
||||||
private_key: Option<String>,
|
|
||||||
created_at: chrono::DateTime<chrono::Utc>,
|
created_at: chrono::DateTime<chrono::Utc>,
|
||||||
updated_at: chrono::DateTime<chrono::Utc>,
|
updated_at: chrono::DateTime<chrono::Utc>,
|
||||||
}
|
}
|
||||||
@@ -74,7 +72,7 @@ impl TopFriendRepository for PgTopFriendRepository {
|
|||||||
"SELECT tf.user_id AS tf_user_id, tf.friend_id, tf.position,
|
"SELECT tf.user_id AS tf_user_id, tf.friend_id, tf.position,
|
||||||
u.id, u.username, u.email, u.password_hash, u.display_name, u.bio,
|
u.id, u.username, u.email, u.password_hash, u.display_name, u.bio,
|
||||||
u.avatar_url, u.header_url, u.custom_css, u.local, u.ap_id, u.inbox_url,
|
u.avatar_url, u.header_url, u.custom_css, u.local, u.ap_id, u.inbox_url,
|
||||||
u.public_key, u.private_key, u.created_at, u.updated_at
|
u.created_at, u.updated_at
|
||||||
FROM top_friends tf JOIN users u ON u.id=tf.friend_id
|
FROM top_friends tf JOIN users u ON u.id=tf.friend_id
|
||||||
WHERE tf.user_id=$1 ORDER BY tf.position",
|
WHERE tf.user_id=$1 ORDER BY tf.position",
|
||||||
)
|
)
|
||||||
@@ -105,8 +103,6 @@ impl TopFriendRepository for PgTopFriendRepository {
|
|||||||
local: r.local,
|
local: r.local,
|
||||||
ap_id: r.ap_id,
|
ap_id: r.ap_id,
|
||||||
inbox_url: r.inbox_url,
|
inbox_url: r.inbox_url,
|
||||||
public_key: r.public_key,
|
|
||||||
private_key: r.private_key,
|
|
||||||
created_at: r.created_at,
|
created_at: r.created_at,
|
||||||
updated_at: r.updated_at,
|
updated_at: r.updated_at,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ pub(crate) struct UserRow {
|
|||||||
pub local: bool,
|
pub local: bool,
|
||||||
pub ap_id: Option<String>,
|
pub ap_id: Option<String>,
|
||||||
pub inbox_url: Option<String>,
|
pub inbox_url: Option<String>,
|
||||||
pub public_key: Option<String>,
|
|
||||||
pub private_key: Option<String>,
|
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
pub updated_at: DateTime<Utc>,
|
pub updated_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
@@ -52,15 +50,13 @@ impl From<UserRow> for User {
|
|||||||
local: r.local,
|
local: r.local,
|
||||||
ap_id: r.ap_id,
|
ap_id: r.ap_id,
|
||||||
inbox_url: r.inbox_url,
|
inbox_url: r.inbox_url,
|
||||||
public_key: r.public_key,
|
|
||||||
private_key: r.private_key,
|
|
||||||
created_at: r.created_at,
|
created_at: r.created_at,
|
||||||
updated_at: r.updated_at,
|
updated_at: r.updated_at,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const USER_SELECT: &str = "SELECT id,username,email,password_hash,display_name,bio,avatar_url,header_url,custom_css,local,ap_id,inbox_url,public_key,private_key,created_at,updated_at FROM users";
|
const USER_SELECT: &str = "SELECT id,username,email,password_hash,display_name,bio,avatar_url,header_url,custom_css,local,ap_id,inbox_url,created_at,updated_at FROM users";
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl UserRepository for PgUserRepository {
|
impl UserRepository for PgUserRepository {
|
||||||
@@ -93,15 +89,14 @@ impl UserRepository for PgUserRepository {
|
|||||||
|
|
||||||
async fn save(&self, user: &User) -> Result<(), DomainError> {
|
async fn save(&self, user: &User) -> Result<(), DomainError> {
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"INSERT INTO users (id,username,email,password_hash,display_name,bio,avatar_url,header_url,custom_css,local,ap_id,inbox_url,public_key,private_key,created_at,updated_at)
|
"INSERT INTO users (id,username,email,password_hash,display_name,bio,avatar_url,header_url,custom_css,local,ap_id,inbox_url,created_at,updated_at)
|
||||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16)
|
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)
|
||||||
ON CONFLICT(id) DO UPDATE SET
|
ON CONFLICT(id) DO UPDATE SET
|
||||||
username=EXCLUDED.username, email=EXCLUDED.email,
|
username=EXCLUDED.username, email=EXCLUDED.email,
|
||||||
password_hash=EXCLUDED.password_hash, display_name=EXCLUDED.display_name,
|
password_hash=EXCLUDED.password_hash, display_name=EXCLUDED.display_name,
|
||||||
bio=EXCLUDED.bio, avatar_url=EXCLUDED.avatar_url,
|
bio=EXCLUDED.bio, avatar_url=EXCLUDED.avatar_url,
|
||||||
header_url=EXCLUDED.header_url, custom_css=EXCLUDED.custom_css,
|
header_url=EXCLUDED.header_url, custom_css=EXCLUDED.custom_css,
|
||||||
local=EXCLUDED.local, ap_id=EXCLUDED.ap_id, inbox_url=EXCLUDED.inbox_url,
|
local=EXCLUDED.local, ap_id=EXCLUDED.ap_id, inbox_url=EXCLUDED.inbox_url,
|
||||||
public_key=EXCLUDED.public_key, private_key=EXCLUDED.private_key,
|
|
||||||
updated_at=NOW()"
|
updated_at=NOW()"
|
||||||
)
|
)
|
||||||
.bind(user.id.as_uuid())
|
.bind(user.id.as_uuid())
|
||||||
@@ -116,8 +111,6 @@ impl UserRepository for PgUserRepository {
|
|||||||
.bind(user.local)
|
.bind(user.local)
|
||||||
.bind(&user.ap_id)
|
.bind(&user.ap_id)
|
||||||
.bind(&user.inbox_url)
|
.bind(&user.inbox_url)
|
||||||
.bind(&user.public_key)
|
|
||||||
.bind(&user.private_key)
|
|
||||||
.bind(user.created_at)
|
.bind(user.created_at)
|
||||||
.bind(user.updated_at)
|
.bind(user.updated_at)
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ use domain::{
|
|||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
events::DomainEvent,
|
events::DomainEvent,
|
||||||
models::social::{Block, Boost, Follow, FollowState, Like},
|
models::social::{Block, Boost, Follow, FollowState, Like},
|
||||||
ports::{BlockRepository, BoostRepository, EventPublisher, FollowRepository, LikeRepository},
|
ports::{
|
||||||
value_objects::{BoostId, LikeId, ThoughtId, UserId},
|
BlockRepository, BoostRepository, EventPublisher, FederationActionPort, FollowRepository,
|
||||||
|
LikeRepository, UserRepository,
|
||||||
|
},
|
||||||
|
value_objects::{BoostId, LikeId, ThoughtId, UserId, Username},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn like_thought(
|
pub async fn like_thought(
|
||||||
@@ -87,6 +90,27 @@ pub async fn unboost_thought(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn follow_actor(
|
||||||
|
follows: &dyn FollowRepository,
|
||||||
|
users: &dyn UserRepository,
|
||||||
|
federation: &dyn FederationActionPort,
|
||||||
|
events: &dyn EventPublisher,
|
||||||
|
follower_id: &UserId,
|
||||||
|
username: &str,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
|
if username.contains('@') {
|
||||||
|
federation.follow_remote(follower_id, username).await
|
||||||
|
} else {
|
||||||
|
let uname = Username::new(username)
|
||||||
|
.map_err(|_| DomainError::InvalidInput("invalid username".into()))?;
|
||||||
|
let target = users
|
||||||
|
.find_by_username(&uname)
|
||||||
|
.await?
|
||||||
|
.ok_or(DomainError::NotFound)?;
|
||||||
|
follow_user(follows, events, follower_id, &target.id).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn follow_user(
|
pub async fn follow_user(
|
||||||
follows: &dyn FollowRepository,
|
follows: &dyn FollowRepository,
|
||||||
events: &dyn EventPublisher,
|
events: &dyn EventPublisher,
|
||||||
@@ -315,6 +339,37 @@ mod tests {
|
|||||||
assert!(matches!(err, DomainError::InvalidInput(_)));
|
assert!(matches!(err, DomainError::InvalidInput(_)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn follow_actor_local_routes_to_follow_user() {
|
||||||
|
let store = TestStore::default();
|
||||||
|
let alice = user("alice");
|
||||||
|
let bob = user("bob");
|
||||||
|
store.users.lock().unwrap().push(bob.clone());
|
||||||
|
follow_actor(&store, &store, &store, &store, &alice.id, "bob")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(store.follows.lock().unwrap().len(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn follow_actor_remote_routes_to_federation() {
|
||||||
|
let store = TestStore::default();
|
||||||
|
let alice = user("alice");
|
||||||
|
follow_actor(
|
||||||
|
&store,
|
||||||
|
&store,
|
||||||
|
&store,
|
||||||
|
&store,
|
||||||
|
&alice.id,
|
||||||
|
"@bob@example.com",
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
// TestStore.follow_remote is a no-op that returns Ok(())
|
||||||
|
// no local follow should be recorded
|
||||||
|
assert!(store.follows.lock().unwrap().is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn boost_and_unboost() {
|
async fn boost_and_unboost() {
|
||||||
let store = TestStore::default();
|
let store = TestStore::default();
|
||||||
|
|||||||
@@ -57,11 +57,12 @@ pub async fn create_thought(
|
|||||||
input: CreateThoughtInput,
|
input: CreateThoughtInput,
|
||||||
) -> Result<CreateThoughtOutput, DomainError> {
|
) -> Result<CreateThoughtOutput, DomainError> {
|
||||||
let content = Content::new_local(input.content)?;
|
let content = Content::new_local(input.content)?;
|
||||||
let visibility = input
|
let visibility = match input.visibility.as_deref() {
|
||||||
.visibility
|
Some("followers") => Visibility::Followers,
|
||||||
.as_deref()
|
Some("unlisted") => Visibility::Unlisted,
|
||||||
.map(Visibility::from_db_str)
|
Some("direct") => Visibility::Direct,
|
||||||
.unwrap_or(Visibility::Public);
|
_ => Visibility::Public,
|
||||||
|
};
|
||||||
let thought = Thought::new_local(
|
let thought = Thought::new_local(
|
||||||
ThoughtId::new(),
|
ThoughtId::new(),
|
||||||
input.user_id,
|
input.user_id,
|
||||||
|
|||||||
@@ -9,26 +9,6 @@ pub enum NotificationType {
|
|||||||
Mention,
|
Mention,
|
||||||
Reply,
|
Reply,
|
||||||
}
|
}
|
||||||
impl NotificationType {
|
|
||||||
pub fn from_db_str(s: &str) -> Self {
|
|
||||||
match s {
|
|
||||||
"like" => Self::Like,
|
|
||||||
"boost" => Self::Boost,
|
|
||||||
"follow" => Self::Follow,
|
|
||||||
"mention" => Self::Mention,
|
|
||||||
_ => Self::Reply,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn as_str(&self) -> &str {
|
|
||||||
match self {
|
|
||||||
Self::Like => "like",
|
|
||||||
Self::Boost => "boost",
|
|
||||||
Self::Follow => "follow",
|
|
||||||
Self::Mention => "mention",
|
|
||||||
Self::Reply => "reply",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Notification {
|
pub struct Notification {
|
||||||
|
|||||||
@@ -25,22 +25,6 @@ pub enum FollowState {
|
|||||||
Accepted,
|
Accepted,
|
||||||
Rejected,
|
Rejected,
|
||||||
}
|
}
|
||||||
impl FollowState {
|
|
||||||
pub fn from_db_str(s: &str) -> Self {
|
|
||||||
match s {
|
|
||||||
"pending" => Self::Pending,
|
|
||||||
"rejected" => Self::Rejected,
|
|
||||||
_ => Self::Accepted,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn as_str(&self) -> &str {
|
|
||||||
match self {
|
|
||||||
Self::Pending => "pending",
|
|
||||||
Self::Accepted => "accepted",
|
|
||||||
Self::Rejected => "rejected",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Follow {
|
pub struct Follow {
|
||||||
|
|||||||
@@ -8,24 +8,6 @@ pub enum Visibility {
|
|||||||
Unlisted,
|
Unlisted,
|
||||||
Direct,
|
Direct,
|
||||||
}
|
}
|
||||||
impl Visibility {
|
|
||||||
pub fn from_db_str(s: &str) -> Self {
|
|
||||||
match s {
|
|
||||||
"followers" => Self::Followers,
|
|
||||||
"unlisted" => Self::Unlisted,
|
|
||||||
"direct" => Self::Direct,
|
|
||||||
_ => Self::Public,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn as_str(&self) -> &str {
|
|
||||||
match self {
|
|
||||||
Self::Public => "public",
|
|
||||||
Self::Followers => "followers",
|
|
||||||
Self::Unlisted => "unlisted",
|
|
||||||
Self::Direct => "direct",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Thought {
|
pub struct Thought {
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ pub struct User {
|
|||||||
pub local: bool,
|
pub local: bool,
|
||||||
pub ap_id: Option<String>,
|
pub ap_id: Option<String>,
|
||||||
pub inbox_url: Option<String>,
|
pub inbox_url: Option<String>,
|
||||||
pub public_key: Option<String>,
|
|
||||||
pub private_key: Option<String>,
|
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
pub updated_at: DateTime<Utc>,
|
pub updated_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
@@ -42,8 +40,6 @@ impl User {
|
|||||||
local: true,
|
local: true,
|
||||||
ap_id: None,
|
ap_id: None,
|
||||||
inbox_url: None,
|
inbox_url: None,
|
||||||
public_key: None,
|
|
||||||
private_key: None,
|
|
||||||
created_at: now,
|
created_at: now,
|
||||||
updated_at: now,
|
updated_at: now,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -771,8 +771,6 @@ impl ActivityPubRepository for TestStore {
|
|||||||
local: false,
|
local: false,
|
||||||
ap_id: Some(actor_ap_url.to_string()),
|
ap_id: Some(actor_ap_url.to_string()),
|
||||||
inbox_url: None,
|
inbox_url: None,
|
||||||
public_key: None,
|
|
||||||
private_key: None,
|
|
||||||
created_at: chrono::Utc::now(),
|
created_at: chrono::Utc::now(),
|
||||||
updated_at: chrono::Utc::now(),
|
updated_at: chrono::Utc::now(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,13 +21,23 @@ use axum::{
|
|||||||
use domain::models::feed::PageParams;
|
use domain::models::feed::PageParams;
|
||||||
use domain::value_objects::UserId;
|
use domain::value_objects::UserId;
|
||||||
|
|
||||||
|
fn visibility_as_str(v: &domain::models::thought::Visibility) -> &'static str {
|
||||||
|
use domain::models::thought::Visibility;
|
||||||
|
match v {
|
||||||
|
Visibility::Public => "public",
|
||||||
|
Visibility::Followers => "followers",
|
||||||
|
Visibility::Unlisted => "unlisted",
|
||||||
|
Visibility::Direct => "direct",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn to_thought_response(e: &domain::models::feed::FeedEntry) -> ThoughtResponse {
|
pub fn to_thought_response(e: &domain::models::feed::FeedEntry) -> ThoughtResponse {
|
||||||
ThoughtResponse {
|
ThoughtResponse {
|
||||||
id: e.thought.id.as_uuid(),
|
id: e.thought.id.as_uuid(),
|
||||||
content: e.thought.content.as_str().to_string(),
|
content: e.thought.content.as_str().to_string(),
|
||||||
author: to_user_response(&e.author),
|
author: to_user_response(&e.author),
|
||||||
in_reply_to_id: e.thought.in_reply_to_id.as_ref().map(|id| id.as_uuid()),
|
in_reply_to_id: e.thought.in_reply_to_id.as_ref().map(|id| id.as_uuid()),
|
||||||
visibility: e.thought.visibility.as_str().to_string(),
|
visibility: visibility_as_str(&e.thought.visibility).to_string(),
|
||||||
content_warning: e.thought.content_warning.clone(),
|
content_warning: e.thought.content_warning.clone(),
|
||||||
sensitive: e.thought.sensitive,
|
sensitive: e.thought.sensitive,
|
||||||
like_count: e.like_count,
|
like_count: e.like_count,
|
||||||
|
|||||||
@@ -57,12 +57,15 @@ pub async fn post_follow(
|
|||||||
AuthUser(uid): AuthUser,
|
AuthUser(uid): AuthUser,
|
||||||
Path(username): Path<String>,
|
Path(username): Path<String>,
|
||||||
) -> Result<StatusCode, ApiError> {
|
) -> Result<StatusCode, ApiError> {
|
||||||
if username.contains('@') {
|
follow_actor(
|
||||||
s.federation.follow_remote(&uid, &username).await?;
|
&*s.follows,
|
||||||
} else {
|
&*s.users,
|
||||||
let target = get_user_by_username(&*s.users, &username).await?;
|
&*s.federation,
|
||||||
follow_user(&*s.follows, &*s.events, &uid, &target.id).await?;
|
&*s.events,
|
||||||
}
|
&uid,
|
||||||
|
&username,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
Ok(StatusCode::NO_CONTENT)
|
Ok(StatusCode::NO_CONTENT)
|
||||||
}
|
}
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
|
|||||||
@@ -20,6 +20,16 @@ use axum::{
|
|||||||
use domain::value_objects::ThoughtId;
|
use domain::value_objects::ThoughtId;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
fn visibility_as_str(v: &domain::models::thought::Visibility) -> &'static str {
|
||||||
|
use domain::models::thought::Visibility;
|
||||||
|
match v {
|
||||||
|
Visibility::Public => "public",
|
||||||
|
Visibility::Followers => "followers",
|
||||||
|
Visibility::Unlisted => "unlisted",
|
||||||
|
Visibility::Direct => "direct",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn thought_to_json(
|
fn thought_to_json(
|
||||||
t: &domain::models::thought::Thought,
|
t: &domain::models::thought::Thought,
|
||||||
author: &domain::models::user::User,
|
author: &domain::models::user::User,
|
||||||
@@ -32,7 +42,7 @@ fn thought_to_json(
|
|||||||
"content": t.content.as_str(),
|
"content": t.content.as_str(),
|
||||||
"author": to_user_response(author),
|
"author": to_user_response(author),
|
||||||
"replyToId": t.in_reply_to_id.as_ref().map(|x| x.as_uuid()),
|
"replyToId": t.in_reply_to_id.as_ref().map(|x| x.as_uuid()),
|
||||||
"visibility": t.visibility.as_str(),
|
"visibility": visibility_as_str(&t.visibility),
|
||||||
"contentWarning": t.content_warning,
|
"contentWarning": t.content_warning,
|
||||||
"sensitive": t.sensitive,
|
"sensitive": t.sensitive,
|
||||||
"likeCount": like_count,
|
"likeCount": like_count,
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
FROM nginx:stable-alpine
|
|
||||||
|
|
||||||
RUN rm /etc/nginx/conf.d/default.conf
|
|
||||||
|
|
||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
upstream frontend {
|
|
||||||
server frontend:3000;
|
|
||||||
}
|
|
||||||
|
|
||||||
upstream backend {
|
|
||||||
server backend:8000;
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name localhost;
|
|
||||||
|
|
||||||
location /health {
|
|
||||||
return 200 "OK";
|
|
||||||
access_log off;
|
|
||||||
}
|
|
||||||
|
|
||||||
proxy_connect_timeout 300s;
|
|
||||||
proxy_send_timeout 300s;
|
|
||||||
proxy_read_timeout 300s;
|
|
||||||
send_timeout 300s;
|
|
||||||
|
|
||||||
location /api/ {
|
|
||||||
rewrite /api/(.*) /$1 break;
|
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
|
|
||||||
proxy_pass http://backend;
|
|
||||||
}
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
|
|
||||||
proxy_pass http://frontend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user