fix: filter active in news
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
package newsrepository
|
||||
|
||||
import newsdomain "legalgo-BE-go/internal/domain/news"
|
||||
import (
|
||||
newsdomain "legalgo-BE-go/internal/domain/news"
|
||||
timeutils "legalgo-BE-go/internal/utilities/time_utils"
|
||||
)
|
||||
|
||||
type is_active string
|
||||
|
||||
const (
|
||||
active is_active = "true"
|
||||
notActive is_active = "false"
|
||||
)
|
||||
|
||||
func (a *accessor) GetAll(filter newsdomain.NewsFilter) ([]newsdomain.News, error) {
|
||||
var news []newsdomain.News
|
||||
@@ -20,6 +30,10 @@ func (a *accessor) GetAll(filter newsdomain.NewsFilter) ([]newsdomain.News, erro
|
||||
Where("nt.tag_id IN (?)", filter.Tags)
|
||||
}
|
||||
|
||||
if filter.Active == string(active) {
|
||||
query = query.Where("news.live_at <= ?", timeutils.Now())
|
||||
}
|
||||
|
||||
query.
|
||||
Select("news.*, COUNT(content_logs.content_id) as clicked").
|
||||
Group("news.id").
|
||||
|
||||
Reference in New Issue
Block a user