Skip to content

Commit

Permalink
[refactor][#53] Profile 관련 기능 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ProtoSeo committed Jul 22, 2022
1 parent a4adbbc commit 02aaf3b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,13 +47,13 @@ public ResponseEntity<LoginResponse> login(@Valid @RequestBody LoginRequest logi
}

@PostMapping("/refresh")
public ResponseEntity<AccessTokenResponse> getAccessToken(@RequestBody RefreshOrLogoutRequest request) {
public ResponseEntity<AccessTokenResponse> getAccessToken(@RequestBody RefreshRequest request) {
AccessTokenResponse accessTokenResponse = authService.refreshToken(request);
return ResponseEntity.ok(accessTokenResponse);
}

@PostMapping("/logout")
public ResponseEntity<CommonResponse> logout(@RequestBody RefreshOrLogoutRequest request) {
public ResponseEntity<CommonResponse> logout(@RequestBody LogoutRequest request) {
CommonResponse commonResponse = authService.logout(request);
return ResponseEntity.ok(commonResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserProfileResponse> getUserProfile(@PathVariable Long userId) {
return ResponseEntity.ok(userService.getUserProfile(userId));
return ResponseEntity.ok(profileService.getUserProfile(userId));
}

@PutMapping("/users/{userId}/introduce")
public ResponseEntity<Map<String, String>> updateUserNicknameAndIntroduce(
@PathVariable Long userId,
@RequestBody NicknameAndIntroduceRequest nicknameAndIntroduceRequest) {
String value = userService.updateNicknameAndIntroduce(userId, nicknameAndIntroduceRequest);
Map<String, String> result = makeResponseBody("nickname", value);
result.put("introduce", nicknameAndIntroduceRequest.getIntroduce());
return ResponseEntity.ok(result);
}

@PutMapping("/users/{userId}/github-url")
public ResponseEntity<Map<String, String>> updateUserGithubUrl(@PathVariable Long userId,
@RequestBody GithubUrlRequest githubUrlRequest) {
String value = userService.updateGithubUrl(userId, githubUrlRequest);
Map<String, String> result = makeResponseBody("github_url", value);
return ResponseEntity.ok(result);
}

@PutMapping("/users/{userId}/blog-url")
public ResponseEntity<Map<String, String>> updateUserBlogUrl(@PathVariable Long userId,
@RequestBody BlogUrlRequest blogUrlRequest) {
String value = userService.updateBlogUrl(userId, blogUrlRequest);
Map<String, String> result = makeResponseBody("blog_url", value);
return ResponseEntity.ok(result);
}

@PutMapping("/users/{userId}/baekjoon-id")
public ResponseEntity<Map<String, String>> updateUserBaekjoonId(@PathVariable Long userId,
@RequestBody BaekjoonIdRequest baekjoonIdRequest) {
String value = userService.updateBaekjoonId(userId, baekjoonIdRequest);
Map<String, String> result = makeResponseBody("baekjoon_id", value);
return ResponseEntity.ok(result);
@PutMapping("/users/{userId}/profile")
public ResponseEntity<UserProfileResponse> updateUserProfile(@PathVariable Long userId,
@RequestBody ProfileRequest profileRequest) {
UserProfileResponse response = profileService.updateProfile(userId, profileRequest);
return ResponseEntity.ok(response);
}

@PutMapping("/users/{userId}/skills")
Expand All @@ -80,21 +47,9 @@ public ResponseEntity<SkillTagResponse> updateUserSkills(@PathVariable Long user
return ResponseEntity.ok(skillTagResponse);
}

@PostMapping("/users/{userId}/image")
public ResponseEntity<String> updateUserProfileImage(@PathVariable Long userId,
@RequestPart("image") MultipartFile multipartFile) {
return ResponseEntity.ok(userService.updateUserProfileImage(userId, multipartFile));
}

@DeleteMapping("/users/{userId}/skills/{skillId}")
public ResponseEntity<CommonResponse> deleteUserSkill(@PathVariable Long userId, @PathVariable Long skillId) {
skillTagService.deleteSkillTagToUser(userId, skillId);
return ResponseEntity.ok(new CommonResponse(true, "해당 기술태그가 삭제되었습니다."));
}

private Map<String, String> makeResponseBody(String key, String value) {
Map<String, String> result = new HashMap<>();
result.put(key, value);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,6 +50,18 @@ public ResponseEntity<CommonResponse> changeUserPassword(@PathVariable Long user
return ResponseEntity.ok(result);
}

@PostMapping("/users/{userId}/image")
public ResponseEntity<String> updateUserNickname(@PathVariable Long userId,
@RequestPart("image") MultipartFile multipartFile) {
return ResponseEntity.ok(userService.updateUserProfileImage(userId, multipartFile));
}

@PutMapping("/users/{userId}/nickname")
public ResponseEntity<String> updateUserNickname(@PathVariable Long userId,
@RequestBody NicknameRequest nicknameRequest) {
return ResponseEntity.ok(userService.updateNickname(userId, nicknameRequest));
}

@DeleteMapping("/users/{userId}")
public ResponseEntity<Long> leaveMembership(@PathVariable Long userId) {
return ResponseEntity.ok(userService.deleteUser(userId));
Expand Down

0 comments on commit 02aaf3b

Please sign in to comment.