From ea728345afa5bd5b5d7eaf48fcccd03be065bec1 Mon Sep 17 00:00:00 2001
From: rlacko <rlacko@sch.bme.hu>
Date: Mon, 3 Aug 2020 18:47:53 +0200
Subject: [PATCH] Solution documentation

---
 src/resources/solution/solutionDocs.yml  | 124 +++++++++++++++++++++++
 src/resources/solution/solutionModel.js  |   2 -
 src/resources/solution/solutionRouter.js |   8 +-
 3 files changed, 128 insertions(+), 6 deletions(-)
 create mode 100644 src/resources/solution/solutionDocs.yml

diff --git a/src/resources/solution/solutionDocs.yml b/src/resources/solution/solutionDocs.yml
new file mode 100644
index 0000000..00b37c6
--- /dev/null
+++ b/src/resources/solution/solutionDocs.yml
@@ -0,0 +1,124 @@
+openapi: '3.0.2'
+info:
+  title: 'Solution Endpoint'
+  version: '1.0'
+
+paths:
+  /solution:
+    get:
+      tags:
+        - 'Solution'
+      summary: 'Get a List of solution'
+      description: 'Have to be accepted or mentor. 
+        As an accepted only own solutions can be seen.'
+      operationId: 'getAllSolution'
+      responses:
+        '200':
+          description: OK
+          content:
+            application/json:
+              schema:
+                type: 'array'
+                items:
+                  $ref: '#/components/schemas/Solution'
+    post:
+      tags:
+        - 'Solution'
+      summary: 'Create a solution'
+      description: 'Have to be accepted or mentor. 
+        As an accepted only own own solution can be made.'
+      operationId: 'createSolution'
+      requestBody:
+        content:
+          application/json:
+            schema:
+              $ref: '#/components/schemas/Solution'
+      responses:
+        '200':
+          description: OK
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/Solution'
+  /solution/id/{id}:
+    get:
+      tags:
+        - 'Solution'
+      summary: 'Get a solution by ID'
+      description: 'Have to be accepted or mentor. 
+        As an accepted only own solutions can be get.'
+      operationId: 'getSolution'
+      responses:
+        '200':
+          description: OK
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/Solution'
+    put:
+      tags:
+        - 'Solution'
+      summary: 'Update a solution by ID'
+      description: 'Have to be accepted or mentor. 
+        As an accepted only own solutions can be get. 
+        After deadline cant make new solution as accepted.'
+      operationId: 'updateOneSolution'
+      requestBody:
+        content:
+          application/json:
+            schema:
+              $ref: '#/components/schemas/Solution'
+      responses:
+        '200':
+          description: OK
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/Solution'
+    delete:
+      tags:
+        - 'Solution'
+      summary: 'Delete a solution by ID'
+      description: 'Have to be accepted or mentor. 
+      As an accepted only own solutions can be delted. 
+      After deadline cant make new solution as accepted.'
+      operationId: 'deleteSolution'
+      responses:
+        '200':
+          description: OK
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/Solution'
+
+components:
+  schemas:
+    Solution:
+      type: object
+      properties:
+        task:
+          type: string
+          description: cuid of the task
+        title:
+          type: string
+        description:
+          type: string
+        file:
+          type: string
+        creator:
+          type: string
+          description: schacc of the user
+        comments:
+          type: array
+          items:
+            type: string
+            description: cuid of each comment
+        isAccepted:
+          type: boolean
+          default: false
+      required:
+        - task
+        - title
+        - description
+        - creator
+        - isAccepted
diff --git a/src/resources/solution/solutionModel.js b/src/resources/solution/solutionModel.js
index c589ca9..11c1a52 100644
--- a/src/resources/solution/solutionModel.js
+++ b/src/resources/solution/solutionModel.js
@@ -17,7 +17,6 @@ const SolutionSchema = new mongoose.Schema(
     },
     file: {
       type: String,
-      required: true,
     },
     creator: {
       type: String,
@@ -27,7 +26,6 @@ const SolutionSchema = new mongoose.Schema(
       {
         type: mongoose.Schema.Types.ObjectId,
         ref: 'comment',
-        required: true,
       },
     ],
     isAccepted: {
diff --git a/src/resources/solution/solutionRouter.js b/src/resources/solution/solutionRouter.js
index 7ec1a2f..ec24893 100644
--- a/src/resources/solution/solutionRouter.js
+++ b/src/resources/solution/solutionRouter.js
@@ -4,17 +4,17 @@ const { isLoggedIn, isAcceptedOrMentor } = require('../../middlewares/auth')
 
 const router = Router()
 
-// /api/item
+// /api/v1/solution
 router
   .route('/')
   .get(isLoggedIn, isAcceptedOrMentor, controllers.default.getMany)
   .post(isLoggedIn, isAcceptedOrMentor, controllers.default.createOne)
 
-// /api/item/:id
+// /api/v1/solution/id/:id
 router
-  .route('/:id')
+  .route('/id/:id')
   .get(isLoggedIn, isAcceptedOrMentor, controllers.default.getOne)
-  .delete(isLoggedIn, isAcceptedOrMentor, controllers.default.notSupported)
   .put(isLoggedIn, isAcceptedOrMentor, controllers.default.notSupported)
+  .delete(isLoggedIn, isAcceptedOrMentor, controllers.default.notSupported)
 
 exports.default = router
-- 
GitLab