Skip to content

Latest commit

 

History

History
423 lines (360 loc) · 6.63 KB

File metadata and controls

423 lines (360 loc) · 6.63 KB

API Documentation

Base URL

http://localhost:5000

Endpoints

Authentication

Register User

POST /auth/signup
Content-Type: application/json

Request Body:

{
  "name": "John",
  "email": "john@gmail.com",
  "password": "testpassword"
}

Response:

{
  "id": 1,
  "name": "John",
  "email": "john@gmail.com",
  "message": "User created successfully"
}

Login User

POST /auth/login
Content-Type: application/json

Request Body:

{
  "email": "john@gmail.com",
  "password": "testpassword"
}

Response:

{
  "message": "Login successful",
  "user_id": 1,
  "name": "John"
}

Logout User

POST /auth/logout

Response:

{
  "message": "Logout successful"
}

Profiles

Get User Profile

GET /profile/{user_id}

Response:

{
  "id": 1,
  "name": "John",
  "email": "john@gmail.com",
  "bio": "I love teaching and learning new skills!",
  "location": "San Francisco, CA",
  "skills_to_offer": ["Python", "JavaScript", "Cooking"],
  "skills_to_learn": ["Guitar", "Spanish"],
  "image_url": "/upload/uploads/profile_images/profile_1_20241201_143022_abc12345.jpg",
  "average_rating": 4.5,
  "created_at": "2024-01-15T10:30:00Z"
}

Update User Profile

PUT /profile/{user_id}
Content-Type: application/json

Request Body:

{
  "bio": "Updated bio text",
  "location": "New York, NY",
  "skills_to_offer": ["Python", "JavaScript", "Cooking", "Photography"],
  "skills_to_learn": ["Guitar", "Spanish", "Yoga"]
}

Response:

{
  "message": "Profile updated successfully"
}

File Uploads

Upload Profile Image

POST /upload/profile-image/{user_id}
Content-Type: multipart/form-data

Form Data:

  • image: File (PNG, JPG, JPEG, max 5MB)

Response:

{
  "message": "Profile image uploaded successfully",
  "image_url": "/upload/uploads/profile_images/profile_1_20241201_143022_abc12345.jpg",
  "filename": "profile_1_20241201_143022_abc12345.jpg"
}

Delete Profile Image

DELETE /upload/profile-image/{user_id}

Response:

{
  "message": "Profile image deleted successfully"
}

Serve Uploaded Files

GET /upload/uploads/{filename}

Response: Returns the actual file content (images, etc.)

Matching

Get Potential Matches

GET /matches/{user_id}

Response:

{
  "matches": [
    {
      "id": 2,
      "name": "Jane",
      "email": "jane@gmail.com",
      "bio": "Passionate about music and languages",
      "location": "San Francisco, CA",
      "skills_to_offer": ["Guitar", "Spanish"],
      "skills_to_learn": ["Python", "Cooking"],
      "image_url": "/upload/uploads/profile_images/profile_2_20241201_143055_def67890.jpg",
      "average_rating": 4.8,
      "offer_matches": ["Python matches Python", "Cooking matches Cooking"],
      "learn_matches": ["Guitar matches Guitar", "Spanish matches Spanish"]
    }
  ],
  "count": 1,
  "ai_enabled": true
}

Notes:

  • offer_matches: Skills the user can teach to the candidate
  • learn_matches: Skills the user can learn from the candidate
  • ai_enabled: Whether AI matching is available
  • Matches only include users where both can teach and learn from each other

AI Matching: For detailed information about AI-powered skill matching, see the AI Setup Guide.

Chat

Get User's Chats

GET /chats/{user_id}

Response:

{
  "chats": [
    {
      "id": 1,
      "user1_id": 1,
      "user2_id": 2,
      "created_at": "2024-01-15T10:00:00Z"
    }
  ]
}

Create New Chat

POST /chats
Content-Type: application/json

Request Body:

{
  "user1_id": 1,
  "user2_id": 2
}

Response:

{
  "message": "Chat created successfully",
  "chat_id": 1
}

Get Chat Messages

GET /chats/{chat_id}/messages

Response:

{
  "messages": [
    {
      "id": 1,
      "content": "Hi! I saw we matched for Python and Guitar lessons",
      "sender_id": 1,
      "timestamp": "2024-01-15T10:05:00Z",
      "is_read": true
    },
    {
      "id": 2,
      "content": "Yes! I'd love to learn Python from you",
      "sender_id": 2,
      "timestamp": "2024-01-15T10:10:00Z",
      "is_read": true
    }
  ]
}

Send Message

POST /chats/{chat_id}/messages
Content-Type: application/json

Request Body:

{
  "content": "Great! When would you like to meet?",
  "sender_id": 1
}

Response:

{
  "message": "Message sent successfully",
  "message_id": 6
}

Delete Chat

DELETE /chats/{chat_id}

Response:

{
  "message": "Chat deleted successfully"
}

Mark Messages as Read

PUT /chats/{chat_id}/messages/read
Content-Type: application/json

Request Body:

{
  "user_id": 1
}

Response:

{
  "message": "Messages marked as read"
}

Ratings

Get User Ratings

GET /ratings/{user_id}

Response:

{
  "ratings": [
    {
      "id": 1,
      "rater_id": 2,
      "rated_id": 1,
      "rating": 5,
      "comment": "Excellent Python teacher! Very patient and clear explanations.",
      "skill": "Python",
      "created_at": "2024-01-15T16:00:00Z"
    }
  ],
  "average_rating": 4.8,
  "total_ratings": 5
}

Create Rating

POST /ratings
Content-Type: application/json

Request Body:

{
  "rater_id": 2,
  "rated_id": 1,
  "rating": 5,
  "comment": "Excellent Python teacher! Very patient and clear explanations.",
  "skill": "Python"
}

Response:

{
  "message": "Rating created successfully",
  "rating_id": 1
}

Error Responses

400 Bad Request

{
  "error": "Invalid request data",
  "details": "Specific error message"
}

401 Unauthorized

{
  "error": "Authentication required"
}

403 Forbidden

{
  "error": "Access denied"
}

404 Not Found

{
  "error": "Resource not found"
}

500 Internal Server Error

{
  "error": "Internal server error"
}

CORS

The API supports CORS for cross-origin requests from the frontend application.

File Upload Limits

  • Maximum file size: 5MB
  • Supported formats: PNG, JPG, JPEG
  • Files are stored in the /uploads/profile_images/ directory
  • Images are automatically resized to max 800x800 pixels
  • Old profile images are automatically cleaned up (keeps only the most recent)

Additional Resources