Bläddra i källkod

1.orphan - cek delete data parent yg masih dipakai
2.lempar id integer
3.update error kalo project tidak lengkap - lempar id saja - bikin non entity

athrainsky 1 år sedan
förälder
incheckning
85065a48db

+ 14 - 8
src/main/kotlin/com/swagger/rest/controllers/PlatformController.kt

@@ -71,28 +71,34 @@ class PlatformController(
     }
 
     @PutMapping("/platforms/{id}")
-    fun updatePlatformById(@PathVariable("id") id: Long, @RequestBody platform: Platform): Any {
+    fun updatePlatformById(@PathVariable("id") id: Long, @RequestBody platform: PlatformInput): Any {
         val platformData: Optional<Platform?> = platformRepository.findById(id)
         val found = platformRepository.findByName(platform.name, platform.project_id.toString())!!.size
-        val foundProject = projectRepository.findById(platform.project_id!!.id).isPresent
-        return if (platform.name.isNotBlank()) {
-            if (platform.name.length > 100) {
+        val foundProject = projectRepository.findById(platform.project_id!!.toLong())
+        return if (platform.name!!.isNotBlank()) {
+            if (platform.name!!.length > 100) {
                 ResponseEntity<Platform>(HttpStatus.PAYLOAD_TOO_LARGE)
-            } else if (!foundProject) {
+            } else if (foundProject.isEmpty) {
+                println(1)
                 ResponseEntity<Platform>(HttpStatus.NOT_FOUND)
             } else if (platformData.isPresent) {
-                if ((platform.name == platformData.get().name && found > 0) || (platform.name !== platformData.get().name && found == 0)) {
+                println(2)
+                if (((platform.name == platformData.get().name && found > 0) || (platform.name !== platformData.get().name && found == 0))) {
+                    println(3)
                     val savePlatform: Platform = platformData.get()
-                    savePlatform.project_id = platform.project_id
-                    savePlatform.name = platform.name
+                    savePlatform.project_id = foundProject.get()
+                    savePlatform.name = platform.name!!
                     ResponseEntity<Platform>(platformRepository.save(savePlatform), HttpStatus.OK)
                 } else {
+                    println(4)
                     ResponseEntity<Platform>(HttpStatus.CONFLICT)
                 }
             } else {
+                println(5)
                 ResponseEntity<Platform>(HttpStatus.NOT_FOUND)
             }
         } else {
+            println(6)
             ResponseEntity<Platform>(HttpStatus.BAD_REQUEST)
         }
     }

+ 1 - 1
src/main/kotlin/com/swagger/rest/models/PlatformInput.kt

@@ -4,6 +4,6 @@ class PlatformInput {
 
     var name: String? = ""
 
-    var project_name: String? = ""
+    var project_id: Long? = 0
 
 }