-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pull request to show code #1
base: automaticallyGeneratedCode
Are you sure you want to change the base?
Changes from all commits
8e77819
1f97d4b
faff851
bc3c6d8
f5b6cd3
88191c8
5c90012
e4124b0
806ad87
5ab36dd
11bcac7
a5c58da
1ce605c
4ead81a
02d2544
ef935b6
a9bfa78
1ff2e8c
e981aeb
3d1f79e
4bba25a
d426b47
cacf9bb
738152c
4c2d361
05ce075
1fd39c2
9a86047
1a7bcbd
763992a
568c5f6
298ed23
f2e9599
567a28c
b7f17c3
571b75b
8d8f435
61ddf0b
32c48ec
af65eba
02f0ff3
573b954
11e04ac
6cb9b2e
c1e5c53
5a0470d
1bacdd0
be27e61
470a046
37060d2
e320a83
91fe48c
6457b73
a14e602
18ad083
536c798
e3b08ce
1656155
268596f
ae9636e
a23b92e
60df68f
76e0250
2fa4ca3
002237f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
To build and run run build.sh | ||
|
||
To run scenario | ||
cd scenario | ||
./scenario.sh | ||
|
||
When sending third http request in curl one can use ticket types as follows: | ||
adult: 1, | ||
student: 2, | ||
child: 3 | ||
|
||
Assumptions: | ||
- I assumed, that reservation expiration date is equal to movie screening start time |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
./gradlew bootRun |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"movieScreeningId": 1, | ||
"name": "Pawel", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A co z polskimi znakami ?:) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Polskie znaki są obsługiwane, niestety nie wpisałem polskich znaków do tego "scenario" skryptu. Polskie znaki znajdują się w testach |
||
"surname": "Czajka", | ||
"seats": [ | ||
{ | ||
"seatId": 1, | ||
"ticketType": 1 | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
curl -H "Content-Type: application/json" 'http://localhost:8080/api/screenings?minimalStartTime=2100-01-01T07:00:00.000%2B00:00&maximalEndTime=2100-01-02T23:40:00.000%2B00:00&offset=0&limit=1000' | json_pp | ||
|
||
echo '' | ||
echo '' | ||
|
||
curl -H "Content-Type: application/json" 'http://localhost:8080/api/screening?screeningId=1' | json_pp | ||
|
||
echo '' | ||
echo '' | ||
|
||
curl -H "Content-Type: application/json" -d "@reservationRequest.json" -X POST 'http://localhost:8080/api/createReservation' | json_pp | ||
|
||
echo '' | ||
echo '' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example.ticketbookingapp.config | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
|
||
@ConfigurationProperties(prefix = "custom") | ||
data class CustomConfigProperties( | ||
val minimalTimeBetweenBookingAndScreeningStart: Int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nie wiadomo, czy ten czas jest w minutach czy w sekundach, jak byś to poprawił :) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jedno rozwiązanie to zmiana nazwy na Lepsze rozwiązanie to by było zmienić typ tego na Duration. Wówczas mogę w properties napisać |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.example.ticketbookingapp.databaseInitialization | ||
|
||
import com.example.ticketbookingapp.domain.* | ||
import com.example.ticketbookingapp.service.MovieReservationService | ||
import com.example.ticketbookingapp.service.SeatAndTicketType | ||
import jakarta.persistence.EntityManager | ||
import jakarta.persistence.PersistenceContext | ||
import org.springframework.transaction.annotation.Transactional | ||
import org.springframework.stereotype.Service | ||
import java.math.BigDecimal | ||
import java.time.LocalDateTime | ||
import java.time.ZoneOffset | ||
|
||
@Service | ||
class DatabaseInitializationForTest( | ||
private val reservationService: MovieReservationService, | ||
private val databaseInitializationUtils: DatabaseInitializationUtils, | ||
) { | ||
@PersistenceContext | ||
private lateinit var entityManager: EntityManager | ||
|
||
@Transactional(rollbackFor = [Exception::class]) | ||
fun initializeDatabase() { | ||
val adultTicketType = databaseInitializationUtils.initializeTicketType("adult", BigDecimal("25")) | ||
val studentTicketType = databaseInitializationUtils.initializeTicketType("student", BigDecimal("18")) | ||
val childTicketType = databaseInitializationUtils.initializeTicketType("child", BigDecimal("12.5")) | ||
|
||
val room1 = databaseInitializationUtils.initializeRoom("room 1", 5, 5) | ||
val room2 = databaseInitializationUtils.initializeRoom("room 2", 10, 10) | ||
val room3 = databaseInitializationUtils.initializeRoom("room 3", 15, 15) | ||
|
||
val movie1 = databaseInitializationUtils.initializeMovie("Schindler's List", 90) | ||
val movie2 = databaseInitializationUtils.initializeMovie("The Shawshank Redemption", 90) | ||
val movie3 = databaseInitializationUtils.initializeMovie("The Lord of the Rings: The Return of the King", 90) | ||
|
||
val screening_1_1 = initializeScreening(room1, movie1, 10) | ||
val screening_1_2 = initializeScreening(room1, movie2, 20) | ||
|
||
val screening_2_2 = initializeScreening(room2, movie2, 9) | ||
databaseInitializationUtils.initializeScreening( | ||
room1, | ||
movie1, | ||
LocalDateTime.of(2100, 1, 1, 0, 0, 0), | ||
30 | ||
) | ||
initializeScreening(room2, movie3, 21) | ||
|
||
initializeScreening(room3, movie3, 11) | ||
initializeScreening(room3, movie1, 19) | ||
|
||
// to make sure ids of movie screenings are accessible | ||
entityManager.flush() | ||
|
||
val instantInThePast = LocalDateTime.of(1999, 1, 1, 0, 0).toInstant(ZoneOffset.UTC) | ||
|
||
reservationService.createReservation( | ||
screening_1_1, | ||
User("Name", "Surname"), | ||
screening_1_1.screeningRoom.seats | ||
.filter { seat -> seat.columnName == "1" } | ||
.map { e -> SeatAndTicketType(e, studentTicketType) }, | ||
instantInThePast | ||
) | ||
|
||
reservationService.createReservation( | ||
screening_1_1, | ||
User( | ||
"Namee", | ||
"Surnamee", | ||
), | ||
screening_1_1.screeningRoom.seats | ||
.filter { seat -> seat.columnName == "4" } | ||
.map { e -> SeatAndTicketType(e, adultTicketType) }, | ||
instantInThePast | ||
) | ||
|
||
reservationService.createReservation( | ||
screening_1_2, | ||
User( | ||
"Nameee", | ||
"Surnameee", | ||
), | ||
screening_1_2.screeningRoom.seats | ||
.filter { seat -> seat.columnName == "5" } | ||
.map { e -> SeatAndTicketType(e, childTicketType) }, | ||
instantInThePast | ||
) | ||
|
||
reservationService.createReservation( | ||
screening_2_2, | ||
User( | ||
"Nameee", | ||
"Surnameee", | ||
), | ||
screening_2_2.screeningRoom.seats | ||
.filter { seat -> seat.columnName == "2" } | ||
.map { e -> SeatAndTicketType(e, childTicketType) }, | ||
instantInThePast | ||
) | ||
} | ||
|
||
private fun initializeScreening( | ||
screeningRoom: ScreeningRoom, | ||
movie: Movie, | ||
hour: Int, | ||
): MovieScreening { | ||
return databaseInitializationUtils.initializeScreening( | ||
screeningRoom, | ||
movie, | ||
LocalDateTime.of(2000, 1, 1, hour, 0, 0), | ||
30 | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.example.ticketbookingapp.databaseInitialization | ||
|
||
import com.example.ticketbookingapp.domain.* | ||
import jakarta.persistence.EntityManager | ||
import jakarta.persistence.PersistenceContext | ||
import org.springframework.transaction.annotation.Transactional | ||
import org.springframework.stereotype.Service | ||
import java.math.BigDecimal | ||
import java.time.LocalDateTime | ||
|
||
@Service | ||
class DatabaseInitializationService( | ||
private val databaseInitializationUtils: DatabaseInitializationUtils, | ||
) { | ||
@PersistenceContext | ||
private lateinit var entityManager: EntityManager | ||
|
||
@Transactional(rollbackFor = [Exception::class]) | ||
fun initializeDatabase() { | ||
databaseInitializationUtils.initializeTicketType("adult", BigDecimal("25")) | ||
databaseInitializationUtils.initializeTicketType("student", BigDecimal("18")) | ||
databaseInitializationUtils.initializeTicketType("child", BigDecimal("12.5")) | ||
|
||
val room1 = databaseInitializationUtils.initializeRoom("room 1", 3, 3) | ||
val room2 = databaseInitializationUtils.initializeRoom("room 2", 15, 15) | ||
val room3 = databaseInitializationUtils.initializeRoom("room 3", 20, 20) | ||
|
||
val movie1 = databaseInitializationUtils.initializeMovie("Schindler's List ęóąśłżźćń", 100) | ||
val movie2 = databaseInitializationUtils.initializeMovie("The Shawshank Redemption", 120) | ||
val movie3 = databaseInitializationUtils.initializeMovie("The Lord of the Rings: The Return of the King", 140) | ||
|
||
initializeScreening(room1, movie1, 10) | ||
initializeScreening(room1, movie2, 20) | ||
|
||
initializeScreening(room2, movie2, 9) | ||
initializeScreening(room2, movie3, 21) | ||
|
||
initializeScreening(room3, movie3, 11) | ||
initializeScreening(room3, movie1, 19) | ||
|
||
// to make sure ids of movie screenings are accessible | ||
entityManager.flush() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wydaje mi się, że to nie byłoby konieczne, jeżeli metody initialize* zwracałyby obiekt z metody save There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Korzystam z metody save() z JpaRepository i te metody initialize* zwracają wynik tej metody. Nie zdawałem sobie sprawy, że metoda save() zwraca obiekty z ustawionym id, wiedziałem że może być z tym problem jak się używa entityManager.persist i stąd się zabezpieczyłem. Swoją drogą, nawet jakby metoda save() zwracała obiekty z nie ustawionym id to i tak to flush() tutaj i w klasie DatabaseInitializationForTest nie było by potrzebne, ponieważ nie korzystam z wygenerowanego id, zamiast tego korzystam z referencji do java obiektów. Kiedyś odnosiłem się do id w tutaj poniżej tego flush() |
||
} | ||
|
||
private fun initializeScreening( | ||
screeningRoom: ScreeningRoom, | ||
movie: Movie, | ||
hour: Int | ||
): MovieScreening { | ||
return databaseInitializationUtils.initializeScreening( | ||
screeningRoom, | ||
movie, | ||
LocalDateTime.of(2100, 1, 1, hour, 0, 0), | ||
30 | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.example.ticketbookingapp.databaseInitialization | ||
|
||
import com.example.ticketbookingapp.domain.* | ||
import com.example.ticketbookingapp.repositories.* | ||
import org.springframework.stereotype.Service | ||
import java.math.BigDecimal | ||
import java.time.LocalDateTime | ||
import java.time.ZoneOffset | ||
|
||
@Service | ||
class DatabaseInitializationUtils( | ||
private val movieRepository: MovieRepository, | ||
private val screeningRoomRepository: ScreeningRoomRepository, | ||
private val seatRepository: SeatRepository, | ||
private val movieScreeningRepository: MovieScreeningRepository, | ||
private val ticketTypeRepository: TicketTypeRepository, | ||
) { | ||
fun initializeTicketType(name: String, price: BigDecimal): TicketType { | ||
return TicketType(name, price).let { ticketTypeRepository.save(it) } | ||
} | ||
|
||
fun initializeRoom(roomName: String, numberOfRows: Int, numberOfColumns: Int): ScreeningRoom { | ||
val screeningRoom = ScreeningRoom(roomName).let { screeningRoomRepository.save(it) } | ||
val rowNames = ('A'..'Z').toList() | ||
val seatsArray = buildList { | ||
repeat(numberOfRows) { row -> | ||
add(buildList { | ||
repeat(numberOfColumns) { column -> | ||
add( | ||
Seat( | ||
screeningRoom, | ||
rowNames[row].toString(), | ||
(column + 1).toString() | ||
).let { seatRepository.save(it) } | ||
) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
for (row in seatsArray) { | ||
for ((rowIndex, seat) in row.withIndex()) { | ||
seat.seatToLeft = row.getOrNull(rowIndex - 1) | ||
seat.seatToRight = row.getOrNull(rowIndex + 1) | ||
} | ||
} | ||
|
||
return screeningRoom | ||
} | ||
|
||
fun initializeMovie( | ||
movieName: String, movieLengthInMinutes: Int | ||
): Movie { | ||
return Movie(movieName, movieLengthInMinutes) | ||
.let { movieRepository.save(it) } | ||
} | ||
|
||
fun initializeScreening( | ||
screeningRoom: ScreeningRoom, | ||
movie: Movie, | ||
dateTimeOfStart: LocalDateTime, | ||
commercialsLengthInMinutes: Int, | ||
): MovieScreening { | ||
val instantOfStart = dateTimeOfStart | ||
.toInstant(ZoneOffset.UTC) | ||
val instantOfEnd = | ||
instantOfStart.plusSeconds((commercialsLengthInMinutes + movie.lengthInMinutes).toLong() * 60) | ||
|
||
return MovieScreening(movie, screeningRoom, instantOfStart, instantOfEnd) | ||
.let { movieScreeningRepository.save(it) } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dlaczego akurat
Readme.txt
zamiastReadme.md
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Traktuję ten pr jako diff po którym można pisać komentarze, ten pr nigdy nie zostanie zmergowany. Z tego powodu nie zwracałem uwagi na to jak nazywa się target oraz source branch. W prawdziwej pracy zrobił bym odwrotnie tak, by po zmergowaniu tego pr zmienił się stan mastera.
Readme.md było by pewnie lepszym wyborem, bo pozwoliło by mi korzystać z markdownu, pewnie jest to też bardziej standardowy wybór. Nie zwróciłem na to uwagi.