Skip to content

Commit eff42a1

Browse files
committed
feat: ExecutiveService 인터페이스 구현 및 기존 파일 이름 변경 (DASOMBE-14)
1 parent 615ea4f commit eff42a1

File tree

4 files changed

+63
-46
lines changed

4 files changed

+63
-46
lines changed

src/main/java/dmu/dasom/api/domain/executive/controller/ExecutiveController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import dmu.dasom.api.domain.executive.dto.ExecutiveRequestDto;
55
import dmu.dasom.api.domain.executive.dto.ExecutiveResponseDto;
66
import dmu.dasom.api.domain.executive.dto.ExecutiveUpdateRequestDto;
7-
import dmu.dasom.api.domain.executive.service.ExecutiveService;
7+
import dmu.dasom.api.domain.executive.service.ExecutiveServiceImpl;
88
import io.swagger.v3.oas.annotations.Operation;
99
import io.swagger.v3.oas.annotations.tags.Tag;
1010
import jakarta.validation.Valid;
@@ -19,7 +19,7 @@
1919
@RequestMapping("/api/executives")
2020
public class ExecutiveController {
2121

22-
private final ExecutiveService executiveService;
22+
private final ExecutiveServiceImpl executiveService;
2323

2424
@Operation(summary = "임원진 조회")
2525
@GetMapping("/{id}")
Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,17 @@
11
package dmu.dasom.api.domain.executive.service;
22

3-
import dmu.dasom.api.domain.common.exception.CustomException;
4-
import dmu.dasom.api.domain.common.exception.ErrorCode;
53
import dmu.dasom.api.domain.executive.dto.ExecutiveCreationResponseDto;
64
import dmu.dasom.api.domain.executive.dto.ExecutiveRequestDto;
75
import dmu.dasom.api.domain.executive.dto.ExecutiveResponseDto;
86
import dmu.dasom.api.domain.executive.dto.ExecutiveUpdateRequestDto;
9-
import dmu.dasom.api.domain.executive.entity.ExecutiveEntity;
10-
import dmu.dasom.api.domain.executive.repository.ExecutiveRepository;
11-
import lombok.RequiredArgsConstructor;
12-
import org.springframework.stereotype.Service;
13-
import org.springframework.transaction.annotation.Transactional;
147

15-
@Service
16-
@RequiredArgsConstructor
17-
@Transactional(readOnly = true) // 기본값 : 읽기 전용
18-
public class ExecutiveService {
8+
public interface ExecutiveService {
199

20-
private final ExecutiveRepository executiveRepository;
10+
ExecutiveResponseDto getExecutiveById(Long id);
2111

22-
// 임원진 멤버 조회
23-
// 이름, 직책, 깃허브 주소 검색
24-
public ExecutiveResponseDto getExecutiveById(Long id) {
25-
ExecutiveEntity executive = executiveRepository.findById(id)
26-
.orElseThrow(() -> new CustomException(ErrorCode.EXECUTIVE_NOT_FOUND));
12+
ExecutiveCreationResponseDto createExecutive(ExecutiveRequestDto requestDto);
2713

28-
return executive.toResponseDto();
29-
}
14+
void deleteExective(Long id);
3015

31-
// 임원진 멤버 생성
32-
public ExecutiveCreationResponseDto createExecutive(ExecutiveRequestDto requestDto) {
33-
return new ExecutiveCreationResponseDto(executiveRepository.save(requestDto.toEntity()).getId());
34-
}
35-
36-
// 임원진 멤버 삭제
37-
@Transactional
38-
public void deleteExective(Long id) {
39-
ExecutiveEntity executive = executiveRepository.findById(id)
40-
.orElseThrow(() -> new CustomException(ErrorCode.EXECUTIVE_NOT_FOUND));
41-
42-
executiveRepository.delete(executive);
43-
}
44-
45-
// 임원진 멤버 수정
46-
@Transactional
47-
public ExecutiveResponseDto updateExecutive(Long id, ExecutiveUpdateRequestDto requestDto) {
48-
ExecutiveEntity executive = executiveRepository.findById(id)
49-
.orElseThrow(() -> new CustomException(ErrorCode.EXECUTIVE_NOT_FOUND));
50-
51-
executive.update(requestDto.getName(), requestDto.getPosition(), requestDto.getGithubUrl());
52-
53-
return executive.toResponseDto();
54-
}
16+
ExecutiveResponseDto updateExecutive(Long id, ExecutiveUpdateRequestDto requestDto);
5517
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package dmu.dasom.api.domain.executive.service;
2+
3+
import dmu.dasom.api.domain.common.exception.CustomException;
4+
import dmu.dasom.api.domain.common.exception.ErrorCode;
5+
import dmu.dasom.api.domain.executive.dto.ExecutiveCreationResponseDto;
6+
import dmu.dasom.api.domain.executive.dto.ExecutiveRequestDto;
7+
import dmu.dasom.api.domain.executive.dto.ExecutiveResponseDto;
8+
import dmu.dasom.api.domain.executive.dto.ExecutiveUpdateRequestDto;
9+
import dmu.dasom.api.domain.executive.entity.ExecutiveEntity;
10+
import dmu.dasom.api.domain.executive.repository.ExecutiveRepository;
11+
import lombok.RequiredArgsConstructor;
12+
import org.springframework.stereotype.Service;
13+
import org.springframework.transaction.annotation.Transactional;
14+
15+
@Service
16+
@RequiredArgsConstructor
17+
@Transactional(readOnly = true) // 기본값 : 읽기 전용
18+
public class ExecutiveServiceImpl implements ExecutiveService {
19+
20+
private final ExecutiveRepository executiveRepository;
21+
22+
// 임원진 멤버 조회
23+
// 이름, 직책, 깃허브 주소 검색
24+
public ExecutiveResponseDto getExecutiveById(Long id) {
25+
ExecutiveEntity executive = executiveRepository.findById(id)
26+
.orElseThrow(() -> new CustomException(ErrorCode.EXECUTIVE_NOT_FOUND));
27+
28+
return executive.toResponseDto();
29+
}
30+
31+
// 임원진 멤버 생성
32+
public ExecutiveCreationResponseDto createExecutive(ExecutiveRequestDto requestDto) {
33+
return new ExecutiveCreationResponseDto(executiveRepository.save(requestDto.toEntity()).getId());
34+
}
35+
36+
// 임원진 멤버 삭제
37+
@Transactional
38+
public void deleteExective(Long id) {
39+
ExecutiveEntity executive = executiveRepository.findById(id)
40+
.orElseThrow(() -> new CustomException(ErrorCode.EXECUTIVE_NOT_FOUND));
41+
42+
executiveRepository.delete(executive);
43+
}
44+
45+
// 임원진 멤버 수정
46+
@Transactional
47+
public ExecutiveResponseDto updateExecutive(Long id, ExecutiveUpdateRequestDto requestDto) {
48+
ExecutiveEntity executive = executiveRepository.findById(id)
49+
.orElseThrow(() -> new CustomException(ErrorCode.EXECUTIVE_NOT_FOUND));
50+
51+
executive.update(requestDto.getName(), requestDto.getPosition(), requestDto.getGithubUrl());
52+
53+
return executive.toResponseDto();
54+
}
55+
}

src/test/java/dmu/dasom/api/domain/executive/service/ExecutiveServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ExecutiveServiceTest {
2727

2828
// 생성자 주입
2929
@InjectMocks
30-
private ExecutiveService executiveService;
30+
private ExecutiveServiceImpl executiveService;
3131

3232
@Test
3333
@DisplayName("임원진 멤버 조회 - 성공")

0 commit comments

Comments
 (0)