diff --git a/app/module/article_files/mapper/article_files.mapper.go b/app/module/article_files/mapper/article_files.mapper.go index f92b462..cad2088 100644 --- a/app/module/article_files/mapper/article_files.mapper.go +++ b/app/module/article_files/mapper/article_files.mapper.go @@ -5,8 +5,8 @@ import ( res "go-humas-be/app/module/article_files/response" ) -func ArticleFilesResponseMapper(articleFilesReq *entity.ArticleFiles) (articleFilesRes *res.ArticleFilesResponse) { - fileUrl := "/article-files/viewer/" +func ArticleFilesResponseMapper(articleFilesReq *entity.ArticleFiles, host string) (articleFilesRes *res.ArticleFilesResponse) { + fileUrl := host + "/article-files/viewer/" if articleFilesReq.FileName != nil { fileUrl += *articleFilesReq.FileName } diff --git a/app/module/article_files/service/article_files.service.go b/app/module/article_files/service/article_files.service.go index a9146c7..9a613bf 100644 --- a/app/module/article_files/service/article_files.service.go +++ b/app/module/article_files/service/article_files.service.go @@ -10,6 +10,7 @@ import ( "go-humas-be/app/module/article_files/repository" "go-humas-be/app/module/article_files/request" "go-humas-be/app/module/article_files/response" + config "go-humas-be/config/config" minioStorage "go-humas-be/config/config" "go-humas-be/utils/paginator" "io" @@ -29,6 +30,7 @@ import ( type articleFilesService struct { Repo repository.ArticleFilesRepository Log zerolog.Logger + Cfg *config.Config MinioStorage *minioStorage.MinioStorage } @@ -45,11 +47,12 @@ type ArticleFilesService interface { } // NewArticleFilesService init ArticleFilesService -func NewArticleFilesService(repo repository.ArticleFilesRepository, log zerolog.Logger, minioStorage *minioStorage.MinioStorage) ArticleFilesService { +func NewArticleFilesService(repo repository.ArticleFilesRepository, log zerolog.Logger, cfg *config.Config, minioStorage *minioStorage.MinioStorage) ArticleFilesService { return &articleFilesService{ Repo: repo, Log: log, + Cfg: cfg, MinioStorage: minioStorage, } } @@ -72,8 +75,10 @@ func (_i *articleFilesService) All(req request.ArticleFilesQueryRequest) (articl return } + host := _i.Cfg.App.Domain + for _, result := range results { - articleFiless = append(articleFiless, mapper.ArticleFilesResponseMapper(result)) + articleFiless = append(articleFiless, mapper.ArticleFilesResponseMapper(result, host)) } return @@ -85,7 +90,9 @@ func (_i *articleFilesService) Show(id uint) (articleFiles *response.ArticleFile return nil, err } - return mapper.ArticleFilesResponseMapper(result), nil + host := _i.Cfg.App.Domain + + return mapper.ArticleFilesResponseMapper(result, host), nil } func (_i *articleFilesService) SaveAsync(c *fiber.Ctx, id uint) (err error) {