Skip to content

Commit

Permalink
feat: 기관 프로필 이미지 변경 컨트롤러 구현
Browse files Browse the repository at this point in the history
- 프로필 이미지 업데이트 엔드 포인트 구현
- 테스트및 검증 완료
  • Loading branch information
7zrv committed Feb 3, 2025
1 parent 53d2384 commit f992a53
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.somemore.center.controller;

import com.somemore.center.dto.request.CenterProfileImgUpdateRequestDto;
import com.somemore.center.usecase.UpdateCenterProfileImgUseCase;
import com.somemore.global.auth.annotation.UserId;
import com.somemore.global.common.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@Tag(name = "Center Command API", description = "기관 프로필 수정 API")
@RequiredArgsConstructor
@RequestMapping("/api/center")
@RestController
public class CenterCommandApiController {

private final UpdateCenterProfileImgUseCase updateCenterProfileImgUseCase;

@Secured("ROLE_CENTER")
@Operation(summary = "기관 프로필 이미지 수정", description = "기관의 프로필 이미지를 수정합니다.")
@PutMapping("/profileImgUpdate")
public ApiResponse<String> updateCenterProfile(
@UserId UUID centerId,
CenterProfileImgUpdateRequestDto requestDto
) {

String presignedUrl = updateCenterProfileImgUseCase.updateCenterProfileImg(centerId, requestDto);

return ApiResponse.ok(presignedUrl,"센터 프로필 수정 성공");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.somemore.center.controller;

import com.somemore.center.dto.request.CenterProfileImgUpdateRequestDto;
import com.somemore.center.usecase.UpdateCenterProfileImgUseCase;
import com.somemore.support.ControllerTestSupport;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.UUID;

class CenterCommandApiControllerTest extends ControllerTestSupport {

@MockBean
private UpdateCenterProfileImgUseCase updateCenterProfileImgUseCase;

@DisplayName("기관 프로필 이미지를 수정할 수 있다. (controller)")
@Test
void updateCenterProfile() throws Exception {

// given
UUID centerId = UUID.randomUUID();
CenterProfileImgUpdateRequestDto requestDto = new CenterProfileImgUpdateRequestDto("test.jpg");

String expectedPresignedUrl = "https://example.com/presigned-url/test.jpg";
when(updateCenterProfileImgUseCase.updateCenterProfileImg(centerId, requestDto))
.thenReturn(expectedPresignedUrl);

// when & then
mockMvc.perform(
put("/api/center/profileImgUpdate")
.header("X-User-Id", centerId.toString()) // @UserId를 시뮬레이션
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(requestDto))
)
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value("200"))
.andExpect(jsonPath("$.message").value("센터 프로필 수정 성공"))
.andExpect(jsonPath("$.data").value(expectedPresignedUrl));

verify(updateCenterProfileImgUseCase, times(1)).updateCenterProfileImg(centerId, requestDto);
}

}

0 comments on commit f992a53

Please sign in to comment.