комменты (их нет) и тьэги

This commit is contained in:
dex_moth 2024-04-16 13:42:08 +04:00
parent 2bfbd97010
commit e50b161335
5 changed files with 31 additions and 30 deletions

View File

@ -11,7 +11,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.example.demo.news.model.NewEntity; import com.example.demo.news.model.NewEntity;
import com.example.demo.news.service.NewService; import com.example.demo.news.service.NewService;
import com.example.demo.users.model.UserEntity;
import com.example.demo.users.service.UserService; import com.example.demo.users.service.UserService;
@SpringBootApplication @SpringBootApplication

View File

@ -1,7 +1,9 @@
package com.example.demo.news.api; package com.example.demo.news.api;
import java.util.Date; import java.util.Date;
import java.util.List;
import com.example.demo.tage.model.TageEntity;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
@ -17,9 +19,7 @@ public class NewDto {
@NotNull @NotNull
@PastOrPresent @PastOrPresent
private Date date; private Date date;
@NotBlank private List<TageEntity> tages;
@Size(min = 1, max = 30)
private String tage;
@NotBlank @NotBlank
@Size(min = 1, max = 30) @Size(min = 1, max = 30)
private String text; private String text;
@ -49,12 +49,12 @@ public class NewDto {
this.date = date; this.date = date;
} }
public String getTage() { public List<TageEntity> getTage() {
return tage; return tages;
} }
public void setTage(String tage) { public void setTage(List<TageEntity> tages) {
this.tage = tage; this.tages = tages;
} }
public String getText() { public String getText() {

View File

@ -1,25 +1,29 @@
package com.example.demo.news.model; package com.example.demo.news.model;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.TreeMap;
import com.example.demo.core.model.BaseEntity; import com.example.demo.core.model.BaseEntity;
import com.example.demo.tage.model.TageEntity;
public class NewEntity extends BaseEntity { public class NewEntity extends BaseEntity {
private String title; private String title;
private Date date; private Date date;
private String tage; private List<TageEntity> tages;
private String text; private String text;
public NewEntity() { public NewEntity() {
super(); super();
} }
public NewEntity(Long id, String title, Date date, String tage, String text) { public NewEntity(Long id, String title, Date date, List<TageEntity> tages, String text) {
super(id); super(id);
this.title = title; this.title = title;
this.date = date; this.date = date;
this.tage = tage; this.tages = tages;
this.text = text; this.text = text;
} }
@ -39,12 +43,12 @@ public class NewEntity extends BaseEntity {
this.date = date; this.date = date;
} }
public String getTage() { public List<TageEntity> getTage() {
return tage; return tages;
} }
public void setTage(String tage) { public void setTage(List<TageEntity> tages) {
this.tage = tage; this.tages = tages;
} }
public String getText() { public String getText() {
@ -57,7 +61,7 @@ public class NewEntity extends BaseEntity {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(id, title, date, tage, text); return Objects.hash(id, title, date, tages, text);
} }
@Override @Override
@ -70,8 +74,7 @@ public class NewEntity extends BaseEntity {
return Objects.equals(other.getId(), id) return Objects.equals(other.getId(), id)
&& Objects.equals(other.getTitle(), title) && Objects.equals(other.getTitle(), title)
&& Objects.equals(other.getDate(), date) && Objects.equals(other.getDate(), date)
&& Objects.equals(other.getTage(), tage) && Objects.equals(other.getTage(), tages)
&& Objects.equals(other.getText(), text); && Objects.equals(other.getText(), text);
} }
} }

View File

@ -28,7 +28,7 @@ class NewsServiceTest {
newsService.create(new NewEntity(null, "Название", new Date(), "тэг", "текст новости")); newsService.create(new NewEntity(null, "Название", new Date(), "тэг", "текст новости"));
final NewEntity last = newsService final NewEntity last = newsService
.create(new NewEntity(null, "9 апреля", new Date(), "весна", "просто наступил апрель")); .create(new NewEntity(null, "9 апреля", new Date(), "весна", "просто наступил апрель"));
Assertions.assertEquals(1, newsService.getAll().size()); Assertions.assertEquals(2L, newsService.getAll().size());
Assertions.assertEquals(last, newsService.get(1L)); Assertions.assertEquals(last, newsService.get(2L));
} }
} }

View File

@ -28,35 +28,34 @@ class UserServiceTest {
@Test @Test
@Order(1) @Order(1)
void createTest() { void createTest() {
userService.create(new UserEntity(null, "beko", "111", "ddwwdd", "beko@mail.ru", new Date())); userService.create(new UserEntity(null, "beko", "111", "ddwwdd",
userService.create(new UserEntity(null, "rara", "rara", "dererere", "rara@mail.ru", new Date())); "beko@mail.ru", new Date()));
Assertions.assertEquals(1, userService.getAll().size()); userService.create(new UserEntity(null, "rara", "rara", "dererere",
"rara@mail.ru", new Date()));
Assertions.assertEquals(2, userService.getAll().size());
} }
@Test @Test
@Order(2) @Order(2)
void updateTest() { void updateTest() {
final String test = "TEST"; final String test = "TEST";
final UserEntity entity = userService.get(3L);
final String oldName = entity.getName();
final UserEntity newEntity = userService.update(1L, final UserEntity newEntity = userService.update(1L,
new UserEntity(1L, test, test, test, "test@mail.ru", new Date())); 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(newEntity, userService.get(1L));
Assertions.assertEquals(test, newEntity.getName()); Assertions.assertEquals(test, newEntity.getName());
Assertions.assertEquals(oldName, newEntity.getName());
} }
@Test @Test
@Order(3) @Order(3)
void deleteTest() { void deleteTest() {
userService.delete(1L); userService.delete(1L);
Assertions.assertEquals(2, userService.getAll().size()); Assertions.assertEquals(1L, userService.getAll().size());
final UserEntity last = userService.get(2L); final UserEntity last = userService.get(2L);
Assertions.assertEquals(2L, last.getId()); Assertions.assertEquals(2L, last.getId());
final UserEntity newEntity = userService.create(new UserEntity(null, "1", "1", "1", "1@mail.ru", new Date())); 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, userService.getAll().size());
Assertions.assertEquals(2L, newEntity.getId()); Assertions.assertEquals(3L, newEntity.getId());
} }
} }