617 lines
18 KiB
YAML
617 lines
18 KiB
YAML
openapi: 3.0.0
|
|
info:
|
|
title: PHP Course Exam
|
|
version: 1.0.0
|
|
contact:
|
|
name: Kilian Kurt Hofmann
|
|
email: khofmann@zedat.fu-berlin.de
|
|
description: PHP Course (ABV FU Berlin) 2024 Exam
|
|
paths:
|
|
/login:
|
|
post:
|
|
summary: Login
|
|
description: Log in user.
|
|
requestBody:
|
|
required: true
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/LoginRequest"
|
|
responses:
|
|
200:
|
|
description: Success.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/BooleanResponse"
|
|
examples:
|
|
Success:
|
|
value: true
|
|
400:
|
|
description: Missing fields.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/ErrorResponse"
|
|
examples:
|
|
Missing fields:
|
|
value: { "message": "Missing email" }
|
|
401:
|
|
description: Invalid credentials.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/ErrorResponse"
|
|
examples:
|
|
Invalid username or password:
|
|
value: { "message": "Invalid username or password" }
|
|
404:
|
|
description: User not found.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/ErrorResponse"
|
|
examples:
|
|
User not found:
|
|
value: { "message": "User not found" }
|
|
500:
|
|
description: Failed.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/ErrorResponse"
|
|
examples:
|
|
Failed:
|
|
value: { "message": "Login failed" }
|
|
tags:
|
|
- Login/Logout
|
|
/logout:
|
|
post:
|
|
summary: Logout
|
|
description: Log out user.
|
|
security:
|
|
- BasicAuth: []
|
|
responses:
|
|
200:
|
|
description: Success.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/BooleanResponse"
|
|
examples:
|
|
Success:
|
|
value: true
|
|
tags:
|
|
- Login/Logout
|
|
/register:
|
|
post:
|
|
summary: Register
|
|
description: Register a new user
|
|
requestBody:
|
|
required: true
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/RegisterRequest"
|
|
responses:
|
|
200:
|
|
description: Success
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/BooleanResponse"
|
|
examples:
|
|
Success:
|
|
value: true
|
|
400:
|
|
description: Missing fields or duplicate
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/ErrorResponse"
|
|
examples:
|
|
Missing fields:
|
|
value: { "message": "Missing email" }
|
|
Duplicate:
|
|
value:
|
|
{
|
|
"message": "A user with this username or email already exists",
|
|
}
|
|
tags:
|
|
- Register
|
|
patch:
|
|
summary: Confirm register
|
|
description: Confirm a registration
|
|
requestBody:
|
|
required: true
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/ConfirmRequest"
|
|
responses:
|
|
200:
|
|
description: Success
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/BooleanResponse"
|
|
examples:
|
|
Success:
|
|
value: true
|
|
400:
|
|
description: Missing fields
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/ErrorResponse"
|
|
examples:
|
|
Missing fields:
|
|
value: { "message": "Missing code" }
|
|
404:
|
|
description: User not found
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/ErrorResponse"
|
|
examples:
|
|
User not found:
|
|
value: { "message": "User not found" }
|
|
tags:
|
|
- Register
|
|
/users:
|
|
get:
|
|
summary: List users
|
|
description: List all users.
|
|
security:
|
|
- BasicAuth: []
|
|
parameters:
|
|
- in: query
|
|
name: p
|
|
schema:
|
|
type: integer
|
|
minimum: 0
|
|
default: 0
|
|
description: Current page.
|
|
- in: query
|
|
name: l
|
|
schema:
|
|
type: integer
|
|
minimum: 0
|
|
maximum: 30
|
|
default: 10
|
|
description: The number of items to return.
|
|
responses:
|
|
200:
|
|
description: Success
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/UserListResponse"
|
|
examples:
|
|
Success:
|
|
value:
|
|
{
|
|
"pages": 1,
|
|
"data":
|
|
[
|
|
{
|
|
"id": 1,
|
|
"username": "Admin",
|
|
"status": 1,
|
|
"email": "marvin@zedat.fu-berlin.de",
|
|
"image": "669d41fbdb56b.png",
|
|
"isAdmin": true,
|
|
"memberSince":
|
|
{
|
|
"date": "2024-07-22 14:02:49.000000",
|
|
"timezone_type": 3,
|
|
"timezone": "Europe/Berlin",
|
|
},
|
|
"postCount": 3,
|
|
},
|
|
{
|
|
"id": 2,
|
|
"username": "Max",
|
|
"status": 1,
|
|
"email": "max@moritz.net",
|
|
"image": "profilbilder/max.svg",
|
|
"isAdmin": false,
|
|
"memberSince":
|
|
{
|
|
"date": "2024-07-22 03:07:41.000000",
|
|
"timezone_type": 3,
|
|
"timezone": "Europe/Berlin",
|
|
},
|
|
"postCount": 2,
|
|
},
|
|
],
|
|
}
|
|
tags:
|
|
- User
|
|
/user{id}:
|
|
get:
|
|
summary: Get user
|
|
description: Get user by ID.
|
|
security:
|
|
- BasicAuth: [isAdmin]
|
|
parameters:
|
|
- name: id
|
|
in: path
|
|
description: User ID
|
|
required: true
|
|
schema:
|
|
type: integer
|
|
format: int14
|
|
responses:
|
|
200:
|
|
description: Success.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/UserResponse"
|
|
examples:
|
|
Success:
|
|
value:
|
|
{
|
|
"id": 1,
|
|
"username": "Admin",
|
|
"status": 1,
|
|
"email": "marvin@zedat.fu-berlin.de",
|
|
"image": "669d41fbdb56b.png",
|
|
"isAdmin": true,
|
|
"memberSince":
|
|
{
|
|
"date": "2024-07-22 14:02:49.000000",
|
|
"timezone_type": 3,
|
|
"timezone": "Europe/Berlin",
|
|
},
|
|
"postCount": 3,
|
|
}
|
|
404:
|
|
description: User not found.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/ErrorResponse"
|
|
examples:
|
|
User not found:
|
|
value: { "message": "User not found" }
|
|
tags:
|
|
- User
|
|
patch:
|
|
summary: Update user
|
|
description:
|
|
Update user with ID. Fields are updated in order username, password, image. If one fails, subsequent are not updated. <br>
|
|
Use special ID <code>self</code> to update logged in user. <br>
|
|
Requires logged in user to have admin permissions for any ID other than <code>self</code>.
|
|
security:
|
|
- BasicAuth: [isAdmin]
|
|
parameters:
|
|
- name: id
|
|
in: path
|
|
description: User ID
|
|
required: true
|
|
schema:
|
|
type: integer
|
|
format: int14
|
|
requestBody:
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/UserUpdateRequest"
|
|
responses:
|
|
200:
|
|
description: Success.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/BooleanResponse"
|
|
examples:
|
|
Success:
|
|
value: true
|
|
404:
|
|
description: User not found.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/ErrorResponse"
|
|
examples:
|
|
User not found:
|
|
value: { "message": "User not found" }
|
|
500:
|
|
description: Update failed.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/ErrorResponse"
|
|
examples:
|
|
User not found:
|
|
value: { "message": "Failed to update username" }
|
|
tags:
|
|
- User
|
|
delete:
|
|
summary: Delete user
|
|
description: Delete user with ID.
|
|
security:
|
|
- BasicAuth: [isAdmin]
|
|
parameters:
|
|
- name: id
|
|
in: path
|
|
description: User ID
|
|
required: true
|
|
schema:
|
|
type: integer
|
|
format: int14
|
|
responses:
|
|
200:
|
|
description: Success.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/BooleanResponse"
|
|
examples:
|
|
Success:
|
|
value: true
|
|
404:
|
|
description: User not found.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/ErrorResponse"
|
|
examples:
|
|
User not found:
|
|
value: { "message": "User not found" }
|
|
tags:
|
|
- User
|
|
/posts:
|
|
get:
|
|
summary: List posts
|
|
description: List all posts, return full user data if authenticated.
|
|
security:
|
|
- {}
|
|
- BasicAuth: []
|
|
parameters:
|
|
- in: query
|
|
name: p
|
|
schema:
|
|
type: integer
|
|
minimum: 0
|
|
default: 0
|
|
description: Current page.
|
|
- in: query
|
|
name: l
|
|
schema:
|
|
type: integer
|
|
minimum: 0
|
|
maximum: 30
|
|
default: 10
|
|
description: The number of items to return.
|
|
responses:
|
|
200:
|
|
description: Success.
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: "#/components/schemas/PostListResponse"
|
|
examples:
|
|
Not authenticated:
|
|
value:
|
|
{
|
|
"pages": 1,
|
|
"data":
|
|
[
|
|
{
|
|
"id": 1,
|
|
"user": { "username": "Admin" },
|
|
"content": "Hey,\r\nGästebucher sind cool…\r\nDas Gästebuch ist freigegeben.\r\nIch hoffe auf viele Beiträge!",
|
|
"postedAt":
|
|
{
|
|
"date": "2020-03-03 09:03:00.000000",
|
|
"timezone_type": 3,
|
|
"timezone": "Europe/Berlin",
|
|
},
|
|
},
|
|
{
|
|
"id": 2,
|
|
"user": { "username": "Max" },
|
|
"content": "Bin über Google auf deine Seite gestoßen, danke für das geniale Gästebuch. Werde in Zukunft des Öftern vorbeischaun…\r\n\r\nLiebe Grüsse, Max",
|
|
"postedAt":
|
|
{
|
|
"date": "2020-03-04 12:26:40.000000",
|
|
"timezone_type": 3,
|
|
"timezone": "Europe/Berlin",
|
|
},
|
|
},
|
|
],
|
|
}
|
|
Authenticated:
|
|
value:
|
|
{
|
|
"pages": 1,
|
|
"data":
|
|
[
|
|
{
|
|
"id": 1,
|
|
"user":
|
|
{
|
|
"id": 1,
|
|
"username": "Admin",
|
|
"status": 1,
|
|
"email": "marvin@zedat.fu-berlin.de",
|
|
"image": "669d41fbdb56b.png",
|
|
"isAdmin": true,
|
|
"memberSince":
|
|
{
|
|
"date": "2024-07-22 14:02:49.000000",
|
|
"timezone_type": 3,
|
|
"timezone": "Europe/Berlin",
|
|
},
|
|
"postCount": 3,
|
|
},
|
|
"content": "Hey,\r\nGästebucher sind cool…\r\nDas Gästebuch ist freigegeben.\r\nIch hoffe auf viele Beiträge!",
|
|
"postedAt":
|
|
{
|
|
"date": "2020-03-03 09:03:00.000000",
|
|
"timezone_type": 3,
|
|
"timezone": "Europe/Berlin",
|
|
},
|
|
},
|
|
{
|
|
"id": 2,
|
|
"user":
|
|
{
|
|
"id": 2,
|
|
"username": "Max",
|
|
"status": 1,
|
|
"email": "max@moritz.net",
|
|
"image": "profilbilder/max.svg",
|
|
"isAdmin": false,
|
|
"memberSince":
|
|
{
|
|
"date": "2024-07-22 03:07:41.000000",
|
|
"timezone_type": 3,
|
|
"timezone": "Europe/Berlin",
|
|
},
|
|
"postCount": 2,
|
|
},
|
|
"content": "Bin über Google auf deine Seite gestoßen, danke für das geniale Gästebuch. Werde in Zukunft des Öftern vorbeischaun…\r\n\r\nLiebe Grüsse, Max",
|
|
"postedAt":
|
|
{
|
|
"date": "2020-03-04 12:26:40.000000",
|
|
"timezone_type": 3,
|
|
"timezone": "Europe/Berlin",
|
|
},
|
|
},
|
|
],
|
|
}
|
|
tags:
|
|
- Post
|
|
externalDocs:
|
|
url: https://khofmann.userpage.fu-berlin.de/phpCourse/exam/api/docs/
|
|
security: []
|
|
servers:
|
|
- url: https://khofmann.userpage.fu-berlin.de/phpCourse/exam/api/
|
|
components:
|
|
schemas:
|
|
BooleanResponse:
|
|
type: boolean
|
|
ErrorResponse:
|
|
type: object
|
|
properties:
|
|
message:
|
|
type: string
|
|
LoginRequest:
|
|
type: object
|
|
required:
|
|
- username
|
|
- password
|
|
properties:
|
|
username:
|
|
type: string
|
|
password:
|
|
type: string
|
|
UserResponse:
|
|
type: object
|
|
properties:
|
|
id:
|
|
type: number
|
|
username:
|
|
type: string
|
|
status:
|
|
type: number
|
|
email:
|
|
type: string
|
|
image:
|
|
type: string
|
|
nullable: true
|
|
isAdmin:
|
|
type: boolean
|
|
memberSince:
|
|
type: object
|
|
properties:
|
|
date:
|
|
type: string
|
|
format: date-time
|
|
timezone_type:
|
|
type: number
|
|
timezone:
|
|
type: string
|
|
postCount:
|
|
type: number
|
|
UserUpdateRequest:
|
|
type: object
|
|
properties:
|
|
username:
|
|
type: string
|
|
password:
|
|
type: string
|
|
image:
|
|
type: string
|
|
format: binary
|
|
RegisterRequest:
|
|
type: object
|
|
required:
|
|
- username
|
|
- email
|
|
- password
|
|
properties:
|
|
username:
|
|
type: string
|
|
email:
|
|
type: string
|
|
password:
|
|
type: string
|
|
ConfirmRequest:
|
|
type: object
|
|
required:
|
|
- code
|
|
properties:
|
|
code:
|
|
type: string
|
|
format: uuid4
|
|
UserListResponse:
|
|
type: object
|
|
properties:
|
|
pages:
|
|
type: number
|
|
data:
|
|
type: array
|
|
items:
|
|
$ref: "#/components/schemas/UserResponse"
|
|
PostResponse:
|
|
type: object
|
|
properties:
|
|
id:
|
|
type: number
|
|
user:
|
|
$ref: "#/components/schemas/UserResponse"
|
|
postedAt:
|
|
type: object
|
|
properties:
|
|
date:
|
|
type: string
|
|
format: date-time
|
|
timezone_type:
|
|
type: number
|
|
timezone:
|
|
type: string
|
|
PostListResponse:
|
|
type: object
|
|
properties:
|
|
pages:
|
|
type: number
|
|
data:
|
|
type: array
|
|
items:
|
|
$ref: "#/components/schemas/PostResponse"
|
|
securitySchemes:
|
|
BasicAuth:
|
|
type: apiKey
|
|
name: token
|
|
in: header
|
|
tags:
|
|
- name: Login/Logout
|
|
- name: Register
|
|
- name: User
|
|
- name: Post
|