From 812b9c435d20478adb817dda3842e95ee72b6584 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 17 Mar 2022 16:18:21 +0400 Subject: [PATCH] #7 -- link with news, add date --- build.gradle | 13 ++++--- data/db.mv.db | Bin 49152 -> 65536 bytes .../configuration/SecurityConfiguration.java | 2 +- src/main/java/ru/ulstu/meeting/Meeting.java | 32 +++++++++++++++++- .../java/ru/ulstu/meeting/MeetingService.java | 27 ++++++++++----- src/main/java/ru/ulstu/news/News.java | 13 +++++++ src/main/java/ru/ulstu/news/NewsService.java | 15 ++++++-- src/main/resources/templates/default.html | 16 ++++----- src/main/resources/templates/editMeeting.html | 21 ++++++++---- src/main/resources/templates/index.html | 13 +++++-- src/main/resources/templates/meetings.html | 6 ---- src/main/resources/templates/news.html | 15 ++++++-- 12 files changed, 130 insertions(+), 43 deletions(-) diff --git a/build.gradle b/build.gradle index 791ff3d..f9157cd 100644 --- a/build.gradle +++ b/build.gradle @@ -36,17 +36,20 @@ dependencies { implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '3.1.0' implementation group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity5' implementation group: 'com.h2database', name:'h2' - implementation group: 'javax.xml.bind', name:'jaxb-api' - implementation group: 'org.javassist', name:'javassist' + implementation group: 'javax.xml.bind', name: 'jaxb-api' + implementation group: 'org.javassist', name: 'javassist' - implementation group: 'org.eclipse.jetty', name: 'jetty-servlet', version: versionJetty + implementation group: 'org.eclipse.jetty', name: 'jetty-servlet', version: versionJetty implementation group: 'org.webjars', name: 'jquery', version: '3.6.0' - implementation group: 'org.webjars', name: 'bootstrap', version: '4.6.0' + implementation group: 'org.webjars', name: 'bootstrap', version: '4.3.0' implementation group: 'org.webjars', name: 'bootstrap-select', version: '1.13.8' + implementation group: 'org.webjars', name: 'bootstrap-datetimepicker', version: '2.4.4' implementation group: 'org.webjars', name: 'font-awesome', version: '4.7.0' + implementation group: 'org.webjars', name: 'momentjs', version: '2.24.0' + implementation group: 'org.webjars', name: 'bootstrap-glyphicons', version: 'bdd2cbfba0' - testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test' + testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test' } diff --git a/data/db.mv.db b/data/db.mv.db index d0caecb2c30cdec0710bf4a5b751ece2c0e0f63c..9e2a8ec6f2ab158a9afcf4bc604d9d1b4095b66e 100644 GIT binary patch literal 65536 zcmeHw36vdIdFJa@my9J#Sn?(>vP zICIX-vDqBPX2~!(3V|~rfx&oY4&aG{*=)092#E==Vd5lk00ZNJgaaml2^<*keD~hk z-s`u?mIgai+p1T~t-t>J-}S%C_w62$hKh5GrPquU+3!^4--IKgAP7UHW3`3XjEGWT z43(C{pc2xjS+D{H=Fx?91E~sWrE6J#>3tUt!?ECkkg?a=0+?LEN>! zy6paXvT7-NNnV#<~66BsaxPa|gJC+#&8TcZ9o@ zdlh#Z_iFBTZic&q3%DXz;>uje&2mS%V_XF~YSJ(e7*6XPTcgffBM+A zLSYkc2)--Xo-MhiWhtVe*}g2xw(Xmit>gB<7KpsDCy}3d%h#z$-#0u{*96_Od_l83 zQP3RKRb_}5RmWGT$eVi-`Mrn!7t>O;Wy8=sO_K%RHXT8-3_)>p!Ep>xQ3Wc}=}F|b z-}ry2NZWNx&((ZOR$R|ER2>>BitqWZ=V*$nQjuOyBER#sH(p3=smqF{`?}&Px@k$G zDnOK_il*;dqT_fL73udR@=f=@g^H9EMHf6(msCadeND0*#q6*x{Z;-uK8~QIVofXxo_`D#RCl*pp_D{`7B|NXZjT({m)nk}MOwFgNN)wX=q zS0t1dq=jdpFblG7>4qV?1`~O-Cy`Hm=UY^yqU)YUntQbIx@CJv3lTNDje?}2Z^7($ ztS6CAeDC`#;>ganiFV9{I8%}&*HR1YK{Sm{aR=l=31RHSCOqHUpV(Od_0 zgDYCDZFsmP_`0fVtlGV^Cy{Uc;ZLbZbaDg`>vlhI+4e2{=y9V#R%{$(KD%LZzmAsLMs}92%-i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?>daFy`#P*U!dTIzo5xJq4-}FUf!o!=Bi=bx%?e=_cZRXYb+M{;lx4Kz_z|N zDC3_@$P?Y_6Dm_TLJv(po;EaPoK4WwjTlZ5^YhTu%`u!JIgOzy$uTq~5kpfNF*GG1 zLsJqlG^G(mQyNh;bt8sTtTc+IZjRv;Esdcm$uXQFNyyNYETLhXLLvS9-{pHkW&bm2 YfJyy+>o@4Y51opMJG4eRG$+LV1PAX@mH+?% diff --git a/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java b/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java index 2674025..f316307 100644 --- a/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java @@ -45,7 +45,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { log.debug("Security enabled"); http.authorizeRequests() .antMatchers("/").permitAll() - .antMatchers("/login", "/index", "/news/**", "/meetings/**", "/files/**", "/docs/**", "/h2-console/*", "/h2-console").permitAll() + .antMatchers("/login", "/index", "/news/**", "/meetings/**", "/files/**", "/docs/**", "/webjars/**", "/h2-console/*", "/h2-console").permitAll() .antMatchers("/swagger-ui.html").hasAuthority(UserRoleConstants.ADMIN) .anyRequest().authenticated() .and() diff --git a/src/main/java/ru/ulstu/meeting/Meeting.java b/src/main/java/ru/ulstu/meeting/Meeting.java index fcc9266..c118b45 100644 --- a/src/main/java/ru/ulstu/meeting/Meeting.java +++ b/src/main/java/ru/ulstu/meeting/Meeting.java @@ -2,9 +2,14 @@ package ru.ulstu.meeting; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.model.BaseEntity; +import ru.ulstu.news.News; +import javax.persistence.CascadeType; import javax.persistence.Entity; +import javax.persistence.JoinColumn; import javax.persistence.Lob; +import javax.persistence.OneToOne; +import javax.persistence.Transient; import javax.validation.constraints.NotEmpty; import java.util.Date; @@ -13,13 +18,20 @@ public class Meeting extends BaseEntity { @NotEmpty(message = "Заголовок не может быть пустым") private String title; - @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm") + @DateTimeFormat(pattern = "dd.MM.yyyy HH:mm") private Date date; @Lob @NotEmpty(message = "Текст заседания не может быть пустым") private String text; + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "news_id", referencedColumnName = "id") + private News news; + + @Transient + private Integer newsId; + public Meeting() { } @@ -52,4 +64,22 @@ public class Meeting extends BaseEntity { public String getText() { return text; } + + public News getNews() { + return news; + } + + public void setNews(News news) { + this.news = news; + } + + public Integer getNewsId() { + return newsId == null + ? (news != null) ? news.getId() : null + : newsId; + } + + public void setNewsId(Integer newsId) { + this.newsId = newsId; + } } diff --git a/src/main/java/ru/ulstu/meeting/MeetingService.java b/src/main/java/ru/ulstu/meeting/MeetingService.java index 904b54d..42f8634 100644 --- a/src/main/java/ru/ulstu/meeting/MeetingService.java +++ b/src/main/java/ru/ulstu/meeting/MeetingService.java @@ -3,8 +3,10 @@ package ru.ulstu.meeting; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import ru.ulstu.news.News; import ru.ulstu.news.NewsService; +import javax.transaction.Transactional; import javax.validation.constraints.NotNull; @Service @@ -18,17 +20,21 @@ public class MeetingService { this.newsService = newsService; } - public void create(Meeting meeting) { - meetingRepository.save(meeting); - newsService.create("Очередное заседание семинара", "Заседание семинара состоится " + meeting.getDate()); + @Transactional + public Meeting create(Meeting meeting) { + meeting = meetingRepository.save(meeting); + News news = newsService.create("Объявление о заседании семинара", meeting); + meeting.setNews(news); + return save(meeting); } - public void save(Meeting meeting) { - if (meeting.getId() != null && (meeting.getId() != 0)) { - meetingRepository.save(meeting); - } else { - create(meeting); + public Meeting save(Meeting meeting) { + if (meeting.getNewsId() != null) { + meeting.setNews(newsService.getById(meeting.getNewsId())); } + return (meeting.getId() != null && (meeting.getId() != 0)) + ? meetingRepository.save(meeting) + : create(meeting); } public Meeting getById(@NotNull Integer id) { @@ -37,7 +43,12 @@ public class MeetingService { .orElseThrow(() -> new RuntimeException("Запись о заседании не найдена")); } + @Transactional public void delete(Integer id) { + Meeting meeting = meetingRepository.getById(id); + if (meeting.getNews() != null) { + newsService.delete(meeting.getNews().getId()); + } meetingRepository.deleteById(id); } diff --git a/src/main/java/ru/ulstu/news/News.java b/src/main/java/ru/ulstu/news/News.java index 002a79b..d15e7e7 100644 --- a/src/main/java/ru/ulstu/news/News.java +++ b/src/main/java/ru/ulstu/news/News.java @@ -2,10 +2,12 @@ package ru.ulstu.news; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.web.multipart.MultipartFile; +import ru.ulstu.meeting.Meeting; import ru.ulstu.model.BaseEntity; import javax.persistence.Entity; import javax.persistence.Lob; +import javax.persistence.OneToOne; import javax.persistence.Transient; import javax.validation.constraints.NotEmpty; import java.util.Date; @@ -29,6 +31,9 @@ public class News extends BaseEntity { @Transient private MultipartFile imageFile; + @OneToOne(mappedBy = "news") + private Meeting meeting; + public News() { } @@ -78,6 +83,14 @@ public class News extends BaseEntity { this.imageFile = imageFile; } + public Meeting getMeeting() { + return meeting; + } + + public void setMeeting(Meeting meeting) { + this.meeting = meeting; + } + public String getPreview() { return text != null && text.length() > MAX_NEWS_TEXT_PREVIEW_LENGTH ? text.substring(0, MAX_NEWS_TEXT_PREVIEW_LENGTH) + "..." diff --git a/src/main/java/ru/ulstu/news/NewsService.java b/src/main/java/ru/ulstu/news/NewsService.java index eba9a17..b108a3a 100644 --- a/src/main/java/ru/ulstu/news/NewsService.java +++ b/src/main/java/ru/ulstu/news/NewsService.java @@ -5,7 +5,9 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import ru.ulstu.files.FileSystemStorageService; import ru.ulstu.files.FileUtil; +import ru.ulstu.meeting.Meeting; +import javax.transaction.Transactional; import javax.validation.constraints.NotNull; import java.io.IOException; import java.util.Date; @@ -20,12 +22,19 @@ public class NewsService { } public void create(String title, String text) { - newsRepository.save(new News(title, new Date(), text)); + create(new News(title, new Date(), text)); } - public void create(News news) { + @Transactional + public News create(String title, Meeting meeting) { + News news = new News(title, new Date(), "Новость о заседении семинара"); + news.setMeeting(meeting); + return create(news); + } + + public News create(News news) { news.setDate(new Date()); - newsRepository.save(news); + return newsRepository.save(news); } public void save(News news) throws IOException { diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index dbba1e2..bcf3b65 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -1,9 +1,3 @@ - - app-name - + + + - + + + + diff --git a/src/main/resources/templates/editMeeting.html b/src/main/resources/templates/editMeeting.html index 1413858..f220219 100644 --- a/src/main/resources/templates/editMeeting.html +++ b/src/main/resources/templates/editMeeting.html @@ -1,9 +1,3 @@ - - +
@@ -26,8 +21,22 @@

Не может быть пустым

+
+ + +

+ Не может быть пустым

+
Отмена + diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 4d04259..f45ab31 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -16,10 +16,19 @@
-
+
+
-
+
+
+
+