2
0

refactor(repo): rename RepoHiddenFolder to HiddenFolder and cleanup
All checks were successful
Build and Release / Create Release (push) Successful in 0s
Build and Release / Unit Tests (push) Successful in 3m2s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 4m58s
Build and Release / Lint (push) Successful in 5m8s
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Successful in 2m56s
Build and Release / Build Binaries (amd64, darwin, macos) (push) Successful in 3m59s
Build and Release / Build Binaries (arm64, darwin, macos) (push) Successful in 4m29s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Successful in 9h5m17s
Build and Release / Build Binary (linux/arm64) (push) Successful in 10m36s

Simplify model name from RepoHiddenFolder to HiddenFolder since the repo context is already clear. Update function signatures to use comma-separated bool parameters and fix test calls to include new hidden folder parameters. Replace strings.Split with strings.SplitSeq for better performance.
This commit is contained in:
2026-01-27 09:07:42 -05:00
parent 43adbaeffe
commit 2d8a10e30d
4 changed files with 14 additions and 15 deletions

View File

@@ -11,9 +11,8 @@ import (
"code.gitcaddy.com/server/v3/modules/timeutil"
)
// RepoHiddenFolder represents a folder that is hidden from the code browser
// for non-admin users.
type RepoHiddenFolder struct {
// HiddenFolder represents a folder hidden from the code browser for non-admin users.
type HiddenFolder struct {
ID int64 `xorm:"pk autoincr"`
RepoID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
FolderPath string `xorm:"UNIQUE(s) NOT NULL"`
@@ -21,12 +20,12 @@ type RepoHiddenFolder struct {
}
func init() {
db.RegisterModel(new(RepoHiddenFolder))
db.RegisterModel(new(HiddenFolder))
}
// GetHiddenFolders returns all hidden folders for a repository.
func GetHiddenFolders(ctx context.Context, repoID int64) ([]*RepoHiddenFolder, error) {
folders := make([]*RepoHiddenFolder, 0)
func GetHiddenFolders(ctx context.Context, repoID int64) ([]*HiddenFolder, error) {
folders := make([]*HiddenFolder, 0)
return folders, db.GetEngine(ctx).Where("repo_id = ?", repoID).OrderBy("folder_path").Find(&folders)
}
@@ -45,12 +44,12 @@ func GetHiddenFolderPaths(ctx context.Context, repoID int64) (map[string]bool, e
// IsHiddenFolder checks if a specific folder path is hidden.
func IsHiddenFolder(ctx context.Context, repoID int64, folderPath string) (bool, error) {
return db.GetEngine(ctx).Where("repo_id = ? AND folder_path = ?", repoID, folderPath).Exist(&RepoHiddenFolder{})
return db.GetEngine(ctx).Where("repo_id = ? AND folder_path = ?", repoID, folderPath).Exist(&HiddenFolder{})
}
// AddHiddenFolder adds a folder to the hidden list.
func AddHiddenFolder(ctx context.Context, repoID int64, folderPath string) error {
_, err := db.GetEngine(ctx).Insert(&RepoHiddenFolder{
_, err := db.GetEngine(ctx).Insert(&HiddenFolder{
RepoID: repoID,
FolderPath: folderPath,
})
@@ -59,7 +58,7 @@ func AddHiddenFolder(ctx context.Context, repoID int64, folderPath string) error
// RemoveHiddenFolder removes a folder from the hidden list.
func RemoveHiddenFolder(ctx context.Context, repoID int64, folderPath string) error {
_, err := db.GetEngine(ctx).Where("repo_id = ? AND folder_path = ?", repoID, folderPath).Delete(&RepoHiddenFolder{})
_, err := db.GetEngine(ctx).Where("repo_id = ? AND folder_path = ?", repoID, folderPath).Delete(&HiddenFolder{})
return err
}