Skip to content

Commit ec704cd

Browse files
committed
feat(center): center 프로필 수정 service, controller 구현
1 parent 601a710 commit ec704cd

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.somemore.center.controller;
2+
3+
import com.somemore.auth.annotation.CurrentUser;
4+
import com.somemore.center.dto.request.CenterProfileUpdateRequestDto;
5+
import com.somemore.center.usecase.command.UpdateCenterProfileUseCase;
6+
import com.somemore.global.common.response.ApiResponse;
7+
import com.somemore.imageupload.dto.ImageUploadRequestDto;
8+
import com.somemore.imageupload.usecase.ImageUploadUseCase;
9+
import io.swagger.v3.oas.annotations.Operation;
10+
import io.swagger.v3.oas.annotations.tags.Tag;
11+
import jakarta.validation.Valid;
12+
import lombok.RequiredArgsConstructor;
13+
import org.springframework.security.access.annotation.Secured;
14+
import org.springframework.web.bind.annotation.*;
15+
import org.springframework.web.multipart.MultipartFile;
16+
17+
import java.util.UUID;
18+
19+
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
20+
21+
@Tag(name = "Center Command API", description = "센터 프로필 수정 API")
22+
@RequiredArgsConstructor
23+
@RequestMapping("/api/center/profile")
24+
@RestController
25+
public class CenterProfileCommandApiController {
26+
27+
private final UpdateCenterProfileUseCase updateCenterProfileUseCase;
28+
private final ImageUploadUseCase imageUploadUseCase;
29+
30+
@Secured("ROLE_CENTER")
31+
@Operation(summary = "센터 프로필 수정", description = "센터 프로필을 수정합니다.")
32+
@PutMapping(value = "/{centerId}", consumes = MULTIPART_FORM_DATA_VALUE)
33+
public ApiResponse<String> updateCenterProfile(
34+
@CurrentUser UUID centerId,
35+
@Valid @RequestPart("data") CenterProfileUpdateRequestDto requestDto,
36+
@RequestPart(value = "img_file", required = false) MultipartFile image
37+
) {
38+
String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image));
39+
updateCenterProfileUseCase.updateCenterProfile(centerId, requestDto, imgUrl);
40+
41+
return ApiResponse.ok("센터 프로필 수정 성공");
42+
}
43+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.somemore.center.service.command;
2+
3+
import com.somemore.center.domain.Center;
4+
import com.somemore.center.dto.request.CenterProfileUpdateRequestDto;
5+
import com.somemore.center.repository.CenterRepository;
6+
import com.somemore.center.usecase.command.UpdateCenterProfileUseCase;
7+
import com.somemore.global.exception.BadRequestException;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.stereotype.Service;
10+
import org.springframework.transaction.annotation.Transactional;
11+
12+
import java.util.UUID;
13+
14+
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_CENTER;
15+
16+
@RequiredArgsConstructor
17+
@Transactional
18+
@Service
19+
public class UpdateCenterProfileService implements UpdateCenterProfileUseCase {
20+
21+
private final CenterRepository centerRepository;
22+
23+
@Override
24+
public void updateCenterProfile(UUID centerId, CenterProfileUpdateRequestDto requestDto, String imgUrl) {
25+
Center center = centerRepository.findCenterById(centerId)
26+
.orElseThrow(() -> new BadRequestException(NOT_EXISTS_CENTER));
27+
28+
center.updateWith(requestDto, imgUrl);
29+
}
30+
}

0 commit comments

Comments
 (0)