Add project likes backend endpoints#175
Open
raza-khan0108 wants to merge 1 commit intoTheSoftwareDevGuild:mainfrom
Open
Add project likes backend endpoints#175raza-khan0108 wants to merge 1 commit intoTheSoftwareDevGuild:mainfrom
raza-khan0108 wants to merge 1 commit intoTheSoftwareDevGuild:mainfrom
Conversation
Contributor
|
Hi @raza-khan0108 , First of all welcome to the project! A few things...
Best, Antoine |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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
project_likestable viabackend/migrations/006_create_project_likes_table.sqlproject_id (UUID),user_address (VARCHAR(42)),created_at (timestamptz)(project_id, user_address)to enforce one-like-per-user-per-projectproject_id -> projects(id)withON DELETE CASCADEproject_idanduser_addressDomain / Infrastructure
ProjectLikeRepositoryPostgresProjectLikeRepositoryAPI
Routes added:
POST /projects/:id/likes(protected)201 Created409 Conflictif the like already exists404 Not Foundif the project doesn’t existDELETE /projects/:id/likes(protected)204 No Content404 Not Foundif the like doesn’t exist (or project doesn’t exist)GET /projects/:id/likes?limit=&offset=(public){ project_id, total, likes: [{ user_address, created_at }, ...] }Behavior / Constraints
POSTis not idempotent: duplicate like attempts return409DELETEis not idempotent: deleting a non-existent like returns404VerifiedWallet), including JWT support already implemented in the codebase.Files of note
backend/migrations/006_create_project_likes_table.sqlbackend/src/presentation/api.rsbackend/src/presentation/handlers.rsbackend/src/application/dtos/like_dtos.rsbackend/src/application/commands/create_project_like.rsbackend/src/application/commands/delete_project_like.rsbackend/src/application/queries/get_project_likes.rsbackend/src/domain/repositories/project_like_repository.rsbackend/src/infrastructure/repositories/postgres_project_like_repository.rsTesting
backend/tests/project_likes_api_tests.rsvalidates the CRD flow and status codes.backend/tests/integration_github_handle.rsRun:
cd backendcargo testNotes / Follow-ups
GET /projects/:id, we can extendget_project/project DTOs to includelikes_total(and optionallyliked_by_mewhen authenticated).