summaryrefslogtreecommitdiff
path: root/src/repo
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-09-18 22:49:38 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-09-20 16:42:44 -0400
commit22348bfa35f009e62abe2f30863e0434079a1fe2 (patch)
treec5b5b5e660a1ee2a05785f4669102c1023b6e7b0 /src/repo
parentaafdeb9ffaf9a993ca4462b3422667e04469b2e3 (diff)
Remove the HTML client, and expose a JSON API.
This API structure fell out of a conversation with Kit. Described loosely: kit: ok kit: Here's what I'm picturing in a client kit: list channels, make-new-channel, zero to one active channels, post-to-active. kit: login/sign-up, logout owen: you will likely also want "am I logged in" here kit: sure, whoami
Diffstat (limited to 'src/repo')
-rw-r--r--src/repo/channel.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/repo/channel.rs b/src/repo/channel.rs
index 8e3a471..95516d2 100644
--- a/src/repo/channel.rs
+++ b/src/repo/channel.rs
@@ -16,7 +16,7 @@ impl<'c> Provider for Transaction<'c, Sqlite> {
pub struct Channels<'t>(&'t mut SqliteConnection);
-#[derive(Debug)]
+#[derive(Debug, serde::Serialize)]
pub struct Channel {
pub id: Id,
pub name: String,
@@ -24,15 +24,16 @@ pub struct Channel {
impl<'c> Channels<'c> {
/// Create a new channel.
- pub async fn create(&mut self, name: &str) -> Result<Id, sqlx::Error> {
+ pub async fn create(&mut self, name: &str) -> Result<Channel, sqlx::Error> {
let id = Id::generate();
- let channel = sqlx::query_scalar!(
+ let channel = sqlx::query_as!(
+ Channel,
r#"
insert
into channel (id, name)
values ($1, $2)
- returning id as "id: Id"
+ returning id as "id: Id", name
"#,
id,
name,