fix: update fixing bookmarks
This commit is contained in:
parent
719cadc1b4
commit
d8087681fb
|
|
@ -16,5 +16,5 @@ type Bookmarks struct {
|
||||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||||
|
|
||||||
// Relations
|
// Relations
|
||||||
Article Articles `json:"article" gorm:"foreignKey:ArticleId"`
|
Article Articles `json:"article" gorm:"foreignKey:ArticleId;references:ID"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,14 +41,13 @@ func NewBookmarksRepository(db *database.Database, log zerolog.Logger, cfg *conf
|
||||||
func (_i *bookmarksRepository) GetAll(clientId *uuid.UUID, req request.BookmarksQueryRequest) (bookmarks []*entity.Bookmarks, paging paginator.Pagination, err error) {
|
func (_i *bookmarksRepository) GetAll(clientId *uuid.UUID, req request.BookmarksQueryRequest) (bookmarks []*entity.Bookmarks, paging paginator.Pagination, err error) {
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
query := _i.DB.DB.Model(&entity.Bookmarks{}).Preload("User").Preload("Article")
|
query := _i.DB.DB.Model(&entity.Bookmarks{}).Preload("Article")
|
||||||
|
|
||||||
// Apply client filter
|
// Apply client filter
|
||||||
if clientId != nil && _i.Cfg.App.PrimaryClientKey != clientId.String() {
|
if clientId != nil && _i.Cfg.App.PrimaryClientKey != clientId.String() {
|
||||||
query = query.Where("client_id = ?", clientId)
|
query = query.Where("client_id = ?", clientId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply filters
|
|
||||||
if req.UserId != nil {
|
if req.UserId != nil {
|
||||||
query = query.Where("user_id = ?", *req.UserId)
|
query = query.Where("user_id = ?", *req.UserId)
|
||||||
}
|
}
|
||||||
|
|
@ -83,7 +82,7 @@ func (_i *bookmarksRepository) GetAll(clientId *uuid.UUID, req request.Bookmarks
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *bookmarksRepository) FindOne(clientId *uuid.UUID, id uint) (bookmark *entity.Bookmarks, err error) {
|
func (_i *bookmarksRepository) FindOne(clientId *uuid.UUID, id uint) (bookmark *entity.Bookmarks, err error) {
|
||||||
query := _i.DB.DB.Model(&entity.Bookmarks{}).Preload("User").Preload("Article")
|
query := _i.DB.DB.Model(&entity.Bookmarks{}).Preload("Article")
|
||||||
|
|
||||||
// Apply client filter
|
// Apply client filter
|
||||||
if clientId != nil {
|
if clientId != nil {
|
||||||
|
|
@ -160,7 +159,7 @@ func (_i *bookmarksRepository) Delete(clientId *uuid.UUID, id uint) (err error)
|
||||||
func (_i *bookmarksRepository) GetByUserId(clientId *uuid.UUID, userId uint, req request.BookmarksQueryRequest) (bookmarks []*entity.Bookmarks, paging paginator.Pagination, err error) {
|
func (_i *bookmarksRepository) GetByUserId(clientId *uuid.UUID, userId uint, req request.BookmarksQueryRequest) (bookmarks []*entity.Bookmarks, paging paginator.Pagination, err error) {
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
query := _i.DB.DB.Model(&entity.Bookmarks{}).Preload("User").Preload("Article")
|
query := _i.DB.DB.Model(&entity.Bookmarks{}).Preload("Article")
|
||||||
|
|
||||||
// Apply client filter
|
// Apply client filter
|
||||||
if clientId != nil {
|
if clientId != nil {
|
||||||
|
|
|
||||||
|
|
@ -59,17 +59,11 @@ func (_i *bookmarksService) All(authToken string, req request.BookmarksQueryRequ
|
||||||
user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||||
if user != nil && user.ClientId != nil {
|
if user != nil && user.ClientId != nil {
|
||||||
clientId = user.ClientId
|
clientId = user.ClientId
|
||||||
|
req.UserId = &user.ID
|
||||||
_i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token")
|
_i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
|
||||||
if user == nil {
|
|
||||||
_i.Log.Error().Msg("User not found from auth token")
|
|
||||||
return nil, paging, errors.New("user not found")
|
|
||||||
}
|
|
||||||
req.UserId = &user.ID
|
|
||||||
|
|
||||||
bookmarksEntity, paging, err := _i.Repo.GetAll(clientId, req)
|
bookmarksEntity, paging, err := _i.Repo.GetAll(clientId, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_i.Log.Error().Err(err).Msg("Failed to get all bookmarks")
|
_i.Log.Error().Err(err).Msg("Failed to get all bookmarks")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue