Skip to content

Add project likes backend endpoints#175

Open
raza-khan0108 wants to merge 1 commit intoTheSoftwareDevGuild:mainfrom
raza-khan0108:codex/project-likes-backend
Open

Add project likes backend endpoints#175
raza-khan0108 wants to merge 1 commit intoTheSoftwareDevGuild:mainfrom
raza-khan0108:codex/project-likes-backend

Conversation

@raza-khan0108
Copy link

Summary

Adds backend support for “likes” on projects. Any authenticated user (JWT via existing Authorization: Bearer ... handling) can like/unlike a project, with a hard guarantee of one like per user per project.

What changed

Database

  • Added project_likes table via backend/migrations/006_create_project_likes_table.sql
    • Columns: project_id (UUID), user_address (VARCHAR(42)), created_at (timestamptz)
    • Primary key: (project_id, user_address) to enforce one-like-per-user-per-project
    • Foreign key: project_id -> projects(id) with ON DELETE CASCADE
    • Indexes on project_id and user_address

Domain / Infrastructure

  • New repository abstraction: ProjectLikeRepository
  • New Postgres implementation: PostgresProjectLikeRepository

API

Routes added:

  • POST /projects/:id/likes (protected)
    • Creates a like for the authenticated user
    • Returns 201 Created
    • Returns 409 Conflict if the like already exists
    • Returns 404 Not Found if the project doesn’t exist
  • DELETE /projects/:id/likes (protected)
    • Removes the authenticated user’s like
    • Returns 204 No Content
    • Returns 404 Not Found if the like doesn’t exist (or project doesn’t exist)
  • GET /projects/:id/likes?limit=&offset= (public)
    • Lists likes for a project (paginated)
    • Returns { project_id, total, likes: [{ user_address, created_at }, ...] }

Behavior / Constraints

  • Idempotency:
    • POST is not idempotent: duplicate like attempts return 409
    • DELETE is not idempotent: deleting a non-existent like returns 404
  • Project existence is validated for all three endpoints.
  • User identity comes from the existing auth middleware (VerifiedWallet), including JWT support already implemented in the codebase.

Files of note

  • Migration: backend/migrations/006_create_project_likes_table.sql
  • API wiring: backend/src/presentation/api.rs
  • Handlers: backend/src/presentation/handlers.rs
  • DTOs: backend/src/application/dtos/like_dtos.rs
  • Commands/Query:
    • backend/src/application/commands/create_project_like.rs
    • backend/src/application/commands/delete_project_like.rs
    • backend/src/application/queries/get_project_likes.rs
  • Repository + Postgres implementation:
    • backend/src/domain/repositories/project_like_repository.rs
    • backend/src/infrastructure/repositories/postgres_project_like_repository.rs

Testing

  • Added router-level API tests (no DB required):
    • backend/tests/project_likes_api_tests.rs validates the CRD flow and status codes.
  • Updated existing Postgres integration tests to skip cleanly when Postgres is unavailable:
    • backend/tests/integration_github_handle.rs

Run:

  • cd backend
  • cargo test

Notes / Follow-ups

  • If we later want “like count” returned on GET /projects/:id, we can extend get_project/project DTOs to include likes_total (and optionally liked_by_me when authenticated).

@joelamouche
Copy link
Contributor

Hi @raza-khan0108 ,

First of all welcome to the project!

A few things...

Best,

Antoine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments