Skip to content

Commit

Permalink
[Tech] clean after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Oct 13, 2023
1 parent ffdd911 commit 048d224
Show file tree
Hide file tree
Showing 34 changed files with 532 additions and 570 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.websocket.server.PathParam
import java.time.ZonedDateTime
import org.springframework.format.annotation.DateTimeFormat
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.DeleteMapping
Expand All @@ -28,67 +27,68 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import java.time.ZonedDateTime

@RestController
@RequestMapping("/bff/v1/reportings")
@Tag(description = "API des Signalements", name = "Reportings")
class ReportingsController(
private val createOrUpdateReporting: CreateOrUpdateReporting,
private val getReportingById: GetReportingById,
private val getReportings: GetReportings,
private val deleteReporting: DeleteReporting,
private val deleteReportings: DeleteReportings,
private val archiveReportings: ArchiveReportings,
private val mapper: ObjectMapper,
private val createOrUpdateReporting: CreateOrUpdateReporting,
private val getReportingById: GetReportingById,
private val getReportings: GetReportings,
private val deleteReporting: DeleteReporting,
private val deleteReportings: DeleteReportings,
private val archiveReportings: ArchiveReportings,
private val mapper: ObjectMapper,
) {

@GetMapping("")
@Operation(summary = "Get reportings")
fun getReportingsController(
@Parameter(description = "page number")
@RequestParam(name = "pageNumber")
pageNumber: Int?,
@Parameter(description = "page size") @RequestParam(name = "pageSize") pageSize: Int?,
@Parameter(description = "Reporting created after date")
@RequestParam(name = "startedAfterDateTime", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
startedAfterDateTime: ZonedDateTime?,
@Parameter(description = "Reporting created before date")
@RequestParam(name = "startedBeforeDateTime", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
startedBeforeDateTime: ZonedDateTime?,
@Parameter(description = "Reporting type")
@RequestParam(name = "reportingType", required = false)
reportingType: List<ReportingTypeEnum>?,
@Parameter(description = "Facades")
@RequestParam(name = "seaFronts", required = false)
seaFronts: List<String>?,
@Parameter(description = "Reporting source types")
@RequestParam(name = "sourcesType", required = false)
sourcesType: List<SourceTypeEnum>?,
@Parameter(description = "Reporting status")
@RequestParam(name = "status", required = false)
status: List<String>?,
@Parameter(description = "page number")
@RequestParam(name = "pageNumber")
pageNumber: Int?,
@Parameter(description = "page size") @RequestParam(name = "pageSize") pageSize: Int?,
@Parameter(description = "Reporting created after date")
@RequestParam(name = "startedAfterDateTime", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
startedAfterDateTime: ZonedDateTime?,
@Parameter(description = "Reporting created before date")
@RequestParam(name = "startedBeforeDateTime", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
startedBeforeDateTime: ZonedDateTime?,
@Parameter(description = "Reporting type")
@RequestParam(name = "reportingType", required = false)
reportingType: List<ReportingTypeEnum>?,
@Parameter(description = "Facades")
@RequestParam(name = "seaFronts", required = false)
seaFronts: List<String>?,
@Parameter(description = "Reporting source types")
@RequestParam(name = "sourcesType", required = false)
sourcesType: List<SourceTypeEnum>?,
@Parameter(description = "Reporting status")
@RequestParam(name = "status", required = false)
status: List<String>?,
): List<ReportingsDataOutput> {
return getReportings.execute(
pageNumber = pageNumber,
pageSize = pageSize,
reportingType = reportingType,
seaFronts = seaFronts,
sourcesType = sourcesType,
startedAfterDateTime = startedAfterDateTime,
startedBeforeDateTime = startedBeforeDateTime,
status = status,
)
.map { ReportingsDataOutput.fromReportingDTO(it) }
pageNumber = pageNumber,
pageSize = pageSize,
reportingType = reportingType,
seaFronts = seaFronts,
sourcesType = sourcesType,
startedAfterDateTime = startedAfterDateTime,
startedBeforeDateTime = startedBeforeDateTime,
status = status,
)
.map { ReportingsDataOutput.fromReportingDTO(it) }
}

@PutMapping("", consumes = ["application/json"])
@Operation(summary = "Create a new reporting")
@ResponseStatus(HttpStatus.CREATED)
fun createReportingController(
@RequestBody createReporting: CreateOrUpdateReportingDataInput,
): ReportingDetailedDataOutput {
@RequestBody createReporting: CreateOrUpdateReportingDataInput,
): ReportingDataOutput {
val newReporting = createReporting.toReportingEntity()
val createdReporting = createOrUpdateReporting.execute(newReporting)
return ReportingDataOutput.fromReportingDTO(createdReporting)
Expand All @@ -97,29 +97,29 @@ class ReportingsController(
@GetMapping("/{id}")
@Operation(summary = "Get reporting by id")
fun getReportingByIdController(
@PathParam("reporting id") @PathVariable(name = "id") id: Int,
@PathParam("reporting id") @PathVariable(name = "id") id: Int,
): ReportingDataOutput {
return getReportingById.execute(id).let { ReportingDataOutput.fromReportingDTO(it) }
}

@PutMapping(value = ["/{id}"], consumes = ["application/json"])
@Operation(summary = "update a reporting")
fun updateReportingController(
@PathParam("reporting id") @PathVariable(name = "id") id: Int,
@RequestBody reporting: CreateOrUpdateReportingDataInput,
@PathParam("reporting id") @PathVariable(name = "id") id: Int,
@RequestBody reporting: CreateOrUpdateReportingDataInput,
): ReportingDataOutput {
require(id == reporting.id) { "id in path and body must be the same" }
return createOrUpdateReporting.execute(
reporting.toReportingEntity(),
)
.let { ReportingDataOutput.fromReportingDTO(it) }
reporting.toReportingEntity(),
)
.let { ReportingDataOutput.fromReportingDTO(it) }
}

@DeleteMapping(value = ["/{id}"])
@Operation(summary = "Delete a reporting")
@ResponseStatus(HttpStatus.NO_CONTENT)
fun deleteController(
@PathParam("Id") @PathVariable(name = "id") id: Int,
@PathParam("Id") @PathVariable(name = "id") id: Int,
) {
deleteReporting.execute(id = id)
}
Expand Down
Loading

0 comments on commit 048d224

Please sign in to comment.