fix: update fixing bookmarks
This commit is contained in:
parent
ee61a0411c
commit
2a61cf9987
|
|
@ -5,7 +5,7 @@ import (
|
|||
"netidhub-saas-be/app/module/bookmarks/response"
|
||||
)
|
||||
|
||||
func ToBookmarksResponse(bookmark *entity.Bookmarks) *response.BookmarksResponse {
|
||||
func ToBookmarksResponse(domain string, bookmark *entity.Bookmarks) *response.BookmarksResponse {
|
||||
return &response.BookmarksResponse{
|
||||
ID: bookmark.ID,
|
||||
UserId: bookmark.UserId,
|
||||
|
|
@ -22,7 +22,7 @@ func ToBookmarksResponse(bookmark *entity.Bookmarks) *response.BookmarksResponse
|
|||
CategoryId: bookmark.Article.CategoryId,
|
||||
TypeId: bookmark.Article.TypeId,
|
||||
Tags: bookmark.Article.Tags,
|
||||
ThumbnailUrl: getThumbnailUrl(bookmark.Article.ThumbnailPath),
|
||||
ThumbnailUrl: getThumbnailUrl(domain, bookmark.Article.ThumbnailName),
|
||||
PageUrl: bookmark.Article.PageUrl,
|
||||
CreatedById: bookmark.Article.CreatedById,
|
||||
ShareCount: bookmark.Article.ShareCount,
|
||||
|
|
@ -39,17 +39,17 @@ func ToBookmarksResponse(bookmark *entity.Bookmarks) *response.BookmarksResponse
|
|||
}
|
||||
}
|
||||
|
||||
func ToBookmarksResponseList(bookmarks []entity.Bookmarks) []*response.BookmarksResponse {
|
||||
func ToBookmarksResponseList(domain string, bookmarks []entity.Bookmarks) []*response.BookmarksResponse {
|
||||
var responses []*response.BookmarksResponse
|
||||
for _, bookmark := range bookmarks {
|
||||
responses = append(responses, ToBookmarksResponse(&bookmark))
|
||||
responses = append(responses, ToBookmarksResponse(domain, &bookmark))
|
||||
}
|
||||
return responses
|
||||
}
|
||||
|
||||
func getThumbnailUrl(thumbnailPath *string) string {
|
||||
if thumbnailPath != nil && *thumbnailPath != "" {
|
||||
return *thumbnailPath
|
||||
func getThumbnailUrl(domain string, thumbnailName *string) string {
|
||||
if thumbnailName != nil && *thumbnailName != "" {
|
||||
return domain + "/articles/thumbnail/viewer/" + *thumbnailName
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"netidhub-saas-be/app/module/bookmarks/request"
|
||||
"netidhub-saas-be/app/module/bookmarks/response"
|
||||
usersRepository "netidhub-saas-be/app/module/users/repository"
|
||||
"netidhub-saas-be/config/config"
|
||||
"netidhub-saas-be/utils/paginator"
|
||||
utilSvc "netidhub-saas-be/utils/service"
|
||||
|
||||
|
|
@ -22,6 +23,7 @@ type bookmarksService struct {
|
|||
ArticlesRepo articlesRepository.ArticlesRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
Log zerolog.Logger
|
||||
Cfg *config.Config
|
||||
}
|
||||
|
||||
// BookmarksService define interface of IBookmarksService
|
||||
|
|
@ -41,6 +43,7 @@ func NewBookmarksService(
|
|||
repo repository.BookmarksRepository,
|
||||
articlesRepo articlesRepository.ArticlesRepository,
|
||||
usersRepo usersRepository.UsersRepository,
|
||||
cfg *config.Config,
|
||||
log zerolog.Logger,
|
||||
) BookmarksService {
|
||||
return &bookmarksService{
|
||||
|
|
@ -48,6 +51,7 @@ func NewBookmarksService(
|
|||
ArticlesRepo: articlesRepo,
|
||||
UsersRepo: usersRepo,
|
||||
Log: log,
|
||||
Cfg: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +79,9 @@ func (_i *bookmarksService) All(authToken string, req request.BookmarksQueryRequ
|
|||
for _, b := range bookmarksEntity {
|
||||
bookmarksSlice = append(bookmarksSlice, *b)
|
||||
}
|
||||
bookmarks = mapper.ToBookmarksResponseList(bookmarksSlice)
|
||||
|
||||
domain := _i.Cfg.App.Domain
|
||||
bookmarks = mapper.ToBookmarksResponseList(domain, bookmarksSlice)
|
||||
return bookmarks, paging, nil
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +102,8 @@ func (_i *bookmarksService) Show(authToken string, id uint) (bookmark *response.
|
|||
return nil, err
|
||||
}
|
||||
|
||||
bookmark = mapper.ToBookmarksResponse(bookmarkEntity)
|
||||
domain := _i.Cfg.App.Domain
|
||||
bookmark = mapper.ToBookmarksResponse(domain, bookmarkEntity)
|
||||
return bookmark, nil
|
||||
}
|
||||
|
||||
|
|
@ -192,7 +199,9 @@ func (_i *bookmarksService) GetByUserId(authToken string, req request.BookmarksQ
|
|||
for _, b := range bookmarksEntity {
|
||||
bookmarksSlice = append(bookmarksSlice, *b)
|
||||
}
|
||||
bookmarks = mapper.ToBookmarksResponseList(bookmarksSlice)
|
||||
|
||||
domain := _i.Cfg.App.Domain
|
||||
bookmarks = mapper.ToBookmarksResponseList(domain, bookmarksSlice)
|
||||
return bookmarks, paging, nil
|
||||
}
|
||||
|
||||
|
|
@ -293,7 +302,9 @@ func (_i *bookmarksService) GetBookmarkSummary(authToken string) (summary *respo
|
|||
for _, b := range recentBookmarksEntity {
|
||||
bookmarksSlice = append(bookmarksSlice, *b)
|
||||
}
|
||||
recentBookmarks := mapper.ToBookmarksResponseList(bookmarksSlice)
|
||||
|
||||
domain := _i.Cfg.App.Domain
|
||||
recentBookmarks := mapper.ToBookmarksResponseList(domain, bookmarksSlice)
|
||||
|
||||
summary = &response.BookmarksSummaryResponse{
|
||||
TotalBookmarks: int(totalCount),
|
||||
|
|
|
|||
Loading…
Reference in New Issue