File tree 4 files changed +17
-10
lines changed
core/src/main/java/com/qa/blog/core/domain
mariadb/src/main/java/com/qa/blog/mariadb/mapper
main/java/com/qa/blog/springweb/mapper
test/java/com/qa/blog/springweb/post
4 files changed +17
-10
lines changed Original file line number Diff line number Diff line change 3
3
import com .qa .blog .core .exception .BlogErrorCode ;
4
4
import com .qa .blog .core .exception .BlogException ;
5
5
6
- import java .util .List ;
6
+ import java .util .Set ;
7
+
7
8
public record Post (Long id ,
8
9
Author author ,
9
10
Category category ,
10
- List <Tag > tags ,
11
+ Set <Tag > tags ,
11
12
String title ,
12
13
String content ,
13
14
String image ) {
Original file line number Diff line number Diff line change 10
10
import com .qa .blog .mariadb .entity .TagEntity ;
11
11
import org .springframework .stereotype .Component ;
12
12
13
+ import java .util .HashSet ;
13
14
import java .util .List ;
14
15
import java .util .Set ;
15
16
import java .util .stream .Collectors ;
@@ -18,9 +19,9 @@ public class PostEntityMapper {
18
19
public Post toDomain (PostEntity entity ) {
19
20
Author author = new Author (entity .getAuthor ().getId (), entity .getAuthor ().getName ());
20
21
Category category = new Category (entity .getCategory ().getId (), entity .getCategory ().getName ());
21
- List <Tag > tags = entity .getTags ().stream ()
22
+ Set <Tag > tags = entity .getTags ().stream ()
22
23
.map (tagEntityEntity -> new Tag (tagEntityEntity .getId (), tagEntityEntity .getName ()))
23
- .toList ( );
24
+ .collect ( Collectors . toSet () );
24
25
25
26
return new Post (
26
27
entity .getId (),
Original file line number Diff line number Diff line change 10
10
import com .qa .blog .core .domain .Tag ;
11
11
12
12
import java .util .List ;
13
+ import java .util .Set ;
14
+ import java .util .stream .Collectors ;
13
15
14
16
@ Component
15
17
public class PostWebMapper {
16
18
public Post toDomain (PostRequest request ) throws BlogException {
17
19
Author author = new Author (null , request .author ());
18
20
Category category = new Category (null , request .category ());
19
- List <Tag > tags = request .tags ().stream ()
21
+ Set <Tag > tags = request .tags ().stream ()
20
22
.map (tag -> new Tag (null , tag ))
21
- .toList ( );
23
+ .collect ( Collectors . toSet () );
22
24
return new Post (
23
25
null ,
24
26
author ,
@@ -33,9 +35,9 @@ public Post toDomain(PostRequest request) throws BlogException {
33
35
public Post toDomain (PostDTO postDTO ) throws BlogException {
34
36
Author author = new Author (null , postDTO .author ());
35
37
Category category = new Category (null , postDTO .category ());
36
- List <Tag > tags = postDTO .tags ().stream ()
38
+ Set <Tag > tags = postDTO .tags ().stream ()
37
39
.map (tag -> new Tag (null , tag ))
38
- .toList ( );
40
+ .collect ( Collectors . toSet () );
39
41
return new Post (
40
42
postDTO .id (),
41
43
author ,
Original file line number Diff line number Diff line change 23
23
import org .springframework .test .web .servlet .request .MockMvcRequestBuilders ;
24
24
25
25
import java .util .ArrayList ;
26
+ import java .util .HashSet ;
26
27
import java .util .List ;
28
+ import java .util .Set ;
27
29
28
30
import static org .mockito .ArgumentMatchers .any ;
29
31
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
@@ -61,9 +63,10 @@ void createPostSuccessfully() throws Exception {
61
63
var postDomain = new Post (42L ,
62
64
new Author (41L , "Antonio Alvino" ),
63
65
new Category (33L , "Tech" ),
64
- new ArrayList <>(List .of (
66
+ new HashSet <>(Set .of (
65
67
new Tag (1L , "Java" ),
66
- new Tag (2L , "Programming" ))),
68
+ new Tag (2L , "Programming" ))) {
69
+ },
67
70
"Titolo" ,
68
71
"Contenuto 123 Prova" ,
69
72
"http://example.com/image.jpg" );
You can’t perform that action at this time.
0 commit comments