From 12f7176467447d5f0db8e81c4d8b937b83bdfff5 Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Sat, 27 Jul 2024 02:52:24 +0200 Subject: [PATCH] Email change on user --- exam/api/Users/Users.php | 8 ++--- exam/api/docs/api.yaml | 17 ++++++--- exam/api/docs/index.html | 6 ++-- exam/classes/ApiError/ApiError.php | 3 +- exam/classes/Models/Post/Post.php | 22 ++++++++++-- exam/classes/Models/User/User.php | 55 ++++++++++++++++++++++++------ 6 files changed, 86 insertions(+), 25 deletions(-) diff --git a/exam/api/Users/Users.php b/exam/api/Users/Users.php index 1bf0512..de61baa 100644 --- a/exam/api/Users/Users.php +++ b/exam/api/Users/Users.php @@ -42,12 +42,12 @@ class Users extends Api // Fetch all inputs. $username = Input::patch("username"); $password = Input::patch("password"); - $image = Input::file("image"); + $email = Input::patch("email"); // Try and update user. // Throw errors according to situation. try { - Response::json(User::getByID($id)->update($username, $password, $image)); + Response::json(User::getByID($id)->update($username, $password, $email)); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": @@ -65,12 +65,12 @@ class Users extends Api $token = Request::token(); $username = Input::patch("username"); $password = Input::patch("password"); - $image = Input::file("image"); + $email = Input::patch("email"); // Try and update user. // Throw errors according to situation. try { - Response::json(User::getByToken($token)->update($username, $password, $image)); + Response::json(User::getByToken($token)->update($username, $password, $email)); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": diff --git a/exam/api/docs/api.yaml b/exam/api/docs/api.yaml index ddde78e..52f0dd6 100644 --- a/exam/api/docs/api.yaml +++ b/exam/api/docs/api.yaml @@ -254,7 +254,12 @@ paths: $ref: "#/components/schemas/FailedUpdateResponse" examples: Failed: - value: { "code": "FailedUpdate", "fields": ["content"] } + value: + { + "code": "FailedUpdate", + "fields": ["content"], + "reasons": ["string"], + } tags: - Post delete: @@ -481,7 +486,8 @@ paths: value: { "code": "FailedUpdate", - "fields": ["username", "password", "image"], + "fields": ["username", "password", "email"], + "reasons": ["string", "string", "string"], } tags: - User @@ -572,6 +578,10 @@ components: type: array items: type: string + reasons: + type: array + items: + type: string ErrorResponse: type: object properties: @@ -629,9 +639,8 @@ components: type: string password: type: string - image: + email: type: string - format: binary RegisterRequest: type: object required: diff --git a/exam/api/docs/index.html b/exam/api/docs/index.html index fa46510..c6b185c 100644 --- a/exam/api/docs/index.html +++ b/exam/api/docs/index.html @@ -490,13 +490,13 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ " class="sc-euGpHm sc-exayXG fwfkcU kqJXdD">

Update user 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.

Authorizations:
BasicAuthBasicAuth
path Parameters
id
required
integer <int14>

User ID

-
Request Body schema: application/json
username
string
password
string
image
string <binary>

Responses

Request samples

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

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}

Delete user

Request samples

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

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}

Delete user

Delete user with ID.

Authorizations:
BasicAuth
path Parameters
id
required
integer <int14>

User ID

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

User not found.

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}