feat: scope articles by brand
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
type WorkspaceRecentArticle struct {
|
||||
ID int64
|
||||
BrandID *int64
|
||||
GenerateStatus string
|
||||
PublishStatus string
|
||||
SourceType string
|
||||
@@ -40,10 +41,10 @@ type WorkspaceKolCard struct {
|
||||
}
|
||||
|
||||
type WorkspaceRepository interface {
|
||||
CountArticlesByTenant(ctx context.Context, tenantID int64) (int64, error)
|
||||
CountPublishedArticlesByTenant(ctx context.Context, tenantID int64) (int64, error)
|
||||
CountArticlesByTenantAndBrand(ctx context.Context, tenantID, brandID int64) (int64, error)
|
||||
CountPublishedArticlesByTenantAndBrand(ctx context.Context, tenantID, brandID int64) (int64, error)
|
||||
CountBrandsByTenant(ctx context.Context, tenantID int64) (int64, error)
|
||||
GetRecentArticles(ctx context.Context, tenantID int64) ([]WorkspaceRecentArticle, error)
|
||||
GetRecentArticlesByBrand(ctx context.Context, tenantID, brandID int64) ([]WorkspaceRecentArticle, error)
|
||||
GetQuotaSummary(ctx context.Context, tenantID int64) (int, error)
|
||||
GetActivePlanForTenant(ctx context.Context, tenantID int64) (*WorkspacePlan, error)
|
||||
ListKolCards(ctx context.Context, tenantID int64) ([]WorkspaceKolCard, error)
|
||||
@@ -57,28 +58,39 @@ func NewWorkspaceRepository(db generated.DBTX) WorkspaceRepository {
|
||||
return &workspaceRepository{q: newQuerier(db)}
|
||||
}
|
||||
|
||||
func (r *workspaceRepository) CountArticlesByTenant(ctx context.Context, tenantID int64) (int64, error) {
|
||||
return r.q.CountArticlesByTenant(ctx, tenantID)
|
||||
func (r *workspaceRepository) CountArticlesByTenantAndBrand(ctx context.Context, tenantID, brandID int64) (int64, error) {
|
||||
return r.q.CountArticlesByTenantAndBrand(ctx, generated.CountArticlesByTenantAndBrandParams{
|
||||
TenantID: tenantID,
|
||||
BrandID: brandID,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *workspaceRepository) CountPublishedArticlesByTenant(ctx context.Context, tenantID int64) (int64, error) {
|
||||
return r.q.CountPublishedArticlesByTenant(ctx, tenantID)
|
||||
func (r *workspaceRepository) CountPublishedArticlesByTenantAndBrand(ctx context.Context, tenantID, brandID int64) (int64, error) {
|
||||
return r.q.CountPublishedArticlesByTenantAndBrand(ctx, generated.CountPublishedArticlesByTenantAndBrandParams{
|
||||
TenantID: tenantID,
|
||||
BrandID: brandID,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *workspaceRepository) CountBrandsByTenant(ctx context.Context, tenantID int64) (int64, error) {
|
||||
return r.q.CountBrandsByTenant(ctx, tenantID)
|
||||
}
|
||||
|
||||
func (r *workspaceRepository) GetRecentArticles(ctx context.Context, tenantID int64) ([]WorkspaceRecentArticle, error) {
|
||||
rows, err := r.q.GetRecentArticles(ctx, tenantID)
|
||||
func (r *workspaceRepository) GetRecentArticlesByBrand(ctx context.Context, tenantID, brandID int64) ([]WorkspaceRecentArticle, error) {
|
||||
rows, err := r.q.GetRecentArticlesByBrand(ctx, generated.GetRecentArticlesByBrandParams{
|
||||
TenantID: tenantID,
|
||||
BrandID: brandID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
articles := make([]WorkspaceRecentArticle, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
brandID := row.BrandID
|
||||
articles = append(articles, WorkspaceRecentArticle{
|
||||
ID: row.ID,
|
||||
BrandID: &brandID,
|
||||
GenerateStatus: row.GenerateStatus,
|
||||
PublishStatus: row.PublishStatus,
|
||||
SourceType: row.SourceType,
|
||||
|
||||
Reference in New Issue
Block a user