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 d0caecb..9e2a8ec 100644 Binary files a/data/db.mv.db and b/data/db.mv.db differ 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 @@
-
+
+
-
+
+
+
+
-
-
+
+
-
+
+
+
+