Big refactoring #77
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.workgroup.routes
|
||||
|
||||
import fr.dcproject.common.response.toOutput
|
||||
import fr.dcproject.common.security.assert
|
||||
import fr.dcproject.common.utils.receiveOrBadRequest
|
||||
import fr.dcproject.component.auth.citizen
|
||||
@@ -44,8 +45,11 @@ object CreateWorkgroup {
|
||||
}.let { workgroup ->
|
||||
ac.assert { canCreate(workgroup, citizenOrNull) }
|
||||
repo.upsert(workgroup)
|
||||
}.let {
|
||||
call.respond(HttpStatusCode.Created, it)
|
||||
}.let { w ->
|
||||
call.respond(
|
||||
HttpStatusCode.Created,
|
||||
w.toOutput()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ object EditWorkgroup {
|
||||
).let { workgroup ->
|
||||
ac.assert { canUpdate(workgroup, citizenOrNull) }
|
||||
repo.upsert(workgroup)
|
||||
call.respond(HttpStatusCode.OK, it)
|
||||
}.let {
|
||||
call.respond(HttpStatusCode.OK, it.toOutput())
|
||||
}
|
||||
}
|
||||
} ?: call.respond(HttpStatusCode.NotFound)
|
||||
|
||||
@@ -25,7 +25,10 @@ object GetWorkgroup {
|
||||
get<WorkgroupRequest> {
|
||||
repo.findById(it.workgroup.id)?.let { workgroup ->
|
||||
ac.assert { canView(workgroup, citizenOrNull) }
|
||||
call.respond(workgroup)
|
||||
call.respond(
|
||||
HttpStatusCode.OK,
|
||||
workgroup.toOutput()
|
||||
)
|
||||
} ?: call.respond(HttpStatusCode.NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.workgroup.routes
|
||||
|
||||
import fr.dcproject.common.response.toOutput
|
||||
import fr.dcproject.common.security.assert
|
||||
import fr.dcproject.common.utils.toUUID
|
||||
import fr.dcproject.component.auth.citizenOrNull
|
||||
@@ -7,6 +8,7 @@ import fr.dcproject.component.workgroup.WorkgroupAccessControl
|
||||
import fr.dcproject.component.workgroup.database.WorkgroupRepository
|
||||
import fr.postgresjson.repository.RepositoryI
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||
import io.ktor.locations.Location
|
||||
import io.ktor.locations.get
|
||||
@@ -43,7 +45,10 @@ object GetWorkgroups {
|
||||
WorkgroupRepository.Filter(createdById = it.createdBy, members = it.members)
|
||||
)
|
||||
ac.assert { canView(workgroups.result, citizenOrNull) }
|
||||
call.respond(workgroups)
|
||||
call.respond(
|
||||
HttpStatusCode.OK,
|
||||
workgroups.toOutput { it.toOutputListing() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package fr.dcproject.component.workgroup.routes
|
||||
|
||||
import fr.dcproject.common.response.toOutput
|
||||
import fr.dcproject.component.workgroup.database.WorkgroupForView
|
||||
import org.joda.time.DateTime
|
||||
import java.util.UUID
|
||||
|
||||
fun WorkgroupForView<*>.toOutput(): Any = this.let { w ->
|
||||
object {
|
||||
val id: UUID = w.id
|
||||
val name: String = w.name
|
||||
val description: String = w.description
|
||||
val logo: String? = w.logo
|
||||
val anonymous: Boolean = w.anonymous
|
||||
val createdAt: DateTime = w.createdAt
|
||||
val createdBy: Any = w.createdBy.toOutput()
|
||||
val members: Any = w.members.map { m ->
|
||||
object {
|
||||
val citizen: Any = object {
|
||||
val id: UUID = m.citizen.id
|
||||
val name: Any = m.citizen.name.let { n ->
|
||||
object {
|
||||
val firstName: String = n.firstName
|
||||
val lastName: String = n.lastName
|
||||
}
|
||||
}
|
||||
}
|
||||
val roles: List<String> = m.roles.map { it.toString() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun WorkgroupForView<*>.toOutputListing(): Any = this.let { w ->
|
||||
object {
|
||||
val id: UUID = w.id
|
||||
val name: String = w.name
|
||||
val description: String = w.description
|
||||
val logo: String? = w.logo
|
||||
val createdAt: DateTime = w.createdAt
|
||||
}
|
||||
}
|
||||
@@ -1123,6 +1123,158 @@ paths:
|
||||
401:
|
||||
$ref: '#/components/responses/401'
|
||||
|
||||
/workgroups:
|
||||
get:
|
||||
summary: Get all Workgroup (Paginated)
|
||||
security:
|
||||
- JWTAuth: [ ]
|
||||
tags:
|
||||
- workgroup
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/page'
|
||||
- $ref: '#/components/parameters/limit'
|
||||
- $ref: '#/components/parameters/workgroupSort'
|
||||
- $ref: '#/components/parameters/direction'
|
||||
- $ref: '#/components/parameters/search'
|
||||
- $ref: '#/components/parameters/createdBy'
|
||||
responses:
|
||||
200:
|
||||
description: paginated list of workgroup
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/Paginated'
|
||||
- type: object
|
||||
properties:
|
||||
result:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/WorkgroupListing'
|
||||
post:
|
||||
summary: Create new Workgroup
|
||||
security:
|
||||
- JWTAuth: [ ]
|
||||
tags:
|
||||
- workgroup
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
required:
|
||||
- name
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
format: uuid
|
||||
nullable: true
|
||||
name:
|
||||
type: string
|
||||
example: Les partisants du RIC
|
||||
description:
|
||||
type: string
|
||||
example: Group formé pour la conception d'un RIC
|
||||
logo:
|
||||
type: string
|
||||
nullable: true
|
||||
anonymous:
|
||||
type: boolean
|
||||
example: false
|
||||
nullable: true
|
||||
default: true
|
||||
responses:
|
||||
201:
|
||||
description: Workgroup created
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Workgroup'
|
||||
/workgroups/{workgroup}:
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/workgroup'
|
||||
get:
|
||||
summary: Get one workgroup by ID
|
||||
security:
|
||||
- JWTAuth: [ ]
|
||||
tags:
|
||||
- workgroup
|
||||
responses:
|
||||
200:
|
||||
description: Workgroup
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Workgroup'
|
||||
404:
|
||||
description: Workshop not exist or are deleted
|
||||
# put:
|
||||
# summary: Edit one workgroup
|
||||
# security:
|
||||
# - JWTAuth: [ ]
|
||||
# tags:
|
||||
# - workgroup
|
||||
# requestBody:
|
||||
# content:
|
||||
# application/json:
|
||||
# schema:
|
||||
# required:
|
||||
# - name
|
||||
# properties:
|
||||
# name:
|
||||
# type: string
|
||||
# example: Les partisants du RIC
|
||||
# description:
|
||||
# type: string
|
||||
# example: Group formé pour la conception d'un RIC
|
||||
# logo:
|
||||
# type: string
|
||||
# nullable: true
|
||||
# anonymous:
|
||||
# type: boolean
|
||||
# example: false
|
||||
# nullable: true
|
||||
# default: true
|
||||
# owner:
|
||||
# type: string
|
||||
# format: uuid
|
||||
# example: 6434f4f9-f570-f22a-c134-8668350651ff
|
||||
# nullable: true
|
||||
# responses:
|
||||
# 200:
|
||||
# description: Workgroup updated
|
||||
# content:
|
||||
# application/json:
|
||||
# schema:
|
||||
# properties:
|
||||
# id:
|
||||
# type: string
|
||||
# format: uuid
|
||||
# name:
|
||||
# type: string
|
||||
# example: Les partisants du RIC
|
||||
# description:
|
||||
# type: string
|
||||
# example: Group formé pour la conception d'un RIC
|
||||
# logo:
|
||||
# type: string
|
||||
# anonymous:
|
||||
# type: boolean
|
||||
# example: false
|
||||
# owner:
|
||||
# type: string
|
||||
# format: uuid
|
||||
delete:
|
||||
summary: Delete one workgroup
|
||||
security:
|
||||
- JWTAuth: [ ]
|
||||
tags:
|
||||
- workgroup
|
||||
responses:
|
||||
204:
|
||||
description: Workgroup deleted
|
||||
404:
|
||||
description: Workshop not exist or are already deleted
|
||||
|
||||
components:
|
||||
parameters:
|
||||
page:
|
||||
@@ -1167,6 +1319,17 @@ components:
|
||||
- createdAt
|
||||
- vote
|
||||
- popularity
|
||||
workgroupSort:
|
||||
name: sort
|
||||
in: query
|
||||
description: The sort field name
|
||||
example: createdAt
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
enum:
|
||||
- name
|
||||
- createdAt
|
||||
direction:
|
||||
name: direction
|
||||
in: query
|
||||
@@ -1245,6 +1408,17 @@ components:
|
||||
type: string
|
||||
format: uuid
|
||||
|
||||
workgroup:
|
||||
name: workgroup
|
||||
in: path
|
||||
description: ID of workgroup
|
||||
example: 82a0e60a-bb55-dbc0-1c3d-0a804df2b5df
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
|
||||
|
||||
responses:
|
||||
401:
|
||||
description: Unautorized
|
||||
@@ -1892,6 +2066,67 @@ components:
|
||||
type: string
|
||||
format: 'date-time'
|
||||
|
||||
WorkgroupListing:
|
||||
description: Workgroup
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
format: uuid
|
||||
name:
|
||||
type: string
|
||||
example: Les partisants du RIC
|
||||
description:
|
||||
type: string
|
||||
example: Group formé pour la conception d'un RIC
|
||||
logo:
|
||||
type: string
|
||||
nullable: true
|
||||
|
||||
Workgroup:
|
||||
description: Workgroup
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
- description
|
||||
- logo
|
||||
- anonymous
|
||||
- createdBy
|
||||
- members
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
format: uuid
|
||||
name:
|
||||
type: string
|
||||
example: Les partisants du RIC
|
||||
description:
|
||||
type: string
|
||||
example: Group formé pour la conception d'un RIC
|
||||
logo:
|
||||
type: string
|
||||
nullable: true
|
||||
anonymous:
|
||||
type: boolean
|
||||
createdBy:
|
||||
$ref: '#/components/schemas/CitizenCreator'
|
||||
members:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
citizen:
|
||||
type: object
|
||||
items:
|
||||
properties:
|
||||
id:
|
||||
$ref: '#/components/schemas/UUID'
|
||||
roles:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
|
||||
securitySchemes:
|
||||
JWTAuth:
|
||||
type: http
|
||||
|
||||
Reference in New Issue
Block a user