From 8da535b8bbf62ed14c225126bebcc5fc83307afa Mon Sep 17 00:00:00 2001 From: senkim102 <147796658+senkim102@users.noreply.github.com> Date: Fri, 13 Feb 2026 12:16:15 +0700 Subject: [PATCH] completed 00 01 --- .vscode/settings.json | 4 + openapi.yaml | 628 ++++++++++++++++++++++++++++++++++++ python/PROJECT_STRUCTURE.md | 9 + python/main.py | 35 ++ 4 files changed, 676 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 openapi.yaml create mode 100644 python/PROJECT_STRUCTURE.md create mode 100644 python/main.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..51a564d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "chat.tools.autoApprove": true, + "chat.agent.maxRequests": 100 +} \ No newline at end of file diff --git a/openapi.yaml b/openapi.yaml new file mode 100644 index 0000000..a680462 --- /dev/null +++ b/openapi.yaml @@ -0,0 +1,628 @@ +# OpenAPI specification for Simple Social Media Application +openapi: 3.0.1 +info: + title: Simple Social Media Application API + version: 1.0.0 + description: | + API for a basic social networking service supporting posts, comments, and likes. + Designed for MVP and educational use cases. +servers: + - url: http://localhost:8080/api +paths: + /posts: + get: + summary: List all posts + responses: + '200': + description: List of posts + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Post' + post: + summary: Create a new post + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/PostCreateRequest' + responses: + '201': + description: Post created + content: + application/json: + schema: + $ref: '#/components/schemas/Post' + '400': + $ref: '#/components/responses/BadRequest' + /posts/{postId}: + get: + summary: Get a single post + parameters: + - $ref: '#/components/parameters/PostId' + responses: + '200': + description: Post details + content: + application/json: + schema: + $ref: '#/components/schemas/Post' + '404': + $ref: '#/components/responses/NotFound' + patch: + summary: Update a post + parameters: + - $ref: '#/components/parameters/PostId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/PostUpdateRequest' + responses: + '200': + description: Post updated + content: + application/json: + schema: + $ref: '#/components/schemas/Post' + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + delete: + summary: Delete a post + parameters: + - $ref: '#/components/parameters/PostId' + responses: + '204': + description: Post deleted + '404': + $ref: '#/components/responses/NotFound' + /posts/{postId}/comments: + get: + summary: List comments for a post + parameters: + - $ref: '#/components/parameters/PostId' + responses: + '200': + description: List of comments + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Comment' + '404': + $ref: '#/components/responses/NotFound' + post: + summary: Create a comment on a post + parameters: + - $ref: '#/components/parameters/PostId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CommentCreateRequest' + responses: + '201': + description: Comment created + content: + application/json: + schema: + $ref: '#/components/schemas/Comment' + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + /posts/{postId}/comments/{commentId}: + get: + summary: Get a specific comment + parameters: + - $ref: '#/components/parameters/PostId' + - $ref: '#/components/parameters/CommentId' + responses: + '200': + description: Comment details + content: + application/json: + schema: + $ref: '#/components/schemas/Comment' + '404': + $ref: '#/components/responses/NotFound' + patch: + summary: Update a comment + parameters: + - $ref: '#/components/parameters/PostId' + - $ref: '#/components/parameters/CommentId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CommentUpdateRequest' + responses: + '200': + description: Comment updated + content: + application/json: + schema: + $ref: '#/components/schemas/Comment' + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + delete: + summary: Delete a comment + parameters: + - $ref: '#/components/parameters/PostId' + - $ref: '#/components/parameters/CommentId' + responses: + '204': + description: Comment deleted + '404': + $ref: '#/components/responses/NotFound' + /posts/{postId}/likes: + post: + summary: Like a post + parameters: + - $ref: '#/components/parameters/PostId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/LikeRequest' + responses: + '201': + description: Post liked + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + delete: + summary: Unlike a post + parameters: + - $ref: '#/components/parameters/PostId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/LikeRequest' + responses: + '204': + description: Like removed + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' +components: + parameters: + PostId: + name: postId + in: path + required: true + schema: + type: string + description: Unique identifier for a post + CommentId: + name: commentId + in: path + required: true + schema: + type: string + description: Unique identifier for a comment + responses: + BadRequest: + description: Bad request + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + NotFound: + description: Resource not found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + schemas: + Post: + type: object + properties: + id: + type: string + username: + type: string + content: + type: string + createdAt: + type: string + format: date-time + updatedAt: + type: string + format: date-time + likes: + type: integer + comments: + type: integer + required: [id, username, content, createdAt, updatedAt, likes, comments] + PostCreateRequest: + type: object + properties: + username: + type: string + content: + type: string + required: [username, content] + PostUpdateRequest: + type: object + properties: + username: + type: string + content: + type: string + required: [username, content] + Comment: + type: object + properties: + id: + type: string + postId: + type: string + username: + type: string + content: + type: string + createdAt: + type: string + format: date-time + updatedAt: + type: string + format: date-time + required: [id, postId, username, content, createdAt, updatedAt] + CommentCreateRequest: + type: object + properties: + username: + type: string + content: + type: string + required: [username, content] + CommentUpdateRequest: + type: object + properties: + username: + type: string + content: + type: string + required: [username, content] + LikeRequest: + type: object + properties: + username: + type: string + required: [username] + Error: + type: object + properties: + message: + type: string + code: + type: integer + required: [message, code] +openapi: 3.0.1 +info: + title: Simple Social Media Application API + version: 1.0.0 + description: | + API for a basic social networking service supporting posts, comments, and likes. +servers: + - url: http://localhost:8080/api +paths: + /posts: + get: + summary: List all posts + responses: + '200': + description: List of posts + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Post' + post: + summary: Create a new post + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/PostCreateRequest' + responses: + '201': + description: Post created + content: + application/json: + schema: + $ref: '#/components/schemas/Post' + '400': + $ref: '#/components/responses/BadRequest' + /posts/{postId}: + get: + summary: Get a single post + parameters: + - $ref: '#/components/parameters/PostId' + responses: + '200': + description: Post details + content: + application/json: + schema: + $ref: '#/components/schemas/Post' + '404': + $ref: '#/components/responses/NotFound' + patch: + summary: Update a post + parameters: + - $ref: '#/components/parameters/PostId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/PostUpdateRequest' + responses: + '200': + description: Post updated + content: + application/json: + schema: + $ref: '#/components/schemas/Post' + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + delete: + summary: Delete a post + parameters: + - $ref: '#/components/parameters/PostId' + responses: + '204': + description: Post deleted + '404': + $ref: '#/components/responses/NotFound' + /posts/{postId}/comments: + get: + summary: List comments for a post + parameters: + - $ref: '#/components/parameters/PostId' + responses: + '200': + description: List of comments + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Comment' + '404': + $ref: '#/components/responses/NotFound' + post: + summary: Create a comment on a post + parameters: + - $ref: '#/components/parameters/PostId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CommentCreateRequest' + responses: + '201': + description: Comment created + content: + application/json: + schema: + $ref: '#/components/schemas/Comment' + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + /posts/{postId}/comments/{commentId}: + get: + summary: Get a specific comment + parameters: + - $ref: '#/components/parameters/PostId' + - $ref: '#/components/parameters/CommentId' + responses: + '200': + description: Comment details + content: + application/json: + schema: + $ref: '#/components/schemas/Comment' + '404': + $ref: '#/components/responses/NotFound' + patch: + summary: Update a comment + parameters: + - $ref: '#/components/parameters/PostId' + - $ref: '#/components/parameters/CommentId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CommentUpdateRequest' + responses: + '200': + description: Comment updated + content: + application/json: + schema: + $ref: '#/components/schemas/Comment' + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + delete: + summary: Delete a comment + parameters: + - $ref: '#/components/parameters/PostId' + - $ref: '#/components/parameters/CommentId' + responses: + '204': + description: Comment deleted + '404': + $ref: '#/components/responses/NotFound' + /posts/{postId}/likes: + post: + summary: Like a post + parameters: + - $ref: '#/components/parameters/PostId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/LikeRequest' + responses: + '201': + description: Post liked + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + delete: + summary: Unlike a post + parameters: + - $ref: '#/components/parameters/PostId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/LikeRequest' + responses: + '204': + description: Like removed + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' +components: + parameters: + PostId: + name: postId + in: path + required: true + schema: + type: string + CommentId: + name: commentId + in: path + required: true + schema: + type: string + schemas: + Post: + type: object + properties: + id: + type: string + username: + type: string + content: + type: string + createdAt: + type: string + format: date-time + updatedAt: + type: string + format: date-time + likeCount: + type: integer + commentCount: + type: integer + required: [id, username, content, createdAt, updatedAt, likeCount, commentCount] + PostCreateRequest: + type: object + properties: + username: + type: string + content: + type: string + required: [username, content] + PostUpdateRequest: + type: object + properties: + username: + type: string + content: + type: string + required: [username, content] + Comment: + type: object + properties: + id: + type: string + postId: + type: string + username: + type: string + content: + type: string + createdAt: + type: string + format: date-time + updatedAt: + type: string + format: date-time + required: [id, postId, username, content, createdAt, updatedAt] + CommentCreateRequest: + type: object + properties: + username: + type: string + content: + type: string + required: [username, content] + CommentUpdateRequest: + type: object + properties: + username: + type: string + content: + type: string + required: [username, content] + LikeRequest: + type: object + properties: + username: + type: string + required: [username] + Error: + type: object + properties: + message: + type: string + required: [message] + responses: + BadRequest: + description: Bad request + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + NotFound: + description: Resource not found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' diff --git a/python/PROJECT_STRUCTURE.md b/python/PROJECT_STRUCTURE.md new file mode 100644 index 0000000..b92b645 --- /dev/null +++ b/python/PROJECT_STRUCTURE.md @@ -0,0 +1,9 @@ +# FastAPI SNS API Project Structure + +- main.py (entrypoint) +- models.py (SQLAlchemy models) +- schemas.py (Pydantic schemas) +- database.py (DB connection/init) +- openapi.yaml (OpenAPI spec, already present) + +All code will reside in the python directory. Proceeding to create or update main.py as the entrypoint, and will scaffold supporting files as needed. \ No newline at end of file diff --git a/python/main.py b/python/main.py new file mode 100644 index 0000000..810dedf --- /dev/null +++ b/python/main.py @@ -0,0 +1,35 @@ +from fastapi import FastAPI, Request, Response, status +from fastapi.middleware.cors import CORSMiddleware +from fastapi.responses import JSONResponse, FileResponse +from fastapi.openapi.docs import get_swagger_ui_html +import os + +app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None) + +# Allow CORS from everywhere +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +OPENAPI_YAML_PATH = os.path.join(os.path.dirname(__file__), "../openapi.yaml") + +@app.get("/", include_in_schema=False) +def swagger_ui_html(): + return get_swagger_ui_html( + openapi_url="/openapi.yaml", + title="Simple Social Media Application API" + ) + +@app.get("/openapi.yaml", include_in_schema=False) +def serve_openapi_yaml(): + return FileResponse(OPENAPI_YAML_PATH, media_type="application/yaml") + +# ...endpoint implementations will be added here... + +if __name__ == "__main__": + import uvicorn + uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)