Skip to content

Commit

Permalink
Type: 회원 프로필 이미지 수정 기능 추가 (#45)
Browse files Browse the repository at this point in the history
[Feat] User 프로필 이미지 수정 기능 추가
  • Loading branch information
pingowl authored Oct 17, 2023
2 parents 368e9ef + 1fc117b commit ca10f33
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/main/java/igoMoney/BE/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import igoMoney.BE.dto.request.UserUpdateRequest;
import igoMoney.BE.dto.response.NotificationResponse;
import igoMoney.BE.dto.response.RecordResponse;
import igoMoney.BE.dto.response.UserResponse;
import igoMoney.BE.service.UserService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
//import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
Expand Down Expand Up @@ -44,7 +43,7 @@ public ResponseEntity<Void> checkNicknameDuplicate(@PathVariable("nickname") Str

// 회원정보 수정
@PatchMapping("")
public ResponseEntity<Void> updateUser(UserUpdateRequest request) throws IOException {
public ResponseEntity<Void> updateUser(@Valid UserUpdateRequest request) throws IOException {

userService.updateUser(request);

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/igoMoney/BE/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ public String getPassword() {


// 회원관리
public void updateUser(UserUpdateRequest request) {
public void updateUser(UserUpdateRequest request, String imageUrl) {
this.nickname = request.getNickname();
if(request.getImageChanged()){
this.image = imageUrl;
}
}
public void updateUser(Boolean inChallenge, Long myChallengeId) {
public void updateUserStatus(Boolean inChallenge, Long myChallengeId) {
this.inChallenge = inChallenge;
this.myChallengeId = myChallengeId;
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/igoMoney/BE/dto/request/UserUpdateRequest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package igoMoney.BE.dto.request;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import org.springframework.web.multipart.MultipartFile;

@Getter
@Setter
Expand All @@ -12,7 +14,9 @@ public class UserUpdateRequest {

@NotNull
private Long id;
@NotEmpty
private String nickname;
// private MultipartFile image;
// private Boolean isChanged; // image 수정 여부 체크. true면 이미지 수정된 것.
private MultipartFile image;
@NotNull
private Boolean imageChanged; // 프로필 이미지 변경 여부
}
10 changes: 5 additions & 5 deletions src/main/java/igoMoney/BE/service/ChallengeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Long createChallenge(ChallengeCreateRequest request) {
challengeRepository.save(challenge);
// 회원 - 챌린지 참여중으로 상태 변경
// 회원 - 현재 진행중인 챌린지 저장
findUser.updateUser(true, challenge.getId());
findUser.updateUserStatus(true, challenge.getId());
findUser.addChallengeCount();

ChallengeUser challengeUser = ChallengeUser.builder()
Expand All @@ -131,7 +131,7 @@ public void applyChallenge(Long userId, Long challengeId) {
throw new CustomException(ErrorCode.EXIST_USER_CHALLENGE);
}
Challenge findChallenge = getChallengeOrThrow(challengeId);
findUser.updateUser(true, challengeId); // 챌린지 참여 정보 업데이트
findUser.updateUserStatus(true, challengeId); // 챌린지 참여 정보 업데이트
findUser.addChallengeCount();

ChallengeUser challengeUser = ChallengeUser.builder()
Expand Down Expand Up @@ -178,14 +178,14 @@ private void cancelChallenge(User user) {
Challenge findChallenge = getChallengeOrThrow(user.getMyChallengeId());

findChallenge.stopChallenge(); // 챌린지 중단 설정
user.updateUser(false, null); // 사용자 챌린지 상태 변경
user.updateUserStatus(false, null); // 사용자 챌린지 상태 변경

User user2 = getChallengeOtherUser(user.getMyChallengeId(), user.getId());
if (user2 == null){ return;} // 상대방 없을 때

// 상대방 있을 때
user.deleteBadge(); // 뱃지 개수 차감하기
user2.updateUser(false, null); // 상대방 챌린지 상태 변경
user2.updateUserStatus(false, null); // 상대방 챌린지 상태 변경
user2.addBadge();
user2.addWinCount();
findChallenge.setWinner(user2.getId());
Expand Down Expand Up @@ -262,7 +262,7 @@ else if (((BigDecimal) obj[1]).intValue() < minCost){
User lose = getChallengeOtherUser(c.getId(), winnerId);
for(User u : userList) {
// 유저 : 챌린지 종료로 설정
u.updateUser(false, null);
u.updateUserStatus(false, null);

if (u.getId().equals(winnerId)) {
// 챌린지 승리자
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/igoMoney/BE/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class UserService {

private final UserRepository userRepository;
private final NotificationRepository notificationRepository;
private final ImageService imageService;

// 회원 정보 조회
@Transactional(readOnly = true)
Expand Down Expand Up @@ -55,16 +56,23 @@ public void checkNicknameDuplicate(String nickname) {
}


// 닉네임 변경하기 (회원가입 시 애플은 빈칸으로 가입됨. 닉네임 설정 후 홈화면 나옴)
// 회원정보 변경하기 (회원가입 시 애플은 빈칸으로 가입됨. 닉네임 설정 후 홈화면 나옴)
public void updateUser(UserUpdateRequest request) throws IOException {

User findUser = getUserOrThrow(request.getId());
String image = null;

if (!request.getNickname().equals(findUser.getNickname())) {
checkNicknameDuplicate(request.getNickname());
}
if(request.getImageChanged()){
if(request.getImage().isEmpty() || request.getImage() == null){
throw new CustomException(ErrorCode.SHOULD_EXIST_IMAGE);
}
image = imageService.uploadImage(request.getImage());
}

findUser.updateUser(request);
findUser.updateUser(request, image);
}

// 확인 안한 알림 목록 조회
Expand Down

0 comments on commit ca10f33

Please sign in to comment.