diff --git a/controllers/validation.js b/controllers/validation.js index 8051ef9..070a4e2 100644 --- a/controllers/validation.js +++ b/controllers/validation.js @@ -8,7 +8,7 @@ const {Validator, ValidationError} = require('jsonschema'); const userSchema = require('../schemas/user.json').definitions.user; -const appSchema = require('../schemas/application.schema.js'); +const appSchema = require('../schemas/application.json').definitions.application; /** * Wrapper that returns a Koa middleware validator for a given schema. diff --git a/docs/openapi/index.html b/docs/openapi/index.html index f71c6bb..ca02866 100644 --- a/docs/openapi/index.html +++ b/docs/openapi/index.html @@ -1,7 +1,7 @@ - Blog API Docs + Gym API Docs diff --git a/schemas/application.json b/schemas/application.json new file mode 100644 index 0000000..4133944 --- /dev/null +++ b/schemas/application.json @@ -0,0 +1,81 @@ +{ +"$schema": "https://json-schema.org/draft-07/schema#", +"definitions": { + "application": { + + "title": "Application", + "description": "Gym membership application", + + "type": "object", + "properties": { + + "firstName": { + "type": "string", + "maxLength": 64, + "description": "First Name" + }, + + "lastName": { + "type": "string", + "maxLength": 64, + "description": "Last Name" + }, + + "email": { + "type": "string", + "maxLength": 64, + "description": "Email of user" + }, + + "address": { + "type": "string", + "maxLength": 255, + "description": "Address of user" + }, + + "paymentDetails": { + "type": "string", + "maxLength": 64, + "description": "Payment Details of user" + }, + + "fitnessGoals": { + "type": "string", + "maxLength": 255, + "description": "User's fitness goals" + }, + + "medicalHistory": { + "type": "string", + "maxLength": 255, + "description": "Medical history of user" + } + }, + + "required": [""], + "additionalProperties": false + }, + + "applicationCreation": { + "$id": "#applicationCreation", + "title": "Application Creation", + "description": "Creation of application", + + "type": "object", + "properties": { + "ID": { + "description": "ID of created application", + "type": "Integer" + } + } + + }, + "getAllApplications": { + "$id": "#getAllApplications", + "title": "Getting all applications", + "description": "JSON data of application returned", + "type": "object", + "allOf": [{ "$ref": "#/definitions/application" }] + } +} +} diff --git a/schemas/application.schema.js b/schemas/application.schema.js deleted file mode 100644 index ddf20c5..0000000 --- a/schemas/application.schema.js +++ /dev/null @@ -1,40 +0,0 @@ -module.exports = { - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "/application", - "title": "Application", - "description": "An application filled by a prospective client of the gym", - "type": "object", - "properties": { - "firstName": { - "description": "The first name of the user", - "type": "string" - }, - "lastName": { - "description": "The last name of the user", - "type": "string" - }, - "email": { - "description": "The email of the user", - "type": "string" - }, - "address": { - "description": "The address of the user", - "type": "string", - - }, - "paymentDetails": { - "description": "Details about how the user is going to pay for the membership", - "type": "string" - }, - "fitnessGoals": { - "description": "The fitness goals of the user", - "type": "string", - }, - "medicalHistory": { - "description": "Relevant medical history of the user", - "type": "string", - }, - }, - "required": [], - "additionalProperties": false -} \ No newline at end of file diff --git a/schemas/openapi.yaml b/schemas/openapi.yaml index 512cc37..3682e05 100644 --- a/schemas/openapi.yaml +++ b/schemas/openapi.yaml @@ -10,13 +10,13 @@ info: name: Apache 2.0 url: 'https://www.apache.org/licenses/LICENSE-2.0.html' servers: - - url: 'https://ecology-fiction-3000.codio-box.uk/api/v1' + - url: 'https://exile-region-3000.codio-box.uk/api/v1' description: Development server tags: - name: Users description: API endpoints for user management. - - name: Articles - description: Access and perform CRUD operations on blog entries. + - name: Applications + description: Access and perform CRUD operations on application entries. paths: /users: summary: Represents an individual user @@ -116,4 +116,106 @@ paths: '401': description: Only admin users can delete accounts '404': - description: Not found \ No newline at end of file + description: Not found + + /applications: + summary: Represents membership application resource + description: This resource represents membership application resources stored within the database. + get: + tags: + - Applications + description: + Retrieve all membership applications from database. + responses: + '200': + description: All membership applications retrieved + content: + application/json: + schema: + $ref: ./application.json#/definitions/getAllApplications + + + post: + tags: + - Applications + description: + Create a membership application. + requestBody: + description: New membership application data added. + required: true + content: + application/json: + schema: + $ref: ./application.json#/definitions/application + responses: + '201': + description: Application submitted successfully. + content: + application/json: + schema: + $ref: ./application.json#/definitions/applicationCreation + '500': + description: Internal server error. + + + + /applications/{id}: + parameters: + - in: path + name: id + content: + application/json + required: true + description: id of membership. + get: + tags: + - Applications + description: Retrieves membership application based on ID + + responses: + '200': + description: Membership application returned. + content: + application/json: + schema: + $ref: ./application.json#/definitions/application + + + put: + tags: + - Applications + description: Update membership application by id + responses: + '200': + description: Application updated successfully. + content: + application/json: + schema: + $ref: ./application.json#/definitions/applicationCreation + + '403': + description: Only admins have the necessary permissions to update this record. + '404': + description: Not Found. + '500': + description: Internal Server Error. + delete: + tags: + - Applications + description: Remove membership application by id + responses: + '200': + description: Membership application deleted successfully. + content: + application/json: + schema: + $ref: ./application.json#/definitions/applicationCreation + + '403': + description: Only admins have the necessary necessary permissions to delete this record. + '404': + description: Not Found. + '500': + description: Internal Server Error. + + \ No newline at end of file