diff --git a/src/main/java/com/wooyeon/yeon/user/controller/ProfileController.java b/src/main/java/com/wooyeon/yeon/user/controller/ProfileController.java new file mode 100644 index 0000000..4369b5d --- /dev/null +++ b/src/main/java/com/wooyeon/yeon/user/controller/ProfileController.java @@ -0,0 +1,50 @@ +package com.wooyeon.yeon.user.controller; + +import com.wooyeon.yeon.common.security.SecurityService; +import com.wooyeon.yeon.user.domain.Profile; +import com.wooyeon.yeon.user.dto.FindProfileResponseDto; +import com.wooyeon.yeon.user.dto.ProfileRequestDto; +import com.wooyeon.yeon.user.dto.InsertProfileResponseDto; +import com.wooyeon.yeon.user.service.ProfileService; +import lombok.RequiredArgsConstructor; +import lombok.extern.log4j.Log4j2; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.List; + +@RestController +@RequiredArgsConstructor +@Log4j2 +public class ProfileController { + + private final ProfileService profileService; + private final SecurityService securityService; + + /** 프로필 등록 API */ + @PostMapping(value = "/users/register/profile") + public ResponseEntity createProfile(@RequestPart(value = "profileInfo") ProfileRequestDto profileRequestDto, + @RequestPart(value = "profilePhoto", required = false) List profilePhotoUpload) throws IOException { + InsertProfileResponseDto insertProfileResponseDto = profileService.insertProfile(profileRequestDto, profilePhotoUpload); + return ResponseEntity.ok(insertProfileResponseDto); + } + + /** 프로필 조회 API */ + @GetMapping("/users/profile") + public ResponseEntity findProfile() { + String loginEmail = securityService.getCurrentUserEmail(); + return ResponseEntity.ok(profileService.findProfile(loginEmail)); + } + + /** GPS 수신 API */ + @PostMapping(value = "/users/profile/gps", produces = "application/json;charset=UTF-8") + public ResponseEntity receiveUsersGps(@RequestBody String gpsLocation) { +// String accessToken = parseBearerToken(request); + String loginEmail = securityService.getCurrentUserEmail(); + log.info("loginEmail : {}", loginEmail); + return ResponseEntity.ok(profileService.updateUsersGpsLocation(loginEmail, gpsLocation)); + } +} diff --git a/src/main/java/com/wooyeon/yeon/user/controller/UserController.java b/src/main/java/com/wooyeon/yeon/user/controller/UserController.java index fdefa4a..d696f06 100644 --- a/src/main/java/com/wooyeon/yeon/user/controller/UserController.java +++ b/src/main/java/com/wooyeon/yeon/user/controller/UserController.java @@ -51,7 +51,7 @@ public class UserController { @Value("${email-auth-background-image}") private String emailAuthBackgroundImg; - // 사용자에게 인증메일 전송 및 프론트엔드와 SSE 연결 + /** 사용자에게 인증메일 전송 및 프론트엔드와 SSE 연결 */ @PostMapping(value = "/auth/email", produces = "application/json;charset=UTF-8") public SseEmitter sendEmailVerify(@RequestBody EmailRequestDto emailRequestDto) throws MessagingException { SseEmitter emitter = new SseEmitter(Long.MAX_VALUE); @@ -72,7 +72,7 @@ public SseEmitter sendEmailVerify(@RequestBody EmailRequestDto emailRequestDto) return emitter; } - // 사용자의 이메일 인증 (ModelAndView로 인증완료 페이지 html 보여주기) + /** 사용자의 이메일 인증 (ModelAndView로 인증완료 페이지 html 보여주기) */ @GetMapping(value = "/auth/email/verify") public ModelAndView verifyEmail(@RequestParam String auth) { @@ -88,7 +88,7 @@ public ModelAndView verifyEmail(@RequestParam String auth) { return mv; } - // RSA 공개키 전송 + /** RSA 공개키 전송 */ @GetMapping("/encrypt/key") public RsaPublicResponseDto sendRsaPublicKey() { RsaPublicResponseDto rsaPublicResponseDto = userService.sendRsaPublicKey(); @@ -96,7 +96,7 @@ public RsaPublicResponseDto sendRsaPublicKey() { return rsaPublicResponseDto; } - // 암호화된 비밀번호와 RSA 공개키로 암호화된 AES 복호화 키 전달 + /** 암호화된 비밀번호와 RSA 공개키로 암호화된 AES 복호화 키 전달 */ @PostMapping("/encrypt/pw") public PasswordEncryptResponseDto passwordEncrypt(@RequestBody PasswordEncryptRequestDto passwordEncryptRequestDto) throws Exception { @@ -104,15 +104,7 @@ public PasswordEncryptResponseDto passwordEncrypt(@RequestBody PasswordEncryptRe return passwordEncryptResponseDto; } - // 프로필 등록 - @PostMapping(value = "/users/register/profile") - public ResponseEntity createProfile(@RequestPart(value = "profileInfo") ProfileRequestDto profileRequestDto, - @RequestPart(value = "profilePhoto", required = false) List profilePhotoUpload) throws IOException { - ProfileResponseDto profileResponseDto = profileService.insertProfile(profileRequestDto, profilePhotoUpload); - return ResponseEntity.ok(profileResponseDto); - } - - // accessToken 검증 + /** accessToken 검증 */ @GetMapping("/users/profile-state") public ResponseEntity checkExpiredTokenAndProfile(HttpServletRequest request) { String accessToken = parseBearerToken(request); @@ -120,23 +112,14 @@ public ResponseEntity checkExpiredTokenAnd return ResponseEntity.ok(loginService.checkTokenAndProfile(accessToken)); } - // GPS 수신 API - @PostMapping(value = "/users/profile/gps", produces = "application/json;charset=UTF-8") - public ResponseEntity receiveUsersGps(@RequestBody String gpsLocation) { -// String accessToken = parseBearerToken(request); - String loginEmail = securityService.getCurrentUserEmail(); - log.info("loginEmail : {}", loginEmail); - return ResponseEntity.ok(profileService.updateUsersGpsLocation(loginEmail, gpsLocation)); - } - - // 사용자의 휴대폰으로 인증번호 전송 + /** 사용자의 휴대폰으로 인증번호 전송 */ @PostMapping(value = "/auth/phone", produces = "application/json;charset=UTF-8") public ResponseEntity sendSmsVerify(@RequestBody PhoneInfoRequestDto phoneInfoRequestDto) throws UnsupportedEncodingException, URISyntaxException, NoSuchAlgorithmException, InvalidKeyException, JsonProcessingException { SmsAuthResponseDto responseDto = smsAuthService.sendSms(phoneInfoRequestDto); return ResponseEntity.ok().body(responseDto); } - // 인증번호 확인 + /** 인증번호 확인 */ @PostMapping(value = "/auth/phone/verify", produces = "application/json;charset=UTF-8") public ResponseEntity verifyPhone(@RequestBody PhoneAuthRequestDto phoneAuthRequestDto) throws UnsupportedEncodingException, URISyntaxException, NoSuchAlgorithmException, InvalidKeyException, JsonProcessingException { PhoneAuthResponseDto responseDto = smsAuthService.verifyPhone(phoneAuthRequestDto); @@ -144,7 +127,7 @@ public ResponseEntity verifyPhone(@RequestBody PhoneAuthRe } - // 이메일 인증 시, 프론트엔드에게 SSE emitter로 인증완료 전송 + /** 이메일 인증 시, 프론트엔드에게 SSE emitter로 인증완료 전송 */ public SseEmitter sendSseEmitter(EmailAuthResponseDto emailAuthResponseDto) { SseEmitter emitter = userEmitters.get(emailAuthResponseDto.getEmail()); diff --git a/src/main/java/com/wooyeon/yeon/user/dto/FindProfileResponseDto.java b/src/main/java/com/wooyeon/yeon/user/dto/FindProfileResponseDto.java new file mode 100644 index 0000000..24b981d --- /dev/null +++ b/src/main/java/com/wooyeon/yeon/user/dto/FindProfileResponseDto.java @@ -0,0 +1,25 @@ +package com.wooyeon.yeon.user.dto; + +import com.wooyeon.yeon.user.domain.ProfilePhoto; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +import java.util.List; +import java.util.UUID; + +@Builder +@AllArgsConstructor +@Getter +public class FindProfileResponseDto { + private char gender; + private String nickname; + private String birthday; + private String locationInfo; + private String gpsLocationInfo; + private String mbti; + private String intro; + private String hobby; + private String interest; + private List profilePhotos; +} diff --git a/src/main/java/com/wooyeon/yeon/user/dto/ProfileResponseDto.java b/src/main/java/com/wooyeon/yeon/user/dto/InsertProfileResponseDto.java similarity index 86% rename from src/main/java/com/wooyeon/yeon/user/dto/ProfileResponseDto.java rename to src/main/java/com/wooyeon/yeon/user/dto/InsertProfileResponseDto.java index 2bbcb49..c72fa70 100644 --- a/src/main/java/com/wooyeon/yeon/user/dto/ProfileResponseDto.java +++ b/src/main/java/com/wooyeon/yeon/user/dto/InsertProfileResponseDto.java @@ -9,7 +9,7 @@ @AllArgsConstructor @Getter @Builder -public class ProfileResponseDto { +public class InsertProfileResponseDto { private int statusCode; private String statusName; } diff --git a/src/main/java/com/wooyeon/yeon/user/repository/ProfilePhotoRepository.java b/src/main/java/com/wooyeon/yeon/user/repository/ProfilePhotoRepository.java index 3da6c19..569a623 100644 --- a/src/main/java/com/wooyeon/yeon/user/repository/ProfilePhotoRepository.java +++ b/src/main/java/com/wooyeon/yeon/user/repository/ProfilePhotoRepository.java @@ -4,9 +4,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; @Repository public interface ProfilePhotoRepository extends JpaRepository { Optional findByProfileId(Long profileId); + + List findByProfile_Id(Long profileId); } diff --git a/src/main/java/com/wooyeon/yeon/user/repository/ProfileRepository.java b/src/main/java/com/wooyeon/yeon/user/repository/ProfileRepository.java index 9e0108d..37c42d7 100644 --- a/src/main/java/com/wooyeon/yeon/user/repository/ProfileRepository.java +++ b/src/main/java/com/wooyeon/yeon/user/repository/ProfileRepository.java @@ -12,5 +12,4 @@ public interface ProfileRepository extends JpaRepository { Optional findByNicknameContains(String searchWord); Optional findByUser(User user); - } diff --git a/src/main/java/com/wooyeon/yeon/user/service/ProfileService.java b/src/main/java/com/wooyeon/yeon/user/service/ProfileService.java index d7ce941..a043cc0 100644 --- a/src/main/java/com/wooyeon/yeon/user/service/ProfileService.java +++ b/src/main/java/com/wooyeon/yeon/user/service/ProfileService.java @@ -6,8 +6,9 @@ import com.wooyeon.yeon.user.domain.Profile; import com.wooyeon.yeon.user.domain.ProfilePhoto; import com.wooyeon.yeon.user.domain.User; +import com.wooyeon.yeon.user.dto.FindProfileResponseDto; import com.wooyeon.yeon.user.dto.ProfileRequestDto; -import com.wooyeon.yeon.user.dto.ProfileResponseDto; +import com.wooyeon.yeon.user.dto.InsertProfileResponseDto; import com.wooyeon.yeon.user.repository.ProfilePhotoRepository; import com.wooyeon.yeon.user.repository.ProfileRepository; import com.wooyeon.yeon.user.repository.UserRepository; @@ -16,9 +17,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.core.Authentication; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; @@ -30,6 +29,7 @@ import javax.transaction.Transactional; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -69,7 +69,7 @@ private S3Client createS3Client() { return s3Client; } - public ProfileResponseDto insertProfile(ProfileRequestDto profileRequestDto, List profilePhotoUpload) throws IOException { + public InsertProfileResponseDto insertProfile(ProfileRequestDto profileRequestDto, List profilePhotoUpload) throws IOException { // token에서 user 정보 추출하기 String userEmail = securityService.getCurrentUserEmail(); log.info("추출한 user Email : {}", userEmail); @@ -96,11 +96,11 @@ public ProfileResponseDto insertProfile(ProfileRequestDto profileRequestDto, Lis S3Client s3Client = createS3Client(); lightsailFileUpload(profile, s3Client, profilePhotoUpload); - ProfileResponseDto profileResponseDto = ProfileResponseDto.builder() + InsertProfileResponseDto insertProfileResponseDto = InsertProfileResponseDto.builder() .statusCode(202) .statusName("success") .build(); - return profileResponseDto; + return insertProfileResponseDto; } void lightsailFileUpload(Profile profile, S3Client s3Client, List profilePhotoUpload) throws IOException { @@ -132,19 +132,36 @@ void lightsailFileUpload(Profile profile, S3Client s3Client, List @Transactional public HttpStatus updateUsersGpsLocation(String userEmail, String gpsLocation) { -// Authentication authentication = authenticationManagerBuilder.getObject().authenticate(accessToken); User user = userRepository.findByEmail(userEmail); Profile profile = profileRepository.findByUser(user) .orElseThrow(() -> new WooyeonException(ExceptionCode.PROFILE_NOT_FOUND)); - -// Profile profile = profileRepository.findByUserDomain(user); - log.info("user 정보(gps): {}", profile.getId()); - log.info("gpsLocation: {}", gpsLocation); - profile.updateGpsLocationInfo(gpsLocation); - log.info("gpsLocationInfo: {}", profile.getGpsLocationInfo()); return HttpStatus.OK; } + + public FindProfileResponseDto findProfile(String email) { + User user = userRepository.findByEmail(email); + Profile profile = profileRepository.findByUser(user) + .orElseThrow(() -> new WooyeonException(ExceptionCode.PROFILE_NOT_FOUND)); + + List profilePhotoList = profilePhotoRepository.findByProfile_Id(profile.getId()); + List profilePhotos = new ArrayList<>(); + for(int i=0; i