Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ public GetMyProjectList.Response getMyProjectList(Long memberId, String filter)
public GetCompanyProject.Response getCompanyProject(Long companyId, String filter) {
Company company = companyService.getCompany(companyId);
List<Project> findProjects = projectService.getCompanyProject(company.getId(), filter);

List<GetCompanyProject.CompanyProject> companyProjects = findProjects.stream()
.map(project ->
GetCompanyProject.CompanyProject.toDto(
project,
projectService.getProjectTags(project.getId())
))
.toList();

return GetCompanyProject.Response.toDto(company.getId(), companyProjects);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 리뷰를 통해 몇 가지 개선 사항과 잠재적인 버그 위험 요소를 제안하겠습니다.

  1. Null 체크: company가 null일 가능성에 대한 검증이 없습니다. companyService.getCompany(companyId)가 null을 반환하면 이후의 코드에서 NPE(Null Pointer Exception)가 발생할 수 있습니다. 회사가 존재하지 않는 경우에 대한 예외 처리를 추가하는 것이 좋습니다.

    if (company == null) {
        throw new CompanyNotFoundException("Company not found for id: " + companyId);
    }
  2. filter 유효성 검사: filter 파라미터에 대한 유효성 검사가 필요합니다. 전달된 filter 값이 비어있거나 유효하지 않은 경우에 대한 검증 로직을 추가하는 것이 좋습니다.

  3. 메소드 분리: 코드 가독성을 높이기 위해 findProjectscompanyProjects를 생성하는 부분을 별도의 메소드로 분리할 수 있습니다. 이는 코드의 재사용성을 높이고 단위를 분리하는 데 도움이 됩니다.

  4. Stream API 성능 고려: 프로젝트 태그를 가져오는 projectService.getProjectTags(project.getId())가 각각의 프로젝트에 대해 호출됩니다. 만약 findProjects에 프로젝트 수가 많다면 성능 이슈가 발생할 수 있습니다. 필요한 태그를 한 번에 가져오고 이를 매핑하는 방식으로 개선할 수 있습니다.

  5. 예외 처리: projectService.getProjectTags에서 발생할 수 있는 예외에 대한 처리를 고려해야 합니다. 외부 호출에 대해 예외 처리를 하지 않으면 시스템의 안정성에 영향을 줄 수 있습니다.

  6. 주석 추가: 코드의 각 부분이 어떤 역할을 하는지를 설명하는 주석을 추가하는 것이 좋습니다. 다른 개발자가 코드를 이해하는 데 도움이 됩니다.

위의 사항들을 고려하여 코드를 수정하면 더욱 견고하고 유지보수하기 쉬운 코드가 될 것입니다.

Loading