Update template

This commit is contained in:
aditya.siregar
2025-05-06 15:21:12 +07:00
parent 5111fedfa8
commit 4be9c7d73c
7 changed files with 139 additions and 68 deletions
+29
View File
@@ -18,6 +18,10 @@ type CustomerRepo interface {
FindByPhone(ctx mycontext.Context, phone string) (*entity.Customer, error)
FindByEmail(ctx mycontext.Context, email string) (*entity.Customer, error)
AddPoints(ctx mycontext.Context, id int64, points int, reference string) error
GetPointsByCustomerID(
ctx mycontext.Context,
customerID int64,
) (*entity.CustomerPoints, error)
FindSequence(ctx mycontext.Context, partnerID int64) (int64, error)
GetAllCustomers(ctx mycontext.Context, req entity.MemberSearch) (entity.MemberList, int, error)
VerifyOTP(ctx mycontext.Context, verificationHash string, otpCode string) (int64, error)
@@ -172,6 +176,31 @@ func (r *customerRepository) AddPoints(ctx mycontext.Context, customerID int64,
return nil
}
func (r *customerRepository) GetPointsByCustomerID(
ctx mycontext.Context,
customerID int64,
) (*entity.CustomerPoints, error) {
var cp models.CustomerPointsDB
if err := r.db.Where("customer_id = ?", customerID).First(&cp).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errors.New("customer not found")
}
return nil, errors.Wrap(err, "failed to find customer point by customer_id")
}
return r.toDomainCustomerPoint(cp), nil
}
func (r *customerRepository) toDomainCustomerPoint(dbModel models.CustomerPointsDB) *entity.CustomerPoints {
return &entity.CustomerPoints{
ID: dbModel.ID,
CustomerID: dbModel.CustomerID,
TotalPoints: dbModel.TotalPoints,
AvailablePoints: dbModel.AvailablePoints,
}
}
func (r *customerRepository) toCustomerDBModel(customer *entity.Customer) models.CustomerDB {
return models.CustomerDB{
ID: customer.ID,