athrainsky 11 månader sedan
förälder
incheckning
c4579bb028

BIN
bug.jpg


+ 32 - 11
src/main/kotlin/com/swagger/rest/controllers/PlatformController.kt

@@ -2,21 +2,18 @@ package com.swagger.rest.controllers
 
 import com.swagger.rest.models.Platform
 import com.swagger.rest.models.PlatformInput
-import com.swagger.rest.models.Project
+import com.swagger.rest.models.PlatformOutput
 import com.swagger.rest.repositories.MemberRepository
 import com.swagger.rest.repositories.PlatformRepository
 import com.swagger.rest.repositories.ProjectRepository
 import com.swagger.rest.repositories.UserRepository
-import jakarta.persistence.criteria.Predicate
 import org.springframework.data.domain.PageRequest
 import org.springframework.data.domain.Pageable
 import org.springframework.data.domain.Sort
-import org.springframework.data.jpa.domain.Specification
 import org.springframework.http.HttpStatus
 import org.springframework.http.ResponseEntity
 import org.springframework.security.core.context.SecurityContextHolder
 import org.springframework.web.bind.annotation.*
-import java.util.*
 
 @RestController
 @RequestMapping("/api/v1")
@@ -67,7 +64,14 @@ class PlatformController(
                 }
                 val pagingSort: Pageable = PageRequest.of(page, limit, Sort.by(orders as List<Sort.Order>))
                 val platforms = platformRepository.findOwnerOrMember(userId.id.toString(), pagingSort)
-                val ret: List<Platform?> = platforms.content
+                val output = platforms.map {
+                    PlatformOutput(
+                        id = it.id,
+                        name = it.name,
+                        project = it.project!!.description
+                    )
+                }
+                val ret: List<PlatformOutput?> = output.content
                 val response: MutableMap<String, Any> = HashMap()
                 response["currentPage"] = platforms.number
                 response["totalRecord"] = platforms.totalElements
@@ -86,19 +90,26 @@ class PlatformController(
     }
 
     @GetMapping("/platforms/{id}")
-    fun getPlatformById(@PathVariable("id") id: Long): ResponseEntity<Platform> {
-        val platformData: Optional<Platform?> = platformRepository.findById(id)
+    fun getPlatformById(@PathVariable("id") id: Long): Any {
+        val platformData = platformRepository.findById(id)
+        val output = platformData.map {
+            PlatformOutput(
+                id = it.id,
+                name = it.name,
+                project = it.project!!.description
+            )
+        }
         return if (platformData.isPresent) {
-            ResponseEntity<Platform>(platformData.get(), HttpStatus.OK)
+            ResponseEntity<PlatformOutput>(output.get(), HttpStatus.OK)
         } else {
-            ResponseEntity<Platform>(HttpStatus.NOT_FOUND)
+            ResponseEntity<PlatformOutput>(HttpStatus.NOT_FOUND)
         }
     }
 
     @PostMapping("/platforms")
     fun addPlatformByProjectId(
         @RequestBody platform: PlatformInput
-    ): ResponseEntity<Platform> {
+    ): Any {
         val proj = (projectRepository.countByName(platform.project_name))
         return if (proj > 0 && platform.project_name!!.isNotBlank()) {
             val foundProject = projectRepository.findByName(platform.project_name)
@@ -116,7 +127,17 @@ class PlatformController(
                         val newPlatform = Platform()
                         newPlatform.name = platform.name!!.trim()
                         newPlatform.project = foundProject
-                        ResponseEntity<Platform>(platformRepository.save(newPlatform), HttpStatus.CREATED)
+                        val save = platformRepository.save(newPlatform)
+                        if (listOf(save).isNotEmpty()) {
+                            val output = PlatformOutput(
+                                id = newPlatform.id,
+                                name = newPlatform.name,
+                                project = newPlatform.project!!.description
+                            )
+                            ResponseEntity(output, HttpStatus.CREATED)
+                        } else {
+                            ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR)
+                        }
                     }
                 } else {//invalid name
                     ResponseEntity<Platform>(HttpStatus.BAD_REQUEST)

+ 11 - 0
src/main/kotlin/com/swagger/rest/models/PlatformOutput.kt

@@ -0,0 +1,11 @@
+package com.swagger.rest.models
+
+class PlatformOutput (
+
+    var id: Long? = 0,
+
+    var name: String? = "",
+
+    var project: String? = null
+
+)

+ 7 - 67
swagger3 project.yml

@@ -626,7 +626,7 @@ components:
     roleQuery:
       name: role
       in: query
-      description: filter role
+      description: filter role (role = QC, Programmer, Admin)
       schema:
         type: string
     sortQuery:
@@ -758,28 +758,8 @@ components:
                         name:
                           type: string
                           example: mobile
-                        project_id:
-                          properties:
-                            id:
-                              type: integer
-                              example: 1
-                            name:
-                              type: string
-                              example: TM
-                            description:
-                              type: string
-                              example: TelMessenger
-                            owner:
-                              properties:
-                                id:
-                                  type: integer
-                                  example: 1
-                                username:
-                                  type: string
-                                  example: abi
-                                name:
-                                  type: string
-                                  example: abidzar            
+                        project:
+                          example: TelMessenger
     successAddPlatform:
       description: record successfully added
       content:
@@ -792,28 +772,8 @@ components:
               name:
                 type: string
                 example: mobile
-              project_id:
-                properties:
-                  id:
-                    type: integer
-                    example: 1
-                  name:
-                    type: string
-                    example: TM
-                  description:
-                    type: string
-                    example: TelMessenger
-                  owner:
-                    properties:
-                      id:
-                        type: integer
-                        example: 1
-                      username:
-                        type: string
-                        example: abi
-                      name:
-                        type: string
-                        example: abidzar
+              project:
+                example: TelMessenger
     getSinglePlatform:
       description: successful operation
       content:
@@ -826,28 +786,8 @@ components:
               name:
                 type: string
                 example: mobile
-              project_id:
-                properties:
-                  id:
-                    type: integer
-                    example: 1
-                  name:
-                    type: string
-                    example: TM
-                  description:
-                    type: string
-                    example: TelMessenger
-                  owner:
-                    properties:
-                      id:
-                        type: integer
-                        example: 1
-                      username:
-                        type: string
-                        example: abi
-                      name:
-                        type: string
-                        example: abidzar
+              project:
+                example: TelMessenger
     getArrayUser:
       description: successful operation
       content: