feat: show user avatars on /users page
All checks were successful
CI / Check / Test / Build (push) Successful in 24m46s
All checks were successful
CI / Check / Test / Build (push) Successful in 24m46s
This commit is contained in:
@@ -229,6 +229,7 @@ pub(crate) struct UserSummaryRow {
|
||||
pub email: String,
|
||||
pub total_movies: i64,
|
||||
pub avg_rating: Option<f64>,
|
||||
pub avatar_path: Option<String>,
|
||||
}
|
||||
|
||||
impl UserSummaryRow {
|
||||
@@ -238,6 +239,7 @@ impl UserSummaryRow {
|
||||
Email::new(self.email)?,
|
||||
self.total_movies,
|
||||
self.avg_rating,
|
||||
self.avatar_path,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,10 +270,11 @@ impl UserRepository for PostgresUserRepository {
|
||||
sqlx::query_as::<_, UserSummaryRow>(
|
||||
r#"SELECT u.id, u.email,
|
||||
COUNT(DISTINCT r.movie_id) AS total_movies,
|
||||
AVG(r.rating::float) AS avg_rating
|
||||
AVG(r.rating::float) AS avg_rating,
|
||||
u.avatar_path
|
||||
FROM users u
|
||||
LEFT JOIN reviews r ON r.user_id = u.id AND r.remote_actor_url IS NULL
|
||||
GROUP BY u.id, u.email
|
||||
GROUP BY u.id, u.email, u.avatar_path
|
||||
ORDER BY u.email ASC"#,
|
||||
)
|
||||
.fetch_all(&self.pool)
|
||||
|
||||
@@ -240,6 +240,7 @@ pub(crate) struct UserSummaryRow {
|
||||
pub email: String,
|
||||
pub total_movies: i64,
|
||||
pub avg_rating: Option<f64>,
|
||||
pub avatar_path: Option<String>,
|
||||
}
|
||||
|
||||
impl UserSummaryRow {
|
||||
@@ -249,6 +250,7 @@ impl UserSummaryRow {
|
||||
Email::new(self.email)?,
|
||||
self.total_movies,
|
||||
self.avg_rating,
|
||||
self.avatar_path,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,10 +229,11 @@ impl UserRepository for SqliteUserRepository {
|
||||
r#"SELECT u.id AS "id!: String",
|
||||
u.email AS "email!: String",
|
||||
COUNT(DISTINCT r.movie_id) AS "total_movies!: i64",
|
||||
AVG(CAST(r.rating AS REAL)) AS avg_rating
|
||||
AVG(CAST(r.rating AS REAL)) AS avg_rating,
|
||||
u.avatar_path
|
||||
FROM users u
|
||||
LEFT JOIN reviews r ON r.user_id = u.id AND r.remote_actor_url IS NULL
|
||||
GROUP BY u.id, u.email
|
||||
GROUP BY u.id, u.email, u.avatar_path
|
||||
ORDER BY u.email ASC"#
|
||||
)
|
||||
.fetch_all(&self.pool)
|
||||
|
||||
@@ -170,6 +170,7 @@ struct UserSummaryView {
|
||||
initial: char,
|
||||
avg_rating_display: String,
|
||||
total_movies: i64,
|
||||
avatar_url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
@@ -495,6 +496,7 @@ impl HtmlRenderer for AskamaHtmlRenderer {
|
||||
initial,
|
||||
avg_rating_display,
|
||||
total_movies: u.total_movies,
|
||||
avatar_url: u.avatar_path.as_ref().map(|p| format!("/images/{}", p)),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -12,7 +12,11 @@
|
||||
{% endif %}
|
||||
{% for user in users %}
|
||||
<div class="user-row">
|
||||
{% if let Some(url) = &user.avatar_url %}
|
||||
<img class="user-avatar user-avatar-img" src="{{ url }}" alt="{{ user.initial }}" style="width:40px;height:40px;border-radius:50%;object-fit:cover;">
|
||||
{% else %}
|
||||
<div class="user-avatar">{{ user.initial }}</div>
|
||||
{% endif %}
|
||||
<div class="user-info">
|
||||
<div class="user-name">{{ user.display_name }}</div>
|
||||
<div class="user-meta">{{ user.total_movies }} movies · avg {{ user.avg_rating_display }}★</div>
|
||||
|
||||
@@ -461,15 +461,23 @@ pub struct UserSummary {
|
||||
email: Email,
|
||||
pub total_movies: i64,
|
||||
pub avg_rating: Option<f64>,
|
||||
pub avatar_path: Option<String>,
|
||||
}
|
||||
|
||||
impl UserSummary {
|
||||
pub fn new(user_id: UserId, email: Email, total_movies: i64, avg_rating: Option<f64>) -> Self {
|
||||
pub fn new(
|
||||
user_id: UserId,
|
||||
email: Email,
|
||||
total_movies: i64,
|
||||
avg_rating: Option<f64>,
|
||||
avatar_path: Option<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
user_id,
|
||||
email,
|
||||
total_movies,
|
||||
avg_rating,
|
||||
avatar_path,
|
||||
}
|
||||
}
|
||||
pub fn email(&self) -> &str {
|
||||
|
||||
Reference in New Issue
Block a user