This document divides all the changes needed to replicate the SC 12th December version into 3 logical, balanced tasks for the backend team members.
Each team member will work on a complete, self-contained feature area that can be developed and tested independently. All tasks should be completed and pushed to the main branch.
Assigned to: Team Member 1
Implement the complete swap request system - backend service, API endpoints, and frontend components for managing swap requests.
create_swap_request()get_swap_request()get_pending_requests_for_item()get_pending_requests_for_owner()get_requests_for_requester()get_approved_swaps_for_user()update_swap_request()cancel_other_pending_requests()Backend/data/swap_requests.json for storage[]from services import swap_serviceGET /items/swap-requests
GET /items/swap-history
POST /items/{item_id}/swap
POST /items/{item_id}/swap/{request_id}/approve
POST /items/{item_id}/swap/{request_id}/reject
GET /items/ - Check for pending requests and update
status to âpendingâ if neededGET /items/{item_id} - Check for pending requests and
update status to âpendingâ if neededBackend.services to services (relative
imports)itemsAPI.getSwapRequests(),
approveSwapRequest(), rejectSwapRequest()itemsAPI.getSwapHistory()itemsAPI:
requestSwap(itemId) - Request a swap for an itemapproveSwapRequest(itemId, requestId) - Approve a swap
requestrejectSwapRequest(itemId, requestId) - Reject a swap
requestgetSwapRequests() - Get swap requests for usergetSwapHistory() - Get swap history for userSwapRequests
component)SwapHistory
componentSwapRequests and
SwapHistory componentsitemsAPI.getSwapHistory()Assigned to: Team Member 2
Enhance the credit system with transaction tracking, automatic credit awards, and improved performance.
[]add_credits() function:
transaction_type (default âcredit_addâ)
and description (optional)update_user() (O(1) instead of O(n))from services.user_service import get_user_by_id, update_userdeduct_credits() function:
update_user() (for performance)from services.user_service import get_user_by_id, update_userget_user_balance() function:
if transaction.get("type") in ["credit_add", "swap_credit", "item_upload"]:sync_user_credits_from_transactions(user_id)
Backend.services.user_service to
services.user_servicecreate_item() endpoint, after successfully creating
the item:
credit_service.add_credits(user_id=owner_id, amount=2.0, transaction_type="item_upload", description=f"Credits awarded for uploading item: {item.title}")from services import credit_servicelock_item() endpoint:
if item_owner_id and item_owner_id == user_id: raise HTTPException(403, "You cannot swap or purchase your own items")unlock_item() endpoint:
if item_owner_id and item_owner_id != user_id: raise HTTPException(403, "Only the item owner can unlock this item")userAPI.getUser()
responseAssigned to: Team Member 3
Update core infrastructure (error handling, imports), improve API integration, and add utility functions.
from fastapi import Request, statusfrom fastapi.exceptions import RequestValidationErrorfrom fastapi.responses import JSONResponsefrom pydantic import ValidationError@app.exception_handler(RequestValidationError)
decoratorvalidation_exception_handler() functionfrom Backend.database.connection â
from database.connectionfrom Backend.routes.item_routes â
from routes.item_routesfrom Backend.routes.auth_routes â
from routes.auth_routesfrom Backend.routes.user_routes â
from routes.user_routesROOT = Path(__file__).resolve().parentSTATIC_DIR = ROOT / "static"app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")from pathlib import Pathcreate_item() endpoint:
from Backend.models.item_model â
from models.item_modelfrom Backend.services â
from servicesimport json and
import re (for parsing credits from description)parseItemMetadata(description) - Extracts metadata from
item descriptionsgetImageUrl(image, apiBaseUrl) - Constructs full image
URLscreateItem() function:
import { userAPI, itemsAPI } from '@/services/api'import { parseItemMetadata, getImageUrl } from '@/utils/itemParser'userAPI.getUser(owner_id)parseItemMetadata() to extract metadata from
descriptiongetImageUrl() to construct image URLsimport { itemsAPI } from '@/services/api'handleSwapClick() function that calls
itemsAPI.requestSwap(productData.id)isOwner)import { itemsAPI, userAPI } from '@/services/api'import { parseItemMetadata, getImageUrl } from '@/utils/itemParser'userAPI.getUser(authUser.id)itemsAPI.getItems() and filter
by owner_idparseItemMetadata() and getImageUrl()
utilitiesAll team members need to be aware that import paths are changing from
Backend. prefix to relative imports. Make sure to update
all imports in files youâre modifying.
Old:
from Backend.services.user_service import get_user_by_id
New:
from services.user_service import get_user_by_id
After all tasks are complete, verify:
feat: Implement swap request system
- Add swap_service.py for managing swap requests
- Add swap endpoints to item_routes (create, approve, reject, get requests/history)
- Add SwapRequests and SwapHistory frontend components
- Update Profile component with swap tabs
- Add swap API methods to api.js
feat: Enhance credit system with transaction tracking
- Update credit_service with transaction types and direct credit updates
- Add automatic 2 credit award on item upload
- Add transaction history tracking
- Update lock/unlock endpoints with ownership checks
- Improve credit service performance
feat: Improve core infrastructure and API integration
- Add validation error handler to main.py
- Update all imports to relative paths
- Improve static file mounting
- Add itemParser utility functions
- Enhance API error handling
- Connect ProductDetail and Profile to backend
- Remove unused backend_stuff folder
git checkout -b task-{number}-{your-name}Good luck! đ