Skip to main content
POST
/
api
/
plan
/
generate-plan
Generate Study Plan
curl --request POST \
  --url https://api.example.com/api/plan/generate-plan \
  --header 'Content-Type: application/json' \
  --data '
{
  "barExamTestDate": "<string>",
  "currentScore": 123,
  "targetScore": 123,
  "weeklyHours": 123,
  "challengingAreas": [
    {}
  ],
  "specificAreas": [
    {}
  ],
  "preferredSchedule": "<string>",
  "barExamPreparationMaterial": "<string>",
  "additionalInformation": "<string>"
}
'
{
  "barExamTestDate": "<string>",
  "currentScore": 123,
  "targetScore": 123,
  "weeklyHours": 123,
  "challengingAreas": [
    {}
  ],
  "specificAreas": [
    {}
  ],
  "preferredSchedule": "<string>",
  "barExamPreparationMaterial": "<string>",
  "additionalInformation": "<string>",
  "currentStreak": 123,
  "lastRequestDate": "<string>",
  "updatedAt": "<string>",
  "error": "<string>"
}

Overview

This endpoint generates and saves a personalized bar exam study plan for a user. It updates the user’s profile in Firestore with study preferences, calculates and maintains study streaks, and returns the updated user data.

Authentication

Requires a valid user UUID passed as a query parameter.

Request

uuid
string
required
Unique identifier for the user

Body Parameters

barExamTestDate
string
required
Target date for the bar exam (ISO format)
currentScore
number
required
User’s current bar exam score or baseline assessment score
targetScore
number
required
Desired bar exam score
weeklyHours
number
required
Available study hours per week
challengingAreas
array
required
List of challenging subject areas for the user
specificAreas
array
required
Specific topics the user wants to focus on
preferredSchedule
string
required
User’s preferred study schedule (e.g., “Morning”, “Evening”, “Weekends”)
barExamPreparationMaterial
string
required
Preparation materials the user is using
additionalInformation
string
required
Any additional information or notes from the user

Response

barExamTestDate
string
The user’s bar exam test date
currentScore
number
Current bar exam score
targetScore
number
Target bar exam score
weeklyHours
number
Available study hours per week
challengingAreas
array
List of challenging areas
specificAreas
array
Specific focus areas
preferredSchedule
string
Preferred study schedule
barExamPreparationMaterial
string
Preparation materials being used
additionalInformation
string
Additional user notes
currentStreak
number
Current consecutive days of study plan requests
lastRequestDate
string
Date of the last study plan request (YYYY-MM-DD format)
updatedAt
string
Timestamp of the last update (ISO format)

Streak Calculation Logic

The endpoint implements smart streak tracking:
  • Same Day: If a request is made on the same day, the streak remains unchanged
  • Next Day: If a request is made the next consecutive day, the streak increments by 1
  • Gap: If there’s a gap of more than one day, the streak resets to 1
Source: /workspace/source/src/app/api/plan/generate-plan/route.ts:60-87

Example Request

curl -X POST 'https://api.lsattraining.com/api/plan/generate-plan?uuid=user123' \
  -H 'Content-Type: application/json' \
  -d '{
    "barExamTestDate": "2024-07-30",
    "currentScore": 145,
    "targetScore": 165,
    "weeklyHours": 20,
    "challengingAreas": ["Contracts", "Torts"],
    "specificAreas": ["Case Analysis", "Legal Writing"],
    "preferredSchedule": "Morning",
    "barExamPreparationMaterial": "Barbri",
    "additionalInformation": "Need help with essay writing"
  }'

Example Response

{
  "barExamTestDate": "2024-07-30",
  "currentScore": 145,
  "targetScore": 165,
  "weeklyHours": 20,
  "challengingAreas": ["Contracts", "Torts"],
  "specificAreas": ["Case Analysis", "Legal Writing"],
  "preferredSchedule": "Morning",
  "barExamPreparationMaterial": "Barbri",
  "additionalInformation": "Need help with essay writing",
  "currentStreak": 5,
  "lastRequestDate": "2024-03-03",
  "updatedAt": "2024-03-03T10:30:00.000Z"
}

Error Responses

error
string
Error message describing what went wrong

400 Bad Request

{
  "error": "UUID is required"
}
{
  "error": "Missing required fields"
}

404 Not Found

{
  "error": "User not found"
}

500 Internal Server Error

{
  "error": "Failed to update Firestore document"
}
{
  "error": "Failed to update user data"
}

Implementation Details

  • Database: Uses Firebase Firestore for data persistence
  • Merge Strategy: Preserves existing user fields while updating plan-specific data
  • Validation: All required fields are validated before processing
  • UUID Processing: Trims whitespace from UUID for consistency
Source: /workspace/source/src/app/api/plan/generate-plan/route.ts

Build docs developers (and LLMs) love