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:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: OK
|
* 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:
|
* 401:
|
||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
* 404:
|
* 404:
|
||||||
* description: Schedule was not found
|
* description: Schedule was not found
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function getHandler(req: NextApiRequest) {
|
export async function getHandler(req: NextApiRequest) {
|
||||||
const { prisma, query } = req;
|
const { prisma, query } = req;
|
||||||
const { id } = schemaQueryIdParseInt.parse(query);
|
const { id } = schemaQueryIdParseInt.parse(query);
|
||||||
|
|
|
@ -27,7 +27,7 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
|
||||||
* required: true
|
* required: true
|
||||||
* description: Your API Key
|
* description: Your API Key
|
||||||
* requestBody:
|
* requestBody:
|
||||||
* description: Create a new schedule
|
* description: Edit an existing schedule
|
||||||
* required: true
|
* required: true
|
||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
|
@ -37,19 +37,49 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
|
||||||
* name:
|
* name:
|
||||||
* type: string
|
* type: string
|
||||||
* description: Name of the schedule
|
* description: Name of the schedule
|
||||||
* timezone:
|
* timeZone:
|
||||||
* type: string
|
* type: string
|
||||||
* description: The timezone for this schedule
|
* description: The timezone for this schedule
|
||||||
|
* examples:
|
||||||
|
* schedule:
|
||||||
|
* value:
|
||||||
|
* {
|
||||||
|
* "name": "Updated Schedule",
|
||||||
|
* "timeZone": "Asia/Calcutta"
|
||||||
|
* }
|
||||||
* tags:
|
* tags:
|
||||||
* - schedules
|
* - schedules
|
||||||
* responses:
|
* responses:
|
||||||
* 201:
|
* 200:
|
||||||
* description: OK, schedule edited successfully
|
* 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:
|
* 400:
|
||||||
* description: Bad request. Schedule body is invalid.
|
* description: Bad request. Schedule body is invalid.
|
||||||
* 401:
|
* 401:
|
||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function patchHandler(req: NextApiRequest) {
|
export async function patchHandler(req: NextApiRequest) {
|
||||||
const { prisma, query } = req;
|
const { prisma, query } = req;
|
||||||
const { id } = schemaQueryIdParseInt.parse(query);
|
const { id } = schemaQueryIdParseInt.parse(query);
|
||||||
|
|
|
@ -30,11 +30,51 @@ export const schemaUserIds = z
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: OK
|
* 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:
|
* 401:
|
||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
* 404:
|
* 404:
|
||||||
* description: No schedules were found
|
* description: No schedules were found
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function handler(req: NextApiRequest) {
|
async function handler(req: NextApiRequest) {
|
||||||
const { prisma, userId, isAdmin } = req;
|
const { prisma, userId, isAdmin } = req;
|
||||||
const args: Prisma.ScheduleFindManyArgs = isAdmin ? {} : { where: { userId } };
|
const args: Prisma.ScheduleFindManyArgs = isAdmin ? {} : { where: { userId } };
|
||||||
|
|
|
@ -29,24 +29,55 @@ import { schemaCreateScheduleBodyParams, schemaSchedulePublic } from "~/lib/vali
|
||||||
* type: object
|
* type: object
|
||||||
* required:
|
* required:
|
||||||
* - name
|
* - name
|
||||||
* - timezone
|
* - timeZone
|
||||||
* properties:
|
* properties:
|
||||||
* name:
|
* name:
|
||||||
* type: string
|
* type: string
|
||||||
* description: Name of the schedule
|
* description: Name of the schedule
|
||||||
* timezone:
|
* timeZone:
|
||||||
* type: string
|
* type: string
|
||||||
* description: The timezone for this schedule
|
* description: The timeZone for this schedule
|
||||||
|
* examples:
|
||||||
|
* schedule:
|
||||||
|
* value:
|
||||||
|
* {
|
||||||
|
* "name": "Sample Schedule",
|
||||||
|
* "timeZone": "Asia/Calcutta"
|
||||||
|
* }
|
||||||
* tags:
|
* tags:
|
||||||
* - schedules
|
* - schedules
|
||||||
* responses:
|
* responses:
|
||||||
* 201:
|
* 200:
|
||||||
* description: OK, schedule created
|
* 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:
|
* 400:
|
||||||
* description: Bad request. Schedule body is invalid.
|
* description: Bad request. Schedule body is invalid.
|
||||||
* 401:
|
* 401:
|
||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function postHandler(req: NextApiRequest) {
|
async function postHandler(req: NextApiRequest) {
|
||||||
const { userId, isAdmin, prisma } = req;
|
const { userId, isAdmin, prisma } = req;
|
||||||
const body = schemaCreateScheduleBodyParams.parse(req.body);
|
const body = schemaCreateScheduleBodyParams.parse(req.body);
|
||||||
|
|
Loading…
Reference in New Issue