комменты (их нет) и тьэги
This commit is contained in:
parent
2bfbd97010
commit
e50b161335
@ -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
|
||||
|
@ -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<TageEntity> 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<TageEntity> getTage() {
|
||||
return tages;
|
||||
}
|
||||
|
||||
public void setTage(String tage) {
|
||||
this.tage = tage;
|
||||
public void setTage(List<TageEntity> tages) {
|
||||
this.tages = tages;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
|
@ -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<TageEntity> 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<TageEntity> 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<TageEntity> getTage() {
|
||||
return tages;
|
||||
}
|
||||
|
||||
public void setTage(String tage) {
|
||||
this.tage = tage;
|
||||
public void setTage(List<TageEntity> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user