Added activities module
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -19,11 +20,12 @@ type TransactionService interface {
|
||||
}
|
||||
|
||||
type transactionService struct {
|
||||
repo repositories.TransactionRepository
|
||||
repo repositories.TransactionRepository
|
||||
activityRepo repositories.ActivityRepository
|
||||
}
|
||||
|
||||
func NewTransactionService(repo repositories.TransactionRepository) TransactionService {
|
||||
return &transactionService{repo: repo}
|
||||
func NewTransactionService(repo repositories.TransactionRepository, activityRepo repositories.ActivityRepository) TransactionService {
|
||||
return &transactionService{repo: repo, activityRepo: activityRepo}
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -58,6 +60,18 @@ func (s *transactionService) Create(ctx context.Context, req domain.CreateTransa
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if s.activityRepo != nil {
|
||||
description := fmt.Sprintf("Created transaction %d", transaction.ID)
|
||||
_ = s.activityRepo.Create(ctx, &domain.ActivityLog{
|
||||
FamilyID: &transaction.FamilyID,
|
||||
UserID: transaction.CreatedBy,
|
||||
Action: "create",
|
||||
EntityType: "transaction",
|
||||
EntityID: &transaction.ID,
|
||||
Description: description,
|
||||
})
|
||||
}
|
||||
|
||||
return transaction, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user