From d4b514a9b0631d287314d990ea21f685497f5c27 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 24 Apr 2019 21:24:32 +0400 Subject: [PATCH] #68 added ping in db --- .../ru/ulstu/conference/repository/ConferenceRepository.java | 5 +++++ .../java/ru/ulstu/conference/service/ConferenceService.java | 4 ++-- src/main/java/ru/ulstu/ping/model/Ping.java | 2 -- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index cb8a488..25a481c 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -1,6 +1,7 @@ package ru.ulstu.conference.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import ru.ulstu.conference.model.Conference; @@ -16,4 +17,8 @@ public interface ConferenceRepository extends JpaRepository @Query("SELECT c FROM Conference c WHERE c.beginDate > :date") List findAllActive(@Param("date") Date date); + + @Modifying + @Query("UPDATE Conference c SET c.ping = (c.ping + 1) WHERE c.id = :id") + int updatePingConference(@Param("id") Integer id); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 0287e31..370d7d6 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -146,7 +146,6 @@ public class ConferenceService { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); conference.setUrl(conferenceDto.getUrl()); - Integer pingCount = conferenceDto.getPing() - conference.getPing(); // for notification conference.setPing(conference.getPing()); conference.setBeginDate(conferenceDto.getBeginDate()); conference.setEndDate(conferenceDto.getEndDate()); @@ -180,9 +179,10 @@ public class ConferenceService { return conferenceRepository.findAllActive(new Date()); } + @Transactional public void ping(ConferenceDto conferenceDto) throws IOException { pingService.addPing(findOne(conferenceDto.getId())); -// conferenceDto.setPing(conferenceDto.getPing() + 1); + conferenceRepository.updatePingConference(conferenceDto.getId()); } public Conference findOne(Integer conferenceId) { diff --git a/src/main/java/ru/ulstu/ping/model/Ping.java b/src/main/java/ru/ulstu/ping/model/Ping.java index 5ab0860..c7e4c5e 100644 --- a/src/main/java/ru/ulstu/ping/model/Ping.java +++ b/src/main/java/ru/ulstu/ping/model/Ping.java @@ -1,7 +1,6 @@ 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; @@ -26,7 +25,6 @@ public class Ping extends BaseEntity { @JoinColumn(name = "users_id") private User user; - @Nullable @ManyToOne(optional = false) @JoinColumn(name = "conference_id") private Conference conference;