File tree Expand file tree Collapse file tree 5 files changed +40
-3
lines changed
main/java/com/joaov1ct0r/restful_api_users_java/modules/posts
test/java/com/joaov1ct0r/restful_api_users_java/modules/posts/services Expand file tree Collapse file tree 5 files changed +40
-3
lines changed Original file line number Diff line number Diff line change 1
1
package com .joaov1ct0r .restful_api_users_java .modules .posts .dtos ;
2
2
3
+ import com .joaov1ct0r .restful_api_users_java .modules .users .dtos .UserDTO ;
4
+
3
5
import java .time .LocalDateTime ;
4
6
import java .util .UUID ;
5
7
@@ -10,6 +12,16 @@ public class PostDTO {
10
12
public LocalDateTime updatedAt ;
11
13
public UUID userWhoCreatedId ;
12
14
15
+ public UserDTO getUserWhoCreated () {
16
+ return this .userWhoCreated ;
17
+ }
18
+
19
+ public void setUserWhoCreated (UserDTO userWhoCreated ) {
20
+ this .userWhoCreated = userWhoCreated ;
21
+ }
22
+
23
+ public UserDTO userWhoCreated ;
24
+
13
25
public UUID getId () {
14
26
return this .id ;
15
27
}
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ public class PostEntity {
31
31
@ Column ()
32
32
private UUID userWhoCreatedId ;
33
33
34
- @ ManyToOne
34
+ @ ManyToOne ( fetch = FetchType . EAGER )
35
35
@ JoinColumn (name = "UserWhoCreatedId" , insertable = false , updatable = false )
36
36
private UserEntity userWhoCreated ;
37
37
@@ -82,4 +82,12 @@ public void setUpdatedAt(LocalDateTime updatedAt) {
82
82
public UUID getUserWhoCreatedId () {
83
83
return this .userWhoCreatedId ;
84
84
}
85
+
86
+ public UserEntity getUserWhoCreated () {
87
+ return this .userWhoCreated ;
88
+ }
89
+
90
+ public void setUserWhoCreated (UserEntity userWhoCreated ) {
91
+ this .userWhoCreated = userWhoCreated ;
92
+ }
85
93
}
Original file line number Diff line number Diff line change 3
3
import com .joaov1ct0r .restful_api_users_java .modules .posts .dtos .CreatePostDTO ;
4
4
import com .joaov1ct0r .restful_api_users_java .modules .posts .dtos .PostDTO ;
5
5
import com .joaov1ct0r .restful_api_users_java .modules .posts .entities .PostEntity ;
6
+ import com .joaov1ct0r .restful_api_users_java .modules .users .mappers .UserMapper ;
6
7
7
8
import java .time .LocalDateTime ;
8
9
import java .util .UUID ;
@@ -15,6 +16,11 @@ public static PostDTO toDTO(PostEntity post) {
15
16
postDTO .setCreatedAt (post .getCreatedAt ());
16
17
postDTO .setUpdatedAt (post .getUpdatedAt ());
17
18
postDTO .setUserWhoCreatedId (post .getUserWhoCreatedId ());
19
+
20
+ if (post .getUserWhoCreated () != null ) {
21
+ postDTO .setUserWhoCreated (UserMapper .toDTO (post .getUserWhoCreated ()));
22
+ };
23
+
18
24
return postDTO ;
19
25
}
20
26
Original file line number Diff line number Diff line change 11
11
import org .springframework .data .domain .PageRequest ;
12
12
import org .springframework .data .domain .Sort ;
13
13
import org .springframework .stereotype .Service ;
14
+
15
+ import java .util .Arrays ;
14
16
import java .util .List ;
15
17
16
18
@ Service
@@ -30,7 +32,6 @@ public List<PostDTO> execute(FindAllPostsDTO query) {
30
32
query .getContent (),
31
33
page
32
34
);
33
-
34
35
} else {
35
36
posts = this .postRepository .findAll (page );
36
37
}
Original file line number Diff line number Diff line change 1
1
package com .joaov1ct0r .restful_api_users_java .modules .posts .services ;
2
2
3
3
import com .joaov1ct0r .restful_api_users_java .modules .posts .dtos .CreatePostDTO ;
4
+ import com .joaov1ct0r .restful_api_users_java .modules .posts .entities .PostEntity ;
4
5
import com .joaov1ct0r .restful_api_users_java .modules .posts .mappers .PostMapper ;
5
6
import com .joaov1ct0r .restful_api_users_java .modules .posts .repositories .PostRepository ;
6
7
import com .joaov1ct0r .restful_api_users_java .modules .posts .services .CreatePostService ;
7
8
import com .joaov1ct0r .restful_api_users_java .modules .domain .repositories .ErrorLogsRepository ;
9
+ import com .joaov1ct0r .restful_api_users_java .modules .users .entities .UserEntity ;
8
10
import org .junit .jupiter .api .BeforeEach ;
9
11
import org .junit .jupiter .api .Test ;
10
12
import static org .assertj .core .api .Assertions .assertThat ;
16
18
import org .mockito .junit .jupiter .MockitoExtension ;
17
19
import org .mockito .junit .jupiter .MockitoSettings ;
18
20
import org .mockito .quality .Strictness ;
21
+
22
+ import java .time .LocalDateTime ;
19
23
import java .util .UUID ;
20
24
import static org .mockito .Mockito .when ;
21
25
import static org .mockito .Mockito .any ;
@@ -46,7 +50,13 @@ public void shouldBeAbleToRegisterANewPost() throws Exception {
46
50
"any_content"
47
51
);
48
52
when (this .postRepository .save (any ())).thenReturn (
49
- PostMapper .toPersistence (post , userId )
53
+ new PostEntity (
54
+ UUID .randomUUID (),
55
+ post .getContent (),
56
+ LocalDateTime .now (),
57
+ null ,
58
+ userId
59
+ )
50
60
);
51
61
52
62
var createdPost = this .sut .execute (post , userId );
You can’t perform that action at this time.
0 commit comments