Swagger/schedules request and response examples (#257)
This PR adds request body and response body examples to swagger in /schedules endpoint Added for: - [x] `/schedules/_post` - [x] `/schedules/_get` - [x] `/schedules/[id]/_get` - [x] `/schedules/[id]/_post` - [x] `/schedules/[id]/_patch`pull/9078/head
parent
d5db1e4171
commit
38987b77bb
|
@ -29,11 +29,48 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
|
|||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* content:
|
||||
* application/json:
|
||||
* examples:
|
||||
* schedule:
|
||||
* value:
|
||||
* {
|
||||
* "schedule": {
|
||||
* "id": 12345,
|
||||
* "userId": 182,
|
||||
* "name": "Sample Schedule",
|
||||
* "timeZone": "Asia/Calcutta",
|
||||
* "availability": [
|
||||
* {
|
||||
* "id": 111,
|
||||
* "eventTypeId": null,
|
||||
* "days": [0, 1, 2, 3, 4, 6],
|
||||
* "startTime": "00:00:00",
|
||||
* "endTime": "23:45:00"
|
||||
* },
|
||||
* {
|
||||
* "id": 112,
|
||||
* "eventTypeId": null,
|
||||
* "days": [5],
|
||||
* "startTime": "00:00:00",
|
||||
* "endTime": "12:00:00"
|
||||
* },
|
||||
* {
|
||||
* "id": 113,
|
||||
* "eventTypeId": null,
|
||||
* "days": [5],
|
||||
* "startTime": "15:00:00",
|
||||
* "endTime": "23:45:00"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: Schedule was not found
|
||||
*/
|
||||
|
||||
export async function getHandler(req: NextApiRequest) {
|
||||
const { prisma, query } = req;
|
||||
const { id } = schemaQueryIdParseInt.parse(query);
|
||||
|
|
|
@ -27,7 +27,7 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
|
|||
* required: true
|
||||
* description: Your API Key
|
||||
* requestBody:
|
||||
* description: Create a new schedule
|
||||
* description: Edit an existing schedule
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
|
@ -37,19 +37,49 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
|
|||
* name:
|
||||
* type: string
|
||||
* description: Name of the schedule
|
||||
* timezone:
|
||||
* timeZone:
|
||||
* type: string
|
||||
* description: The timezone for this schedule
|
||||
* examples:
|
||||
* schedule:
|
||||
* value:
|
||||
* {
|
||||
* "name": "Updated Schedule",
|
||||
* "timeZone": "Asia/Calcutta"
|
||||
* }
|
||||
* tags:
|
||||
* - schedules
|
||||
* responses:
|
||||
* 201:
|
||||
* 200:
|
||||
* description: OK, schedule edited successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* examples:
|
||||
* schedule:
|
||||
* value:
|
||||
* {
|
||||
* "schedule": {
|
||||
* "id": 12345,
|
||||
* "userId": 1,
|
||||
* "name": "Total Testing Part 2",
|
||||
* "timeZone": "Asia/Calcutta",
|
||||
* "availability": [
|
||||
* {
|
||||
* "id": 4567,
|
||||
* "eventTypeId": null,
|
||||
* "days": [1, 2, 3, 4, 5],
|
||||
* "startTime": "09:00:00",
|
||||
* "endTime": "17:00:00"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
* 400:
|
||||
* description: Bad request. Schedule body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
|
||||
export async function patchHandler(req: NextApiRequest) {
|
||||
const { prisma, query } = req;
|
||||
const { id } = schemaQueryIdParseInt.parse(query);
|
||||
|
|
|
@ -30,11 +30,51 @@ export const schemaUserIds = z
|
|||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* content:
|
||||
* application/json:
|
||||
* examples:
|
||||
* schedules:
|
||||
* value:
|
||||
* {
|
||||
* "schedules": [
|
||||
* {
|
||||
* "id": 1234,
|
||||
* "userId": 5678,
|
||||
* "name": "Sample Schedule 1",
|
||||
* "timeZone": "America/Chicago",
|
||||
* "availability": [
|
||||
* {
|
||||
* "id": 987,
|
||||
* "eventTypeId": null,
|
||||
* "days": [1, 2, 3, 4, 5],
|
||||
* "startTime": "09:00:00",
|
||||
* "endTime": "23:00:00"
|
||||
* }
|
||||
* ]
|
||||
* },
|
||||
* {
|
||||
* "id": 2345,
|
||||
* "userId": 6789,
|
||||
* "name": "Sample Schedule 2",
|
||||
* "timeZone": "Europe/Amsterdam",
|
||||
* "availability": [
|
||||
* {
|
||||
* "id": 876,
|
||||
* "eventTypeId": null,
|
||||
* "days": [1, 2, 3, 4, 5],
|
||||
* "startTime": "09:00:00",
|
||||
* "endTime": "17:00:00"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No schedules were found
|
||||
*/
|
||||
|
||||
async function handler(req: NextApiRequest) {
|
||||
const { prisma, userId, isAdmin } = req;
|
||||
const args: Prisma.ScheduleFindManyArgs = isAdmin ? {} : { where: { userId } };
|
||||
|
|
|
@ -29,24 +29,55 @@ import { schemaCreateScheduleBodyParams, schemaSchedulePublic } from "~/lib/vali
|
|||
* type: object
|
||||
* required:
|
||||
* - name
|
||||
* - timezone
|
||||
* - timeZone
|
||||
* properties:
|
||||
* name:
|
||||
* type: string
|
||||
* description: Name of the schedule
|
||||
* timezone:
|
||||
* timeZone:
|
||||
* type: string
|
||||
* description: The timezone for this schedule
|
||||
* description: The timeZone for this schedule
|
||||
* examples:
|
||||
* schedule:
|
||||
* value:
|
||||
* {
|
||||
* "name": "Sample Schedule",
|
||||
* "timeZone": "Asia/Calcutta"
|
||||
* }
|
||||
* tags:
|
||||
* - schedules
|
||||
* responses:
|
||||
* 201:
|
||||
* 200:
|
||||
* description: OK, schedule created
|
||||
* content:
|
||||
* application/json:
|
||||
* examples:
|
||||
* schedule:
|
||||
* value:
|
||||
* {
|
||||
* "schedule": {
|
||||
* "id": 79471,
|
||||
* "userId": 182,
|
||||
* "name": "Total Testing",
|
||||
* "timeZone": "Asia/Calcutta",
|
||||
* "availability": [
|
||||
* {
|
||||
* "id": 337917,
|
||||
* "eventTypeId": null,
|
||||
* "days": [1, 2, 3, 4, 5],
|
||||
* "startTime": "09:00:00",
|
||||
* "endTime": "17:00:00"
|
||||
* }
|
||||
* ]
|
||||
* },
|
||||
* "message": "Schedule created successfully"
|
||||
* }
|
||||
* 400:
|
||||
* description: Bad request. Schedule body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
|
||||
async function postHandler(req: NextApiRequest) {
|
||||
const { userId, isAdmin, prisma } = req;
|
||||
const body = schemaCreateScheduleBodyParams.parse(req.body);
|
||||
|
|
Loading…
Reference in New Issue