From 2c321b294c0c661ce5bc9fc3f5541bf72c75d944 Mon Sep 17 00:00:00 2001 From: viktor436 Date: Thu, 26 Jan 2023 01:42:31 +0200 Subject: [PATCH] Displaying simple rating --- .../Controllers/JobOfferController.java | 15 +++++++++++---- .../Repositories/JobApplicationRepository.java | 1 + src/main/resources/templates/offers.html | 18 +++++++++++------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/findwork/findwork/Controllers/JobOfferController.java b/src/main/java/com/findwork/findwork/Controllers/JobOfferController.java index 574ab90..ca1ff7e 100644 --- a/src/main/java/com/findwork/findwork/Controllers/JobOfferController.java +++ b/src/main/java/com/findwork/findwork/Controllers/JobOfferController.java @@ -6,6 +6,7 @@ import com.findwork.findwork.Entities.Users.UserPerson; import com.findwork.findwork.Enums.Category; import com.findwork.findwork.Enums.JobLevel; +import com.findwork.findwork.Repositories.JobApplicationRepository; import com.findwork.findwork.Requests.CreateJobOfferRequest; import com.findwork.findwork.Requests.EditJobOfferRequest; import com.findwork.findwork.Services.OfferService; @@ -17,8 +18,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.support.RedirectAttributes; -import java.util.List; -import java.util.UUID; +import java.util.*; @Controller @AllArgsConstructor @@ -26,12 +26,14 @@ public class JobOfferController { private final ValidationService validationService; private final OfferService offerService; + private final JobApplicationRepository applicationRepo; @GetMapping("/") public String getAllOffers(Model model, @RequestParam(required = false) String search, @RequestParam(required = false) String jobCategory, - @RequestParam(required = false) String jobLevel) { + @RequestParam(required = false) String jobLevel){ + List offers; if (jobCategory != null && jobCategory.equals("--Any--")) @@ -42,7 +44,12 @@ public String getAllOffers(Model model, offers = offerService.getOffers(search, jobCategory, jobLevel); - model.addAttribute("offers", offers); + HashMap offerRating = new HashMap(); + for(JobOffer offer:offers){ + offerRating.put(offer,applicationRepo.countAllByOffer(offer)); + } + + model.addAttribute("offers", offerRating); model.addAttribute("levels", JobLevel.values()); model.addAttribute("categories", Category.values()); return "offers"; diff --git a/src/main/java/com/findwork/findwork/Repositories/JobApplicationRepository.java b/src/main/java/com/findwork/findwork/Repositories/JobApplicationRepository.java index 5c5e47e..5777d2b 100644 --- a/src/main/java/com/findwork/findwork/Repositories/JobApplicationRepository.java +++ b/src/main/java/com/findwork/findwork/Repositories/JobApplicationRepository.java @@ -12,4 +12,5 @@ public interface JobApplicationRepository extends JpaRepository findAllByOffer(JobOffer offer); + Integer countAllByOffer(JobOffer offer); } diff --git a/src/main/resources/templates/offers.html b/src/main/resources/templates/offers.html index 31c57c1..049c45f 100644 --- a/src/main/resources/templates/offers.html +++ b/src/main/resources/templates/offers.html @@ -45,30 +45,34 @@

Offers

-
+
-
- +
- +
- +
- + +
+
+ +