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