diff --git a/exam/api/Users/Posts/Posts.php b/exam/api/Users/Posts/Posts.php new file mode 100644 index 0000000..155c0de --- /dev/null +++ b/exam/api/Users/Posts/Posts.php @@ -0,0 +1,36 @@ +posts($page, $limit, $sort)); + } 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 c822571..034d5ef 100644 --- a/exam/api/docs/api.yaml +++ b/exam/api/docs/api.yaml @@ -593,6 +593,62 @@ paths: } tags: - User + /users/{id}/posts: + get: + summary: Get user posts + description: Get a users posts ID. + security: + - BasicAuth: [] + parameters: + - name: id + in: path + description: User ID + required: true + schema: + type: integer + format: int14 + - 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. + - in: query + name: s + schema: + type: string + enum: + - asc + - desc + default: asc + description: Sort order by time. + responses: + 200: + description: Success. + content: + application/json: + schema: + $ref: "#/components/schemas/PostListResponse" + 404: + description: User not found. + content: + application/json: + schema: + $ref: "#/components/schemas/NotFoundResponse" + examples: + User not found: + value: { "code": "NotFound", "entity": "user" } + tags: + - User externalDocs: url: https://khofmann.userpage.fu-berlin.de/phpCourse/exam/api/docs/ diff --git a/exam/api/docs/index.html b/exam/api/docs/index.html index 165d24a..30aa47b 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*/ -

User not found.

Request samples

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

Response samples

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

Request samples

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

Response samples

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

Get user posts

Get a users posts ID.

+
Authorizations:
BasicAuth
path Parameters
id
required
integer <int14>

User ID

+
query Parameters
p
integer >= 0
Default: 0

Current page.

+
l
integer [ 0 .. 30 ]
Default: 10

The number of items to return.

+
s
string
Default: "asc"
Enum: "asc" "desc"

Sort order by time.

+

Responses

Response samples

Content type
application/json
{
  • "pages": 0,
  • "data": [
    ]
}