Source-only publication of reviewed commit 64e96a7f423673dc29ad56485be9fc79bce8af1c.
Passed in isolation: focused frontend/backend tests, race checks, TypeScript typecheck, lint, Go compilation, Flowgram build, and deterministic SDK build/tests.
Not accepted as a production release: Next.js export/native assembly remains blocked by environment memory limits; browser interaction and MySQL staging acceptance remain unverified. No production server, database/schema, runtime configuration, deployment, release tag, or workflow execution was performed.
Expected source tree: 0a4a7528e9.
122 lines
3.6 KiB
Go
122 lines
3.6 KiB
Go
// Modified in the independent hardening fork; see docs/hardening.
|
|
|
|
package repositories
|
|
|
|
import (
|
|
"agent-desk/internal/models"
|
|
"agent-desk/internal/pkg/enums"
|
|
|
|
"agent-desk/internal/pkg/httpx/params"
|
|
|
|
"github.com/mlogclub/simple/sqls"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
var CustomerIdentityRepository = newCustomerIdentityRepository()
|
|
|
|
func newCustomerIdentityRepository() *customerIdentityRepository {
|
|
return &customerIdentityRepository{}
|
|
}
|
|
|
|
type customerIdentityRepository struct {
|
|
}
|
|
|
|
func (r *customerIdentityRepository) Get(db *gorm.DB, id int64) *models.CustomerIdentity {
|
|
ret := &models.CustomerIdentity{}
|
|
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
|
return nil
|
|
}
|
|
return ret
|
|
}
|
|
|
|
func (r *customerIdentityRepository) Take(db *gorm.DB, where ...interface{}) *models.CustomerIdentity {
|
|
ret := &models.CustomerIdentity{}
|
|
if err := db.Take(ret, where...).Error; err != nil {
|
|
return nil
|
|
}
|
|
return ret
|
|
}
|
|
|
|
// GetBy is the legacy/internal-integration lookup. Ambiguous mappings fail closed.
|
|
func (r *customerIdentityRepository) GetBy(db *gorm.DB, externalSource enums.ExternalSource, externalID string) *models.CustomerIdentity {
|
|
identity, err := r.GetUniqueBy(db, "", externalSource, externalID)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return identity
|
|
}
|
|
|
|
func (r *customerIdentityRepository) FindByCustomerID(db *gorm.DB, customerID int64) []models.CustomerIdentity {
|
|
if customerID <= 0 {
|
|
return nil
|
|
}
|
|
return r.Find(db, sqls.NewCnd().Eq("customer_id", customerID).Eq("status", enums.StatusOk).Desc("id"))
|
|
}
|
|
|
|
func (r *customerIdentityRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.CustomerIdentity) {
|
|
cnd.Find(db, &list)
|
|
return
|
|
}
|
|
|
|
func (r *customerIdentityRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.CustomerIdentity {
|
|
ret := &models.CustomerIdentity{}
|
|
if err := cnd.FindOne(db, &ret); err != nil {
|
|
return nil
|
|
}
|
|
return ret
|
|
}
|
|
|
|
func (r *customerIdentityRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.CustomerIdentity, paging *sqls.Paging) {
|
|
return r.FindPageByCnd(db, ¶ms.Cnd)
|
|
}
|
|
|
|
func (r *customerIdentityRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.CustomerIdentity, paging *sqls.Paging) {
|
|
cnd.Find(db, &list)
|
|
count := cnd.Count(db, &models.CustomerIdentity{})
|
|
|
|
paging = &sqls.Paging{
|
|
Page: cnd.Paging.Page,
|
|
Limit: cnd.Paging.Limit,
|
|
Total: count,
|
|
}
|
|
return
|
|
}
|
|
|
|
func (r *customerIdentityRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.CustomerIdentity) {
|
|
db.Raw(sqlStr, paramArr...).Scan(&list)
|
|
return
|
|
}
|
|
|
|
func (r *customerIdentityRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
|
|
db.Raw(sqlStr, paramArr...).Count(&count)
|
|
return
|
|
}
|
|
|
|
func (r *customerIdentityRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
|
return cnd.Count(db, &models.CustomerIdentity{})
|
|
}
|
|
|
|
func (r *customerIdentityRepository) Create(db *gorm.DB, t *models.CustomerIdentity) (err error) {
|
|
err = db.Create(t).Error
|
|
return
|
|
}
|
|
|
|
func (r *customerIdentityRepository) Update(db *gorm.DB, t *models.CustomerIdentity) (err error) {
|
|
err = db.Save(t).Error
|
|
return
|
|
}
|
|
|
|
func (r *customerIdentityRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
|
|
err = db.Model(&models.CustomerIdentity{}).Where("id = ?", id).Updates(columns).Error
|
|
return
|
|
}
|
|
|
|
func (r *customerIdentityRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
|
|
err = db.Model(&models.CustomerIdentity{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
|
return
|
|
}
|
|
|
|
func (r *customerIdentityRepository) Delete(db *gorm.DB, id int64) {
|
|
db.Delete(&models.CustomerIdentity{}, "id = ?", id)
|
|
}
|