-
Notifications
You must be signed in to change notification settings - Fork 2
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 #23 from GDSC-snowflowerthon/feat/changeInfo-22
[feat] 마이페이지
- Loading branch information
Showing
5 changed files
with
97 additions
and
0 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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/ALGo/ALGo_server/mypage/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,28 @@ | ||
package com.ALGo.ALGo_server.mypage.Controller; | ||
|
||
import com.ALGo.ALGo_server.entity.User; | ||
import com.ALGo.ALGo_server.mypage.Dto.ChangeInfoRequestDto; | ||
import com.ALGo.ALGo_server.mypage.Dto.MyInfoResponseDto; | ||
import com.ALGo.ALGo_server.mypage.Service.MyPageService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/mypage") | ||
public class MyPageController { | ||
private final MyPageService myPageService; | ||
|
||
@GetMapping() | ||
public MyInfoResponseDto getMyInfo(@AuthenticationPrincipal User user){ | ||
return myPageService.getMyInfo(user); | ||
} | ||
|
||
@PutMapping("/change") | ||
public ResponseEntity changeInfo(@AuthenticationPrincipal User user, @RequestBody ChangeInfoRequestDto requestDto){ | ||
return myPageService.changeInfo(user, requestDto); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/ALGo/ALGo_server/mypage/Dto/ChangeInfoRequestDto.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,10 @@ | ||
package com.ALGo.ALGo_server.mypage.Dto; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ChangeInfoRequestDto { | ||
private String language; | ||
private String city; | ||
private String gu; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/ALGo/ALGo_server/mypage/Dto/MyInfoResponseDto.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,15 @@ | ||
package com.ALGo.ALGo_server.mypage.Dto; | ||
|
||
import com.ALGo.ALGo_server.entity.User; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class MyInfoResponseDto { | ||
private String email; | ||
private String language; | ||
private String city; | ||
private String gu; | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/ALGo/ALGo_server/mypage/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,36 @@ | ||
package com.ALGo.ALGo_server.mypage.Service; | ||
|
||
import com.ALGo.ALGo_server.entity.User; | ||
import com.ALGo.ALGo_server.mypage.Dto.ChangeInfoRequestDto; | ||
import com.ALGo.ALGo_server.mypage.Dto.MyInfoResponseDto; | ||
import com.ALGo.ALGo_server.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MyPageService { | ||
private final UserRepository userRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public MyInfoResponseDto getMyInfo(User user){ | ||
MyInfoResponseDto responseDto = MyInfoResponseDto.builder() | ||
.email(user.getEmail()) | ||
.language(user.getLanguage()) | ||
.city(user.getCity()) | ||
.gu(user.getGu()) | ||
.build(); | ||
return responseDto; | ||
} | ||
|
||
@Transactional | ||
public ResponseEntity changeInfo(User user, ChangeInfoRequestDto requestDto){ | ||
user.updateInfo(requestDto); | ||
userRepository.save(user); | ||
return new ResponseEntity(HttpStatus.OK); | ||
} | ||
} |