-
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
JJDZR14KA-40 added delegation and pagination #29
Conversation
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.
- Brakuje komunikatów na froncie, gdy wykonamy jakąś operacjęn np. dodamy nowy transport czy accomodation, to samo się tyczy gdy usuniemy obiekt lub zrobimy update.
- Brak daty przy edycji lub gdy cofnie nas walidacja,
- Masz walidacje @NotNull(message = "Transport list is a required field!") natomiast kiedy dodam delegacje bez transportu to przechodzi
@@ -108,14 +124,14 @@ private void validateAccommodation(Accommodation accommodation){ | |||
|
|||
private void logSuccessMessage(Accommodation accommodation) { | |||
String successMessage = String.format("Successfully updated accommodation: %s, type: $s, address: %s, ", |
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.
String.format("Successfully updated accommodation: %s", accommodation.getNameAccommodation()) ;
przydało by się to wyświetlić na foncie
}); | ||
delegation.setAccommodations(accommodations); | ||
|
||
Double totalPrice = calculatorTotalPrice(transports, accommodations); |
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.
jeślichodzi o obliczanie pieniędzy został do t ego celu stworzony spejcalny obiekt BigDecimal
|
||
public class DelegationNotFoundException extends IOException { | ||
public DelegationNotFoundException(Long delegationId) { | ||
super(String.format("No delegation found with id %d", delegationId)); |
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.
super(String.format("No delegation found with id %d", delegationId)); | |
super(String.format("Not found delegation with provide id: %d", delegationId)); |
public String getAllAccommodations(@RequestParam(value = "page", defaultValue = "0") int page, | ||
@RequestParam(value = "size", defaultValue = "10") int size, | ||
Model model) throws IOException { | ||
Page<Accommodation> accommodations = accommodationService.fetchAccommodationPage(PageRequest.of(page, 10)); |
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.
Page<Accommodation> accommodations = accommodationService.fetchAccommodationPage(PageRequest.of(page, 10)); | |
Page<Accommodation> accommodations = accommodationService.fetchAccommodationPage(PageRequest.of(page, size)); |
List<Accommodation> accommodationList = accommodationService.fetchAccommodationList(); | ||
log.info("Fetched accommodationList: {}", accommodationList.size()); | ||
model.addAttribute("accommodations", accommodationList); | ||
public String getAllAccommodations(@RequestParam(value = "page", defaultValue = "0") int page, |
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.
ze zmiennych defaultValue = "0" powinno zostać wyeksportowane do zmiennej private static final String PAGE_VALUE= "0"
to samo się tyczy size we wszystkich controlerach.
@OneToMany(mappedBy = "delegation", cascade = CascadeType.ALL) | ||
private List<Accommodation> accommodations; | ||
|
||
@Digits(integer = 5, fraction = 2, message = "Invalid format. Max 5 digits and 2 decimals.") |
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.
@Digits(integer = 5, fraction = 2, message = "Invalid format. Max 5 digits and 2 decimals.") | |
@Positive() |
this.employee = employee; | ||
this.transports = transports; | ||
this.accommodations = accommodations; | ||
this.totalPrice = totalPrice != null ? totalPrice : 0.0; |
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.
nie robimy walidacji w konstruktorze
} | ||
|
||
@PostMapping("/delegation") | ||
public String saveDelegation(@Valid @ModelAttribute("delegation") Delegation delegation, |
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.
- Nie potrzebujesz tu try/catch
if (bindingResult.hasErrors()) { | ||
log.error("Validation errors occurred: {}", bindingResult.getAllErrors()); | ||
model.addAttribute("employees", employeeService.loadEmployeeFromFile()); | ||
model.addAttribute("transports", transportService.loadTransportFromFile()); | ||
model.addAttribute("accommodations", accommodationService.loadAccommodationFromFile()); | ||
return "delegation/createDelegationForm"; | ||
} |
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.
if (bindingResult.hasErrors()) { | |
log.error("Validation errors occurred: {}", bindingResult.getAllErrors()); | |
model.addAttribute("employees", employeeService.loadEmployeeFromFile()); | |
model.addAttribute("transports", transportService.loadTransportFromFile()); | |
model.addAttribute("accommodations", accommodationService.loadAccommodationFromFile()); | |
return "delegation/createDelegationForm"; | |
} | |
if (bindingResult.hasErrors()) { | |
log.error("Validation errors occurred: {}", bindingResult.getAllErrors()); | |
return "redirect:/delegation"; | |
} |
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.
radził bym to zrobić w ten sposób, ponieważ ładowanie wszystkich obiektów wszystkich encji jest złą praktyką
} | ||
|
||
@Override | ||
public void createDelegation(Delegation delegation) throws IOException { |
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.
zastanawiam się po szukasz tych wszystkich List transport, accomodation
No description provided.