Authentication
All API routes usegetCurrentUser() to verify authentication. Requests without a valid session receive a 401 Unauthorized response.
User Endpoints
GET /api/user
Get the current authenticated user’s information.Response
User’s unique identifier
User’s email address
User’s display name
Example
Error Responses
- 401 Unauthorized: No valid session
- 500 Internal Server Error: Database error
PATCH /api/user
Update the current user’s profile information.Request Body
User’s phone number
Response
Returns the updated User object with all fields.Example
Error Responses
- 401 Unauthorized: No valid session
- 500 Internal Server Error: Database error
Points Endpoints
GET /api/points
Get the current user’s points balance.Response
Current points balance
Example
Behavior
- If no Points record exists for the user, one is created with balance 0 (upsert pattern)
- Verifies user exists in database before creating Points record
Error Responses
- 401 Unauthorized: No valid session
- 404 Not Found: User not found in database
- 500 Internal Server Error: Database error
POST /api/points
Update the current user’s points balance.Request Body
New points balance (must be non-negative)
Response
Updated points balance
Example
Validation
- Balance must be a number
- Balance must be non-negative (>= 0)
Error Responses
- 400 Bad Request: Invalid balance value
- 401 Unauthorized: No valid session
- 404 Not Found: User not found in database
- 500 Internal Server Error: Database error
Request Endpoints
GET /api/requests
Get all point-sharing requests, ordered by creation date (newest first).Response
Returns an array of Request objects with related user information.Request unique identifier
ID of user requesting points
ID of user who accepted/declined (null if pending)
UCSC dining hall location
Number of points requested
Request status:
pending, accepted, or declinedOptional message from requester
Requester user information
Donor user information (null if pending)
ISO timestamp of request creation
ISO timestamp of last update
Example
Error Responses
- 401 Unauthorized: No valid session
- 500 Internal Server Error: Database error
POST /api/requests
Create a new point-sharing request.Request Body
UCSC dining hall location (must be from predefined list)
Number of points requested (accepts number or numeric string)
Optional message to donors
Response
Returns the created Request object with requester information (status 201).Example
Validation
UsesvalidateCreateRequest() from lib/validation.ts:
- Location must be non-empty
- Points must be a positive number
- Points must be ≤ 1000
Error Responses
- 400 Bad Request: Validation error (invalid location or points)
- 401 Unauthorized: No valid session
- 500 Internal Server Error: Database error
DELETE /api/requests/[id]
Delete a request. Only the requester can delete their own pending requests.URL Parameters
Request ID to delete
Response
True if deletion succeeded
Example
Validation
UsesvalidateDeleteRequest() from lib/validation.ts:
- Request must exist
- User must be the requester
- Request must be pending (cannot delete accepted/declined requests)
Error Responses
- 400 Bad Request: Cannot delete non-pending request
- 401 Unauthorized: No valid session
- 403 Forbidden: User is not the requester
- 404 Not Found: Request not found
- 500 Internal Server Error: Database error
POST /api/requests/[id]/accept
Accept a request and transfer points atomically.URL Parameters
Request ID to accept
Response
True if acceptance succeeded
Example
Atomic Transaction
Executes the following operations in a single transaction:- Decrement donor’s points balance
- Increment requester’s points balance
- Update request status to “accepted” and set donorId
- Create notification for requester
- Create confirmation notification for donor
Validation
UsesvalidateAcceptRequest() from lib/validation.ts:
- Request must exist
- User cannot accept their own request
- Request must be pending
- Donor must have sufficient points balance
Error Responses
- 400 Bad Request: Cannot accept own request, insufficient balance, or not pending
- 401 Unauthorized: No valid session
- 404 Not Found: Request not found
- 500 Internal Server Error: Database error
POST /api/requests/[id]/decline
Decline a request without transferring points.URL Parameters
Request ID to decline
Response
True if decline succeeded
Example
Atomic Transaction
Executes the following operations in a single transaction:- Update request status to “declined” and set donorId
- Create notification for requester
Validation
- Request must exist
- User cannot decline their own request
- Request must be pending
Error Responses
- 400 Bad Request: Cannot decline own request or not pending
- 401 Unauthorized: No valid session
- 404 Not Found: Request not found
- 500 Internal Server Error: Database error
Notification Endpoints
GET /api/notifications
Get all notifications for the current user, ordered by newest first.Response
Returns an array of Notification objects.Notification unique identifier
User ID
Notification type (e.g.,
request_accepted, request_declined)Human-readable notification message
Whether notification has been read
ISO timestamp of notification creation
ISO timestamp of last update
Example
Error Responses
- 401 Unauthorized: No valid session
- 500 Internal Server Error: Database error
PATCH /api/notifications
Update a notification’s read status.Request Body
Notification ID to update
New read status
Response
Returns the updated Notification object.Example
Security
- Users can only update their own notifications (enforced by
userIdin query)
Error Responses
- 400 Bad Request: Missing notification ID
- 401 Unauthorized: No valid session
- 500 Internal Server Error: Database error or notification not found
Error Response Format
All error responses follow this format:Common HTTP Status Codes
- 200 OK: Request succeeded
- 201 Created: Resource created successfully
- 400 Bad Request: Invalid request data or validation error
- 401 Unauthorized: Authentication required or invalid session
- 403 Forbidden: User lacks permission for this action
- 404 Not Found: Resource not found
- 500 Internal Server Error: Database or server error
Rate Limiting
Currently, SlugShare does not implement rate limiting. This should be added before production deployment.