swarooppatilx / scruter

Scruter is a local classifieds and community site designed to bring people together for buying, selling, and exchanging goods and services.
https://scruter.vercel.app
GNU General Public License v3.0
28 stars 135 forks source link

Bookmark backend: schema, serveractions and testing API #514

Closed ShivanshPlays closed 2 weeks ago

ShivanshPlays commented 2 weeks ago

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

  1. 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.
  2. 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.
  3. 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 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

vercel[bot] commented 2 weeks ago

@ShivanshPlays is attempting to deploy a commit to the Piyush's projects Team on Vercel.

A member of the Team first needs to authorize it.