From 7ee04b0a4b0f8b3b2d893cbf74ce4686f5cfe11d Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Mon, 22 Jul 2024 14:18:48 +0200 Subject: [PATCH] User List --- exam/api/Users/Users.php | 15 ++++++ exam/api/docs/api.yaml | 77 ++++++++++++++++++++++++++++++- exam/api/docs/index.html | 16 ++++--- exam/classes/Models/User/User.php | 19 ++++++++ exam/routes/routes.php | 2 + 5 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 exam/api/Users/Users.php diff --git a/exam/api/Users/Users.php b/exam/api/Users/Users.php new file mode 100644 index 0000000..bd2e55d --- /dev/null +++ b/exam/api/Users/Users.php @@ -0,0 +1,15 @@ + + Requires logged in user to have admin permissions. + security: + - BasicAuth: [] + responses: + 200: + description: Success + content: + application/json: + schema: + $ref: "#/components/schemas/UserListResponse" + 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, + }, + { + "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 @@ -187,8 +238,15 @@ paths: "username": "Admin", "status": 1, "email": "marvin@zedat.fu-berlin.de", - "image": "profilbilder\\/admin.svg", + "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 @@ -328,6 +386,18 @@ components: 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: @@ -359,12 +429,15 @@ components: code: type: string format: uuid4 + UserListResponse: + type: array + items: + $ref: "#/components/schemas/UserResponse" securitySchemes: BasicAuth: type: apiKey name: token in: header - format: uuid4 tags: - name: Login/Logout - name: Register diff --git a/exam/api/docs/index.html b/exam/api/docs/index.html index f2098b8..fc773ba 100644 --- a/exam/api/docs/index.html +++ b/exam/api/docs/index.html @@ -366,7 +366,7 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ -

Missing fields

Request samples

Content type
application/json
{
  • "code": "string"
}

Response samples

Content type
application/json
true

User

Get user

Request samples

Content type
application/json
{
  • "code": "string"
}

Response samples

Content type
application/json
true

User

List users

List all users.
Requires logged in user to have admin permissions.

+
Authorizations:
BasicAuth

Responses

Response samples

Content type
application/json
[
  • {
    },
  • {
    }
]

Get user

Get user by ID

Authorizations:
BasicAuth
path Parameters
id
required
integer <int14>

User ID

@@ -424,7 +428,7 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ " class="sc-euGpHm sc-exayXG fwfkcU kqJXdD sc-dHrNzZ dRdjww">

Success

Response samples

Content type
application/json
{
  • "id": 1,
  • "username": "Admin",
  • "status": 1,
  • "email": "marvin@zedat.fu-berlin.de",
  • "image": "profilbilder\\/admin.svg",
  • "isAdmin": true
}

Update user

Response samples

Content type
application/json
{
  • "id": 1,
  • "username": "Admin",
  • "status": 1,
  • "email": "marvin@zedat.fu-berlin.de",
  • "image": "669d41fbdb56b.png",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 3
}

Update user

Update user with ID. Fields are updated in order username, password, image. If one fails, subsequent are not updated.
Use special ID self to update logged in user.
Requires logged in user to have admin permissions for any ID other than self.

Authorizations:
BasicAuth
path Parameters
id
required
integer <int14>

User ID

@@ -434,7 +438,7 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ " class="sc-euGpHm sc-exayXG fwfkcU kqJXdD sc-dHrNzZ dRdjww">

User not found

Request samples

Content type
application/json
{
  • "username": "string",
  • "password": "string",
  • "image": "string"
}

Response samples

Content type
application/json
true

Delete user

Request samples

Content type
application/json
{
  • "username": "string",
  • "password": "string",
  • "image": "string"
}

Response samples

Content type
application/json
true

Delete user

Delete user with ID.
Requires logged in user to have admin permissions.

Authorizations:
BasicAuth
path Parameters
id
required
integer <int14>

User ID

@@ -442,9 +446,9 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ " class="sc-euGpHm sc-exayXG fwfkcU kqJXdD sc-dHrNzZ dRdjww">

Success

Response samples

Content type
application/json
true
+

Response samples

Content type
application/json
true