From 02aaf3b12b0a9ea0197fc83612d7542222e9a224 Mon Sep 17 00:00:00 2001 From: SeoSeunghun Date: Fri, 22 Jul 2022 20:02:47 +0900 Subject: [PATCH] =?UTF-8?q?[refactor][#53]=20Profile=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/AuthController.java | 7 +- .../user/controller/ProfileController.java | 65 +++---------------- .../user/controller/UserController.java | 16 +++++ 3 files changed, 30 insertions(+), 58 deletions(-) diff --git a/src/main/java/kr/startoff/backend/domain/user/controller/AuthController.java b/src/main/java/kr/startoff/backend/domain/user/controller/AuthController.java index 5c73328..19e0faf 100644 --- a/src/main/java/kr/startoff/backend/domain/user/controller/AuthController.java +++ b/src/main/java/kr/startoff/backend/domain/user/controller/AuthController.java @@ -12,7 +12,8 @@ import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import kr.startoff.backend.domain.user.dto.request.LoginRequest; -import kr.startoff.backend.domain.user.dto.request.RefreshOrLogoutRequest; +import kr.startoff.backend.domain.user.dto.request.LogoutRequest; +import kr.startoff.backend.domain.user.dto.request.RefreshRequest; import kr.startoff.backend.domain.user.dto.request.SignupRequest; import kr.startoff.backend.domain.user.dto.response.AccessTokenResponse; import kr.startoff.backend.global.common.dto.CommonResponse; @@ -46,13 +47,13 @@ public ResponseEntity login(@Valid @RequestBody LoginRequest logi } @PostMapping("/refresh") - public ResponseEntity getAccessToken(@RequestBody RefreshOrLogoutRequest request) { + public ResponseEntity getAccessToken(@RequestBody RefreshRequest request) { AccessTokenResponse accessTokenResponse = authService.refreshToken(request); return ResponseEntity.ok(accessTokenResponse); } @PostMapping("/logout") - public ResponseEntity logout(@RequestBody RefreshOrLogoutRequest request) { + public ResponseEntity logout(@RequestBody LogoutRequest request) { CommonResponse commonResponse = authService.logout(request); return ResponseEntity.ok(commonResponse); } diff --git a/src/main/java/kr/startoff/backend/domain/user/controller/ProfileController.java b/src/main/java/kr/startoff/backend/domain/user/controller/ProfileController.java index 3359c50..61cc361 100644 --- a/src/main/java/kr/startoff/backend/domain/user/controller/ProfileController.java +++ b/src/main/java/kr/startoff/backend/domain/user/controller/ProfileController.java @@ -7,70 +7,37 @@ import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; -import kr.startoff.backend.domain.user.dto.request.profile.BaekjoonIdRequest; -import kr.startoff.backend.domain.user.dto.request.profile.BlogUrlRequest; -import kr.startoff.backend.domain.user.dto.request.profile.GithubUrlRequest; -import kr.startoff.backend.domain.user.dto.request.profile.NicknameAndIntroduceRequest; -import kr.startoff.backend.domain.user.dto.request.profile.SkillTagRequest; +import kr.startoff.backend.domain.user.dto.request.ProfileRequest; +import kr.startoff.backend.domain.user.dto.request.SkillTagRequest; +import kr.startoff.backend.domain.user.service.ProfileService; import kr.startoff.backend.global.common.dto.CommonResponse; import kr.startoff.backend.domain.tag.dto.SkillTagResponse; import kr.startoff.backend.domain.user.dto.response.UserProfileResponse; import kr.startoff.backend.domain.tag.service.SkillTagService; -import kr.startoff.backend.domain.user.service.UserService; import lombok.RequiredArgsConstructor; @RestController @RequiredArgsConstructor @RequestMapping("/api/v1") public class ProfileController { - private final UserService userService; + private final ProfileService profileService; private final SkillTagService skillTagService; @GetMapping("/users/{userId}/profile") public ResponseEntity getUserProfile(@PathVariable Long userId) { - return ResponseEntity.ok(userService.getUserProfile(userId)); + return ResponseEntity.ok(profileService.getUserProfile(userId)); } - @PutMapping("/users/{userId}/introduce") - public ResponseEntity> updateUserNicknameAndIntroduce( - @PathVariable Long userId, - @RequestBody NicknameAndIntroduceRequest nicknameAndIntroduceRequest) { - String value = userService.updateNicknameAndIntroduce(userId, nicknameAndIntroduceRequest); - Map result = makeResponseBody("nickname", value); - result.put("introduce", nicknameAndIntroduceRequest.getIntroduce()); - return ResponseEntity.ok(result); - } - - @PutMapping("/users/{userId}/github-url") - public ResponseEntity> updateUserGithubUrl(@PathVariable Long userId, - @RequestBody GithubUrlRequest githubUrlRequest) { - String value = userService.updateGithubUrl(userId, githubUrlRequest); - Map result = makeResponseBody("github_url", value); - return ResponseEntity.ok(result); - } - - @PutMapping("/users/{userId}/blog-url") - public ResponseEntity> updateUserBlogUrl(@PathVariable Long userId, - @RequestBody BlogUrlRequest blogUrlRequest) { - String value = userService.updateBlogUrl(userId, blogUrlRequest); - Map result = makeResponseBody("blog_url", value); - return ResponseEntity.ok(result); - } - - @PutMapping("/users/{userId}/baekjoon-id") - public ResponseEntity> updateUserBaekjoonId(@PathVariable Long userId, - @RequestBody BaekjoonIdRequest baekjoonIdRequest) { - String value = userService.updateBaekjoonId(userId, baekjoonIdRequest); - Map result = makeResponseBody("baekjoon_id", value); - return ResponseEntity.ok(result); + @PutMapping("/users/{userId}/profile") + public ResponseEntity updateUserProfile(@PathVariable Long userId, + @RequestBody ProfileRequest profileRequest) { + UserProfileResponse response = profileService.updateProfile(userId, profileRequest); + return ResponseEntity.ok(response); } @PutMapping("/users/{userId}/skills") @@ -80,21 +47,9 @@ public ResponseEntity updateUserSkills(@PathVariable Long user return ResponseEntity.ok(skillTagResponse); } - @PostMapping("/users/{userId}/image") - public ResponseEntity updateUserProfileImage(@PathVariable Long userId, - @RequestPart("image") MultipartFile multipartFile) { - return ResponseEntity.ok(userService.updateUserProfileImage(userId, multipartFile)); - } - @DeleteMapping("/users/{userId}/skills/{skillId}") public ResponseEntity deleteUserSkill(@PathVariable Long userId, @PathVariable Long skillId) { skillTagService.deleteSkillTagToUser(userId, skillId); return ResponseEntity.ok(new CommonResponse(true, "해당 기술태그가 삭제되었습니다.")); } - - private Map makeResponseBody(String key, String value) { - Map result = new HashMap<>(); - result.put(key, value); - return result; - } } diff --git a/src/main/java/kr/startoff/backend/domain/user/controller/UserController.java b/src/main/java/kr/startoff/backend/domain/user/controller/UserController.java index 44bf231..c38b854 100644 --- a/src/main/java/kr/startoff/backend/domain/user/controller/UserController.java +++ b/src/main/java/kr/startoff/backend/domain/user/controller/UserController.java @@ -9,12 +9,16 @@ import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import kr.startoff.backend.domain.user.dto.request.NicknameRequest; import kr.startoff.backend.domain.user.dto.request.UserPasswordChangeRequest; import kr.startoff.backend.global.common.dto.CommonResponse; import kr.startoff.backend.domain.user.dto.response.UserInfoResponse; @@ -46,6 +50,18 @@ public ResponseEntity changeUserPassword(@PathVariable Long user return ResponseEntity.ok(result); } + @PostMapping("/users/{userId}/image") + public ResponseEntity updateUserNickname(@PathVariable Long userId, + @RequestPart("image") MultipartFile multipartFile) { + return ResponseEntity.ok(userService.updateUserProfileImage(userId, multipartFile)); + } + + @PutMapping("/users/{userId}/nickname") + public ResponseEntity updateUserNickname(@PathVariable Long userId, + @RequestBody NicknameRequest nicknameRequest) { + return ResponseEntity.ok(userService.updateNickname(userId, nicknameRequest)); + } + @DeleteMapping("/users/{userId}") public ResponseEntity leaveMembership(@PathVariable Long userId) { return ResponseEntity.ok(userService.deleteUser(userId));