@@ -11,7 +11,7 @@ import (
1111
1212type (
1313 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 )
1515 GetPostById (ctx context.Context , postId uuid.UUID ) (dto.PostResponse , error )
1616 DeletePostById (ctx context.Context , postId uuid.UUID ) error
1717 }
@@ -31,27 +31,16 @@ func NewPostService(userRepo repository.UserRepository, postRepo repository.Post
3131 }
3232}
3333
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 ) {
4135 if req .ParentID != nil {
4236 _ , err := s .postRepo .GetPostById (ctx , nil , * req .ParentID )
4337 if err != nil {
4438 return dto.PostResponse {}, dto .ErrGetPostById
4539 }
4640 }
4741
48- if err != nil {
49- return dto.PostResponse {}, dto .ErrParseParentID
50- }
51-
5242 post := entity.Post {
5343 Text : req .Text ,
54- UserID : user .ID ,
5544 ParentID : req .ParentID ,
5645 }
5746
@@ -60,6 +49,11 @@ func (s *postService) CreatePost(ctx context.Context, req dto.PostCreateRequest)
6049 return dto.PostResponse {}, dto .ErrCreatePost
6150 }
6251
52+ user , err := s .userRepo .GetUserById (ctx , nil , userId )
53+ if err != nil {
54+ return dto.PostResponse {}, dto .ErrGetUserById
55+ }
56+
6357 return dto.PostResponse {
6458 ID : result .ID .String (),
6559 Text : result .Text ,
0 commit comments