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*/
-{- "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
}{- "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
}Get a users posts ID.
+| id required | integer <int14> User ID + |
| 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. + |
{- "pages": 0,
- "data": [
- {
- "id": 0,
- "user": {
- "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
}, - "content": "string",
- "postedAt": {
- "date": "2019-08-24T14:15:22Z",
- "timezone_type": 0,
- "timezone": "string"
}
}
]
}