@@ -11,7 +11,7 @@ import (
11
11
12
12
type (
13
13
PostService interface {
14
- CreatePost (ctx context.Context , req dto.PostCreateRequest ) (dto.PostResponse , error )
14
+ CreatePost (ctx context.Context , userId string , req dto.PostCreateRequest ) (dto.PostResponse , error )
15
15
GetPostById (ctx context.Context , postId uuid.UUID ) (dto.PostResponse , error )
16
16
DeletePostById (ctx context.Context , postId uuid.UUID ) error
17
17
}
@@ -31,27 +31,16 @@ func NewPostService(userRepo repository.UserRepository, postRepo repository.Post
31
31
}
32
32
}
33
33
34
- func (s * postService ) CreatePost (ctx context.Context , req dto.PostCreateRequest ) (dto.PostResponse , error ) {
35
- user , err := s .userRepo .GetUserById (ctx , nil , req .UserID )
36
-
37
- if err != nil {
38
- return dto.PostResponse {}, dto .ErrGetUserById
39
- }
40
-
34
+ func (s * postService ) CreatePost (ctx context.Context , userId string , req dto.PostCreateRequest ) (dto.PostResponse , error ) {
41
35
if req .ParentID != nil {
42
36
_ , err := s .postRepo .GetPostById (ctx , nil , * req .ParentID )
43
37
if err != nil {
44
38
return dto.PostResponse {}, dto .ErrGetPostById
45
39
}
46
40
}
47
41
48
- if err != nil {
49
- return dto.PostResponse {}, dto .ErrParseParentID
50
- }
51
-
52
42
post := entity.Post {
53
43
Text : req .Text ,
54
- UserID : user .ID ,
55
44
ParentID : req .ParentID ,
56
45
}
57
46
@@ -60,6 +49,11 @@ func (s *postService) CreatePost(ctx context.Context, req dto.PostCreateRequest)
60
49
return dto.PostResponse {}, dto .ErrCreatePost
61
50
}
62
51
52
+ user , err := s .userRepo .GetUserById (ctx , nil , userId )
53
+ if err != nil {
54
+ return dto.PostResponse {}, dto .ErrGetUserById
55
+ }
56
+
63
57
return dto.PostResponse {
64
58
ID : result .ID .String (),
65
59
Text : result .Text ,
0 commit comments