Skip to content

Commit 98b6b64

Browse files
committed
feat: 임원진 멤버 수정 기능 추가
1 parent cde2f8d commit 98b6b64

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import dmu.dasom.api.domain.executive.dto.ExecutiveCreationResponseDto;
44
import dmu.dasom.api.domain.executive.dto.ExecutiveRequestDto;
55
import dmu.dasom.api.domain.executive.dto.ExecutiveResponseDto;
6+
import dmu.dasom.api.domain.executive.dto.ExecutiveUpdateRequestDto;
67
import dmu.dasom.api.domain.executive.service.ExecutiveService;
8+
import dmu.dasom.api.domain.news.dto.NewsUpdateRequestDto;
79
import io.swagger.v3.oas.annotations.Operation;
810
import io.swagger.v3.oas.annotations.tags.Tag;
911
import jakarta.validation.Valid;
@@ -31,4 +33,11 @@ public ResponseEntity<ExecutiveResponseDto> getExecutiveById(@PathVariable @Min(
3133
public ResponseEntity<ExecutiveCreationResponseDto> createExecutive(@Valid @RequestBody ExecutiveRequestDto requestDto) {
3234
return ResponseEntity.status(201).body(executiveService.createExecutive(requestDto));
3335
}
36+
37+
@Operation(summary = "임원진 수정")
38+
@PutMapping("/{id}")
39+
public ResponseEntity<ExecutiveResponseDto> updateExecutive(@PathVariable @Min(1) Long id,
40+
@Valid @RequestBody ExecutiveUpdateRequestDto requestDto) {
41+
return ResponseEntity.ok(executiveService.updateExecutive(id, requestDto));
42+
}
3443
}

src/main/java/dmu/dasom/api/domain/executive/entity/ExecutiveEntity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ public class ExecutiveEntity extends BaseEntity {
3131
@Column(nullable=false, length = 255)
3232
private String githubUrl;
3333

34+
// 엔티티 업데이트 메소드
35+
public void update(String name, String position, String githubUrl) {
36+
this.name = name;
37+
this.position = position;
38+
this.githubUrl = githubUrl;
39+
}
40+
3441
// 엔티티 -> DTO 변환 책임
3542
public ExecutiveResponseDto toResponseDto() {
3643
return ExecutiveResponseDto.builder()

src/main/java/dmu/dasom/api/domain/executive/service/ExecutiveService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dmu.dasom.api.domain.executive.dto.ExecutiveCreationResponseDto;
44
import dmu.dasom.api.domain.executive.dto.ExecutiveRequestDto;
55
import dmu.dasom.api.domain.executive.dto.ExecutiveResponseDto;
6+
import dmu.dasom.api.domain.executive.dto.ExecutiveUpdateRequestDto;
67
import dmu.dasom.api.domain.executive.entity.ExecutiveEntity;
78
import dmu.dasom.api.domain.executive.repository.ExecutiveRepository;
89
import lombok.RequiredArgsConstructor;
@@ -31,8 +32,13 @@ public ExecutiveCreationResponseDto createExecutive(ExecutiveRequestDto requestD
3132
}
3233

3334
// 임원진 멤버 수정
34-
/*@Transactional
35-
public ExecutiveResponseDto updateExecutive(ExecutiveRequestDto requestDto) {
36-
return
37-
}*/
35+
@Transactional
36+
public ExecutiveResponseDto updateExecutive(Long id, ExecutiveUpdateRequestDto requestDto) {
37+
ExecutiveEntity executive = executiveRepository.findById(id)
38+
.orElseThrow(() -> new IllegalArgumentException("Executive not found")); // 임시 에러 코드 출력 나중에 커스텀 에러코드로 수정
39+
40+
executive.update(requestDto.getName(), requestDto.getPosition(), requestDto.getGithubUrl());
41+
42+
return executive.toResponseDto();
43+
}
3844
}

0 commit comments

Comments
 (0)