diff --git a/lab2/src/main/java/com/example/demo/DemoApplication.java b/lab2/src/main/java/com/example/demo/DemoApplication.java index fb9b952..33c7203 100644 --- a/lab2/src/main/java/com/example/demo/DemoApplication.java +++ b/lab2/src/main/java/com/example/demo/DemoApplication.java @@ -11,7 +11,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import com.example.demo.news.model.NewEntity; import com.example.demo.news.service.NewService; -import com.example.demo.users.model.UserEntity; import com.example.demo.users.service.UserService; @SpringBootApplication diff --git a/lab2/src/main/java/com/example/demo/news/api/NewDto.java b/lab2/src/main/java/com/example/demo/news/api/NewDto.java index 912df38..7a8c46d 100644 --- a/lab2/src/main/java/com/example/demo/news/api/NewDto.java +++ b/lab2/src/main/java/com/example/demo/news/api/NewDto.java @@ -1,7 +1,9 @@ package com.example.demo.news.api; import java.util.Date; +import java.util.List; +import com.example.demo.tage.model.TageEntity; import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.validation.constraints.NotBlank; @@ -17,9 +19,7 @@ public class NewDto { @NotNull @PastOrPresent private Date date; - @NotBlank - @Size(min = 1, max = 30) - private String tage; + private List tages; @NotBlank @Size(min = 1, max = 30) private String text; @@ -49,12 +49,12 @@ public class NewDto { this.date = date; } - public String getTage() { - return tage; + public List getTage() { + return tages; } - public void setTage(String tage) { - this.tage = tage; + public void setTage(List tages) { + this.tages = tages; } public String getText() { diff --git a/lab2/src/main/java/com/example/demo/news/model/NewEntity.java b/lab2/src/main/java/com/example/demo/news/model/NewEntity.java index 58124ca..990f786 100644 --- a/lab2/src/main/java/com/example/demo/news/model/NewEntity.java +++ b/lab2/src/main/java/com/example/demo/news/model/NewEntity.java @@ -1,25 +1,29 @@ package com.example.demo.news.model; import java.util.Date; +import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.TreeMap; import com.example.demo.core.model.BaseEntity; +import com.example.demo.tage.model.TageEntity; public class NewEntity extends BaseEntity { private String title; private Date date; - private String tage; + private List tages; private String text; public NewEntity() { super(); } - public NewEntity(Long id, String title, Date date, String tage, String text) { + public NewEntity(Long id, String title, Date date, List tages, String text) { super(id); this.title = title; this.date = date; - this.tage = tage; + this.tages = tages; this.text = text; } @@ -39,12 +43,12 @@ public class NewEntity extends BaseEntity { this.date = date; } - public String getTage() { - return tage; + public List getTage() { + return tages; } - public void setTage(String tage) { - this.tage = tage; + public void setTage(List tages) { + this.tages = tages; } public String getText() { @@ -57,7 +61,7 @@ public class NewEntity extends BaseEntity { @Override public int hashCode() { - return Objects.hash(id, title, date, tage, text); + return Objects.hash(id, title, date, tages, text); } @Override @@ -70,8 +74,7 @@ public class NewEntity extends BaseEntity { return Objects.equals(other.getId(), id) && Objects.equals(other.getTitle(), title) && Objects.equals(other.getDate(), date) - && Objects.equals(other.getTage(), tage) + && Objects.equals(other.getTage(), tages) && Objects.equals(other.getText(), text); } - } diff --git a/lab2/src/test/java/com/example/demo/NewsServiceTest.java b/lab2/src/test/java/com/example/demo/NewsServiceTest.java index 550b4eb..8c880df 100644 --- a/lab2/src/test/java/com/example/demo/NewsServiceTest.java +++ b/lab2/src/test/java/com/example/demo/NewsServiceTest.java @@ -28,7 +28,7 @@ class NewsServiceTest { newsService.create(new NewEntity(null, "Название", new Date(), "тэг", "текст новости")); final NewEntity last = newsService .create(new NewEntity(null, "9 апреля", new Date(), "весна", "просто наступил апрель")); - Assertions.assertEquals(1, newsService.getAll().size()); - Assertions.assertEquals(last, newsService.get(1L)); + Assertions.assertEquals(2L, newsService.getAll().size()); + Assertions.assertEquals(last, newsService.get(2L)); } } \ No newline at end of file diff --git a/lab2/src/test/java/com/example/demo/UserServiceTest.java b/lab2/src/test/java/com/example/demo/UserServiceTest.java index cfaef71..b8f664f 100644 --- a/lab2/src/test/java/com/example/demo/UserServiceTest.java +++ b/lab2/src/test/java/com/example/demo/UserServiceTest.java @@ -28,35 +28,34 @@ class UserServiceTest { @Test @Order(1) void createTest() { - userService.create(new UserEntity(null, "beko", "111", "ddwwdd", "beko@mail.ru", new Date())); - userService.create(new UserEntity(null, "rara", "rara", "dererere", "rara@mail.ru", new Date())); - Assertions.assertEquals(1, userService.getAll().size()); + userService.create(new UserEntity(null, "beko", "111", "ddwwdd", + "beko@mail.ru", new Date())); + userService.create(new UserEntity(null, "rara", "rara", "dererere", + "rara@mail.ru", new Date())); + Assertions.assertEquals(2, userService.getAll().size()); } @Test @Order(2) void updateTest() { final String test = "TEST"; - final UserEntity entity = userService.get(3L); - final String oldName = entity.getName(); final UserEntity newEntity = userService.update(1L, new UserEntity(1L, test, test, test, "test@mail.ru", new Date())); - Assertions.assertEquals(2, userService.getAll().size()); + Assertions.assertEquals(2L, userService.getAll().size()); Assertions.assertEquals(newEntity, userService.get(1L)); Assertions.assertEquals(test, newEntity.getName()); - Assertions.assertEquals(oldName, newEntity.getName()); } @Test @Order(3) void deleteTest() { userService.delete(1L); - Assertions.assertEquals(2, userService.getAll().size()); + Assertions.assertEquals(1L, userService.getAll().size()); final UserEntity last = userService.get(2L); Assertions.assertEquals(2L, last.getId()); final UserEntity newEntity = userService.create(new UserEntity(null, "1", "1", "1", "1@mail.ru", new Date())); - Assertions.assertEquals(2, userService.getAll().size()); - Assertions.assertEquals(2L, newEntity.getId()); + Assertions.assertEquals(2L, userService.getAll().size()); + Assertions.assertEquals(3L, newEntity.getId()); } } \ No newline at end of file