-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create draft PR for #64 * feat(Dashboard): 대시보드 생성 기능 구현 - 대시보드 생성시 기본 프로세스 2개가 생성된다. - 서류지원 프로세스 - 합격 프로세스 * refactor(DashboardService): create 메서드 @transactional 추가 * refactor(DashboardControllerTest): 불필요한 코드 제거 --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: leetaehoon <xogns1514@gmail.com>
- Loading branch information
1 parent
fe6657b
commit 307c703
Showing
8 changed files
with
210 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/cruru/club/exception/ClubNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.cruru.club.exception; | ||
|
||
import com.cruru.advice.NotFoundException; | ||
|
||
public class ClubNotFoundException extends NotFoundException { | ||
|
||
private static final String MESSAGE = "존재하지 않는 동아리입니다."; | ||
|
||
public ClubNotFoundException() { | ||
super(MESSAGE); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/cruru/dashboard/controller/DashboardController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.cruru.dashboard.controller; | ||
|
||
import com.cruru.dashboard.controller.dto.DashboardCreateDto; | ||
import com.cruru.dashboard.service.DashboardService; | ||
import com.cruru.member.controller.dto.MemberCreateResponse; | ||
import java.net.URI; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/v1/dashboards") | ||
@RequiredArgsConstructor | ||
public class DashboardController { | ||
|
||
private final DashboardService dashboardService; | ||
|
||
@PostMapping | ||
public ResponseEntity<MemberCreateResponse> create( | ||
@RequestParam(name = "club_id") Long clubId, | ||
@RequestBody DashboardCreateDto request) { | ||
Long dashboardId = dashboardService.create(clubId, request); | ||
return ResponseEntity.created(URI.create("/v1/dashboards/" + dashboardId)).build(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/cruru/dashboard/controller/dto/DashboardCreateDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.cruru.dashboard.controller.dto; | ||
|
||
public record DashboardCreateDto(String name) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/cruru/dashboard/service/DashboardService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.cruru.dashboard.service; | ||
|
||
import com.cruru.club.domain.Club; | ||
import com.cruru.club.domain.repository.ClubRepository; | ||
import com.cruru.club.exception.ClubNotFoundException; | ||
import com.cruru.dashboard.controller.dto.DashboardCreateDto; | ||
import com.cruru.dashboard.domain.Dashboard; | ||
import com.cruru.dashboard.domain.repository.DashboardRepository; | ||
import com.cruru.process.domain.Process; | ||
import com.cruru.process.domain.repository.ProcessRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class DashboardService { | ||
|
||
private static final Process DEFAULT_FIRST_PROCESS = new Process(1, "지원 접수", "지원자가 이력서를 제출하는 단계", null); | ||
private static final Process DEFAULT_LAST_PROCESS = new Process(2, "합격", "지원자가 최종적으로 합격한 단계", null); | ||
|
||
private final DashboardRepository dashboardRepository; | ||
private final ClubRepository clubRepository; | ||
private final ProcessRepository processRepository; | ||
|
||
@Transactional | ||
public Long create(long clubId, DashboardCreateDto request) { | ||
Club club = clubRepository.findById(clubId).orElseThrow(ClubNotFoundException::new); | ||
|
||
Dashboard savedDashboard = dashboardRepository.save(new Dashboard(request.name(), club)); | ||
|
||
Process firstProcess = new Process( | ||
DEFAULT_FIRST_PROCESS.getSequence(), | ||
DEFAULT_FIRST_PROCESS.getName(), | ||
DEFAULT_FIRST_PROCESS.getDescription(), | ||
savedDashboard | ||
); | ||
|
||
Process lastProcess = new Process( | ||
DEFAULT_LAST_PROCESS.getSequence(), | ||
DEFAULT_LAST_PROCESS.getName(), | ||
DEFAULT_LAST_PROCESS.getDescription(), | ||
savedDashboard | ||
); | ||
|
||
processRepository.saveAll(List.of(firstProcess, lastProcess)); | ||
|
||
return savedDashboard.getId(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/test/java/com/cruru/dashboard/controller/DashboardControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.cruru.dashboard.controller; | ||
|
||
import com.cruru.club.domain.Club; | ||
import com.cruru.club.domain.repository.ClubRepository; | ||
import com.cruru.dashboard.controller.dto.DashboardCreateDto; | ||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
|
||
@DisplayName("대시보드 컨트롤러 테스트") | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
class DashboardControllerTest { | ||
|
||
@LocalServerPort | ||
private int port; | ||
|
||
@Autowired | ||
private ClubRepository clubRepository; | ||
|
||
private Club club; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
RestAssured.port = port; | ||
club = clubRepository.save(new Club("크루루 동아리", null)); | ||
} | ||
|
||
@DisplayName("대시보드 생성 성공 시, 201을 응답한다.") | ||
@Test | ||
void read() { | ||
DashboardCreateDto request = new DashboardCreateDto("크루루대시보드"); | ||
|
||
RestAssured.given().log().all() | ||
.contentType(ContentType.JSON) | ||
.body(request) | ||
.when().post("/v1/dashboards?club_id=" + club.getId()) | ||
.then().log().all().statusCode(201); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/test/java/com/cruru/dashboard/service/DashboardServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.cruru.dashboard.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.cruru.applicant.domain.repository.ApplicantRepository; | ||
import com.cruru.club.domain.Club; | ||
import com.cruru.club.domain.repository.ClubRepository; | ||
import com.cruru.dashboard.controller.dto.DashboardCreateDto; | ||
import com.cruru.dashboard.domain.repository.DashboardRepository; | ||
import com.cruru.process.domain.Process; | ||
import com.cruru.process.domain.repository.ProcessRepository; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@DisplayName("대시보드 서비스 테스트") | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) | ||
class DashboardServiceTest { | ||
|
||
@Autowired | ||
DashboardService dashboardService; | ||
|
||
@Autowired | ||
DashboardRepository dashboardRepository; | ||
|
||
@Autowired | ||
ProcessRepository processRepository; | ||
|
||
@Autowired | ||
ClubRepository clubRepository; | ||
|
||
@Autowired | ||
ApplicantRepository applicantRepository; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
applicantRepository.deleteAll(); | ||
processRepository.deleteAll(); | ||
dashboardRepository.deleteAll(); | ||
clubRepository.deleteAll(); | ||
} | ||
|
||
@DisplayName("새로운 대시보드를 생성시, 기본 프로세스 2개가 생성된다.") | ||
@Test | ||
void createDefaultProcessWhenCreateDashBoard() { | ||
// given | ||
Club club = new Club("크루루동아리", null); | ||
clubRepository.save(club); | ||
|
||
// when | ||
DashboardCreateDto request = new DashboardCreateDto("크루루대시보드"); | ||
Long dashboardId = dashboardService.create(club.getId(), request); | ||
|
||
// then | ||
List<Process> processes = processRepository.findAllByDashboardId(dashboardId); | ||
assertThat(processes).hasSize(2); | ||
} | ||
} |