Added GetAllOffset. Post controller completed.

This commit is contained in:
KamilM1205 2025-09-20 19:34:17 +04:00
parent 5b18009658
commit 41944884b4
12 changed files with 229 additions and 71 deletions

View file

@ -11,6 +11,7 @@ type PostService interface {
FindById(queries.PostFindByIdQuery) (*queries.PostFindByIdResult, error)
FindAllByUserName(queries.PostFindAllByUserNameQuery) (*queries.PostFindAllByUserNameResult, error)
GetAll() (*queries.PostGetAllResult, error)
GetAllOffset(int) (*queries.PostGetAllResult, error)
Update(commands.UpdatePostCommand) (*common.PostResult, error)
Delete(commands.DeletePostCommand) error
}

View file

@ -7,6 +7,7 @@ import (
"58team_blog/internal/application/queries"
"58team_blog/internal/domain/entities"
"58team_blog/internal/domain/repository"
"errors"
"fmt"
"time"
)
@ -86,6 +87,22 @@ func (s *PostService) GetAll() (*queries.PostGetAllResult, error) {
return result, nil
}
func (s *PostService) GetAllOffset(offset int) (*queries.PostGetAllResult, error) {
if offset < 0 {
return nil, errors.New("offset is less than 0")
}
posts, err := s.repo.GetAllOffset(offset)
if err != nil {
return nil, err
}
result := mapper.CreatePostGetAllResult(posts)
return result, nil
}
func (s *PostService) Update(cmd commands.UpdatePostCommand) (*common.PostResult, error) {
post, err := s.repo.FindById(cmd.Id)
if err != nil {