athrainsky 1 год назад
Родитель
Сommit
3596674d07

+ 4 - 6
src/main/kotlin/com/swagger/rest/controllers/PlatformController.kt

@@ -2,10 +2,8 @@ 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.repositories.PlatformRepository
 import com.swagger.rest.repositories.ProjectRepository
-import org.aspectj.asm.internal.ProgramElement.trim
 import org.springframework.http.HttpStatus
 import org.springframework.http.ResponseEntity
 import org.springframework.web.bind.annotation.*
@@ -23,9 +21,9 @@ class PlatformController(
         return try {
             val platforms: List<Platform> =
                 if (project == null) {
-                    platformRepository.findAll() as List<Platform>
+                    platformRepository.findAll()
                 } else {
-                    platformRepository.findByProject(project) as List<Platform>
+                    platformRepository.findByProject(project)
                 }
             if (platforms.isNotEmpty()) {
                 ResponseEntity<List<Platform>?>(platforms, HttpStatus.OK)
@@ -52,7 +50,7 @@ class PlatformController(
         @RequestBody platform: PlatformInput
     ): ResponseEntity<Platform> {
         return try {
-            val found = platformRepository.findByName(platform.name, platform.project_id.toString())!!.size
+            val found = platformRepository.findByName(platform.name, platform.project_id.toString()).size
             val foundProject = projectRepository.findById(platform.project_id!!.toLong()).isPresent
             if (platform.name!!.isNotBlank()) {
                 if (!foundProject) {//project not found
@@ -86,7 +84,7 @@ class PlatformController(
                 ResponseEntity<Platform>(HttpStatus.NOT_FOUND)
             } else {
                 val check = platformRepository.findByName(input.name, input.project_id.toString())
-                if (check!!.isEmpty() || (input.name == platformExist.get().name && input.project_id.toString() == platformExist.get().project_id!!.id.toString())) {//tidak ada yg sama
+                if (check.isEmpty() || (input.name == platformExist.get().name && input.project_id.toString() == platformExist.get().project_id!!.id.toString())) {//tidak ada yg sama
                     val savePlatform = platformExist.get()
                     savePlatform.project_id = targetProject.get()
                     savePlatform.name = input.name!!.trim()

+ 5 - 6
src/main/kotlin/com/swagger/rest/controllers/ProjectController.kt

@@ -3,7 +3,6 @@ package com.swagger.rest.controllers
 import com.swagger.rest.models.Project
 import com.swagger.rest.repositories.PlatformRepository
 import com.swagger.rest.repositories.ProjectRepository
-import org.aspectj.asm.internal.ProgramElement.trim
 import org.springframework.http.HttpStatus
 import org.springframework.http.ResponseEntity
 import org.springframework.web.bind.annotation.*
@@ -20,9 +19,9 @@ class ProjectController(
     fun getProject(@RequestParam(required = false) name: String?): Any {
         return try {
             val projects: List<Project> =
-                if (name == null) projectRepository.findAll() as List<Project> else projectRepository.findByNameContaining(
+                if (name == null) projectRepository.findAll() else projectRepository.findByNameContaining(
                     name
-                ) as List<Project>
+                )
             if (projects.isEmpty()) {
                 arrayOf<String>()
             } else ResponseEntity<List<Project>?>(projects, HttpStatus.OK)
@@ -44,7 +43,7 @@ class ProjectController(
     @PostMapping("/projects")
     fun addProject(@RequestBody project: Project): ResponseEntity<Project> {
         return try {
-            val found = projectRepository.findByNameContaining(project.name)!!.size
+            val found = projectRepository.findByNameContaining(project.name).size
             if (project.name.isNotBlank()) {
                 if (project.name.length > 100 || project.description!!.length > 255) {//too long
                     ResponseEntity<Project>(HttpStatus.PAYLOAD_TOO_LARGE)
@@ -66,7 +65,7 @@ class ProjectController(
     @PutMapping("/projects/{id}")
     fun updateProjectById(@PathVariable("id") id: Long, @RequestBody project: Project): ResponseEntity<out Any?> {
         val projectData = projectRepository.findById(id)
-        val found = projectRepository.findByNameContaining(project.name)!!.size
+        val found = projectRepository.findByNameContaining(project.name).size
         return if (project.name.isNotBlank()) {
             if (project.name.length > 100 || project.description!!.length > 255) {//too long
                 ResponseEntity<Project>(HttpStatus.PAYLOAD_TOO_LARGE)
@@ -90,7 +89,7 @@ class ProjectController(
     @DeleteMapping("/projects/{id}")
     fun deleteProject(@PathVariable("id") id: Long): ResponseEntity<HttpStatus> {
         val find = projectRepository.findById(id)
-        val used = platformRepository.findByProject(id.toString())!!.size
+        val used = platformRepository.findByProject(id.toString()).size
         return try {
             if (used > 0) {//child used in transaction
                 ResponseEntity(HttpStatus.RESET_CONTENT)

+ 3 - 3
src/main/kotlin/com/swagger/rest/controllers/UserController.kt

@@ -20,9 +20,9 @@ class UserController(private val userRepository: UserRepository) {
     fun getUser(@RequestParam(required = false) username: String?): Any {
         return try {
             val users: List<User> = if (username == null) {
-                userRepository.findAll() as List<User>
+                userRepository.findAll()
             } else {
-                userRepository.findByUsernameContaining(username) as List<User>
+                userRepository.findByUsernameContaining(username)
             }
             if (users.isNotEmpty()) {
                 ResponseEntity<List<User>?>(users, HttpStatus.OK)
@@ -45,7 +45,7 @@ class UserController(private val userRepository: UserRepository) {
     }
 
     @PostMapping("/users")
-    fun AddUser(@RequestBody user: User): ResponseEntity<User> {
+    fun addUser(@RequestBody user: User): ResponseEntity<User> {
         return try {
             val found = userRepository.findByUsernameContaining(user.username).size
             if (user.username.isNotBlank()) {

+ 3 - 3
src/main/kotlin/com/swagger/rest/repositories/PlatformRepository.kt

@@ -4,12 +4,12 @@ import com.swagger.rest.models.Platform
 import org.springframework.data.jpa.repository.JpaRepository
 import org.springframework.data.jpa.repository.Query
 
-interface PlatformRepository : JpaRepository<Platform?, Long?> {
+interface PlatformRepository : JpaRepository<Platform, Long> {
     @Query("SELECT f.* FROM platform f WHERE name=?1 AND project_id=?2", nativeQuery = true)
-    fun findByName(name: String?, project: String?): List<Platform?>?
+    fun findByName(name: String?, project: String?): List<Platform>
 
     @Query("SELECT f.* FROM platform f WHERE project_id=?1", nativeQuery = true)
-    fun findByProject(project: String?): List<Platform?>?
+    fun findByProject(project: String?): List<Platform>
 
     fun findByNameContaining(name: String?): List<Platform>
 }

+ 2 - 2
src/main/kotlin/com/swagger/rest/repositories/ProjectRepository.kt

@@ -4,6 +4,6 @@ import com.swagger.rest.models.Project
 import org.springframework.data.jpa.repository.JpaRepository
 
 
-interface ProjectRepository : JpaRepository<Project?, Long?> {
-    fun findByNameContaining(name: String?): List<Project?>?
+interface ProjectRepository : JpaRepository<Project, Long> {
+    fun findByNameContaining(name: String?): List<Project>
 }