-
Notifications
You must be signed in to change notification settings - Fork 16
Front End: CRUD profiles, badges, attestations #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cf6ba32
create hook and components to create a user profile
joelamouche f5fc3f2
add readme to backend
joelamouche c15d837
use wagmi to sign message and create profile
joelamouche d9cbe3d
add get all profiles to backend
joelamouche 5b2b836
add edit profile logic
joelamouche 946ccef
fix tests
joelamouche b20c4b0
Merge branch 'main' into create-profile
joelamouche e3cdaf6
fix tests
joelamouche 6470b61
add delete fun in profiles
joelamouche 4138369
fmt backend
joelamouche 99a1605
list badges in the front end
joelamouche 269c3e4
allow badge creation in the front end
joelamouche 09599b4
allow searching badges
joelamouche 65abfb7
allow searching profiles
joelamouche 452c9b3
create and fetch attestations
joelamouche 3bfc3db
refactor files in appropriate folders
joelamouche bb35c26
add profile page
joelamouche bb293d5
fix fe test
joelamouche 95883cb
fix build with node adapter
joelamouche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # Guild Backend (Rust + Axum + SQLx) | ||
|
|
||
| This service exposes a REST API for managing profiles, backed by PostgreSQL. | ||
|
|
||
| - HTTP: 0.0.0.0:3001 | ||
| - DB: PostgreSQL (SQLx) | ||
| - Migrations: SQLx migrator (on startup and via `bin/migrate`) | ||
|
|
||
| ## 1) Prerequisites | ||
| - Rust (latest stable recommended) | ||
| - PostgreSQL 14+ (`initdb`, `pg_ctl`, `psql` available) | ||
|
|
||
| ## 2) Environment | ||
| Create `backend/.env`: | ||
| ``` | ||
| DATABASE_URL=postgresql://guild_user:guild_password@localhost:5432/guild_genesis | ||
| RUST_LOG=guild_backend=debug,tower_http=debug | ||
| ``` | ||
| The server requires `DATABASE_URL` at runtime. | ||
|
|
||
| ## 3) Start local Postgres | ||
| From the repo root, using Just: | ||
| ``` | ||
| just db-setup | ||
| ``` | ||
| This will: | ||
| - init `.postgres/` if missing | ||
| - start Postgres on localhost:5432 | ||
| - create DB `guild_genesis` and user `guild_user/guild_password` | ||
| - run backend migrations | ||
|
|
||
| Manual alternative (repo root): | ||
| ``` | ||
| initdb -D .postgres | ||
| pg_ctl -D .postgres -l .postgres/postgres.log start | ||
|
|
||
| createdb guild_genesis || true | ||
| psql -d guild_genesis -c "CREATE USER guild_user WITH PASSWORD 'guild_password';" || true | ||
| psql -d guild_genesis -c "GRANT ALL PRIVILEGES ON DATABASE guild_genesis TO guild_user;" || true | ||
| ``` | ||
| Stop Postgres: | ||
| ``` | ||
| pg_ctl -D .postgres stop | ||
| ``` | ||
|
|
||
| ## 4) Run migrations (optional) | ||
| Migrations run on server startup. To run explicitly: | ||
| ``` | ||
| cd backend | ||
| cargo run --bin guild-backend | ||
| ``` | ||
|
|
||
| ## 5) Launch the API | ||
| ``` | ||
| cd backend | ||
| cargo run | ||
| ``` | ||
| The server listens on `http://0.0.0.0:3001`. | ||
|
|
||
| ## 6) API quickstart | ||
| All endpoints require Ethereum header-based auth. | ||
|
|
||
| Create profile: | ||
| ``` | ||
| curl -X POST \ | ||
| -H 'Content-Type: application/json' \ | ||
| -H 'x-eth-address: 0x2581aAa94299787a8A588B2Fceb161A302939E28' \ | ||
| -H 'x-eth-signature: 0x00000000000000' \ | ||
| -H 'x-siwe-message: LOGIN_NONCE' \ | ||
| -d '{ | ||
| "name": "My profile", | ||
| "description": "Hello world", | ||
| "avatar_url": "https://example.com/avatar.png" | ||
| }' \ | ||
| http://0.0.0.0:3001/profiles/ | ||
| ``` | ||
| Get profile: | ||
| ``` | ||
| curl -H 'x-eth-address: 0x2581aAa94299787a8A588B2Fceb161A302939E28' \ | ||
| -H 'x-eth-signature: 0x00000000000000' \ | ||
| -H 'x-siwe-message: LOGIN_NONCE' \ | ||
| http://0.0.0.0:3001/profiles/0x2581aAa94299787a8A588B2Fceb161A302939E28 | ||
| ``` | ||
| Update profile: | ||
| ``` | ||
| curl -X PUT \ | ||
| -H 'Content-Type: application/json' \ | ||
| -H 'x-eth-address: 0x2581aAa94299787a8A588B2Fceb161A302939E28' \ | ||
| -H 'x-eth-signature: 0x00000000000000' \ | ||
| -H 'x-siwe-message: LOGIN_NONCE' \ | ||
| -d '{ "name": "New name", "description": "New desc" }' \ | ||
| http://0.0.0.0:3001/profiles/0x2581aAa94299787a8A588B2Fceb161A302939E28 | ||
| ``` | ||
|
|
||
| ## 7) Troubleshooting | ||
| - initdb locale error: | ||
| ``` | ||
| LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 initdb --locale=en_US.UTF-8 --encoding=UTF8 -D .postgres | ||
| ``` | ||
| - Permission denied on schema `public`: | ||
| ``` | ||
| psql -U postgres -d guild_genesis -c "ALTER SCHEMA public OWNER TO guild_user;" | ||
| psql -U postgres -d guild_genesis -c "GRANT USAGE, CREATE ON SCHEMA public TO guild_user;" | ||
| ``` | ||
| - Rust edition 2024 error: repo pins `base64ct = 1.7.3`. If still present, `rustup update` or `rustup override set nightly` in `backend/`. | ||
|
|
||
| ## 8) Structure | ||
| - `src/main.rs`: boot server, run migrations | ||
| - `src/bin/migrate.rs`: standalone migrator | ||
| - `src/presentation`: routes, handlers, middlewares | ||
| - `src/infrastructure`: Postgres repository, Ethereum verification | ||
| - `src/domain`: entities, repository traits, services | ||
| - `src/application`: commands and DTOs | ||
| - `migrations/`: SQLx migrations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| use crate::application::dtos::profile_dtos::ProfileResponse; | ||
| use crate::domain::repositories::profile_repository::ProfileRepository; | ||
| use std::sync::Arc; | ||
|
|
||
| pub async fn get_all_profiles( | ||
| profile_repository: Arc<dyn ProfileRepository + 'static>, | ||
| ) -> Result<Vec<ProfileResponse>, String> { | ||
| let profiles = profile_repository | ||
| .find_all() | ||
| .await | ||
| .map_err(|e| e.to_string())?; | ||
|
|
||
| Ok(profiles | ||
| .into_iter() | ||
| .map(|profile| ProfileResponse { | ||
| address: profile.address, | ||
| name: profile.name.unwrap_or_default(), | ||
| description: profile.description, | ||
| avatar_url: profile.avatar_url, | ||
| created_at: profile.created_at, | ||
| updated_at: profile.updated_at, | ||
| }) | ||
| .collect()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| pub mod create_profile; | ||
| pub mod get_all_profiles; | ||
| pub mod get_profile; | ||
| pub mod update_profile; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,10 @@ use tower_http::{ | |
| }; | ||
|
|
||
| use super::handlers::{ | ||
| create_profile_handler, delete_profile_handler, get_profile_handler, update_profile_handler, | ||
| create_profile_handler, delete_profile_handler, get_all_profiles_handler, get_profile_handler, | ||
| update_profile_handler, | ||
| }; | ||
|
|
||
| use super::middlewares::eth_auth_layer; | ||
|
|
||
| pub async fn create_app(pool: sqlx::PgPool) -> Router { | ||
|
|
@@ -35,12 +37,19 @@ pub async fn create_app(pool: sqlx::PgPool) -> Router { | |
|
|
||
| let protected = Router::new() | ||
| .route("/profiles/", post(create_profile_handler)) | ||
| .route("/profiles/:address", get(get_profile_handler)) | ||
| .route("/profiles/:address", put(update_profile_handler)) | ||
| .route("/profiles/:address", delete(delete_profile_handler)); | ||
| .route("/profiles/:address", delete(delete_profile_handler)) | ||
| .with_state(state.clone()) | ||
| .layer(from_fn_with_state(state.clone(), eth_auth_layer)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
| let public = Router::new() | ||
| .route("/profiles/:address", get(get_profile_handler)) | ||
| .route("/profiles/", get(get_all_profiles_handler)) | ||
| .with_state(state.clone()); | ||
|
|
||
| Router::new() | ||
| .nest("/", protected) | ||
| .merge(public) | ||
| .with_state(state.clone()) | ||
| .layer( | ||
| ServiceBuilder::new() | ||
|
|
@@ -51,8 +60,7 @@ pub async fn create_app(pool: sqlx::PgPool) -> Router { | |
| .allow_methods([Method::GET, Method::POST, Method::PUT, Method::DELETE]) | ||
| .allow_headers(Any), | ||
| ) | ||
| .layer(DefaultBodyLimit::max(1024 * 1024)) | ||
| .layer(from_fn_with_state(state, eth_auth_layer)), | ||
| .layer(DefaultBodyLimit::max(1024 * 1024)), | ||
| ) | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| [["Map",1,2],"meta::meta",["Map",3,4,5,6],"astro-version","5.13.7","astro-config-digest","{\"root\":{},\"srcDir\":{},\"publicDir\":{},\"outDir\":{},\"cacheDir\":{},\"compressHTML\":true,\"base\":\"/\",\"trailingSlash\":\"ignore\",\"output\":\"static\",\"scopedStyleStrategy\":\"attribute\",\"build\":{\"format\":\"directory\",\"client\":{},\"server\":{},\"assets\":\"_astro\",\"serverEntry\":\"entry.mjs\",\"redirects\":true,\"inlineStylesheets\":\"auto\",\"concurrency\":1},\"server\":{\"open\":false,\"host\":false,\"port\":4321,\"streaming\":true,\"allowedHosts\":[]},\"redirects\":{},\"image\":{\"endpoint\":{\"route\":\"/_image\"},\"service\":{\"entrypoint\":\"astro/assets/services/sharp\",\"config\":{}},\"domains\":[],\"remotePatterns\":[],\"responsiveStyles\":false},\"devToolbar\":{\"enabled\":true},\"markdown\":{\"syntaxHighlight\":{\"type\":\"shiki\",\"excludeLangs\":[\"math\"]},\"shikiConfig\":{\"langs\":[],\"langAlias\":{},\"theme\":\"github-dark\",\"themes\":{},\"wrap\":false,\"transformers\":[]},\"remarkPlugins\":[],\"rehypePlugins\":[],\"remarkRehype\":{},\"gfm\":true,\"smartypants\":true},\"security\":{\"checkOrigin\":true},\"env\":{\"schema\":{},\"validateSecrets\":false},\"experimental\":{\"clientPrerender\":false,\"contentIntellisense\":false,\"headingIdCompat\":false,\"preserveScriptOrder\":false,\"liveContentCollections\":false,\"csp\":false,\"staticImportMetaEnv\":false,\"chromeDevtoolsWorkspace\":false},\"legacy\":{\"collections\":false}}"] | ||
| [["Map",1,2],"meta::meta",["Map",3,4,5,6],"astro-version","5.13.7","astro-config-digest","{\"root\":{},\"srcDir\":{},\"publicDir\":{},\"outDir\":{},\"cacheDir\":{},\"compressHTML\":true,\"base\":\"/\",\"trailingSlash\":\"ignore\",\"output\":\"server\",\"scopedStyleStrategy\":\"attribute\",\"build\":{\"format\":\"directory\",\"client\":{},\"server\":{},\"assets\":\"_astro\",\"serverEntry\":\"entry.mjs\",\"redirects\":true,\"inlineStylesheets\":\"auto\",\"concurrency\":1},\"server\":{\"open\":false,\"host\":false,\"port\":4321,\"streaming\":true,\"allowedHosts\":[]},\"redirects\":{},\"image\":{\"endpoint\":{\"route\":\"/_image\",\"entrypoint\":\"astro/assets/endpoint/node\"},\"service\":{\"entrypoint\":\"astro/assets/services/sharp\",\"config\":{}},\"domains\":[],\"remotePatterns\":[],\"responsiveStyles\":false},\"devToolbar\":{\"enabled\":true},\"markdown\":{\"syntaxHighlight\":{\"type\":\"shiki\",\"excludeLangs\":[\"math\"]},\"shikiConfig\":{\"langs\":[],\"langAlias\":{},\"theme\":\"github-dark\",\"themes\":{},\"wrap\":false,\"transformers\":[]},\"remarkPlugins\":[],\"rehypePlugins\":[],\"remarkRehype\":{},\"gfm\":true,\"smartypants\":true},\"security\":{\"checkOrigin\":true},\"env\":{\"schema\":{},\"validateSecrets\":false},\"experimental\":{\"clientPrerender\":false,\"contentIntellisense\":false,\"headingIdCompat\":false,\"preserveScriptOrder\":false,\"liveContentCollections\":false,\"csp\":false,\"staticImportMetaEnv\":false,\"chromeDevtoolsWorkspace\":false},\"legacy\":{\"collections\":false},\"session\":{\"driver\":\"fs-lite\",\"options\":{\"base\":\"/Users/antoineestienne/GithubRepositories/TheGuildGenesis/frontend/node_modules/.astro/sessions\"}}}"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| /// <reference types="astro/client" /> | ||
| /// <reference path="content.d.ts" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍👍👍