40ab5c7feat: /api/me and a shared identity read model1mo | 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | use serde::Serialize; |
| 8 | use topcoat::{ |
| 9 | Result, |
| 10 | context::Cx, |
| 11 | router::{content::Json, error::unauthorized, route}, |
| 12 | }; |
| 13 | |
| 14 | use super::context::identity; |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | #[derive(Debug, Serialize)] |
| 22 | struct Me { |
| 23 | id: String, |
| 24 | email: String, |
| 25 | handle: String, |
| 26 | } |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | #[route(GET "/api/me")] |
| 33 | async fn me(cx: &Cx) -> Result<Json<Me>> { |
| 34 | let identity = identity(cx).await?.ok_or_else(unauthorized)?; |
| 35 | |
| 36 | Ok(Json(Me { |
| 37 | id: identity.user_id.to_string(), |
| 38 | email: identity.email.to_string(), |
| 39 | handle: identity.handle.to_string(), |
| 40 | })) |
| 41 | } |
a69e380feat: public profile page at /{handle}1mo | 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | #[derive(Debug, Serialize)] |
| 48 | struct Profile { |
| 49 | handle: String, |
| 50 | label: String, |
| 51 | bio: Option<String>, |
| 52 | viewer_is_owner: bool, |
| 53 | } |
| 54 | |
| 55 | #[route(GET "/api/users/{handle}")] |
| 56 | async fn user(cx: &Cx) -> Result<Json<Profile>> { |
| 57 | let profile = super::profile::profile_for(cx).await?; |
| 58 | |
| 59 | Ok(Json(Profile { |
| 60 | handle: profile.handle.to_string(), |
| 61 | label: profile.label, |
| 62 | bio: profile.bio, |
| 63 | viewer_is_owner: profile.viewer_is_owner, |
| 64 | })) |
| 65 | } |