Skip to content

Commit

Permalink
Feat(#171-project): 진행 중/완료된 프로젝트 카운팅 조회 API
Browse files Browse the repository at this point in the history
  • Loading branch information
hojeong2747 committed May 25, 2023
1 parent a15679d commit fda0d61
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com._8attery.seesaw.domain.user.account.UserAccount;
import com._8attery.seesaw.dto.api.request.*;
import com._8attery.seesaw.dto.api.response.ProjectCardResponseDto;
import com._8attery.seesaw.dto.api.response.ProjectCountResponseDto;
import com._8attery.seesaw.dto.api.response.ProjectResponseDto;
import com._8attery.seesaw.exception.BaseException;
import com._8attery.seesaw.exception.BaseResponse;
Expand Down Expand Up @@ -111,6 +112,16 @@ public BaseResponse<List<ProjectCardResponseDto>> getCompleteProject(@Authentica
}
}

// 진행 중, 완료된 프로젝트 카운팅 조회
@GetMapping("/count")
public BaseResponse<ProjectCountResponseDto> getProjectCount(@AuthenticationPrincipal UserAccount userAccount) throws BaseException {
Long userId = userService.resolveUserById(userAccount.getUserId()).getId();

ProjectCountResponseDto res = projectService.getUserProjectCount(userId);

return new BaseResponse<>(res);
}

@GetMapping("/{projectId}")
public ResponseEntity<?> getProjectDetails(@AuthenticationPrincipal UserAccount userAccount, @PathVariable("projectId") Long projectId) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com._8attery.seesaw.domain.project;

import com._8attery.seesaw.dto.api.response.ProjectCardResponseDto;
import com._8attery.seesaw.dto.api.response.ProjectCountResponseDto;
import com._8attery.seesaw.dto.api.response.ProjectResponseDto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
Expand Down Expand Up @@ -36,4 +37,11 @@ public interface ProjectRepository extends JpaRepository<Project, Long> {

@Query(value = "select new com._8attery.seesaw.dto.api.response.ProjectCardResponseDto(p.id, p.projectName, p.startedAt, p.endedAt, p.intensity, v.valueName) from Project p join p.value v where p.user.id=:userId and p.isFinished=true")
List<ProjectCardResponseDto> findCompleteProjectList(@Param("userId") Long userId);

// 진행 중, 완료된 프로젝트 카운팅 조회
@Query(value = "select count(*) from ss_project where user_id=:userId and is_finished=false", nativeQuery = true)
Integer getProgressCount(@Param("userId") Long userId);

@Query(value = "select count(*) from ss_project where user_id=:userId and is_finished=true", nativeQuery = true)
Integer getCompleteCount(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com._8attery.seesaw.dto.api.response;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@ToString
@Data
@NoArgsConstructor
public class ProjectCountResponseDto {

private Integer progressCount;

private Integer completeCount;

public ProjectCountResponseDto(Integer progressCount, Integer completeCount) {
this.progressCount = progressCount;
this.completeCount = completeCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ public List<ProjectCardResponseDto> getCompleteProjectList(Long userId) throws B
}
}

// 진행 중, 완료된 프로젝트 카운팅 조회
public ProjectCountResponseDto getUserProjectCount(Long userId) throws BaseException {
try {
Integer progressCount = projectRepository.getProgressCount(userId);
Integer completeCount = projectRepository.getCompleteCount(userId);

ProjectCountResponseDto res = new ProjectCountResponseDto(progressCount, completeCount);
return res;
} catch (Exception exception) {
exception.printStackTrace();
throw new BaseException(DATABASE_ERROR);
}
}

public ProjectDetailsResponseDto getProjectDetails(Long userId, Long projectId) {
serviceUtils.retrieveUserById(userId);
Project rerievedProject = serviceUtils.retrieveProjectById(projectId);
Expand Down Expand Up @@ -440,4 +454,5 @@ public ProjectReportBatteryResponseDto getProjectReportBattery(Long userId, Long

return result;
}

}

0 comments on commit fda0d61

Please sign in to comment.