Big refactoring #77

Merged
flecomte merged 166 commits from refactoring-component-and-immutable into master 2021-03-24 19:06:07 +01:00
4 changed files with 107 additions and 3 deletions
Showing only changes of commit 9862e112eb - Show all commits

View File

@@ -1,5 +1,6 @@
package fr.dcproject.component.follow.routes.constitution package fr.dcproject.component.follow.routes.constitution
import fr.dcproject.common.response.toOutput
import fr.dcproject.common.security.assert import fr.dcproject.common.security.assert
import fr.dcproject.component.auth.citizen import fr.dcproject.component.auth.citizen
import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.auth.citizenOrNull
@@ -13,6 +14,7 @@ import io.ktor.locations.Location
import io.ktor.locations.get import io.ktor.locations.get
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.routing.Route import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID import java.util.UUID
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
@@ -26,7 +28,22 @@ object GetFollowConstitution {
get<ConstitutionFollowRequest> { get<ConstitutionFollowRequest> {
repo.findFollow(citizen, it.constitution)?.let { follow -> repo.findFollow(citizen, it.constitution)?.let { follow ->
ac.assert { canView(follow, citizenOrNull) } ac.assert { canView(follow, citizenOrNull) }
call.respond(follow) call.respond(
HttpStatusCode.OK,
follow.let { f ->
object {
val id: UUID = f.id
val createdBy: Any = f.createdBy.toOutput()
val target: Any = f.target.let { t ->
object {
val id: UUID = t.id
val reference: String = f.target.reference
}
}
val createdAt: DateTime = f.createdAt
}
}
)
} ?: call.respond(HttpStatusCode.NotFound) } ?: call.respond(HttpStatusCode.NotFound)
} }
} }

View File

@@ -1,16 +1,19 @@
package fr.dcproject.component.follow.routes.constitution package fr.dcproject.component.follow.routes.constitution
import fr.dcproject.common.response.toOutput
import fr.dcproject.common.security.assert import fr.dcproject.common.security.assert
import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.auth.citizenOrNull
import fr.dcproject.component.citizen.database.CitizenRef import fr.dcproject.component.citizen.database.CitizenRef
import fr.dcproject.component.follow.FollowAccessControl import fr.dcproject.component.follow.FollowAccessControl
import fr.dcproject.component.follow.database.FollowConstitutionRepository import fr.dcproject.component.follow.database.FollowConstitutionRepository
import io.ktor.application.call import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.locations.KtorExperimentalLocationsAPI import io.ktor.locations.KtorExperimentalLocationsAPI
import io.ktor.locations.Location import io.ktor.locations.Location
import io.ktor.locations.get import io.ktor.locations.get
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.routing.Route import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID import java.util.UUID
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
@@ -24,7 +27,22 @@ object GetMyFollowsConstitution {
get<CitizenFollowConstitutionRequest> { get<CitizenFollowConstitutionRequest> {
val follows = repo.findByCitizen(it.citizen) val follows = repo.findByCitizen(it.citizen)
ac.assert { canView(follows.result, citizenOrNull) } ac.assert { canView(follows.result, citizenOrNull) }
call.respond(follows) call.respond(
HttpStatusCode.OK,
follows.toOutput { f ->
object {
val id: UUID = f.id
val createdBy: Any = f.createdBy.toOutput()
val target: Any = f.target.let { t ->
object {
val id: UUID = t.id
val reference: String = f.target.reference
}
}
val createdAt: DateTime = f.createdAt
}
}
)
} }
} }
} }

View File

@@ -796,6 +796,75 @@ paths:
items: items:
$ref: '#/components/schemas/FollowResponse' $ref: '#/components/schemas/FollowResponse'
/constitutions/{constitution}/follows:
parameters:
- $ref: '#/components/parameters/constitution'
get:
security:
- JWTAuth: [ ]
summary: Return Follow or nothing if you not follow
tags:
- follow
- constitution
responses:
200:
description: Return your follow
content:
application/json:
schema:
$ref: '#/components/schemas/FollowResponse'
404:
description: You not follow this constitution
post:
security:
- JWTAuth: [ ]
summary: Follow one constitution
tags:
- follow
- constitution
responses:
201:
description: Return only http status 201 on success
401:
$ref: '#/components/responses/401'
delete:
security:
- JWTAuth: [ ]
summary: Unfollow one constitution
tags:
- follow
- constitution
responses:
204:
description: Return only http status 204 on success
401:
$ref: '#/components/responses/401'
/citizens/{citizen}/follows/constitutions:
parameters:
- $ref: '#/components/parameters/citizen'
get:
security:
- JWTAuth: [ ]
summary: Return Follow or nothing if you not follow
tags:
- follow
- constitution
- citizen
responses:
200:
description: Return your follows
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/Paginated'
- type: object
properties:
result:
type: array
items:
$ref: '#/components/schemas/FollowResponse'
components: components:
parameters: parameters:
page: page:

View File

@@ -37,7 +37,7 @@ class `Follow constitutions routes` : BaseTest() {
} }
@Test @Test
fun `I can get follow constitution`() { fun `I can get my follow constitution`() {
withIntegrationApplication { withIntegrationApplication {
`Given I have constitution`(id = "7f642078-8e74-47fc-9712-0c37531674a0") `Given I have constitution`(id = "7f642078-8e74-47fc-9712-0c37531674a0")
`Given I have citizen`("André-Marie", "Ampère", id = "877b45b0-302d-487d-8944-6d03ccdbd0f8") { `Given I have citizen`("André-Marie", "Ampère", id = "877b45b0-302d-487d-8944-6d03ccdbd0f8") {