Skip to content

Commit

Permalink
feat: mypage api 추가 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
JONG-KYEONG committed Aug 13, 2024
1 parent fcc2dc3 commit 2379a6b
Show file tree
Hide file tree
Showing 24 changed files with 85 additions and 9 deletions.
Binary file modified server/.gradle/8.8/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified server/.gradle/8.8/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified server/.gradle/8.8/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified server/.gradle/8.8/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified server/.gradle/8.8/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified server/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion server/build/resources/main/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ app.GitHub.gitHubToken=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
#AWS
cloud.aws.credentials.accessKey=AKIA6ODUZVK7N2P6RB6C
cloud.aws.credentials.secretKey=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
cloud.aws.s3.bucket=glog-image-bucket
cloud.aws.s3.bucket=hackathon-be-bucket
cloud.aws.region.static=ap-northeast-2
cloud.aws.stack.auto=false

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified server/build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.hackathon.user.application;

import com.example.hackathon.exception.BadRequestException;
import com.example.hackathon.user.domain.User;
import com.example.hackathon.user.dto.UserInfoResponse;
import com.example.hackathon.user.repository.UserRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
@AllArgsConstructor
@Service
public class MypageService {
private final UserRepository userRepository;
public UserInfoResponse getUserInfo(Long userId){
User user = userRepository.findById(userId)
.orElseThrow(() -> new BadRequestException("유저 토큰 값을 다시 확인해주세요"));
UserInfoResponse userInfoResponse = UserInfoResponse.builder()
.email(user.getEmail())
.profileImage(user.getImageUrl())
.username(user.getName())
.build();
return userInfoResponse;
}

public String updateUserName(Long userId, String nickName){
User user = userRepository.findById(userId)
.orElseThrow(() -> new BadRequestException("유저 토큰 값을 다시 확인해주세요"));
user.setName(nickName);
userRepository.save(user);
return "success update nickname";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.hackathon.user.controller;

import com.example.hackathon.exception.ResourceNotFoundException;
import com.example.hackathon.oauth.security.CurrentUser;
import com.example.hackathon.user.application.MypageService;
import com.example.hackathon.user.domain.User;
import com.example.hackathon.user.dto.UserInfoResponse;
import com.example.hackathon.user.repository.UserRepository;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@AllArgsConstructor
@RequestMapping("/api/mypage")
public class MypageController {
private final MypageService mypageService;
@GetMapping("/info")
@Operation(summary = "유저 정보를 가져옵니다." ,description = "userId를 파라미터로 넣어주세요")
public ResponseEntity<UserInfoResponse> getUserInfo(@RequestParam Long userId) {
return new ResponseEntity<>(mypageService.getUserInfo(userId), HttpStatus.OK);
}

@PutMapping("/update/nickname")
@Operation(summary = "유저 닉네임 수정 입니다. " ,description = "userId, 수정할 닉네임을 파라미터로 넣어주세요")
public ResponseEntity<String> updateUserInfo(@RequestParam Long userId,
@RequestParam String nickname){
return new ResponseEntity<>(mypageService.updateUserName(userId,nickname), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
@RestController
public class UserController {

@Autowired
private UserRepository userRepository;
// @Autowired
// private UserRepository userRepository;

@GetMapping("/user/me")
@PreAuthorize("hasRole('USER')")
public User getCurrentUser(@CurrentUser UserPrincipal userPrincipal) {
return userRepository.findById(userPrincipal.getId())
.orElseThrow(() -> new ResourceNotFoundException("User", "id", userPrincipal.getId()));
}
// @GetMapping("/user/me")
// @PreAuthorize("hasRole('USER')")
// public User getCurrentUser(@CurrentUser UserPrincipal userPrincipal) {
// return userRepository.findById(userPrincipal.getId())
// .orElseThrow(() -> new ResourceNotFoundException("User", "id", userPrincipal.getId()));
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.hackathon.user.dto;

import lombok.Builder;

@Builder
public record UserInfoResponse(
String username,
String email,
String profileImage
) {
}

0 comments on commit 2379a6b

Please sign in to comment.