-
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.
.
- Loading branch information
Showing
6 changed files
with
156 additions
and
4 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
53 changes: 53 additions & 0 deletions
53
src/main/java/HookKiller/server/user/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,53 @@ | ||
package HookKiller.server.user.controller; | ||
|
||
import HookKiller.server.board.dto.ArticleRequestDto; | ||
import HookKiller.server.board.entity.Article; | ||
import HookKiller.server.board.entity.ArticleContent; | ||
import HookKiller.server.board.service.ArticleContentService; | ||
import HookKiller.server.user.dto.MyPageRequestDto; | ||
import HookKiller.server.user.service.MyPageService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/mypage") | ||
@RequiredArgsConstructor | ||
public class MypageController { | ||
|
||
private final MyPageService myPageService; | ||
private final ArticleContentService articleContentService; | ||
|
||
/** | ||
* 마이페이지 조회 | ||
* @param userId | ||
* @return | ||
*/ | ||
@GetMapping("/{userId}") | ||
public MyPageRequestDto getMyPage(Long userId) { | ||
return myPageService.getMyPage(userId); | ||
} | ||
|
||
/** | ||
* 정보 수정 | ||
* @param requestDto | ||
*/ | ||
@PutMapping | ||
public void updatePasswordAndNickname(@RequestBody MyPageRequestDto requestDto) { | ||
myPageService.updatePasswordAndNickname(requestDto); | ||
} | ||
|
||
/** | ||
* 마이페이지 내가쓴 글 | ||
* | ||
*/ | ||
@GetMapping("/{myList}") | ||
public List<ArticleRequestDto> getMyList(Long userId) { | ||
return myPageService.getMyList(userId); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/HookKiller/server/user/dto/MyPageRequestDto.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,28 @@ | ||
package HookKiller.server.user.dto; | ||
|
||
import HookKiller.server.user.entity.User; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
public class MyPageRequestDto { | ||
|
||
private Long userId; | ||
private String email; | ||
private String password; | ||
private String thumbnail; | ||
private String nickName; | ||
|
||
public static MyPageRequestDto from(User user) { | ||
return MyPageRequestDto.builder() | ||
.userId(user.getId()) | ||
.email(user.getEmail()) | ||
.password(user.getPassword()) | ||
.thumbnail(user.getThumbnail()) | ||
.nickName(user.getNickName()) | ||
.build(); | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
src/main/java/HookKiller/server/user/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,63 @@ | ||
package HookKiller.server.user.service; | ||
|
||
import HookKiller.server.auth.exception.UserNotFoundException; | ||
import HookKiller.server.board.dto.ArticleRequestDto; | ||
import HookKiller.server.common.util.UserUtils; | ||
import HookKiller.server.user.dto.MyPageRequestDto; | ||
import HookKiller.server.user.entity.User; | ||
import HookKiller.server.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class MyPageService { | ||
|
||
private final UserUtils userUtils; | ||
private final UserRepository userRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public MyPageRequestDto getMyPage(Long userId) { | ||
// 로그인한 사용자 정보를 가져옴 | ||
User user = userUtils.getUser(); | ||
|
||
User requestUser = userRepository.findById(userId).orElseThrow(() -> UserNotFoundException.EXCEPTION); | ||
|
||
if (user.getId().equals(requestUser.getId())) { | ||
return MyPageRequestDto.from(requestUser); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Transactional | ||
public void updatePasswordAndNickname(MyPageRequestDto myPageRequestDto) { | ||
User user = userUtils.getUser(); | ||
|
||
User requestUser = userRepository.findById(myPageRequestDto.getUserId()) | ||
.orElseThrow(()-> UserNotFoundException.EXCEPTION); | ||
|
||
if (myPageRequestDto.getPassword() != null) { | ||
requestUser.setPassword(myPageRequestDto.getPassword()); | ||
} | ||
if (myPageRequestDto.getNickName() != null) { | ||
requestUser.setNickName(myPageRequestDto.getNickName()); | ||
} | ||
|
||
userRepository.save(requestUser); | ||
|
||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<ArticleRequestDto> getMyList(Long userId) { | ||
return null; | ||
} | ||
|
||
|
||
|
||
} |