|
@@ -1,8 +1,6 @@
|
|
|
package com.swagger.rest.controllers
|
|
|
|
|
|
-import com.swagger.rest.models.Bug
|
|
|
-import com.swagger.rest.models.BugInput
|
|
|
-import com.swagger.rest.models.BugOutput
|
|
|
+import com.swagger.rest.models.*
|
|
|
import com.swagger.rest.models.Enum
|
|
|
import com.swagger.rest.repositories.*
|
|
|
import jakarta.persistence.criteria.Predicate
|
|
@@ -130,6 +128,163 @@ class BugController(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/projects/{id}/bug")
|
|
|
+ fun getBugByProjectId(
|
|
|
+ @PathVariable("id") id: Long,
|
|
|
+ @RequestParam(defaultValue = 0.toString()) page: Int,
|
|
|
+ @RequestParam(defaultValue = 3.toString()) limit: Int,
|
|
|
+ @RequestParam(defaultValue = "bug_id, desc") sort: Array<String>
|
|
|
+ ): Any {
|
|
|
+ return try {
|
|
|
+ val orders: MutableList<Sort.Order> = ArrayList()
|
|
|
+ val column = listOf(
|
|
|
+ "bug_id",
|
|
|
+ "created",
|
|
|
+ "description",
|
|
|
+ "qc",
|
|
|
+ "dev",
|
|
|
+ "platform",
|
|
|
+ "goodday_url",
|
|
|
+ "image_url",
|
|
|
+ "level",
|
|
|
+ "status",
|
|
|
+ "dev_status"
|
|
|
+ )
|
|
|
+ val sort2 = if (!sort.contains(",")) {
|
|
|
+ sort + ",desc"
|
|
|
+ } else {
|
|
|
+ sort
|
|
|
+ }
|
|
|
+ if (!column.contains(sort2[0])) {
|
|
|
+ ResponseEntity<Bug>(HttpStatus.BAD_REQUEST)
|
|
|
+ } else {
|
|
|
+ if (sort2[0].contains(",")) {
|
|
|
+ // will sort more than 2 fields
|
|
|
+ // sortOrder="field, direction"
|
|
|
+ for (sortOrder in sort2) {
|
|
|
+ val _sort = sortOrder.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
|
|
+ orders.add(Sort.Order(getSortDirection(_sort[1]), _sort[0]))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // sort=[field, direction]
|
|
|
+ orders.add(Sort.Order(getSortDirection(sort2[1]), sort2[0]))
|
|
|
+ }
|
|
|
+ val pagingSort: Pageable = PageRequest.of(page, limit, Sort.by(orders))
|
|
|
+ val bugs = bugRepository.findByProject(id.toString(), pagingSort)
|
|
|
+ val output = bugs.map {
|
|
|
+ BugOutput(
|
|
|
+ id = it.id,
|
|
|
+ created = SimpleDateFormat("dd-MMM-yy HH:mm:ss").format(it.created),
|
|
|
+ description = it.description,
|
|
|
+ qc = it.qc!!.name,
|
|
|
+ dev = it.dev!!.name,
|
|
|
+ platform = it.platform!!.name,
|
|
|
+ goodday_url = it.goodday_url,
|
|
|
+ image_url = it.image_url,
|
|
|
+ level = Enum.Level.values()[it.level],
|
|
|
+ status = Enum.Status.values()[it.status],
|
|
|
+ dev_status = Enum.Dev_Status.values()[it.dev_status]
|
|
|
+ )
|
|
|
+ }
|
|
|
+ val ret = output.content
|
|
|
+ val response: MutableMap<String, Any> = HashMap()
|
|
|
+ response["currentPage"] = output.number
|
|
|
+ response["totalRecord"] = output.totalElements
|
|
|
+ response["totalPage"] = output.totalPages
|
|
|
+ response["results"] = ret
|
|
|
+ if (ret.isNotEmpty()) {
|
|
|
+ ResponseEntity(response, HttpStatus.OK)
|
|
|
+ } else {
|
|
|
+ arrayOf<String>()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ ResponseEntity(e, HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/platforms/{id}/bug")
|
|
|
+ fun getBugByPlatformId(
|
|
|
+ @PathVariable("id") id: Long,
|
|
|
+ @RequestParam(defaultValue = 0.toString()) page: Int,
|
|
|
+ @RequestParam(defaultValue = 3.toString()) limit: Int,
|
|
|
+ @RequestParam(defaultValue = "id, desc") sort: Array<String>
|
|
|
+ ): Any {
|
|
|
+ return try {
|
|
|
+ val orders: MutableList<Sort.Order> = ArrayList()
|
|
|
+ val column = listOf(
|
|
|
+ "id",
|
|
|
+ "created",
|
|
|
+ "description",
|
|
|
+ "qc",
|
|
|
+ "dev",
|
|
|
+ "platform",
|
|
|
+ "goodday_url",
|
|
|
+ "image_url",
|
|
|
+ "level",
|
|
|
+ "status",
|
|
|
+ "dev_status"
|
|
|
+ )
|
|
|
+ val sort2 = if (!sort.contains(",")) {
|
|
|
+ sort + ",desc"
|
|
|
+ } else {
|
|
|
+ sort
|
|
|
+ }
|
|
|
+ if (!column.contains(sort2[0])) {
|
|
|
+ ResponseEntity<Bug>(HttpStatus.BAD_REQUEST)
|
|
|
+ } else {
|
|
|
+ if (sort2[0].contains(",")) {
|
|
|
+ // will sort more than 2 fields
|
|
|
+ // sortOrder="field, direction"
|
|
|
+ for (sortOrder in sort2) {
|
|
|
+ val _sort = sortOrder.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
|
|
+ orders.add(Sort.Order(getSortDirection(_sort[1]), _sort[0]))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // sort=[field, direction]
|
|
|
+ orders.add(Sort.Order(getSortDirection(sort2[1]), sort2[0]))
|
|
|
+ }
|
|
|
+ val pagingSort: Pageable = PageRequest.of(page, limit, Sort.by(orders))
|
|
|
+ val spec = Specification<Bug> { root, query, builder ->
|
|
|
+ val list: MutableList<Predicate> = mutableListOf()
|
|
|
+ list.add(builder.equal(root.get<Platform>("platform").get<Long>("id"), id))
|
|
|
+ builder.and(*list.toTypedArray())
|
|
|
+ }
|
|
|
+ val bugs = bugRepository.findAll(spec, pagingSort)
|
|
|
+ val output = bugs.map {
|
|
|
+ BugOutput(
|
|
|
+ id = it.id,
|
|
|
+ created = SimpleDateFormat("dd-MMM-yy HH:mm:ss").format(it.created),
|
|
|
+ description = it.description,
|
|
|
+ qc = it.qc!!.name,
|
|
|
+ dev = it.dev!!.name,
|
|
|
+ platform = it.platform!!.name,
|
|
|
+ goodday_url = it.goodday_url,
|
|
|
+ image_url = it.image_url,
|
|
|
+ level = Enum.Level.values()[it.level],
|
|
|
+ status = Enum.Status.values()[it.status],
|
|
|
+ dev_status = Enum.Dev_Status.values()[it.dev_status]
|
|
|
+ )
|
|
|
+ }
|
|
|
+ val ret = output.content
|
|
|
+ val response: MutableMap<String, Any> = HashMap()
|
|
|
+ response["currentPage"] = output.number
|
|
|
+ response["totalRecord"] = output.totalElements
|
|
|
+ response["totalPage"] = output.totalPages
|
|
|
+ response["results"] = ret
|
|
|
+ if (ret.isNotEmpty()) {
|
|
|
+ ResponseEntity(response, HttpStatus.OK)
|
|
|
+ } else {
|
|
|
+ arrayOf<String>()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ ResponseEntity(e, HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping("/bugs/{id}")
|
|
|
fun getBugById(@PathVariable("id") id: Long): Any {
|
|
|
val bugData = bugRepository.findById(id)
|
|
@@ -174,7 +329,7 @@ class BugController(
|
|
|
it.name == bugInput.status.uppercase()
|
|
|
} || !enumValues<Enum.Dev_Status>().any { it.name == bugInput.dev_status.uppercase() }) {
|
|
|
ResponseEntity(HttpStatus.BAD_REQUEST)
|
|
|
- } else if (!regex(bugInput.goodday_url.trim()) || !regex(bugInput.image_url.trim())) {
|
|
|
+ } else if (!regex(bugInput.goodday_url.trim()) || (bugInput.image_url.isNotEmpty() && !regex(bugInput.image_url.trim()))) {
|
|
|
ResponseEntity(HttpStatus.BAD_REQUEST)
|
|
|
} else if (countPlat == 0) {
|
|
|
ResponseEntity(HttpStatus.NOT_FOUND)
|