package controller import ( "git.squidspirit.com/squid/blog.git/backend/internal/adapter/controller/graphdto" "git.squidspirit.com/squid/blog.git/backend/internal/application" "git.squidspirit.com/squid/blog.git/backend/internal/domain" "github.com/thoas/go-funk" ) type QueryPostsController interface { Handle() ([]*graphdto.Post, error) } type queryPostsControllerImpl struct { getAllPostsUseCase application.GetAllPostsUseCase } func NewQueryPostsController(getAllPostsUseCase application.GetAllPostsUseCase) QueryPostsController { return &queryPostsControllerImpl{ getAllPostsUseCase: getAllPostsUseCase, } } func (c *queryPostsControllerImpl) Handle() ([]*graphdto.Post, error) { entities, err := c.getAllPostsUseCase.Execute() if err != nil { return nil, err } return funk.Map(entities, func(entity *domain.Post) *graphdto.Post { return graphdto.NewPostDTO(entity) }).([]*graphdto.Post), nil }