merge upstream
All checks were successful
mnemo-build-and-publish / gractwo-mnemo-build (push) Successful in 44s
All checks were successful
mnemo-build-and-publish / gractwo-mnemo-build (push) Successful in 44s
This commit is contained in:
@@ -42,6 +42,7 @@ pub fn api_router() -> Router {
|
||||
.route("/api/persons/{id}", get(persons::get_by_id))
|
||||
.route("/api/persons/{id}/names", get(persons::pid_names))
|
||||
.route("/api/persons/{id}/addname", post(persons::add_name))
|
||||
.route("/api/names", get(persons::n_all))
|
||||
.route("/api/names/{id}", get(persons::n_by_id))
|
||||
.route("/api/names/{id}/setprimary", post(persons::n_setprimary))
|
||||
// quotes
|
||||
|
||||
@@ -93,6 +93,11 @@ pub async fn add_name(
|
||||
Ok((StatusCode::CREATED, Json(n)).into_response())
|
||||
}
|
||||
|
||||
pub async fn n_all(headers: HeaderMap) -> Result<Response, CompositeError> {
|
||||
User::authenticate(&headers)?.required()?;
|
||||
let conn = database::conn()?;
|
||||
Ok(Json(Name::get_all(&conn)?).into_response())
|
||||
}
|
||||
pub async fn n_by_id(Path(id): Path<Uuid>, headers: HeaderMap) -> Result<Response, CompositeError> {
|
||||
User::authenticate(&headers)?.required()?;
|
||||
let conn = database::conn()?;
|
||||
|
||||
@@ -113,6 +113,20 @@ impl Quote {
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
pub fn get_newest_public(conn: &Connection) -> Result<Option<Quote>, QuoteError> {
|
||||
let id: Option<Uuid> = conn
|
||||
.query_row(
|
||||
"SELECT id FROM quotes ORDER BY id DESC LIMIT 1 WHERE public = 1",
|
||||
(),
|
||||
|r| r.get(0),
|
||||
)
|
||||
.optional()?;
|
||||
|
||||
match id {
|
||||
Some(id) => Ok(Some(Self::get_by_id(conn, id)?)),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
pub fn get_chronological_offset(
|
||||
conn: &Connection,
|
||||
offset: i64,
|
||||
|
||||
@@ -25,7 +25,10 @@ pub async fn page(req: Request) -> Result<Markup, CompositeError> {
|
||||
let u = User::authenticate(req.headers()).ok().flatten();
|
||||
let conn = database::conn()?;
|
||||
|
||||
let newest_quote = Quote::get_newest(&conn)?;
|
||||
let newest_quote = match u {
|
||||
Some(_) => Quote::get_newest(&conn)?,
|
||||
None => Quote::get_newest_public(&conn)?,
|
||||
};
|
||||
|
||||
Ok(base(
|
||||
"Dashboard | Mnemosyne",
|
||||
|
||||
Reference in New Issue
Block a user