diff --git a/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterAlertFacade.java b/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterAlertFacade.java index 3eaa2b5e..d7bb9bf1 100644 --- a/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterAlertFacade.java +++ b/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterAlertFacade.java @@ -9,6 +9,9 @@ import pl.ateam.disasteralerts.disasteralert.dto.DisasterAddDTO; import pl.ateam.disasteralerts.disasteralert.dto.DisasterDTO; +import java.util.List; +import java.util.Optional; + @Component @Validated @RequiredArgsConstructor @@ -18,4 +21,8 @@ public class DisasterAlertFacade { public DisasterDTO createDisaster(@NotNull @Valid DisasterAddDTO disasterAddDTO, @NotNull @NotBlank String source) { return disasterService.createDisaster(disasterAddDTO, source); } + + public List interestingDisasters(Optional type, Optional location) { + return disasterService.interestingDisasters(type, location); + } } diff --git a/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterRepository.java b/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterRepository.java index e6f3124c..b4bbb3c7 100644 --- a/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterRepository.java +++ b/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterRepository.java @@ -2,10 +2,14 @@ import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; import java.util.UUID; interface DisasterRepository extends JpaRepository { Optional findById(UUID id); Optional findFirstByTypeAndLocationAndStatus(DisasterType type, String location, DisasterStatus status); + List findAllByStatus(DisasterStatus status); + List findAllByType(DisasterType type); + List findAllByLocation(String location); } diff --git a/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterService.java b/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterService.java index fc7086c7..1a736c34 100644 --- a/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterService.java +++ b/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterService.java @@ -7,10 +7,14 @@ import pl.ateam.disasteralerts.disasteralert.dto.DisasterAddDTO; import pl.ateam.disasteralerts.disasteralert.dto.DisasterDTO; +import java.util.List; import java.util.Optional; @Validated interface DisasterService { DisasterDTO createDisaster(@NotNull @Valid DisasterAddDTO disasterAddDTO, @NotNull @NotBlank String source); - Optional getActiveDisasterForTypeAndLocation(@NotNull @Valid DisasterType type, String location); + Optional getActiveDisasterForTypeAndLocation(@NotNull @Valid DisasterType type, @NotNull @NotBlank String location); + + List interestingDisasters(Optional type, Optional location); + } diff --git a/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterServiceImpl.java b/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterServiceImpl.java index 3156add1..813e6f3f 100644 --- a/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterServiceImpl.java +++ b/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterServiceImpl.java @@ -8,8 +8,11 @@ import pl.ateam.disasteralerts.disasteralert.dto.DisasterAddDTO; import pl.ateam.disasteralerts.disasteralert.dto.DisasterDTO; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; @Service(value = "prototype") @RequiredArgsConstructor @@ -24,6 +27,7 @@ class DisasterServiceImpl implements DisasterService { public DisasterDTO createDisaster(DisasterAddDTO disasterAddDTO, String source) { Disaster disaster = mapper.mapDisasterAddDtoToDisaster(disasterAddDTO); disaster.setSource(source); + //TODO: trzeba dopracować promt do czata bo przy obecnym trudno osiągnąć wynik pozwalający na uznanie zdarzenia za prawdziwe // if (riskAssessment.assessRisk(disasterAddDTO)) { // disaster.setStatus(DisasterStatus.ACTIVE); // disasterRepository.save(disaster); @@ -60,4 +64,31 @@ public Optional getActiveDisasterForTypeAndLocation(DisasterType ty return disasterRepository.findFirstByTypeAndLocationAndStatus(type, location, DisasterStatus.ACTIVE) .map(mapper::mapDisasterToDisasterDto); } + + @Override + public List interestingDisasters(Optional type, Optional location) { + //TODO: poniższa logika jest nie optymalna, do poprawy po zakończeniu konkursu + + List interestedDisasters = disasterRepository.findAllByStatus(DisasterStatus.ACTIVE).stream() + .map(mapper::mapDisasterToDisasterDto) + .collect(Collectors.toList()); + + if (type.isPresent()) { + List byType = disasterRepository.findAllByType(type.get()).stream() + .map(mapper::mapDisasterToDisasterDto) + .collect(Collectors.toList()); + + interestedDisasters.retainAll(byType); + } + + if (location.isPresent()) { + List byLocation = disasterRepository.findAllByLocation(location.get()).stream() + .map(mapper::mapDisasterToDisasterDto) + .collect(Collectors.toList()); + + interestedDisasters.retainAll(byLocation); + } + + return interestedDisasters; + } } diff --git a/src/main/java/pl/ateam/disasteralerts/disasteralert/dto/DisasterDTO.java b/src/main/java/pl/ateam/disasteralerts/disasteralert/dto/DisasterDTO.java index b0493c53..7c2283a5 100644 --- a/src/main/java/pl/ateam/disasteralerts/disasteralert/dto/DisasterDTO.java +++ b/src/main/java/pl/ateam/disasteralerts/disasteralert/dto/DisasterDTO.java @@ -11,7 +11,7 @@ public record DisasterDTO(UUID id, String description, String source, String location, - LocalDateTime creationDate, + LocalDateTime createDate, LocalDateTime disasterEndTime, DisasterStatus status, UUID userId) { diff --git a/src/main/java/pl/ateam/disasteralerts/web/DisasterViewController.java b/src/main/java/pl/ateam/disasteralerts/web/DisasterViewController.java index 2211acf5..a5b0a396 100644 --- a/src/main/java/pl/ateam/disasteralerts/web/DisasterViewController.java +++ b/src/main/java/pl/ateam/disasteralerts/web/DisasterViewController.java @@ -10,14 +10,21 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import pl.ateam.disasteralerts.disasteralert.DisasterAlertFacade; import pl.ateam.disasteralerts.disasteralert.DisasterStatus; import pl.ateam.disasteralerts.disasteralert.DisasterType; import pl.ateam.disasteralerts.disasteralert.dto.DisasterAddDTO; +import pl.ateam.disasteralerts.disasteralert.dto.DisasterDTO; import pl.ateam.disasteralerts.security.AppUser; import pl.ateam.disasteralerts.util.CitiesInPoland; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + @Controller @RequiredArgsConstructor @RequestMapping("/disasters") @@ -56,6 +63,43 @@ public String createDisaster(Model model, @AuthenticationPrincipal AppUser userD return "redirect:/disasters/add"; } + @GetMapping("list") + public String showDisasterList(Model model, @AuthenticationPrincipal AppUser userDetails) { + baseModel(model, userDetails); + + if (!model.containsAttribute("list")) { + model.addAttribute("list", getDisasterDTOS("Wszystkie", "Wszystkie")); + } + return "listDisasters"; + } + + @PostMapping("list") + public String filterList(@RequestParam(name = "disasterType") String disasterType, + @RequestParam(name = "city") String city, + RedirectAttributes redirectAttributes) { + + redirectAttributes.addFlashAttribute("list", getDisasterDTOS(disasterType, city)); + return "redirect:/disasters/list"; + } + + private List getDisasterDTOS(String disasterType, String city) { + Optional type; + if (disasterType.isEmpty() || disasterType.equals("Wszystkie")){ + type = Optional.empty(); + } else { + type = Optional.of(DisasterType.valueOf(disasterType)); + } + + Optional location; + if (city.isEmpty() || city.equals("Wszystkie")){ + location = Optional.empty(); + } else { + location = Optional.of(city); + } + + return disasterAlertFacade.interestingDisasters(type, location); + } + private void baseModel(Model model, AppUser userDetails) { model.addAttribute("userId", userDetails.getUserDTO().id()); model.addAttribute("disasterType", DisasterType.values()); diff --git a/src/main/resources/static/images/favicon.ico b/src/main/resources/static/images/favicon.ico new file mode 100644 index 00000000..b1171aa1 Binary files /dev/null and b/src/main/resources/static/images/favicon.ico differ diff --git a/src/main/resources/templates/addDisaster.html b/src/main/resources/templates/addDisaster.html index 35e7a8c6..a0d8f519 100644 --- a/src/main/resources/templates/addDisaster.html +++ b/src/main/resources/templates/addDisaster.html @@ -3,19 +3,19 @@ - + - -
-
-
-
-

Dodaj Zdarzenie

-

Wprowadź informacje o nowym zdarzeniu

-
-
-
-
+
+

Dodaj Zdarzenie

+
+

Wprowadź informacje o nowym zdarzeniu. Pamiętaj, że fałszywe zgłoszenia zostaną wykryte.

+
+
+
+
+
+
+
- + +
diff --git a/src/main/resources/templates/fragments.html b/src/main/resources/templates/fragments.html index 324185d2..a82fba43 100644 --- a/src/main/resources/templates/fragments.html +++ b/src/main/resources/templates/fragments.html @@ -1,87 +1,103 @@ - + - - - DisasterAlerts - - - - - + + + DisasterAlerts + + + + + + - - -
-

+ -
-
-

Wybierz miejscowość:

-
- +
+

+
- -
+
+
+

Wybierz miejscowość:

+
+ - -
+ } + +
\ No newline at end of file diff --git a/src/main/resources/templates/listDisasters.html b/src/main/resources/templates/listDisasters.html new file mode 100644 index 00000000..7b3ee2d4 --- /dev/null +++ b/src/main/resources/templates/listDisasters.html @@ -0,0 +1,69 @@ + + + + + + + +
+

Sprawdź Zdarzenia

+
+

Sprawdź informacje o aktywnych zdarzeniach.

+
+
+
+
+
+
+
+
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+ + + + + + + + + + + + + + + + + +
Typ zdarzeniaOpisLokalizacjaData zgłoszenia
+
+
+

Brak Zdarzeń +

+
+
+
+
+
+ + diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html index 1fb3cc20..b5dd7da6 100644 --- a/src/main/resources/templates/login.html +++ b/src/main/resources/templates/login.html @@ -1,23 +1,25 @@ - + - + + + -
+
-

DisasterAlerts

-

Lorem ipsum dolor sit viverra

+

Chroń siebie i swoich bliskich

+

Spokój zaczyna się od ostrzeżenia

-
-
Niepoprawny login lub hasło
+
+
Niepoprawny login lub hasło
Wylogowano
@@ -30,10 +32,10 @@

DisasterAlerts

- - Utwórz konto + + Utwórz konto
- By clicking Sign up, you agree to the terms of use. + Założenie konta oznacza akceptację regulaminu
diff --git a/src/main/resources/templates/signup.html b/src/main/resources/templates/signup.html index 637207c0..7015d361 100644 --- a/src/main/resources/templates/signup.html +++ b/src/main/resources/templates/signup.html @@ -11,22 +11,26 @@

Rejestracja

-
+
-
- - +
+ +
Nazwa użytkownika jest wymagana
-
- - +
+ +
Nazwa użytkownika jest wymagana
@@ -37,7 +41,8 @@

Rejestracja

@ - +
Niewłaściwy format adresu e-mail
@@ -45,13 +50,16 @@

Rejestracja

-
+
- +
-
+
@@ -60,37 +68,8 @@

Rejestracja

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
+
@@ -104,22 +83,5 @@

Rejestracja

  • Pomoc
  • - -
    \ No newline at end of file diff --git a/src/main/resources/templates/updateUser.html b/src/main/resources/templates/updateUser.html index be97498d..f5b7cbad 100644 --- a/src/main/resources/templates/updateUser.html +++ b/src/main/resources/templates/updateUser.html @@ -5,7 +5,7 @@ -
    +
    @@ -13,7 +13,7 @@

    Aktualizacja danychAktualizuj informacje

    -
    +
    @@ -64,7 +64,7 @@

    Aktualizacja danych

    - +