-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from KAKAO-TOUR-API-CONTEST/develop
FIX : PathVariable -> requestParams
- Loading branch information
Showing
8 changed files
with
206 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/java/com/example/ai_jeju/controller/MyPageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.example.ai_jeju.controller; | ||
|
||
import com.example.ai_jeju.domain.User; | ||
import com.example.ai_jeju.service.MyPageService; | ||
import com.example.ai_jeju.service.S3Service; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import static org.springframework.data.jpa.domain.AbstractPersistable_.id; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
public class MyPageController { | ||
|
||
@Autowired | ||
private MyPageService myPageService; | ||
@Autowired | ||
private S3Service s3Service; | ||
|
||
//마이페이지 회원 1명씩 조회 | ||
@GetMapping("/mypage") | ||
public ResponseEntity<User> getUserById(@RequestParam Long userId) { | ||
Optional<User> user = myPageService.getUserById(userId); | ||
if (user.isPresent()) { | ||
return ResponseEntity.ok(user.get()); | ||
} else { | ||
return ResponseEntity.notFound().build(); | ||
} | ||
} | ||
|
||
|
||
@PutMapping("/mypage/nickname") | ||
public ResponseEntity<String> updateNickname(@RequestParam Long userId, @RequestBody Map<String, String> request) { | ||
String nickname = request.get("nickname"); | ||
myPageService.updateNickname(userId, nickname); | ||
return ResponseEntity.ok("Nickname changed"); | ||
} | ||
|
||
//sns프로필 사용하기로 했었나? 사용하면 user쪽에 entity변수 하나 추가해서 해야함 | ||
/* | ||
@PutMapping("/mypage/snsprofile") | ||
public ResponseEntity<String> updateSnsProfile(@RequestParam Long userId, @RequestBody Map<String, String> request) { | ||
String snsprofile = request.get("snsprofile"); | ||
myPageService.updateSnsProfile(id, snsprofile); | ||
return ResponseEntity.ok("snsprofile change"); | ||
}*/ | ||
|
||
//프로필 이미지 변경 | ||
@PutMapping("/mypage/profileimg") | ||
public ResponseEntity<String> updateProfileImage(@RequestParam Long userId, @RequestBody Map<String, String> request) { | ||
String profileimg = request.get("profileimg"); | ||
myPageService.updateProfile(userId, profileimg); | ||
return ResponseEntity.ok("success"); | ||
} | ||
|
||
/* | ||
@DeleteMapping("/mypage/snsprofile") | ||
public ResponseEntity<String> deleteSnsProfile(@RequestParam Long id) { | ||
myPageService.deleteSnsProfile(id); | ||
return ResponseEntity.ok("deleted"); | ||
}*/ | ||
|
||
@DeleteMapping("/mypage/profileimg") | ||
public ResponseEntity<String> deleteProfileImage(@RequestParam Long userId) { | ||
myPageService.deleteProfileImage(userId); | ||
return ResponseEntity.ok("deleted"); | ||
} | ||
|
||
@PostMapping("/mypage/presign") | ||
public ResponseEntity<String> createPresignedUrl(@RequestBody Map<String, String> request) { | ||
String filePath = request.get("filePath"); | ||
String presignedUrl = s3Service.createPresignedUrl(filePath); | ||
return ResponseEntity.ok(presignedUrl); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/com/example/ai_jeju/service/MyPageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.example.ai_jeju.service; | ||
|
||
import com.example.ai_jeju.domain.User; | ||
import com.example.ai_jeju.repository.UserRepository; | ||
import jakarta.transaction.Transactional; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.NoSuchElementException; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class MyPageService { | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
@Autowired | ||
private S3Service s3Service; | ||
|
||
//마이페이지 회원 한명 id로 찾기 | ||
public Optional<User> getUserById(Long id) { | ||
return userRepository.findById(id); | ||
} | ||
|
||
public void updateNickname(Long id, String nickname) { | ||
User user = userRepository.findById(id) | ||
.orElseThrow(() -> new RuntimeException("User not found")); | ||
user.setNickname(nickname); | ||
userRepository.save(user); | ||
} | ||
|
||
public void updateSnsProfile(Long id, String snsprofile) { | ||
User user = userRepository.findById(id) | ||
.orElseThrow(() -> new RuntimeException("User not found")); | ||
user.setSnsprofile(snsprofile); | ||
userRepository.save(user); | ||
} | ||
|
||
@Transactional | ||
public void updateProfile(Long id, String profileimg) { | ||
User user = userRepository.findById(id) | ||
.orElseThrow(() -> new RuntimeException("User not found")); | ||
user.setProfileimg(profileimg); // S3에 업로드된 이미지의 URL을 프로필 이미지로 설정 | ||
userRepository.save(user); | ||
} | ||
|
||
//프로필 이미지 반환 | ||
public String getProfileUrl(Long id) { | ||
User user = userRepository.findById(id) | ||
.orElseThrow(() -> new RuntimeException("Profile not found")); | ||
return user.getProfileimg(); // 프로필 이미지 URL 반환 | ||
} | ||
|
||
public void deleteSnsProfile(Long id) { | ||
Optional<User> userOptional = userRepository.findById(id); | ||
if (userOptional.isPresent()) { | ||
User user = userOptional.get(); | ||
user.setSnsprofile(null); | ||
userRepository.save(user); | ||
} else { | ||
throw new NoSuchElementException("not found"); | ||
} | ||
} | ||
|
||
public void deleteProfileImage(Long id) { | ||
Optional<User> userOptional = userRepository.findById(id); | ||
if (userOptional.isPresent()) { | ||
User user = userOptional.get(); | ||
user.setProfileimg(null); | ||
userRepository.save(user); | ||
} else { | ||
throw new NoSuchElementException("not found"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.example.ai_jeju.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
import software.amazon.awssdk.services.s3.presigner.S3Presigner; | ||
import software.amazon.awssdk.services.s3.presigner.model.PutObjectPresignRequest; | ||
|
||
import java.time.Duration; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class S3Service { | ||
|
||
@Value("${spring.cloud.aws.s3.bucket}") | ||
private String bucket; | ||
private final S3Presigner s3Presigner; | ||
|
||
public String createPresignedUrl(String path) { | ||
var putObjectRequest = PutObjectRequest.builder() | ||
.bucket(bucket) | ||
.key(path) | ||
.build(); | ||
var preSignRequest = PutObjectPresignRequest.builder() | ||
.signatureDuration(Duration.ofMinutes(10)) | ||
.putObjectRequest(putObjectRequest) | ||
.build(); | ||
return s3Presigner.presignPutObject(preSignRequest).url().toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,8 @@ [email protected] | |
jwt.secret_key= aijejubackend | ||
react.app.url=http://localhost:3000 | ||
|
||
|
||
spring.cloud.aws.credentials.accessKey=${AWS_ACCESS_KEY_ID} | ||
spring.cloud.aws.credentials.secretKey=${AWS_SECRET_KEY} | ||
spring.cloud.aws.s3.bucket=ai-jeju | ||
spring.cloud.aws.region.static=ap-northeast-2 |
4da8797
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확인했습니다.