fix: subject add data and some documentation

This commit is contained in:
akhdanre 2025-05-24 15:00:19 +07:00
parent 9c1793088a
commit 7ba31325eb
3 changed files with 245 additions and 95 deletions

View File

@ -1,5 +1,6 @@
from app.services.subject_service import SubjectService from app.services.subject_service import SubjectService
from app.helpers import make_response, make_error_response from app.helpers import make_response, make_error_response
from app.schemas.requests import SubjectCreateRequest
class SubjectController: class SubjectController:
@ -8,7 +9,8 @@ class SubjectController:
def create(self, req_body): def create(self, req_body):
try: try:
new_id = self.service.create_subject(req_body) data = SubjectCreateRequest(**req_body)
new_id = self.service.create_subject(data)
return make_response(message="Subject created", data={"id": new_id}) return make_response(message="Subject created", data={"id": new_id})
except Exception as e: except Exception as e:
return make_error_response(e) return make_error_response(e)

View File

@ -1,10 +1,8 @@
from pydantic import BaseModel, Field from pydantic import BaseModel
from typing import Optional from typing import Optional
class SubjectCreateRequest(BaseModel): class SubjectCreateRequest(BaseModel):
name: str = Field(..., example="Ilmu Pengetahuan ALam") name: str
alias: str = Field(..., examples="IPA", alias="short_name") alias: str
description: Optional[str] = Field( description: Optional[str]
None, example="Pelajaran tentang angka dan logika"
)

View File

@ -5,9 +5,9 @@ info:
version: 1.0.0 version: 1.0.0
servers: servers:
- url: http://127.0.0.1:5000/api/v1 - url: http://127.0.0.1:5000/api
description: Local Server description: Local Server
- url: http://api.example.com/api/v1 - url: http://api.example.com/api
description: Production Server description: Production Server
tags: tags:
@ -17,9 +17,12 @@ tags:
description: User data endpoints description: User data endpoints
- name: Quiz - name: Quiz
description: Quiz endpoints description: Quiz endpoints
# - name: Answer
- name: History - name: History
description: Quiz history endpoints
- name: Subject - name: Subject
description: Subject management endpoints
- name: Session
description: Session management endpoints
paths: paths:
/login: /login:
@ -108,11 +111,7 @@ paths:
type: string type: string
example: "60f6c2d2e1f1c4567a123abc" example: "60f6c2d2e1f1c4567a123abc"
"400": "400":
description: Bad Request $ref: "#/components/responses/BadRequest"
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorMessage"
/quiz/{id}: /quiz/{id}:
get: get:
@ -141,11 +140,7 @@ paths:
meta: meta:
type: object type: object
"404": "404":
description: Quiz not found $ref: "#/components/responses/NotFound"
content:
application/json:
schema:
$ref: "#/components/schemas/NotFoundResponse"
/quiz/user/{user_id}: /quiz/user/{user_id}:
get: get:
@ -181,23 +176,9 @@ paths:
items: items:
$ref: "#/components/schemas/QuizDetails" $ref: "#/components/schemas/QuizDetails"
meta: meta:
type: object $ref: "#/components/schemas/PaginationMeta"
properties:
total:
type: integer
example: 25
page:
type: integer
example: 1
per_page:
type: integer
example: 10
"404": "404":
description: No quizzes found for user $ref: "#/components/responses/NotFound"
content:
application/json:
schema:
$ref: "#/components/schemas/NotFoundResponse"
/quiz/recomendation: /quiz/recomendation:
get: get:
@ -205,18 +186,8 @@ paths:
description: Returns a list of recommended quizzes for the user description: Returns a list of recommended quizzes for the user
tags: [Quiz] tags: [Quiz]
parameters: parameters:
- name: page - $ref: "#/components/parameters/PageParam"
in: query - $ref: "#/components/parameters/LimitParam"
required: false
schema:
type: integer
example: 1
- name: limit
in: query
required: false
schema:
type: integer
example: 4
responses: responses:
"200": "200":
description: Successfully retrieved recommendation quiz list description: Successfully retrieved recommendation quiz list
@ -245,18 +216,8 @@ paths:
schema: schema:
type: string type: string
example: Sejarah example: Sejarah
- name: page - $ref: "#/components/parameters/PageParam"
in: query - $ref: "#/components/parameters/LimitParam"
required: false
schema:
type: integer
example: 1
- name: limit
in: query
required: false
schema:
type: integer
example: 4
responses: responses:
"200": "200":
description: Search result description: Search result
@ -274,6 +235,7 @@ paths:
$ref: "#/components/schemas/RecommendedQuiz" $ref: "#/components/schemas/RecommendedQuiz"
meta: meta:
$ref: "#/components/schemas/SearchMeta" $ref: "#/components/schemas/SearchMeta"
/quiz/ai: /quiz/ai:
post: post:
summary: Generate labeling quiz from passage summary: Generate labeling quiz from passage
@ -305,13 +267,8 @@ paths:
type: array type: array
items: items:
$ref: "#/components/schemas/LabeledQuestion" $ref: "#/components/schemas/LabeledQuestion"
"400": "400":
description: Bad Request $ref: "#/components/responses/BadRequest"
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorMessage"
/quiz/answer: /quiz/answer:
post: post:
@ -330,17 +287,9 @@ paths:
content: content:
application/json: application/json:
schema: schema:
type: object $ref: "#/components/schemas/SuccessResponse"
properties:
message:
type: string
example: Quiz answers submitted successfully
"400": "400":
description: Bad Request $ref: "#/components/responses/BadRequest"
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorMessage"
/quiz/answer/session: /quiz/answer/session:
post: post:
@ -373,13 +322,8 @@ paths:
example: Successfully retrieved the answer example: Successfully retrieved the answer
data: data:
$ref: "#/components/schemas/UserAnswerSession" $ref: "#/components/schemas/UserAnswerSession"
"404": "404":
description: Answer session not found $ref: "#/components/responses/NotFound"
content:
application/json:
schema:
$ref: "#/components/schemas/NotFoundResponse"
/history/{user_id}: /history/{user_id}:
get: get:
@ -408,13 +352,8 @@ paths:
type: array type: array
items: items:
$ref: "#/components/schemas/AnswerHistoryItem" $ref: "#/components/schemas/AnswerHistoryItem"
"404": "404":
description: No history found $ref: "#/components/responses/NotFound"
content:
application/json:
schema:
$ref: "#/components/schemas/NotFoundResponse"
/history/detail/{answer_id}: /history/detail/{answer_id}:
get: get:
@ -441,6 +380,7 @@ paths:
example: success retrive detail history data example: success retrive detail history data
data: data:
$ref: "#/components/schemas/AnswerDetailData" $ref: "#/components/schemas/AnswerDetailData"
/subject: /subject:
get: get:
summary: Get all subjects summary: Get all subjects
@ -462,7 +402,118 @@ paths:
items: items:
$ref: "#/components/schemas/Subject" $ref: "#/components/schemas/Subject"
post:
summary: Create a new subject
tags: [Subject]
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
name:
type: string
example: Teknik Kimia
alias:
type: string
example: KIM
description:
type: string
example: basic Kimia
required:
- name
- alias
- description
responses:
"200":
description: Subject successfully created
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: Subject created
data:
type: object
properties:
id:
type: string
example: 683178ffac911e8a9d04bb0e
meta:
type: object
nullable: true
example: null
/session:
post:
summary: Create a new quiz session
tags: [Session]
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
quiz_id:
type: string
example: 6815da9f37a1ce472ba72819
host_id:
type: string
example: 680f0e63180b5c19b3751d42
limit_participan:
type: integer
example: 2
required:
- quiz_id
- host_id
- limit_participan
responses:
"200":
description: Successfully created a session
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: succes create room
data:
type: object
properties:
session_id:
type: string
example: 68317a6a48d97464ec3aaf1c
session_code:
type: string
example: AE5AFE
meta:
type: object
nullable: true
example: null
components: components:
parameters:
PageParam:
name: page
in: query
required: false
schema:
type: integer
example: 1
LimitParam:
name: limit
in: query
required: false
schema:
type: integer
example: 4
requestBodies: requestBodies:
LoginRequest: LoginRequest:
required: true required: true
@ -470,18 +521,21 @@ components:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/Login" $ref: "#/components/schemas/Login"
GoogleLoginRequest: GoogleLoginRequest:
required: true required: true
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/GoogleLogin" $ref: "#/components/schemas/GoogleLogin"
RegisterRequest: RegisterRequest:
required: true required: true
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/Register" $ref: "#/components/schemas/Register"
UpdateUserRequest: UpdateUserRequest:
required: true required: true
content: content:
@ -500,6 +554,7 @@ components:
token: token:
type: string type: string
example: <jwt_token> example: <jwt_token>
BadRequestLogin: BadRequestLogin:
description: Bad Request description: Bad Request
content: content:
@ -508,6 +563,7 @@ components:
$ref: "#/components/schemas/ErrorMessage" $ref: "#/components/schemas/ErrorMessage"
example: example:
message: Invalid email or password message: Invalid email or password
BadRequestGoogleLogin: BadRequestGoogleLogin:
description: Bad Request description: Bad Request
content: content:
@ -516,6 +572,7 @@ components:
$ref: "#/components/schemas/ErrorMessage" $ref: "#/components/schemas/ErrorMessage"
example: example:
message: Invalid token message: Invalid token
LogoutSuccess: LogoutSuccess:
description: OK description: OK
content: content:
@ -524,6 +581,7 @@ components:
$ref: "#/components/schemas/SuccessMessage" $ref: "#/components/schemas/SuccessMessage"
example: example:
message: Logout successfully message: Logout successfully
UserCreated: UserCreated:
description: OK description: OK
content: content:
@ -532,6 +590,7 @@ components:
$ref: "#/components/schemas/SuccessMessage" $ref: "#/components/schemas/SuccessMessage"
example: example:
message: User created successfully message: User created successfully
UserExists: UserExists:
description: Conflict description: Conflict
content: content:
@ -540,12 +599,14 @@ components:
$ref: "#/components/schemas/ErrorMessage" $ref: "#/components/schemas/ErrorMessage"
example: example:
message: Email already registered message: Email already registered
UserData: UserData:
description: OK description: OK
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/User" $ref: "#/components/schemas/User"
UserUpdated: UserUpdated:
description: OK description: OK
content: content:
@ -555,6 +616,22 @@ components:
example: example:
message: User updated successfully message: User updated successfully
BadRequest:
description: Bad Request
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorMessage"
NotFound:
description: Not Found
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorMessage"
example:
message: Resource not found
schemas: schemas:
Login: Login:
type: object type: object
@ -565,122 +642,175 @@ components:
password: password:
type: string type: string
example: rahasia example: rahasia
GoogleLogin: GoogleLogin:
type: object type: object
properties: properties:
token_id: token_id:
type: string type: string
example: <google_token> example: <google_token>
Register: Register:
type: object type: object
properties: properties:
email: email:
type: string type: string
example: user@example.com
password: password:
type: string type: string
example: secure_password
name: name:
type: string type: string
example: John Doe
birth_date: birth_date:
type: string type: string
example: 1990-01-01
UpdateUser: UpdateUser:
type: object type: object
properties: properties:
email: email:
type: string type: string
example: newemail@example.com example: newemail@example.com
User: User:
type: object type: object
properties: properties:
id: id:
type: integer type: string
example: 680f0e63180b5c19b3751d42
name: name:
type: string type: string
example: John Doe
email: email:
type: string type: string
example: user@example.com
SuccessMessage: SuccessMessage:
type: object type: object
properties: properties:
message: message:
type: string type: string
SuccessResponse:
type: object
properties:
message:
type: string
example: Operation completed successfully
ErrorMessage: ErrorMessage:
type: object type: object
properties: properties:
message: message:
type: string type: string
example: An error occurred
PaginationMeta:
type: object
properties:
total:
type: integer
example: 25
page:
type: integer
example: 1
per_page:
type: integer
example: 10
QuizCreateRequest: QuizCreateRequest:
type: object type: object
properties: properties:
title: title:
type: string type: string
example: Sejarah Indonesia
description: description:
type: string type: string
example: Kuis tentang sejarah Indonesia
is_public: is_public:
type: boolean type: boolean
example: true
author_id: author_id:
type: string type: string
example: 680f0e63180b5c19b3751d42
subject_id: subject_id:
type: string type: string
example: 68131eac43a09ed7dbb2cf44
questions: questions:
type: array type: array
items: items:
$ref: "#/components/schemas/QuizQuestion" $ref: "#/components/schemas/QuizQuestion"
QuizQuestion: QuizQuestion:
type: object type: object
properties: properties:
index: index:
type: integer type: integer
example: 1
question: question:
type: string type: string
example: Siapakah ketua Wali Songo yang juga dikenal sebagai Sunan Gresik?
target_answer: target_answer:
oneOf: oneOf:
- type: string - type: string
- type: boolean - type: boolean
- type: integer - type: integer
example: Maulana Malik Ibrahim
duration: duration:
type: integer type: integer
example: 30
type: type:
type: string type: string
enum: [fill_the_blank, true_false, option] enum: [fill_the_blank, true_false, option]
example: fill_the_blank
options: options:
type: array type: array
items: items:
type: string type: string
nullable: true nullable: true
example: null
QuizDetails: QuizDetails:
type: object type: object
properties: properties:
id: id:
type: string type: string
example: 68283dc9806020760d14e963
author_id: author_id:
type: string type: string
example: 680f0e63180b5c19b3751d42
subject_id: subject_id:
type: string type: string
example: 68131eac43a09ed7dbb2cf44
subject_alias: subject_alias:
type: string type: string
example: IPA
title: title:
type: string type: string
example: Sejarah Indonesia - Proklamasi dan Kemerdekaan
description: description:
type: string type: string
example: Kuis ini membahas peristiwa penting seputar proklamasi dan kemerdekaan Indonesia serta tokoh-tokoh terkait.
is_public: is_public:
type: boolean type: boolean
example: true
date: date:
type: string type: string
example: 17-May-2025
time: time:
type: string type: string
example: 14:30
total_quiz: total_quiz:
type: integer type: integer
example: 10
limit_duration: limit_duration:
type: integer type: integer
example: 300
question_listings: question_listings:
type: array type: array
items: items:
$ref: "#/components/schemas/QuizQuestion" $ref: "#/components/schemas/QuizQuestion"
NotFoundResponse:
type: object
properties:
message:
type: string
example: Quiz not found
RecommendedQuiz: RecommendedQuiz:
type: object type: object
@ -760,6 +890,7 @@ components:
date: date:
type: string type: string
example: 2025-05-18 19:02:02 example: 2025-05-18 19:02:02
QuizAnswerSubmission: QuizAnswerSubmission:
type: object type: object
properties: properties:
@ -792,6 +923,7 @@ components:
- type: string - type: string
- type: boolean - type: boolean
- type: integer - type: integer
example: Maulana Malik Ibrahim
is_correct: is_correct:
type: boolean type: boolean
example: true example: true
@ -847,6 +979,7 @@ components:
type: type:
type: string type: string
enum: [fill_the_blank, true_false, option] enum: [fill_the_blank, true_false, option]
example: fill_the_blank
options: options:
type: array type: array
items: items:
@ -858,6 +991,7 @@ components:
- type: string - type: string
- type: boolean - type: boolean
- type: integer - type: integer
example: Maulana Malik Ibrahim
is_correct: is_correct:
type: boolean type: boolean
example: true example: true
@ -871,23 +1005,31 @@ components:
properties: properties:
answer_id: answer_id:
type: string type: string
example: 6828bcddb5418bf21ab424b2
quiz_id: quiz_id:
type: string type: string
example: 68283dc9806020760d14e963
title: title:
type: string type: string
example: Sejarah Indonesia - Proklamasi dan Kemerdekaan
description: description:
type: string type: string
example: Kuis ini membahas peristiwa penting seputar proklamasi dan kemerdekaan Indonesia serta tokoh-tokoh terkait.
author_id: author_id:
type: string type: string
example: 680f0e63180b5c19b3751d42
answered_at: answered_at:
type: string type: string
example: 17-May-2025 example: 17-May-2025
total_correct: total_correct:
type: integer type: integer
example: 8
total_score: total_score:
type: integer type: integer
example: 80
total_solve_time: total_solve_time:
type: number type: number
example: 240.5
question_listings: question_listings:
type: array type: array
items: items:
@ -898,30 +1040,38 @@ components:
properties: properties:
index: index:
type: integer type: integer
example: 1
question: question:
type: string type: string
example: Siapakah ketua Wali Songo yang juga dikenal sebagai Sunan Gresik?
type: type:
type: string type: string
enum: [fill_the_blank, true_false, option] enum: [fill_the_blank, true_false, option]
example: fill_the_blank
target_answer: target_answer:
oneOf: oneOf:
- type: string - type: string
- type: boolean - type: boolean
- type: integer - type: integer
example: Maulana Malik Ibrahim
user_answer: user_answer:
oneOf: oneOf:
- type: string - type: string
- type: boolean - type: boolean
- type: integer - type: integer
example: Maulana Malik Ibrahim
is_correct: is_correct:
type: boolean type: boolean
example: true
time_spent: time_spent:
type: number type: number
example: 25.3
options: options:
type: array type: array
items: items:
type: string type: string
nullable: true nullable: true
example: null
Subject: Subject:
type: object type: object