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

JJDZR14KA-40 added delegation and pagination #29

Merged
merged 2 commits into from
Aug 8, 2024
Merged

Conversation

Marakra
Copy link
Collaborator

@Marakra Marakra commented Aug 5, 2024

No description provided.

Copy link
Contributor

@szablewski szablewski left a comment

Choose a reason for hiding this comment

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

  1. 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.
  2. Brak daty przy edycji lub gdy cofnie nas walidacja,
  3. 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, ",
Copy link
Contributor

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);
Copy link
Contributor

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));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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,
Copy link
Contributor

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.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@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;
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Nie potrzebujesz tu try/catch

Comment on lines +70 to +76
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";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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";
}

Copy link
Contributor

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 {
Copy link
Contributor

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

@szablewski szablewski merged commit 0d635d2 into main Aug 8, 2024
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