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

Task-44-Active-events-search-frontend #53

Merged
merged 27 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
db3d1f3
removed logout on logo click
YamiHeike Nov 13, 2024
4b96d61
added toast on addDisaster page
YamiHeike Nov 13, 2024
9d40856
fixed login page layout
YamiHeike Nov 14, 2024
ed01c92
fixed field names
YamiHeike Nov 14, 2024
fb33353
deleted not needed style classes
YamiHeike Nov 14, 2024
3400693
Merge remote-tracking branch 'refs/remotes/origin/master' into task-3…
YamiHeike Nov 17, 2024
af180c8
login page: changed headers, redesigned
YamiHeike Nov 18, 2024
9a44919
fixed toast, addDisaster page design
YamiHeike Nov 18, 2024
e9a1cda
fixed fullscreen display, changed layout of addDisaster view
YamiHeike Nov 20, 2024
019f959
Merge branch 'refs/heads/Task-38-Web-navigation' into task-35-update-…
Slawek84PL Nov 21, 2024
41696f9
Updated navbar
Slawek84PL Nov 21, 2024
5b28eb7
Added disaster list view in controller
Slawek84PL Nov 21, 2024
23fe80f
Added disaster list view
Slawek84PL Nov 21, 2024
5e9dc81
Merge branch 'master' into Task-44-Active-events-search-frontend
Slawek84PL Nov 21, 2024
7a33ae8
navbar accessibility
YamiHeike Nov 21, 2024
7fea1a6
Prepare methods declaration
jkuznik Nov 22, 2024
25c559c
Add logic to search disasters
jkuznik Nov 22, 2024
27378c7
Change methods signature, prepare new methods declarations
jkuznik Nov 22, 2024
6e65efd
Fix disaster browser issue
jkuznik Nov 22, 2024
29cf9f4
Fix DisasterDTO property name issue
jkuznik Nov 22, 2024
1c70a09
Unmute sms service
jkuznik Nov 23, 2024
475ecb2
Merge pull request #55 from jkuznik/Task-43-Disaster-Browser
jkuznik Nov 23, 2024
9695cba
Added favicon
Slawek84PL Nov 23, 2024
95c621e
Removed redundant elements
Slawek84PL Nov 23, 2024
18e7325
Extracted method
Slawek84PL Nov 23, 2024
a006b80
Added default list
Slawek84PL Nov 23, 2024
033e837
Added message about empty list
Slawek84PL Nov 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<DisasterDTO> interestingDisasters(Optional<DisasterType> type, Optional<String> location) {
return disasterService.interestingDisasters(type, location);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Disaster, UUID> {
Optional<Disaster> findById(UUID id);
Optional<Disaster> findFirstByTypeAndLocationAndStatus(DisasterType type, String location, DisasterStatus status);
List<Disaster> findAllByStatus(DisasterStatus status);
List<Disaster> findAllByType(DisasterType type);
List<Disaster> findAllByLocation(String location);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<DisasterDTO> getActiveDisasterForTypeAndLocation(@NotNull @Valid DisasterType type, String location);
Optional<DisasterDTO> getActiveDisasterForTypeAndLocation(@NotNull @Valid DisasterType type, @NotNull @NotBlank String location);

List<DisasterDTO> interestingDisasters(Optional<DisasterType> type, Optional<String> location);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -60,4 +64,31 @@ public Optional<DisasterDTO> getActiveDisasterForTypeAndLocation(DisasterType ty
return disasterRepository.findFirstByTypeAndLocationAndStatus(type, location, DisasterStatus.ACTIVE)
.map(mapper::mapDisasterToDisasterDto);
}

@Override
public List<DisasterDTO> interestingDisasters(Optional<DisasterType> type, Optional<String> location) {
//TODO: poniższa logika jest nie optymalna, do poprawy po zakończeniu konkursu

List<DisasterDTO> interestedDisasters = disasterRepository.findAllByStatus(DisasterStatus.ACTIVE).stream()
.map(mapper::mapDisasterToDisasterDto)
.collect(Collectors.toList());

if (type.isPresent()) {
List<DisasterDTO> byType = disasterRepository.findAllByType(type.get()).stream()
.map(mapper::mapDisasterToDisasterDto)
.collect(Collectors.toList());

interestedDisasters.retainAll(byType);
}

if (location.isPresent()) {
List<DisasterDTO> byLocation = disasterRepository.findAllByLocation(location.get()).stream()
.map(mapper::mapDisasterToDisasterDto)
.collect(Collectors.toList());

interestedDisasters.retainAll(byLocation);
}

return interestedDisasters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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<DisasterDTO> getDisasterDTOS(String disasterType, String city) {
Optional<DisasterType> type;
if (disasterType.isEmpty() || disasterType.equals("Wszystkie")){
type = Optional.empty();
} else {
type = Optional.of(DisasterType.valueOf(disasterType));
}

Optional<String> 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());
Expand Down
Binary file added src/main/resources/static/images/favicon.ico
Binary file not shown.
37 changes: 24 additions & 13 deletions src/main/resources/templates/addDisaster.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

<head th:replace="~{fragments :: head('Dodaj Zdarzenie')}"></head>

<body>
<body class="bg-body-tertiary">
<nav th:replace="~{fragments :: nav}"></nav>

<div class="d-flex vh-100 align-items-center justify-content-center bg-body-tertiary">
<div class="container col-xl-10 col-xxl-8 px-4 py-5">
<div class="row align-items-center g-lg-5 py-5">
<div class="col-lg-7 text-center text-lg-start">
<h1 class="display-4 fw-bold lh-1 text-body-emphasis mb-3">Dodaj Zdarzenie</h1>
<p class="col-lg-10 fs-4">Wprowadź informacje o nowym zdarzeniu</p>
</div>
<div class="col-md-10 mx-auto col-lg-5">
<div th:replace="~{fragments :: message}"></div>
<form action="/disasters/add" method="post" th:object="${disasterAddDTO}" class="p-4 p-md-5 rounded-3 bg-body-tertiary">
<div class="px-4 py-5 mt-5 text-center bg-white shadow-sm">
<h1 class="display-5 fw-bold text-body-emphasis">Dodaj <span class="text-primary">Zdarzenie</span></h1>
<div class="col-lg-6 mx-auto">
<p class="lead">Wprowadź informacje o nowym zdarzeniu. Pamiętaj, że fałszywe zgłoszenia zostaną wykryte.</p>
</div>
</div>
<div>
<div class="container col-xl-10 col-xxl-10 px-4 ">
<div class="row g-lg-5 py-5">
<div class="col-md-10 mx-auto col-lg-10">
<form action="/disasters/add" method="post" th:object="${disasterAddDTO}" class="p-4 p-md-2 rounded-3 bg-body-tertiary">
<div class="form-floating mb-3">
<select th:value="${disasterTypSelected}" name="type" class="form-select" id="type" required>
<option th:if="${disasterTypSelected == null}" value="" disabled selected>Wybierz typ zdarzenia</option>
Expand All @@ -37,7 +37,18 @@ <h1 class="display-4 fw-bold lh-1 text-body-emphasis mb-3">Dodaj Zdarzenie</h1>
<input th:value="${userId}" name="userId" type="hidden" class="form-control" id="userId" required readonly>
</div>

<button class="w-100 btn btn-lg btn-success" type="submit">Dodaj Zdarzenie</button>
<button class="w-100 btn btn-lg btn-primary" type="submit">Dodaj Zdarzenie</button>
<div id="toastMessage" class="toast rounded align-items-center border-0 position-fixed bottom-0 end-0 m-3 show" role="alert" aria-live="assertive" aria-atomic="true" th:if="${message}">
<div class="toast-header">
<svg class="bd-placeholder-img rounded me-2" width="20" height="20" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" preserveAspectRatio="xMidYMid slice" focusable="false"><rect width="100%" height="100%" fill="#007aff"/></svg>
<strong class="me-auto">Udało się!</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="d-flex text-secondary bg-light px-3 py-1 fw-light">
<div th:replace="~{fragments :: message}" class="toast-body text-white">
</div>
</div>
</div>
</form>
</div>
</div>
Expand Down
Loading