From c4740f4881c665853e8c6b07796c82b33e56f7e3 Mon Sep 17 00:00:00 2001 From: Anass Bouassaba Date: Mon, 26 Aug 2024 20:55:30 +0200 Subject: [PATCH] refactor(api): use GORM API instead of raw query --- api/repo/group_repo.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/api/repo/group_repo.go b/api/repo/group_repo.go index 5de147ff0..064509788 100644 --- a/api/repo/group_repo.go +++ b/api/repo/group_repo.go @@ -178,17 +178,12 @@ func (repo *groupRepo) Find(id string) (model.Group, error) { } func (repo *groupRepo) Count() (int64, error) { - type Result struct { - Result int64 - } - var res Result - db := repo.db. - Raw("SELECT count(*) as result FROM \"group\""). - Scan(&res) + var count int64 + db := repo.db.Model(&groupEntity{}).Count(&count) if db.Error != nil { return 0, db.Error } - return res.Result, nil + return count, nil } func (repo *groupRepo) GetIDsByFile(fileID string) ([]string, error) {