fix: update fixing get all article & categories

This commit is contained in:
hanif salafi 2025-10-12 23:51:43 +07:00
parent 142f048591
commit 0a2991d618
4 changed files with 32 additions and 22 deletions

View File

@ -2,19 +2,22 @@ package repository
import (
"fmt"
"github.com/google/uuid"
"github.com/rs/zerolog"
"netidhub-saas-be/app/database"
"netidhub-saas-be/app/database/entity"
"netidhub-saas-be/app/module/article_categories/request"
"netidhub-saas-be/config/config"
"netidhub-saas-be/utils/paginator"
utilSvc "netidhub-saas-be/utils/service"
"strings"
"github.com/google/uuid"
"github.com/rs/zerolog"
)
type articleCategoriesRepository struct {
DB *database.Database
Log zerolog.Logger
Cfg *config.Config
}
// ArticleCategoriesRepository define interface of IArticleCategoriesRepository
@ -28,10 +31,11 @@ type ArticleCategoriesRepository interface {
Delete(clientId *uuid.UUID, id uint) (err error)
}
func NewArticleCategoriesRepository(db *database.Database, log zerolog.Logger) ArticleCategoriesRepository {
func NewArticleCategoriesRepository(db *database.Database, log zerolog.Logger, cfg *config.Config) ArticleCategoriesRepository {
return &articleCategoriesRepository{
DB: db,
Log: log,
Cfg: cfg,
}
}
@ -42,7 +46,7 @@ func (_i *articleCategoriesRepository) GetAll(clientId *uuid.UUID, req request.A
query := _i.DB.DB.Model(&entity.ArticleCategories{})
// Add ClientId filter
if clientId != nil {
if clientId != nil && _i.Cfg.App.PrimaryClientKey != clientId.String() {
query = query.Where("article_categories.client_id = ?", clientId)
}

View File

@ -6,6 +6,7 @@ import (
"netidhub-saas-be/app/database/entity"
"netidhub-saas-be/app/module/articles/request"
"netidhub-saas-be/app/module/articles/response"
"netidhub-saas-be/config/config"
"netidhub-saas-be/utils/paginator"
utilSvc "netidhub-saas-be/utils/service"
"strings"
@ -17,6 +18,7 @@ import (
type articlesRepository struct {
DB *database.Database
Cfg *config.Config
Log zerolog.Logger
}
@ -36,10 +38,11 @@ type ArticlesRepository interface {
ArticleMonthlyStats(clientId *uuid.UUID, userLevelId *uint, levelNumber *int, year int) (articleMontlyStats []*response.ArticleMonthlyStats, err error)
}
func NewArticlesRepository(db *database.Database, log zerolog.Logger) ArticlesRepository {
func NewArticlesRepository(db *database.Database, log zerolog.Logger, cfg *config.Config) ArticlesRepository {
return &articlesRepository{
DB: db,
Log: log,
Cfg: cfg,
}
}
@ -48,9 +51,9 @@ func (_i *articlesRepository) GetAll(clientId *uuid.UUID, userLevelId *uint, use
var count int64
query := _i.DB.DB.Model(&entity.Articles{})
// Add client filter
if clientId != nil {
if clientId != nil && _i.Cfg.App.PrimaryClientKey != clientId.String() {
query = query.Where("client_id = ?", clientId)
}

View File

@ -1,29 +1,31 @@
package config
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/compress"
"github.com/pelletier/go-toml/v2"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"os"
"path/filepath"
"runtime"
"strings"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/compress"
"github.com/pelletier/go-toml/v2"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
type app = struct {
Name string `toml:"name"`
Host string `toml:"host"`
Domain string `toml:"domain"`
Port string `toml:"port"`
ExternalPort string `toml:"external-port"`
PrintRoutes bool `toml:"print-routes"`
Prefork bool `toml:"prefork"`
Production bool `toml:"production"`
IdleTimeout time.Duration `toml:"idle-timeout"`
BodyLimit int `toml:"body-limit"`
Name string `toml:"name"`
Host string `toml:"host"`
Domain string `toml:"domain"`
Port string `toml:"port"`
ExternalPort string `toml:"external-port"`
PrintRoutes bool `toml:"print-routes"`
Prefork bool `toml:"prefork"`
Production bool `toml:"production"`
IdleTimeout time.Duration `toml:"idle-timeout"`
BodyLimit int `toml:"body-limit"`
PrimaryClientKey string `toml:"primary-client-key"`
}
// db struct config

View File

@ -10,6 +10,7 @@ print-routes = false
prefork = true
production = false
body-limit = 1048576000 # "100 * 1024 * 1024"
primary-client-key = "78356d32-52fa-4dfc-b836-6cebf4e3eead"
[db.postgres]
dsn = "postgresql://netidhub_user:NetidhubDB@2025@38.47.180.165:5432/netidhub_db" # <driver>://<username>:<password>@<host>:<port>/<database>