This pull request introduces the backend infrastructure for managing bookmarks within the application. It adds schema definitions, server actions, and API endpoints necessary to support bookmarking functionality for users, allowing them to save listings.
Changes Overview
Database Schema:
Added a Bookmark model to create a many-to-many relationship between User and Listing.
Defined relations to enable seamless querying and management of bookmarks in the Prisma schema.
Updated the schema with referential integrity constraints and default values where applicable.
Server Actions:
Created CRUD server actions in the actions/user folder to handle bookmarking operations.
Implemented the following actions:
Add Bookmark: Allows users to bookmark listings.
Remove Bookmark: Deletes a bookmark for a user.
Get All Bookmarks: Retrieves all bookmarks for a specific user.
Check Bookmark Existence: Confirms if a particular listing is bookmarked by a user.
Each server action follows consistent error handling and success responses, enabling clear communication between the backend and frontend.
API Endpoints:
Built RESTful API endpoints to test and interact with the server actions in a structured manner.
The following API routes were created:
POST: /api/bookmark/:userId/:listingId - Adds a bookmark for a specific user and listing.
DELETE: /api/bookmark/:userId/:listingId - Removes a bookmark.
GET: /api/bookmark/:userId - Retrieves all bookmarks for a user.
GET: /api/bookmark/exist/:userId/:listingId - Checks if a bookmark exists for the given user and listing.
All routes return JSON responses with status codes to indicate success or failure, facilitating ease of integration and debugging.
Testing
tested all endpoints
Additional Notes
This implementation lays the foundation for front-end bookmark functionality, allowing users to interact with listings in a personalized manner.
Future enhancements could include bookmark pagination, user notifications upon successful bookmark actions, and analytics on bookmarked listings.
This PR is ready for review. Please check for adherence to backend standards and consistency with the overall project architecture.
Bookmark Backend Implementation
Summary
This pull request introduces the backend infrastructure for managing bookmarks within the application. It adds schema definitions, server actions, and API endpoints necessary to support bookmarking functionality for users, allowing them to save listings.
Changes Overview
Database Schema:
Bookmark
model to create a many-to-many relationship betweenUser
andListing
.Server Actions:
actions/user
folder to handle bookmarking operations.API Endpoints:
/api/bookmark/:userId/:listingId
- Adds a bookmark for a specific user and listing./api/bookmark/:userId/:listingId
- Removes a bookmark./api/bookmark/:userId
- Retrieves all bookmarks for a user./api/bookmark/exist/:userId/:listingId
- Checks if a bookmark exists for the given user and listing.Testing
tested all endpoints
Additional Notes
This PR is ready for review. Please check for adherence to backend standards and consistency with the overall project architecture.
https://github.com/user-attachments/assets/2e4719af-3e3e-407c-9907-57a21306d3e8
PR1 #477