-
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
Full changes log merge from beginning of repo #1
base: pull_request_branch
Are you sure you want to change the base?
Conversation
# Conflicts: # src/main/java/com/ramcel/cinema/reservation/Application.java # src/main/java/com/ramcel/cinema/reservation/functionalities/controllers/TicketController.java # src/main/java/com/ramcel/cinema/reservation/functionalities/ticket/validators/TicketValidator.java # src/main/resources/application.properties # src/test/java/com/ramcel/cinema/reservation/controller/TicketControllerTest.java
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.
Cześć,
dzięki za przesłanie zadania - nie rób proszę już żadnych zmian pomoże nam to łatwiej przeglądać.
Od siebie dodałem kilka komentarzy 🙂
CONTAINER_NAME="mysql-container-nussknacker" | ||
|
||
DB_USER="cinema-app" | ||
DB_PASSWORD="EPqKjMPYhwJIeWKVRVQ7" |
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.
Hasło do bazy danych zapisane jako plain text wygląda groźnie 😨 Czy hasło musi być w repozytorium? Jak mógłbyś to zapisać by nie było zapisane w git'cie ani widoczne dla kogoś kto tego hasła nie ma? 🤔
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.
To prawda, że trochę się zastanawiałem, czy to tak wrzucać, ale to nie jest taki "prawdziwy" secret. Normalnie jest kilka rozwiązań, najbardziej popularne jakie znam, to (przy używaniu apki w dockerze, a ja tego nie zrobiłem), wrzucić secret jako env variable dla kontenera i ustawić w springu jako enviornment variable, np przy użyciu Property. Spring udostępnia też kilka bibliotek takich, jak jasypt czy spring vault pomocnych przy używaniu secretów.
Please install docker, java 21, maven. | ||
|
||
Go to /bash_scripts. | ||
First run the db_setup.bash script - it should start a docker container with mysql 8.0 running. The container is |
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.
Fajnie, że napisałeś skrypt :) a dlaczego nie zdecydowałeś się na użycie docker-compose
?
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.
mvn spring-boot::run to jest moje preferowane podejście przy takich szybkich odpaleniach, nie trzeba nic konfigurować na classpath, zwłaszcza jeśli chodzi o zewnętrzne pliki. Budowanie jara i docker-compose czasem wymagają jakiegoś grzebania, a nie bardzo miałem na to czas. Myślę, że w tym przypadku są to równie eleganckie rozwiązania, maven odpala się zwykle szybciej niż docker i bez problemu.
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> |
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.
Fajnie, że używasz in-memory db - h2 👍
@@ -0,0 +1,69 @@ | |||
About the app: |
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 wybrałeś README jako readme.txt
a nie readme.md
? Jaka jest różnica i co by Tobie (i użytkownikom) to dało? :)
Chyba, że celowo zamysł był na taki low-tech vibe 🤓
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.
Lubię .txt :) Różnica jest taka, że w markdownie można dodać lepszy formatting i np hyperlinki. Trochę ładniej możnaby zrobić.
for SCRIPT in "$SQL_SCRIPTS_DIR"/*.sql; do | ||
SCRIPT_NAME=$(basename "$SCRIPT") |
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.
Znasz może jakieś narzędzia/biblioteki, które pomagają zarządzać wersjonowaniem bazy danych? Np. gdyby zadeklarowane przez ciebie create_schemas.sql
się zmieniło, musiałbyś jakoś tą zmianę dodać, jak byś to zrobił? Co gwarantuje Ci, że pliki zostaną wykonane w prawidłowej kolejności?
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.
Znam flyway i Liquibase, korzystałem trochę z Liquibase z tych dwóch. Nie wiem, czy jest tam jakaś opcja, żeby bezpośrednio zmienić plik, chyba nie. Można np zrobić changeset liquibase, dodać ten skrypcik jako referencję i wtedy już zmieniać rzeczy za pomocą liquibase. Bazowy skrypt pozostaje jako podstawa.
Aktualnie gwarancję, że pliki będą wykonane w prawidłowej kolejności daje to, że akurat ułożyły się alfabetycznie. Narzędziami do wersjonowania można sobie to zapewnić niezależnie od tego.
ADULT(BigDecimal.valueOf(25)), | ||
STUDENT(BigDecimal.valueOf(18)), | ||
CHILD(BigDecimal.valueOf(12.5)); |
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.
Fajnie, że użyłeś BigDecimal
- a dlaczego nie np. Double
? 🙂
Czy kwoty biletów moglibyśmy umieścić w innym miejscu, by nie musieć przebudowywać aplikacji gdy przyjdą np. podwyżki inflacyjne?
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.
BigDecimal ma duży overhead, ale jest precyzyjne - za dużo obliczeń nie wykonujemy, więc chyba lepiej dokładnie policzyć ile chcemy dostać pieniędzy :).
Wartości biletów możnaby np wczytać z zewnętrznego pliku springa i konfigurować za pomocą Value, można zdefiniować Bean w konfiguracji springa. Są też pewnie jakieś metody na pobieranie tego z bazy danych, ale nie bawiłem się w to nigdy.
import org.springframework.boot.autoconfigure.domain.EntityScan; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.ComponentScan; |
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.
Czy te importy są potrzebne?
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.
A co tutaj robi /target
? 🙂
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.
Wrzuciłem, bo bez niego mvn spring-boot czasem mi świrował (chyba miał jakiś problem z zewnętrznymi plikami)
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ |
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.
Celowo się pozbyłeś tych linijek?
import com.ramcel.cinema.reservation.functionalities.screening.Movie; | ||
import com.ramcel.cinema.reservation.functionalities.screening.Screening; | ||
import com.ramcel.cinema.reservation.functionalities.screening.ScreeningService; |
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.
🔍
for (int i = 0; i < seats.size() - 2; i++) { | ||
SeatEntity seat1 = seats.get(i); | ||
SeatEntity seat2 = seats.get(i + 1); | ||
SeatEntity seat3 = seats.get(i + 2); | ||
|
||
if (seat1.getStatus() != SeatStatus.AVAILABLE | ||
&& seat2.getStatus() == SeatStatus.AVAILABLE | ||
&& seat3.getStatus() != SeatStatus.AVAILABLE) { | ||
return false; | ||
} | ||
} | ||
return true; |
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.
Czy można byłoby to zapisać bez użycia for
? 🤔
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.
Dałoby się to zapisać jakimś functional chainem, ale nie próbowałem być zbyt cwany - for był naturalnym rozwiązaniem dla takiego algorytmiku. Problemem zwłaszcza standardowych streamów w javie byłoby tutaj to, że zapominamy o poprzednim elemencie i ciężko byłoby w naturalny sposób porównać ze sobą 3 elementy. Da się, tylko chyba nie warto.
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.
Cześć, pomyślałem jeszcze nad tym podpunktem chwile od wczoraj, bo stwierdziłem, że skoro pytasz, to jest jakiś sprytny myk jak to zrobić. Wymyśliłem coś takiego - do funkcji przekazujemy już listę jednego rzędu siedzeń, więc możemy posortować względem miejsca w rzędzie, odfiltrować puste miejsca i na koniec dać reduce, z warunkiem, że jeśli seatNr(i) + 2 = seatNr(i+1) , to rzucamy false - mamy dziurę. To działa, ale dla mnie jest chyba trochę zbyt skomplikowane w porównaniu do fora. Co o tym myślisz?
Jesli masz jakiś pomysł, jak to rozwiązać w iny sposób, to chętnie go poznam :)
Dzięki za review, odpowiedziałem na wszystkie pytania. |
Pull request for code review.