Skip to content
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

Open
wants to merge 25 commits into
base: pull_request_branch
Choose a base branch
from

Conversation

Diamekod0221
Copy link
Owner

Pull request for code review.

# 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
Copy link

@philemone philemone left a 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"

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? 🤔

Copy link
Owner Author

@Diamekod0221 Diamekod0221 Nov 6, 2023

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

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?

Copy link
Owner Author

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>

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:

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 🤓

Copy link
Owner Author

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ć.

Comment on lines +28 to +29
for SCRIPT in "$SQL_SCRIPTS_DIR"/*.sql; do
SCRIPT_NAME=$(basename "$SCRIPT")

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?

Copy link
Owner Author

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.

Comment on lines +11 to +13
ADULT(BigDecimal.valueOf(25)),
STUDENT(BigDecimal.valueOf(18)),
CHILD(BigDecimal.valueOf(12.5));

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?

Copy link
Owner Author

@Diamekod0221 Diamekod0221 Nov 6, 2023

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.

Comment on lines +6 to +8
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

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?

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? 🙂

Copy link
Owner Author

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)

Comment on lines -2 to -5
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

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?

Comment on lines +4 to +6
import com.ramcel.cinema.reservation.functionalities.screening.Movie;
import com.ramcel.cinema.reservation.functionalities.screening.Screening;
import com.ramcel.cinema.reservation.functionalities.screening.ScreeningService;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍

Comment on lines +155 to +166
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;

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? 🤔

Copy link
Owner Author

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.

Copy link
Owner Author

@Diamekod0221 Diamekod0221 Nov 7, 2023

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 :)

@Diamekod0221
Copy link
Owner Author

Diamekod0221 commented Nov 6, 2023

Dzięki za review, odpowiedziałem na wszystkie pytania.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants