diff --git a/exam/api/Users/Image/Image.php b/exam/api/Users/Image/Image.php
new file mode 100644
index 0000000..de7bd6f
--- /dev/null
+++ b/exam/api/Users/Image/Image.php
@@ -0,0 +1,57 @@
+updateImage($image, $predefined));
+ } catch (Exception $err) {
+ switch ($err->getMessage()) {
+ case "NotFound":
+ throw ApiError::notFound("user");
+ default:
+ // Due to how the failed field is handled, it's ApiError is inside the models update
+ throw $err;
+ }
+ }
+ }
+
+ public function postSelf(): void
+ {
+ // Fetch all inputs.
+ $token = Request::token();
+ $image = Input::file("image");
+ $predefined = Input::post("predefined");
+
+ // Try and update user image.
+ // Throw errors according to situation.
+ try {
+ Response::json(User::getByToken($token)->updateImage($image, $predefined));
+ } catch (Exception $err) {
+ switch ($err->getMessage()) {
+ case "NotFound":
+ throw ApiError::notFound("user");
+ default:
+ // Due to how the failed field is handled, it's ApiError is inside the models update
+ throw $err;
+ }
+ }
+ }
+}
diff --git a/exam/api/docs/api.yaml b/exam/api/docs/api.yaml
index 571a6a1..c822571 100644
--- a/exam/api/docs/api.yaml
+++ b/exam/api/docs/api.yaml
@@ -491,7 +491,7 @@ paths:
$ref: "#/components/schemas/NotFoundResponse"
examples:
User not found:
- value: { "code": "NotFound", "entity": "username" }
+ value: { "code": "NotFound", "entity": "user" }
500:
description: Update failed.
content:
@@ -539,6 +539,60 @@ paths:
value: { "code": "NotFound", "entity": "user" }
tags:
- User
+ /users/{id}/image:
+ post:
+ summary: Update user image
+ description: Update user image with ID.
+ Use special ID self to update logged in user.
+ Requires logged in user to have admin permissions for any ID other than self.
+ security:
+ - BasicAuth: []
+ - 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/UserImageUpdateRequest"
+ responses:
+ 200:
+ description: Success.
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/UserResponse"
+ 404:
+ description: User not found.
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/NotFoundResponse"
+ examples:
+ User not found:
+ value: { "code": "NotFound", "entity": "user" }
+ 500:
+ description: Update failed.
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FailedUpdateResponse"
+ examples:
+ Failed username:
+ value:
+ {
+ "code": "FailedUpdate",
+ "fields": ["image", "predefined"],
+ "reasons": ["string", "string"],
+ }
+ tags:
+ - User
externalDocs:
url: https://khofmann.userpage.fu-berlin.de/phpCourse/exam/api/docs/
@@ -658,6 +712,14 @@ components:
type: string
email:
type: string
+ UserImageUpdateRequest:
+ type: object
+ properties:
+ image:
+ type: string
+ format: binary
+ predefined:
+ type: string
RegisterRequest:
type: object
required:
diff --git a/exam/api/docs/index.html b/exam/api/docs/index.html
index 0e93c01..165d24a 100644
--- a/exam/api/docs/index.html
+++ b/exam/api/docs/index.html
@@ -384,7 +384,7 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/
{- "id": 0,
- "username": "string",
- "status": 0,
- "email": "string",
- "image": "string",
- "isAdmin": true,
- "memberSince": {
- "date": "2019-08-24T14:15:22Z",
- "timezone_type": 0,
- "timezone": "string"
}, - "postCount": 0
}{- "id": 0,
- "username": "string",
- "status": 0,
- "email": "string",
- "image": "string",
- "isAdmin": true,
- "memberSince": {
- "date": "2019-08-24T14:15:22Z",
- "timezone_type": 0,
- "timezone": "string"
}, - "postCount": 0
}Update user image with ID.
Use special ID self to update logged in user.
Requires logged in user to have admin permissions for any ID other than self.
| id required | integer <int14> User ID + |
| image | string <binary> |
| predefined | string |
{- "image": "string",
- "predefined": "string"
}{- "id": 0,
- "username": "string",
- "status": 0,
- "email": "string",
- "image": "string",
- "isAdmin": true,
- "memberSince": {
- "date": "2019-08-24T14:15:22Z",
- "timezone_type": 0,
- "timezone": "string"
}, - "postCount": 0
}