diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 6afa73e..01eac3b 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -21,7 +21,6 @@ import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; import java.util.List; import java.util.stream.Collectors; @@ -58,26 +57,8 @@ public class ConferenceController { @GetMapping("/dashboard") public void getDashboard(ModelMap modelMap) { modelMap.put("conferences", conferenceService.findAllActiveDto()); - //first, add the regional sales - Integer northeastSales = 17089; - Integer westSales = 10603; - Integer midwestSales = 5223; - Integer southSales = 10111; - - modelMap.addAttribute("northeastSales", northeastSales); - modelMap.addAttribute("southSales", southSales); - modelMap.addAttribute("midwestSales", midwestSales); - modelMap.addAttribute("westSales", westSales); - - //now add sales by lure type - List inshoreSales = Arrays.asList(4074, 3455, 4112); - List nearshoreSales = Arrays.asList(3222, 3011, 3788); - List offshoreSales = Arrays.asList(7811, 7098, 6455); - - modelMap.addAttribute("inshoreSales", inshoreSales); - modelMap.addAttribute("nearshoreSales", nearshoreSales); - modelMap.addAttribute("offshoreSales", offshoreSales); + conferenceService.setChartData(modelMap); // example } @GetMapping("/conference") @@ -145,6 +126,15 @@ public class ConferenceController { return CONFERENCE_PAGE; } + @PostMapping(value = "/conference", params = "ping") + public String ping(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { + if (errors.hasErrors()) { + return CONFERENCE_PAGE; + } + conferenceService.ping(conferenceDto); + return CONFERENCE_PAGE; + } + @ModelAttribute("allParticipation") public List getAllParticipation() { return conferenceService.getAllParticipations(); diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index e252e4d..6221b64 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -35,7 +35,7 @@ public class Conference extends BaseEntity { private String url; - private int ping; + private int ping = 0; @Column(name = "begin_date") @Temporal(TemporalType.TIMESTAMP) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index e5ce29f..0287e31 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.ui.ModelMap; import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceFilterDto; @@ -12,6 +13,7 @@ import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.ping.service.PingService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -33,17 +35,20 @@ public class ConferenceService { private final DeadlineService deadlineService; private final PaperService paperService; private final UserService userService; + private final PingService pingService; public ConferenceService(ConferenceRepository conferenceRepository, ConferenceUserService conferenceUserService, DeadlineService deadlineService, PaperService paperService, - UserService userService) { + UserService userService, + PingService pingService) { this.conferenceRepository = conferenceRepository; this.conferenceUserService = conferenceUserService; this.deadlineService = deadlineService; this.paperService = paperService; this.userService = userService; + this.pingService = pingService; } public ConferenceDto getExistConferenceById(Integer id) { @@ -141,7 +146,8 @@ public class ConferenceService { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); conference.setUrl(conferenceDto.getUrl()); - conference.setPing(0); + Integer pingCount = conferenceDto.getPing() - conference.getPing(); // for notification + conference.setPing(conference.getPing()); conference.setBeginDate(conferenceDto.getBeginDate()); conference.setEndDate(conferenceDto.getEndDate()); conference.setPapers(conferenceDto.getPapers()); @@ -173,4 +179,35 @@ public class ConferenceService { public List findAllActive() { return conferenceRepository.findAllActive(new Date()); } + + public void ping(ConferenceDto conferenceDto) throws IOException { + pingService.addPing(findOne(conferenceDto.getId())); +// conferenceDto.setPing(conferenceDto.getPing() + 1); + } + + public Conference findOne(Integer conferenceId) { + return conferenceRepository.findOne(conferenceId); + } + + public void setChartData(ModelMap modelMap) { + //first, add the regional sales + Integer northeastSales = 17089; + Integer westSales = 10603; + Integer midwestSales = 5223; + Integer southSales = 10111; + + modelMap.addAttribute("northeastSales", northeastSales); + modelMap.addAttribute("southSales", southSales); + modelMap.addAttribute("midwestSales", midwestSales); + modelMap.addAttribute("westSales", westSales); + + //now add sales by lure type + List inshoreSales = Arrays.asList(4074, 3455, 4112); + List nearshoreSales = Arrays.asList(3222, 3011, 3788); + List offshoreSales = Arrays.asList(7811, 7098, 6455); + + modelMap.addAttribute("inshoreSales", inshoreSales); + modelMap.addAttribute("nearshoreSales", nearshoreSales); + modelMap.addAttribute("offshoreSales", offshoreSales); + } } diff --git a/src/main/java/ru/ulstu/ping/model/Ping.java b/src/main/java/ru/ulstu/ping/model/Ping.java index d3fea2b..5ab0860 100644 --- a/src/main/java/ru/ulstu/ping/model/Ping.java +++ b/src/main/java/ru/ulstu/ping/model/Ping.java @@ -1,7 +1,9 @@ package ru.ulstu.ping.model; import com.fasterxml.jackson.annotation.JsonProperty; +import com.sun.istack.internal.Nullable; import org.springframework.format.annotation.DateTimeFormat; +import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.user.model.User; @@ -24,6 +26,11 @@ public class Ping extends BaseEntity { @JoinColumn(name = "users_id") private User user; + @Nullable + @ManyToOne(optional = false) + @JoinColumn(name = "conference_id") + private Conference conference; + public Ping() { } @@ -34,10 +41,12 @@ public class Ping extends BaseEntity { public Ping(@JsonProperty("id") Integer id, @JsonProperty("date") Date date, - @JsonProperty("user") User user) { + @JsonProperty("user") User user, + @JsonProperty("conference") Conference conference) { setId(id); this.date = date; this.user = user; + this.conference = conference; } public Date getDate() { @@ -55,4 +64,12 @@ public class Ping extends BaseEntity { public void setUser(User user) { this.user = user; } + + public Conference getConference() { + return conference; + } + + public void setConference(Conference conference) { + this.conference = conference; + } } diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java index 07f108a..ff0d249 100644 --- a/src/main/java/ru/ulstu/ping/service/PingService.java +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -1,13 +1,30 @@ package ru.ulstu.ping.service; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.conference.model.Conference; +import ru.ulstu.ping.model.Ping; import ru.ulstu.ping.repository.PingRepository; +import ru.ulstu.user.service.UserService; + +import java.io.IOException; +import java.util.Date; @Service public class PingService { private final PingRepository pingRepository; + private final UserService userService; - public PingService(PingRepository pingRepository) { + public PingService(PingRepository pingRepository, + UserService userService) { this.pingRepository = pingRepository; + this.userService = userService; + } + + @Transactional + public void addPing(Conference conference) throws IOException { + Ping newPing = new Ping(new Date(), userService.getCurrentUser()); + newPing.setConference(conference); + pingRepository.save(newPing); } } diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 184f5b5..26fa695 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -121,7 +121,10 @@ -
+
+ +

+
+