mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 07:15:43 +00:00
feat(BE): update DeleteOne method to use uint64 for ID and implement soft delete logic
This commit is contained in:
@@ -3,6 +3,8 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
@@ -17,6 +19,7 @@ type ExpenseRepository interface {
|
||||
GetWithSupplier(ctx context.Context, id uint64) (*entity.Expense, error)
|
||||
WithProjectFlockKandangFilter(pfkID, kandangID uint) func(*gorm.DB) *gorm.DB
|
||||
CountUnfinishedByProjectFlockKandang(ctx context.Context, pfkID, kandangID uint, isFinished func(*entity.Approval) bool) (int64, error)
|
||||
DeleteOne(ctx context.Context, id uint) error
|
||||
}
|
||||
|
||||
type ExpenseRepositoryImpl struct {
|
||||
@@ -107,3 +110,23 @@ func (r *ExpenseRepositoryImpl) CountUnfinishedByProjectFlockKandang(ctx context
|
||||
}
|
||||
return unfinished, nil
|
||||
}
|
||||
|
||||
func (r *ExpenseRepositoryImpl) DeleteOne(ctx context.Context, id uint) error {
|
||||
// Cast to uint64 to match entity.Id type
|
||||
id64 := uint64(id)
|
||||
deletedAt := time.Now()
|
||||
|
||||
// Use raw SQL with interpolated integer to avoid type issues
|
||||
// Interpolate id directly as integer literal (safe because it's uint64)
|
||||
result := r.DB().WithContext(ctx).
|
||||
Exec(`UPDATE "expenses" SET "deleted_at" = $1 WHERE "id" = `+fmt.Sprintf("%d", id64)+` AND "deleted_at" IS NULL`,
|
||||
deletedAt)
|
||||
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
if result.RowsAffected == 0 {
|
||||
return gorm.ErrRecordNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user