From 9148fa6c0989c7882cf4f74475b16ea6c118e8d4 Mon Sep 17 00:00:00 2001 From: "taekyu.kang" Date: Tue, 7 May 2024 17:27:00 +0900 Subject: [PATCH] trivial. add attribute to audit --- internal/delivery/http/auth.go | 1 + internal/usecase/audit.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/internal/delivery/http/auth.go b/internal/delivery/http/auth.go index 5e8f702a..ee74f5eb 100644 --- a/internal/delivery/http/auth.go +++ b/internal/delivery/http/auth.go @@ -69,6 +69,7 @@ func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request) { Description: errorResponse.Text(), ClientIP: audit.GetClientIpAddress(w, r), UserId: nil, + UserAccountId: input.AccountId, }) log.Errorf(r.Context(), "error is :%s(%T)", err.Error(), err) ErrorJSON(w, r, err) diff --git a/internal/usecase/audit.go b/internal/usecase/audit.go index d7e50b99..4e9ec1a3 100644 --- a/internal/usecase/audit.go +++ b/internal/usecase/audit.go @@ -18,18 +18,27 @@ type IAuditUsecase interface { } type AuditUsecase struct { - repo repository.IAuditRepository - userRepo repository.IUserRepository + repo repository.IAuditRepository + userRepo repository.IUserRepository + organizationRepo repository.IOrganizationRepository } func NewAuditUsecase(r repository.Repository) IAuditUsecase { return &AuditUsecase{ - repo: r.Audit, - userRepo: r.User, + repo: r.Audit, + userRepo: r.User, + organizationRepo: r.Organization, } } func (u *AuditUsecase) Create(ctx context.Context, dto model.Audit) (auditId uuid.UUID, err error) { + if dto.OrganizationId != "" { + organization, err := u.organizationRepo.Get(ctx, dto.OrganizationId) + if err == nil { + dto.OrganizationName = organization.Name + } + } + if dto.UserId != nil && *dto.UserId != uuid.Nil { user, err := u.userRepo.GetByUuid(ctx, *dto.UserId) if err != nil {