ソースを参照

1.return role bukan angka 2.return project tidak berulang 3.user_id object disebut user saja

athrainsky 11 ヶ月 前
コミット
e1b8b955cd

+ 4 - 119
qc.txt

@@ -1,121 +1,6 @@
-	update project dupl sebelum auth?
-	add platform project name salah -> trim?
-	add member project not found
-
-Ownersip 
-- user yang membuat project otomatis menjadi owner dari project tsb -> spring
-- owner tidak dapat diubah 											-> put tidak merubah owner
-- rights owner: 
-- owner dapat mengubah nama, deskripsi  project 					-> /projects/id put
-- owner dapat menghapus project 									-> /projects/id delete
-- owner dapat menambah, mengubah dan menhapus platform project 		-> /platforms/id post, put, delete
-- owner dapat menambahkan dan menghapus member project 				-> /projects/member post, /projects/id/member delete
-
-Membership:
-- Member memiliki 3 macam role : 0:QC, 1: Programmer, 2:Admin
-- Tiap user bisa memiliki lebih dari 1 role dalam satu project. (contoh: user Joko bisa di daftarkan sebagai QC dan Admin)
-- Tiap Role mempunyai rights berbeda
-Rights Admin:
-- Admin dapat mengubah nama, deskripsi  project						-> /projects/id put
-- Admin dapat menambah, mengubah dan menhapus platform project		-> /platforms/id post, put, delete
-- Admin dapat menambahkan dan menghapus member project				-> /projects/member post, /projects/id/member delete
-- Admin tidak dapat menghapus member dengan role Admin				-> 
-Rights lain menyusul setelah ada table bug.
-
+	return role bukan angka
+	return project tidak berulang
+	user_id object disebut user saja
 
 insert  into `user`(`user_id`,`name`,`password`,`username`) values 
-(1,'test user','$2a$10$Y8LgDPJiAsbw7n5pURhGVOmi5.LWpfJaX7ZgSDbjsQXEnsCFPdhB2','user')
-
-/projects
-get		200	ok
-		401 ok
-post	201 ok
-		400 ok
-		401 ok
-		409	ok
-		413 ok
-/projects/id
-get		200 ok
-		401 ok
-		404 ok
-put		200 ok
-		400 ok
-		401 ok
-		403 ok
-		409 ok
-		413 ok
-delete	200 ok
-		205 ok
-		401 ok
-		403	ok
-/projects/id/member
-get		200 ok
-		401 ok
-		404 ok
-post	201 ok
-		400 ok
-		401 ok
-		403	ok
-		404 ok
-		409 ok
-/projects/member/id
-get		200 ok
-		401 ok
-		404 ok
-delete	200 ok
-		401 ok
-		403	ok
-		404 ok
-/platforms
-get 	200 ok
-		401 ok
-post 	201 ok
-		400 ok
-		401 ok
-		403	ok
-		404 ok
-		409 ok
-		413 ok
-/platforms/id
-get 	200 ok
-		401 ok
-		404 ok
-put 	200 ok
-		400 ok
-		401 ok
-		403	ok
-		404 ok
-		409 ok
-		413 ok
-delete 	200 ok
-		401 ok
-		403	ok
-		404 ok
-/users
-get 	200 ok
-		401 ok
-post	201 ok
-		400 ok
-		401 ok
-		409 ok
-		413 ok
-/users/id
-get		200 ok
-		401 ok
-		404 ok
-put		200 ok
-		400 ok
-		401 ok
-		404 ok
-		409 ok
-		413 ok
-delete	200 ok
-		205 ok
-		401 ok
-		404 ok
-/users/id/password
-put		200 ok
-		400 ok
-		401 ok
-		403 ok
-		404 ok
+(1,'test user','$2a$10$Y8LgDPJiAsbw7n5pURhGVOmi5.LWpfJaX7ZgSDbjsQXEnsCFPdhB2','user')

+ 39 - 17
src/main/kotlin/com/swagger/rest/controllers/MemberController.kt

@@ -1,6 +1,8 @@
 package com.swagger.rest.controllers
 
+import com.swagger.rest.models.Enum
 import com.swagger.rest.models.MemberInput
+import com.swagger.rest.models.MemberOutput
 import com.swagger.rest.models.ProjectMember
 import com.swagger.rest.repositories.MemberRepository
 import com.swagger.rest.repositories.ProjectRepository
@@ -21,8 +23,16 @@ class MemberController(
     @GetMapping("/projects/{id}/member")
     fun getMemberByProject(@PathVariable("id") id: Long): Any {
         val memberData = memberRepository.findByProject(id.toString())
+        val output = memberData.map {
+            MemberOutput(
+                id = it.id,
+                project = it.project!!.description,
+                user = it.user!!.name,
+                role = Enum.Member.values()[it.role]
+            )
+        }
         return if (memberData.isNotEmpty()) {
-            ResponseEntity<List<ProjectMember>>(memberData, HttpStatus.OK)
+            ResponseEntity(output, HttpStatus.OK)
         } else {
             arrayOf<String>()
         }
@@ -31,8 +41,16 @@ class MemberController(
     @GetMapping("/projects/member/{id}")
     fun getMemberProject(@PathVariable("id") id: Long): Any {
         val memberData = memberRepository.findById(id)
+        val output = memberData.map {
+            MemberOutput(
+                id = it.id,
+                project = it.project!!.description,
+                user = it.user!!.name,
+                role = Enum.Member.values()[it.role]
+            )
+        }
         return if (memberData.isPresent) {
-            ResponseEntity<ProjectMember>(memberData.get(), HttpStatus.OK)
+            ResponseEntity<MemberOutput>(output.get(), HttpStatus.OK)
         } else {
             arrayOf<String>()
         }
@@ -44,14 +62,11 @@ class MemberController(
         return try {
             val find = memberRepository.findById(id)
             if (find.isPresent) {
-                val validOwner =
-                    projectRepository.validOwner(find.get().project_id!!.id.toString(), userId.id.toString())
+                val validOwner = projectRepository.validOwner(find.get().project!!.id.toString(), userId.id.toString())
                 val validAdmin =
-                    memberRepository.validRole(find.get().project_id!!.id.toString(), userId.id.toString(), "2")
+                    memberRepository.validRole(find.get().project!!.id.toString(), userId.id.toString(), "2")
                 val targetNotAdmin = memberRepository.targetRole(
-                    find.get().project_id!!.id.toString(),
-                    find.get().user_id!!.id.toString(),
-                    find.get().role.toString()
+                    find.get().project!!.id.toString(), find.get().user!!.id.toString(), find.get().role.toString()
                 )
                 if (validOwner > 0 || (validAdmin > 0 && targetNotAdmin > 0)) {
                     memberRepository.deleteById(id)
@@ -79,18 +94,29 @@ class MemberController(
             val validAdmin = memberRepository.validRole(id.toString(), userId.id.toString(), "2")
             if (found.isPresent && user.isPresent) {
                 if (validOwner > 0 || validAdmin > 0) {
-                    if (enumValues<Member>().any { it.name == member.role!!.uppercase() }) {
-                        val role = Member.valueOf(member.role!!.uppercase()).ordinal
+                    if (enumValues<Enum.Member>().any { it.name == member.role!!.uppercase() }) {
+                        val role = Enum.Member.valueOf(member.role!!.uppercase()).ordinal
                         val dup =
                             memberRepository.findDup(id.toString(), role.toString(), member.user_id.toString()).size
                         if (dup > 0) {//duplicate
                             ResponseEntity<ProjectMember>(HttpStatus.CONFLICT)
                         } else {
                             val saveMember = ProjectMember()
-                            saveMember.project_id = found.get()
-                            saveMember.user_id = user.get()
+                            saveMember.project = found.get()
+                            saveMember.user = user.get()
                             saveMember.role = role
-                            ResponseEntity<ProjectMember>(memberRepository.save(saveMember), HttpStatus.CREATED)
+                            val save = memberRepository.save(saveMember)
+                            if (listOf(save).isNotEmpty()) {
+                                val output = MemberOutput(
+                                    id = save.id,
+                                    project = save.project!!.description,
+                                    user = save.user!!.name,
+                                    role = Enum.Member.values()[save.role]
+                                )
+                                ResponseEntity(output, HttpStatus.CREATED)
+                            } else {
+                                ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR)
+                            }
                         }
                     } else {// invalid
                         ResponseEntity<ProjectMember>(HttpStatus.BAD_REQUEST)
@@ -105,8 +131,4 @@ class MemberController(
             ResponseEntity<ProjectMember>(null, HttpStatus.INTERNAL_SERVER_ERROR)
         }
     }
-}
-
-private enum class Member {
-    QC, PROGRAMMER, ADMIN
 }

+ 9 - 0
src/main/kotlin/com/swagger/rest/models/Enum.kt

@@ -0,0 +1,9 @@
+package com.swagger.rest.models
+
+class Enum {
+
+    enum class Member{
+        QC, PROGRAMMER, ADMIN
+    }
+
+}

+ 12 - 0
src/main/kotlin/com/swagger/rest/models/MemberOutput.kt

@@ -0,0 +1,12 @@
+package com.swagger.rest.models
+
+class MemberOutput (
+
+    var id: Long? = 0,
+
+    var project: String? = "",
+
+    var user: String? = "",
+
+    var role: Enum.Member? = null
+)

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

@@ -22,7 +22,7 @@ class Project {
     @JsonIgnore
     var project_id: List<Platform> = mutableListOf()
 
-    @OneToMany(mappedBy = "project_id", cascade = [CascadeType.ALL])
+    @OneToMany(mappedBy = "project", cascade = [CascadeType.ALL])
     @JsonIgnore
     var member_id: List<ProjectMember> = mutableListOf()
 

+ 2 - 2
src/main/kotlin/com/swagger/rest/models/ProjectMember.kt

@@ -12,11 +12,11 @@ class ProjectMember {
 
     @ManyToOne
     @JoinColumn(name = "project_id", referencedColumnName = "project_id", foreignKey = ForeignKey(name = "FK_memPro"))
-    var project_id: Project? = null
+    var project: Project? = null
 
     @ManyToOne
     @JoinColumn(name = "user_id", referencedColumnName = "user_id", foreignKey = ForeignKey(name = "FK_memUser"))
-    var user_id: User? = null
+    var user: User? = null
 
     @Column(columnDefinition = "TINYINT")
     var role: Int = 0

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

@@ -23,7 +23,7 @@ class User {
     @Column(name = "name", length = 255)
     var name: String = ""
 
-    @OneToMany(mappedBy = "user_id", cascade = [CascadeType.ALL])
+    @OneToMany(mappedBy = "user", cascade = [CascadeType.ALL])
     @JsonIgnore
     var user_id: List<ProjectMember> = mutableListOf()
 

+ 21 - 84
swagger3 project.yml

@@ -171,8 +171,6 @@ paths:
           $ref: '#/components/responses/getSingleMember'
         401:
           $ref: '#/components/responses/UnauthorizedError'
-        404:
-          $ref: '#/components/responses/404'
       security: 
       - testAuth: []
     delete:
@@ -516,18 +514,18 @@ components:
         id:
           type: integer
           uniqueItems: true
-        project_id:
+        project:
           $ref: '#/components/schemas/Project'
-        user_id:
+        user:
           $ref: '#/components/schemas/User'
         role:
           type: number
-          format: int32
+          enum: [0,1,2]
           description: role = 0.QC, 1. Programmer, 2.Admin
       required: 
         - id
-        - project_id
-        - user_id
+        - project
+        - user
         - role
   parameters:
     projectPath:
@@ -654,34 +652,13 @@ components:
               id:
                 type: integer
                 example: 1
-              project_id:
-                properties:
-                  id:
-                    example: 1
-                  name:
-                    example: TM
-                  description:
-                    example: TelMessenger
-                  owner:
-                    properties:
-                      id:
-                        example: 1
-                      username:
-                        example: abi
-                      name:
-                        example: abidzar
-              user_id:
-                properties:
-                  id:
-                    example: 1
-                  username:
-                    example: abi
-                  name:
-                    example: abidzar
+              project:
+                example: TelMessenger
+              user:
+                example: abidzar
               role:
-                type: integer
-                example: 0
-                description: QC      
+                type: string
+                example: QC
     getArrayPlatform:
       description: successful operation
       content:
@@ -841,32 +818,12 @@ components:
             properties:
               id:
                 example: 1
-              project_id:
-                properties:
-                  id:
-                    example: 1
-                  name:
-                    example: TM
-                  description:
-                    example: TelMessenger
-                  owner:
-                    properties:
-                      id:
-                        example: 1
-                      username:
-                        example: abi
-                      name:
-                        example: abidzar
-              user_id:
-                properties:
-                  id:
-                    example: 1
-                  username:
-                    example: abi
-                  name:
-                    example: abidzar
+              project:
+                example: TelMessenger
+              user:
+                example: abidzar
               role:
-                example: 0
+                example: QC
     getArrayMember:
       description: successful operation
       content:
@@ -877,32 +834,12 @@ components:
               properties:
                 id:
                   example: 1
-                project_id:
-                  properties:
-                    id:
-                      example: 1
-                    name:
-                      example: TM
-                    description:
-                      example: TelMessenger
-                    owner:
-                      properties:
-                        id:
-                          example: 1
-                        username:
-                          example: abi
-                        name:
-                          example: abidzar
-                user_id:
-                  properties:
-                    id:
-                      example: 1
-                    username:
-                      example: abi
-                    name:
-                      example: abidzar
+                project:
+                  example: TelMessenger
+                user:
+                  example: abidzar
                 role:
-                  example: 0
+                  example: QC
     400:
       description: invalid data
     403: