Skip to content

Commit

Permalink
Add job name to employee response and preload job in FindById method:…
Browse files Browse the repository at this point in the history
… enhance employee data representation by including job name and improving data retrieval efficiency
  • Loading branch information
IlhamSetiaji committed Dec 20, 2024
1 parent ce2a649 commit d12807c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/http/dto/employee_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func ConvertToSingleEmployeeResponse(employee *entity.Employee) *response.Employ
"name": employee.EmployeeJob.Name,
"emp_organization_id": employee.EmployeeJob.EmpOrganizationID,
"job_id": employee.EmployeeJob.JobID,
"job_name": employee.EmployeeJob.Job.Name,
"employee_id": employee.EmployeeJob.EmployeeID,
"organization_location_id": employee.EmployeeJob.OrganizationLocationID,
},
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/employee_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (r *EmployeeRepository) FindAllPaginated(page int, pageSize int, search str

func (r *EmployeeRepository) FindById(id uuid.UUID) (*entity.Employee, error) {
var employee entity.Employee
err := r.DB.Preload("EmployeeJob").Preload("User").Preload("Organization.OrganizationType").Where("id = ?", id).First(&employee).Error
err := r.DB.Preload("EmployeeJob.Job").Preload("User").Preload("Organization.OrganizationType").Where("id = ?", id).First(&employee).Error
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d12807c

Please sign in to comment.