Skip to content

Merge all to master#1

Open
mateuszkp96 wants to merge 30 commits intomasterfrom
dev
Open

Merge all to master#1
mateuszkp96 wants to merge 30 commits intomasterfrom
dev

Conversation

@mateuszkp96
Copy link
Owner

screening_room_seats
Screening room seats arrangement

= and others added 30 commits June 29, 2019 18:06
Copy link

@MateuszRasinski MateuszRasinski left a comment

Choose a reason for hiding this comment

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

Na plus: zrealizowano funkcjonalność rezerwacji wraz z walidacją miejsc. Dobry interfejs, zmapowane wyjątki, pieniądze w BigDecimal. Widać, że lubisz się i dobrze sobie radzisz z SQLem.
Na minus: brak testu przynajmniej happy path (chociaż jest w bashu, więc tyle dobrze). Pakiety dzielone horyzontalnie (po warstwach technicznych) zamiast wertykalnie (po domenie biznesowej, funkcjonalnościach). Uboga domena, wszystko dzieje się proceduralnie i głównie po stronie bazy danych. Wszystko oprócz walidacji miejsc, która jest bardzo skomplikowana i nieczytelna.

Proszę, nie poprawiaj kodu, ale odnieś się do komentarzy. Dzięki!

@PostMapping
public ShortReservationDTO postReservation(@RequestBody ReservationPostDTO postDTO) {
Reservation reservation = mapper.toReservation(postDTO);
return mapper.toShortReservationDTO(service.saveReservation(reservation));

Choose a reason for hiding this comment

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

nie jestem fanem mapperów, ale spoko. Generalnie do service'u mogłoby przyjść DTO i mogłoby być zwrócone DTO i byłoby OK

private String director;

@Basic
private java.time.LocalTime length;

Choose a reason for hiding this comment

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

import? i po co ten @Basic ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Nie wiem o który import tutaj chodzi, prawdopodobnie o import static. Słyszałem, że dobrą praktyką jest import statyczny tych stałych (zwłaszcza gdy w jednej adnotacji może ich występować więcej). A adnotacja @basic to chyba pozostałość po wcześniejszych wersjach springa, ogólnie wzorowałem się na: https://www.baeldung.com/hibernate-date-time a tam pola oznaczone są tą adnotacją. W springu 5 działa dobrze już bez tej adnotacji.

Choose a reason for hiding this comment

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

Chodziło mi o to, że tą klasę LocalTime można zaimportować i nie mieć kropeczek wtedy (java.time można się pozbyć)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Racja, mój błąd


import lombok.Data;

import javax.persistence.*;

Choose a reason for hiding this comment

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

importy z gwiazdkami nie są preferowane - dobre IDE i tak ci je schowa, a jak chcesz zobaczyć jaka klasa jest importowana to tak nie zobaczysz :(

Copy link
Owner Author

Choose a reason for hiding this comment

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

Nie wiedziałem o tym, ale to kwestia ustawień IDE. Teraz już będę pamiętał

private Room room;

@Column(name = "is_on_edge")
private Boolean isOnEdge;

Choose a reason for hiding this comment

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

ciekawa koncepcja. A bez tego by się dało? I bez dodatkowej tabelki złączeniowej?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Przyjąłem dodatkowe założenie, że miejsce na skraju może być zawsze zarezerwowane( Przy samym założeniu, że nie można zostawić jednego miejsca wolnego byłby problem z rezerwacją tego miejsca na skraju [ REZERWOWANE, WOLNE, ZAJĘTE, .... ]. Wtedy nie musimy sprawdzać sąsiednich miejsc. To pozwala również na układ sali taki, że np. na środku sali może być przejście, wtedy mamy kolejne miejsca na skraju. ) Stąd ta zmienna isOnEdge. Z kolei obeszło by się bez tabelki złączeniowej, po prostu wrzucić numer rzędu i siedzenia do tej klasy.


private String typeName;

private BigDecimal price;

Choose a reason for hiding this comment

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

plus za BigDecimal

}
});
return seats;
}

Choose a reason for hiding this comment

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

dlaczego to nie jest w jakiejś klasie? abstrakcji zamykającej salę kinową?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Tak, tutaj można by to opakować w abstrakcje, jakiś typ generyczny implementujący interfejs do pobierania danych zamiast RoomSeat

}

return true;
}

Choose a reason for hiding this comment

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

ta klasa ma tyle ifów i switchów, że nigdy nie chciałbyś takiej reviewować / utrzymywać.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Sporo ifów się zrobiło z powodu iterowania po liście po sąsiednich miejscach (nie zawsze występują w sąsiedztwie dwa na lewo i dwa na prawo jak w ogólnym przypadku). Nie zastosowałem listIterator, ponieważ po wywołaniu next() lub previous() zmienia się index wskazywanego elementu, a tutaj było to niepożądane.


private boolean hasNext(List<SeatModel> neighbourhood, int index) {
return index + 1 < neighbourhood.size();
}

Choose a reason for hiding this comment

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

te 4 metody wyglądają jakby zawsze dotyczyły tego samego. Może można by je zamknąć w jakiejś jednej klasie? Jest coś takiego jak programowanie obiektowe.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Racja, mogłem to opakować, ewentualnie zamienić na abstrakcję z typem generycznym

import static org.junit.runners.Parameterized.Parameters;

@RunWith(Enclosed.class)
public class SeatValidationServiceTest {

Choose a reason for hiding this comment

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

jeżeli miałbyś napisać jeden test, to jaki byłby to test? Test tego, że osoba wyświetla filmy, wybiera sens, dokonuje rezerwacji i system tą rezerwację przyjmuje; czy testy walidacji zajętych miejsc?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Przyznaję, że brakuje tutaj testów use casów (same w sobie zawierałyby kilka testów rezerwacji miejsc). A test napisany z powodu dużej ilości kombinacji ustawień siedzeń, ciężkie do sprawdzenia w sposób ręczny.
Więc jeśli miałbym wybierać to test use case - sprawdza więcej elementów.


@Test
public void test_validate_good() {
assertTrue(service.validate(reserved, occupied, all));

Choose a reason for hiding this comment

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

trochę mało czytelne te testy

Copy link
Owner Author

Choose a reason for hiding this comment

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

Tutaj kwestia nazewnictwa - te metody mogłyby nazywać się lepiej oraz brakuje wyrównania parametrów w metodach

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