|
@@ -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)
|