diff --git a/docs/openapi.yml b/docs/openapi.yml index 9a064a1d..099f747e 100644 --- a/docs/openapi.yml +++ b/docs/openapi.yml @@ -433,6 +433,86 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' + get: + tags: + - cohort + summary: Get all cohorts + operationId: getAllCohorts + security: + - bearerAuth: [] + responses: + '201': + description: success + content: + application/json: + schema: + type: object + properties: + status: + type: string + data: + properties: + cohort: + $ref: '#/components/schemas/Cohort' + '401': + description: fail + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + '500': + description: Server error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + /cohorts/{id}: + get: + tags: + - cohort + summary: Get a cohort by id + operationId: getCohortById + security: + - bearerAuth: [] + parameters: + - name: id + in: path + description: 'The cohort id' + required: true + schema: + type: integer + responses: + '201': + description: success + content: + application/json: + schema: + type: object + properties: + status: + type: string + data: + properties: + cohort: + $ref: '#/components/schemas/Cohort' + '401': + description: Unautorized + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + '404': + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + '500': + description: Server error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' components: securitySchemes: @@ -460,12 +540,18 @@ components: properties: id: type: integer + cohortName: + type: string createdAt: type: string format: date-time updatedAt: type: string format: date-time + users: + type: array + items: + $ref: '#/components/schemas/User' AllUsers: type: object @@ -729,7 +815,7 @@ components: format: date-time profileImage: type: string - + Error: type: object properties: diff --git a/src/middleware/post.js b/src/middleware/post.js index 8f110acf..f2d189c6 100644 --- a/src/middleware/post.js +++ b/src/middleware/post.js @@ -20,3 +20,22 @@ export async function validatePostOwnership(req, res, next) { return sendDataResponse(res, 500, { content: 'Internal server error' }) } } + +export async function validatePostContent(req, res, next) { + const { content } = req.body + const maxLength = 200 + + if (!content || content.trim() === '') { + return sendDataResponse(res, 400, { + content: 'Content cannot be empty or null' + }) + } + + if (content.length > maxLength) { + return sendDataResponse(res, 400, { + content: `Content cannot exceed ${maxLength} characters` + }) + } + + next() +} diff --git a/src/routes/post.js b/src/routes/post.js index bc9ef6e6..1a337e46 100644 --- a/src/routes/post.js +++ b/src/routes/post.js @@ -7,11 +7,15 @@ import { deleteById } from '../controllers/post.js' import { validateAuthentication } from '../middleware/auth.js' -import { validatePostOwnership } from '../middleware/post.js' + +import { + validatePostOwnership, + validatePostContent +} from '../middleware/post.js' const router = Router() -router.post('/', validateAuthentication, create) +router.post('/', validateAuthentication, validatePostContent, create) router.get('/', validateAuthentication, getAll) router.get('/:id', validateAuthentication, getById) router.patch('/:id', validateAuthentication, validatePostOwnership, updateById)