"We Met" scan experience — capture connections on scan
Experience #1 from the scan-experiences brief: when someone scans a card and shares back, capture the meeting (with coarse geo + time) so the owner gets a "People I met" list. Backend (cardclaws-backend): - migration 0006_connections.sql: connections table (card_id, owner_id, name, email, note, country, city, met_at). Raw IP never stored — only resolved geo. - POST /v1/profile/:handle/connect (public, rate-limited 5/min): captures the connection with geo, emails the owner best-effort. - GET /v1/cards/:id/connections (owner-only): the People-I-met list. - ConnectionRow model + connections queries (insert, list_by_card); profile_service::submit_connection; card_service::list_connections. - 2 tests (capture→owner-list + validation, owner-only); gate green (118 tests). - Verified live end-to-end. Web (cardclaws-profile): - [handle].astro: a "We met?" share-back form posting to /connect; astro check clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
5aba3ef1a1
commit
256f2285b9
@@ -0,0 +1,17 @@
|
||||
-- "We Met" scan experience (PRD §21 Phase 5): when someone scans a card and
|
||||
-- shares back, we capture the meeting (with coarse geo + time) so the owner gets
|
||||
-- a "People I met" list. Raw IP is never stored — only the resolved country/city.
|
||||
CREATE TABLE connections (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
card_id UUID NOT NULL REFERENCES cards(id) ON DELETE CASCADE,
|
||||
owner_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
name TEXT NOT NULL,
|
||||
email TEXT,
|
||||
note TEXT,
|
||||
country TEXT,
|
||||
city TEXT,
|
||||
met_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_connections_card ON connections(card_id, met_at DESC);
|
||||
CREATE INDEX idx_connections_owner ON connections(owner_id, met_at DESC);
|
||||
@@ -0,0 +1,19 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::Serialize;
|
||||
use sqlx::FromRow;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// A "We Met" connection — someone who scanned a card and shared back.
|
||||
#[derive(Debug, Clone, FromRow, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ConnectionRow {
|
||||
pub id: Uuid,
|
||||
pub card_id: Uuid,
|
||||
pub owner_id: Uuid,
|
||||
pub name: String,
|
||||
pub email: Option<String>,
|
||||
pub note: Option<String>,
|
||||
pub country: Option<String>,
|
||||
pub city: Option<String>,
|
||||
pub met_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
pub mod analytics;
|
||||
pub mod card;
|
||||
pub mod connection;
|
||||
pub mod session;
|
||||
pub mod share_link;
|
||||
pub mod team;
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
//! "We Met" connection queries.
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::models::connection::ConnectionRow;
|
||||
use crate::Db;
|
||||
|
||||
pub struct NewConnection<'a> {
|
||||
pub card_id: Uuid,
|
||||
pub owner_id: Uuid,
|
||||
pub name: &'a str,
|
||||
pub email: Option<&'a str>,
|
||||
pub note: Option<&'a str>,
|
||||
pub country: Option<&'a str>,
|
||||
pub city: Option<&'a str>,
|
||||
}
|
||||
|
||||
pub async fn insert(db: &Db, new: NewConnection<'_>) -> Result<ConnectionRow, sqlx::Error> {
|
||||
sqlx::query_as(
|
||||
r#"
|
||||
INSERT INTO connections (card_id, owner_id, name, email, note, country, city)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id, card_id, owner_id, name, email, note, country, city, met_at
|
||||
"#,
|
||||
)
|
||||
.bind(new.card_id)
|
||||
.bind(new.owner_id)
|
||||
.bind(new.name)
|
||||
.bind(new.email)
|
||||
.bind(new.note)
|
||||
.bind(new.country)
|
||||
.bind(new.city)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Most-recent-first connections captured for a card.
|
||||
pub async fn list_by_card(db: &Db, card_id: Uuid) -> Result<Vec<ConnectionRow>, sqlx::Error> {
|
||||
sqlx::query_as(
|
||||
r#"SELECT id, card_id, owner_id, name, email, note, country, city, met_at
|
||||
FROM connections WHERE card_id = $1 ORDER BY met_at DESC LIMIT 200"#,
|
||||
)
|
||||
.bind(card_id)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
pub mod analytics;
|
||||
pub mod cards;
|
||||
pub mod connections;
|
||||
pub mod export;
|
||||
pub mod sessions;
|
||||
pub mod share;
|
||||
|
||||
Reference in New Issue
Block a user