Skip to content

Commit 27ebbb5

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/feature-#4' into feature-#4
2 parents ed274b1 + 26a85de commit 27ebbb5

File tree

9 files changed

+8908
-21
lines changed

9 files changed

+8908
-21
lines changed

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ services:
4545
environment:
4646
- POSTGRESQL_REPLICATION_MODE=slave
4747
- POSTGRESQL_REPLICATION_USER=repl_user
48-
- POSTGRESQL_REPLICATION_PASSWORD=repl_password
48+
- POSTGRESQL_REPLICATION_PASSWORD=repl_cpassword
4949
- POSTGRESQL_MASTER_HOST=postgresql-main
5050
- POSTGRESQL_MASTER_PORT_NUMBER=5432
5151
- POSTGRESQL_USERNAME=my_user

hs_err_pid20680.log

+995
Large diffs are not rendered by default.

replay_pid20680.log

+7,858
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package eom.improve.kafkaboot.common
2+
3+
data class PaginatedResponse<T>(
4+
val response : List<T>,
5+
val currentPage : Long,
6+
val totalPages : Long
7+
)

src/main/kotlin/eom/improve/kafkaboot/controller/FilmController.kt

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package eom.improve.kafkaboot.controller
22

3+
import eom.improve.kafkaboot.common.PaginatedResponse
34
import eom.improve.kafkaboot.dto.Film
45
import jakarta.validation.Valid
56
import org.springframework.web.bind.annotation.*
@@ -12,6 +13,9 @@ interface FilmController {
1213
@GetMapping("/list/all")
1314
fun getAllFilms() : Mono<List<Film>>
1415

16+
@GetMapping("/list/{page}/{limit}")
17+
fun getFilms(@PathVariable page: Long, @PathVariable limit: Long) : Mono<PaginatedResponse<Film>>
18+
1519
@PutMapping("/modify")
1620
fun modifyFilm(@RequestBody updatedFilm : Film) : Mono<Film>
1721

src/main/kotlin/eom/improve/kafkaboot/repository/FilmRepository.kt

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package eom.improve.kafkaboot.repository
22

33
import eom.improve.kafkaboot.model.FilmEntity
4+
import org.springframework.data.domain.Pageable
45
import org.springframework.data.r2dbc.repository.R2dbcRepository
56
import org.springframework.stereotype.Repository
67
import reactor.core.publisher.Flux
@@ -10,4 +11,5 @@ import reactor.core.publisher.Mono
1011
interface FilmRepository : R2dbcRepository<FilmEntity, Int> {
1112
fun findAllBy() : Flux<FilmEntity>
1213
fun deleteByFilmId(filmId: Int) : Mono<Void>
14+
fun findAllByOrderByFilmId(pageable: Pageable) : Flux<FilmEntity>
1315
}

src/main/kotlin/eom/improve/kafkaboot/service/FilmControllerImpl.kt

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package eom.improve.kafkaboot.service
22

3+
import eom.improve.kafkaboot.common.PaginatedResponse
34
import eom.improve.kafkaboot.controller.FilmController
45
import eom.improve.kafkaboot.dto.Film
6+
import org.springframework.data.domain.PageRequest
57
import org.springframework.stereotype.Service
68
import reactor.core.publisher.Mono
79
import reactor.kotlin.core.publisher.toMono
@@ -16,6 +18,10 @@ class FilmControllerImpl(
1618
.collectSortedList((Comparator<Film> { o1, o2 -> o1.filmId.compareTo(o2.filmId) }))
1719
}
1820

21+
override fun getFilms(page: Long, limit: Long): Mono<PaginatedResponse<Film>> {
22+
return filmService.findAllByPageable(PageRequest.of(page.toInt() , limit.toInt()))
23+
}
24+
1925
override fun modifyFilm(updatedFilm : Film) : Mono<Film> {
2026
return filmService.updateFilm(updatedFilm.convert2Entity())
2127
.flatMap { it.convert2Pojo().toMono() }

src/main/kotlin/eom/improve/kafkaboot/service/FilmService.kt

+30-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package eom.improve.kafkaboot.service
22

3+
import eom.improve.kafkaboot.common.PaginatedResponse
4+
import eom.improve.kafkaboot.dto.Film
35
import eom.improve.kafkaboot.model.FilmEntity
6+
import eom.improve.kafkaboot.model.InventoryEntity
7+
import eom.improve.kafkaboot.model.RentalEntity
48
import eom.improve.kafkaboot.repository.*
9+
import org.springframework.data.domain.Pageable
510
import org.springframework.stereotype.Service
611
import reactor.core.publisher.Flux
712
import reactor.core.publisher.Mono
@@ -17,6 +22,13 @@ class FilmService(
1722
private val filmActorRepository: FilmActorRepository,
1823
private val filmCategoryRepository: FilmCategoryRepository
1924
) {
25+
26+
fun findAllByPageable(pageable: Pageable) : Mono<PaginatedResponse<Film>> = filmRepository.findAllByOrderByFilmId(pageable)
27+
.collectSortedList { o1, o2 -> o1.filmId - o2.filmId }
28+
.zipWith(filmRepository.count().toMono())
29+
.map { pagination -> PaginatedResponse<Film>( pagination.t1.map { it.convert2Pojo() } , pageable.pageNumber.toLong() ,pagination.t2 / pageable.pageSize ) }
30+
31+
2032
fun findAll() : Flux<FilmEntity> = filmRepository.findAllBy()
2133

2234
fun updateFilm(updatedFilm : FilmEntity) : Mono<FilmEntity> {
@@ -34,31 +46,31 @@ class FilmService(
3446
return filmRepository.findById(filmId)
3547
.switchIfEmpty(RuntimeException("Not registered film").toMono())
3648
.flatMap { filmEn ->
37-
inventoryRepository.findAllByFilmId(filmEn.filmId)
38-
.flatMap { inventoryEn ->
39-
rentalRepository.findAllByInventoryId(inventoryEn.inventoryId)
40-
.flatMap { rentalEn ->
41-
paymentRepository.findAllByRentalId(rentalEn.rentalId)
42-
.flatMap { paymentEn ->
43-
paymentRepository.deleteByPaymentId(paymentEn.paymentId)
44-
}
45-
.then(rentalEn.toMono())
46-
}
47-
.flatMap { rentalEn ->
49+
inventoryRepository.findAllByFilmId(filmEn.filmId)
50+
.flatMap { inventoryEn ->
51+
rentalRepository.findAllByInventoryId(inventoryEn.inventoryId)
52+
.flatMap { rentalEn ->
53+
paymentRepository.findAllByRentalId(rentalEn.rentalId)
54+
.flatMap { paymentEn ->
55+
paymentRepository.deleteByPaymentId(paymentEn.paymentId)
56+
}
57+
.then(rentalEn.toMono())
58+
}
59+
.flatMap { rentalEn ->
4860
rentalRepository.deleteByRentalId(rentalEn.rentalId)
49-
}.then(inventoryEn.toMono())
50-
}
51-
.flatMap { inventoryEn ->
52-
inventoryRepository.deleteByInventoryId(inventoryEn.inventoryId)
53-
}
54-
.then(filmEn.toMono())
61+
}.then(inventoryEn.toMono())
62+
}
63+
.flatMap { inventoryEn ->
64+
inventoryRepository.deleteByInventoryId(inventoryEn.inventoryId)
65+
}
66+
.then(filmEn.toMono())
5567
}
5668
.flatMap { filmEn ->
5769
Mono.zip(
5870
filmActorRepository.findAllByFilmId(filmEn.filmId)
5971
.flatMap { filmActorRepository.deleteByFilmId(it.filmId) }
6072
.then()
61-
,
73+
,
6274
filmCategoryRepository.findAllByFilmId(filmEn.filmId)
6375
.flatMap { filmCategoryRepository.deleteByFilmId(it.filmId) }
6476
.then()

src/main/resources/application.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
spring:
22
r2dbc:
33
url: r2dbc:postgresql://localhost:5432/dvdrental
4-
username: postgres
5-
password: example
4+
username: my_user
5+
password: my_password
66

77
#kafka
88
kafka:
@@ -20,3 +20,6 @@ spring:
2020
spring.json.use.type.headers: false
2121
properties:
2222
spring.json.trusted.packages: '*'
23+
24+
server:
25+
port: 7477

0 commit comments

Comments
 (0)