Skip to content

Commit d7ae303

Browse files
authored
Feat : 유저 프로필 이미지 수정, 삭제 (#90)
1 parent 5c3938a commit d7ae303

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

src/main/java/ita/tinybite/domain/user/controller/UserController.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,69 @@ public APIResponse<?> validateNickname(@RequestParam String nickname) {
182182
userService.validateNickname(nickname);
183183
return success();
184184
}
185+
186+
@Operation(
187+
summary = "프로필 이미지 변경",
188+
description = "사용자의 프로필 이미지를 변경합니다. 이미지 URL을 전달받아 업데이트합니다."
189+
)
190+
@ApiResponses({
191+
@ApiResponse(
192+
responseCode = "200",
193+
description = "프로필 이미지 변경 성공"
194+
),
195+
@ApiResponse(
196+
responseCode = "400",
197+
description = "잘못된 요청 (유효하지 않은 이미지 URL)",
198+
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
199+
),
200+
@ApiResponse(
201+
responseCode = "401",
202+
description = "인증 실패",
203+
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
204+
),
205+
@ApiResponse(
206+
responseCode = "404",
207+
description = "사용자를 찾을 수 없음",
208+
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
209+
)
210+
})
211+
@PutMapping("/profile-image")
212+
public ResponseEntity<Void> updateProfileImage(
213+
@Parameter(description = "변경할 프로필 이미지 URL", required = true, example = "https://example.com/image.jpg")
214+
@RequestParam("image") String image,
215+
@Parameter(hidden = true)
216+
@AuthenticationPrincipal Long userId) {
217+
218+
userService.updateProfileImage(userId, image);
219+
return ResponseEntity.ok().build();
220+
}
221+
222+
@Operation(
223+
summary = "프로필 이미지 삭제",
224+
description = "사용자의 프로필 이미지를 삭제하고 기본 이미지로 변경합니다."
225+
)
226+
@ApiResponses({
227+
@ApiResponse(
228+
responseCode = "200",
229+
description = "프로필 이미지 삭제 성공 (기본 이미지로 변경됨)"
230+
),
231+
@ApiResponse(
232+
responseCode = "401",
233+
description = "인증 실패",
234+
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
235+
),
236+
@ApiResponse(
237+
responseCode = "404",
238+
description = "사용자를 찾을 수 없음",
239+
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
240+
)
241+
})
242+
@DeleteMapping("/profile-image")
243+
public ResponseEntity<Void> deleteProfileImage(
244+
@Parameter(hidden = true)
245+
@AuthenticationPrincipal Long userId) {
246+
247+
userService.deleteProfileImage(userId);
248+
return ResponseEntity.ok().build();
249+
}
185250
}

src/main/java/ita/tinybite/domain/user/entity/User.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,12 @@ public void withdraw() {
9898
public boolean isWithdrawn() {
9999
return this.status == UserStatus.WITHDRAW;
100100
}
101+
102+
public void updateProfileImage(String image) {
103+
this.profileImage = image;
104+
}
105+
106+
public void deleteProfileImage() {
107+
this.profileImage = "";
108+
}
101109
}

src/main/java/ita/tinybite/domain/user/service/UserService.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,20 @@ public List<PartyCardResponse> getParticipatingParties(Long userId) {
206206
})
207207
.collect(Collectors.toList());
208208
}
209+
210+
@Transactional
211+
public void updateProfileImage(Long userId, String image) {
212+
User user = userRepository.findById(userId)
213+
.orElseThrow(() -> new IllegalArgumentException("사용자를 찾을 수 없습니다"));
214+
215+
user.updateProfileImage(image);
216+
}
217+
218+
@Transactional
219+
public void deleteProfileImage(Long userId) {
220+
User user = userRepository.findById(userId)
221+
.orElseThrow(() -> new IllegalArgumentException("사용자를 찾을 수 없습니다"));
222+
223+
user.deleteProfileImage();
224+
}
209225
}

0 commit comments

Comments
 (0)