Skip to content

Commit

Permalink
Merge pull request #78 from jyjyjy25/refactor/#77-user-by-security-utils
Browse files Browse the repository at this point in the history
Refactor/#77 user by security utils
  • Loading branch information
jyjyjy25 authored Feb 11, 2024
2 parents a65b64f + a1246d6 commit ff13b23
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 107 deletions.
8 changes: 4 additions & 4 deletions src/main/java/tavebalak/OTTify/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public enum ErrorCode {
USER_NOT_FOUND("์œ ์ €๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
OTT_NOT_FOUND("OTT๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
PROGRAM_GENRE_NOT_FOUND("ํ”„๋กœ๊ทธ๋žจ๊ณผ ๊ด€๋ จ๋œ ์žฅ๋ฅด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
PROGRAM_NOT_FOUND("ํ”„๋กœ๊ทธ๋žจ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค"),
USER_FIRST_GENRE_NOT_FOUND("USER๋Š” ์ฒซ๋ฒˆ์งธ ์šฐ์„  ์ˆœ์œ„ ์žฅ๋ฅด๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค"),
REVIEW_TAG_NOT_FOUND("์ง€์ •๋œ ๋ฆฌ๋ทฐ ํƒœ๊ทธ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค"),
REVIEW_NOT_FOUND("๋ฆฌ๋ทฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค"),
PROGRAM_NOT_FOUND("ํ”„๋กœ๊ทธ๋žจ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
USER_FIRST_GENRE_NOT_FOUND("USER๋Š” ์ฒซ๋ฒˆ์งธ ์šฐ์„  ์ˆœ์œ„ ์žฅ๋ฅด๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."),
REVIEW_TAG_NOT_FOUND("์ง€์ •๋œ ๋ฆฌ๋ทฐ ํƒœ๊ทธ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
REVIEW_NOT_FOUND("๋ฆฌ๋ทฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
SAVED_PROGRAM_NOT_FOUND("์ €์žฅ๋œ ํ”„๋กœ๊ทธ๋žจ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
COMMUNITY_NOT_FOUND("ํ† ๋ก ์ฃผ์ œ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
REPLY_NOT_FOUND("๋Œ“๊ธ€์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
Expand Down
92 changes: 36 additions & 56 deletions src/main/java/tavebalak/OTTify/user/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -43,131 +42,112 @@ public class UserController {
private final UserService userService;

@ApiOperation(value = "ํ”„๋กœํ•„ ์กฐํšŒ api", notes = "์œ ์ € ํ”„๋กœํ•„(๋‹‰๋„ค์ž„, ํ”„๋กœํ•„ ์‚ฌ์ง„)์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiImplicitParam(name = "userId", dataType = "long", value = "์œ ์ € id", required = true, paramType = "path")
@GetMapping("/{userId}")
@GetMapping()
@ResponseStatus(HttpStatus.OK)
public BaseResponse<UserProfileDTO> getUserProfile(@PathVariable("userId") Long userId) {
return BaseResponse.success(userService.getUserProfile(userId));
public BaseResponse<UserProfileDTO> getUserProfile() {
return BaseResponse.success(userService.getUserProfile());
}

@ApiOperation(value = "๊ตฌ๋… ์ค‘์ธ OTT ์กฐํšŒ api", notes = "์œ ์ €๊ฐ€ ๊ตฌ๋… ์ค‘์ธ OTT๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiImplicitParam(name = "userId", dataType = "long", value = "์œ ์ € id", required = true, paramType = "path")
@GetMapping("/{userId}/otts")
@GetMapping("/otts")
@ResponseStatus(HttpStatus.OK)
public BaseResponse<UserOttListDTO> getUserOTT(@PathVariable("userId") Long userId) {
return BaseResponse.success(userService.getUserOTT(userId));
public BaseResponse<UserOttListDTO> getUserOTT() {
return BaseResponse.success(userService.getUserOTT());
}

@ApiOperation(value = "ํ”„๋กœํ•„ ์ˆ˜์ • api", notes = "์œ ์ € ํ”„๋กœํ•„(๋‹‰๋„ค์ž„, ํ”„๋กœํ•„ ์‚ฌ์ง„)์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค. โš ๏ธ Content-Type๋ฅผ multipart/form-data๋กœ ์„ค์ •ํ•˜๊ณ  ํŒŒ๋ผ๋ฏธํ„ฐ ๋ณ„๋กœ MediaType์„ ์„ค์ •ํ•ด ์ฃผ์„ธ์š”.")
@ApiImplicitParam(name = "userId", dataType = "long", value = "์œ ์ € id", required = true, paramType = "path")
@ApiResponse(code = 200, message = "์„ฑ๊ณต์ ์œผ๋กœ ํ”„๋กœํ•„์ด ์—…๋ฐ์ดํŠธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
@PatchMapping(value = "/{userId}/profile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@PatchMapping(value = "/profile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(HttpStatus.OK)
public BaseResponse updateUserProfile(@PathVariable("userId") Long userId,
@RequestParam(required = false) final String nickName,
@RequestPart(required = false) final MultipartFile profilePhoto) {
userService.updateUserProfile(userId, nickName, profilePhoto);
public BaseResponse updateUserProfile(@RequestParam(required = false) final String nickName, @RequestPart(required = false) final MultipartFile profilePhoto) {
userService.updateUserProfile(nickName, profilePhoto);
return BaseResponse.success("์„ฑ๊ณต์ ์œผ๋กœ ํ”„๋กœํ•„์ด ์—…๋ฐ์ดํŠธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
}

@ApiOperation(value = "๊ตฌ๋… ์ค‘์ธ OTT ์ˆ˜์ • api", notes = "์œ ์ €๊ฐ€ ๊ตฌ๋… ์ค‘์ธ OTT๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.")
@ApiImplicitParam(name = "userId", dataType = "long", value = "์œ ์ € id", required = true, paramType = "path")
@ApiResponse(code = 200, message = "์„ฑ๊ณต์ ์œผ๋กœ ๊ตฌ๋… ์ค‘์ธ OTT๊ฐ€ ์—…๋ฐ์ดํŠธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
@PatchMapping("/{userId}/otts")
@PatchMapping("/otts")
@ResponseStatus(HttpStatus.OK)
public BaseResponse updateUserOTT(@PathVariable("userId") Long userId,
@RequestBody UserOttUpdateDTO updateRequestDTO) {
userService.updateUserOTT(userId, updateRequestDTO);
public BaseResponse updateUserOTT(@RequestBody UserOttUpdateDTO updateRequestDTO) {
userService.updateUserOTT(updateRequestDTO);
return BaseResponse.success("์„ฑ๊ณต์ ์œผ๋กœ ๊ตฌ๋… ์ค‘์ธ OTT๊ฐ€ ์—…๋ฐ์ดํŠธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
}

@ApiOperation(value = "1์ˆœ์œ„ ์ทจํ–ฅ ์žฅ๋ฅด ์ˆ˜์ • api", notes = "์œ ์ €์˜ 1์ˆœ์œ„ ์ทจํ–ฅ ์žฅ๋ฅด๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.")
@ApiImplicitParam(name = "userId", dataType = "long", value = "์œ ์ € id", required = true, paramType = "path")
@ApiResponse(code = 200, message = "์„ฑ๊ณต์ ์œผ๋กœ 1์ˆœ์œ„ ์žฅ๋ฅด๊ฐ€ ์—…๋ฐ์ดํŠธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
@PatchMapping("/{userId}/1stGenre")
@PatchMapping("/1stGenre")
@ResponseStatus(HttpStatus.OK)
public BaseResponse update1stLikedGenre(@PathVariable("userId") Long userId,
@Validated @RequestBody GenreUpdateDTO updateRequestDto) {
userService.update1stGenre(userId, updateRequestDto);
public BaseResponse update1stLikedGenre(@Validated @RequestBody GenreUpdateDTO updateRequestDto) {
userService.update1stGenre(updateRequestDto);
return BaseResponse.success("์„ฑ๊ณต์ ์œผ๋กœ 1์ˆœ์œ„ ์žฅ๋ฅด๊ฐ€ ์—…๋ฐ์ดํŠธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
}

@ApiOperation(value = "2์ˆœ์œ„ ์ทจํ–ฅ ์žฅ๋ฅด ์ˆ˜์ • api", notes = "์œ ์ €์˜ 2์ˆœ์œ„ ์ทจํ–ฅ ์žฅ๋ฅด๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.")
@ApiImplicitParam(name = "userId", dataType = "long", value = "์œ ์ € id", required = true, paramType = "path")
@ApiResponse(code = 200, message = "์„ฑ๊ณต์ ์œผ๋กœ 2์ˆœ์œ„ ์žฅ๋ฅด๊ฐ€ ์—…๋ฐ์ดํŠธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
@PatchMapping("/{userId}/2ndGenre")
@PatchMapping("/2ndGenre")
@ResponseStatus(HttpStatus.OK)
public BaseResponse update2ndLikedGenre(@PathVariable("userId") Long userId,
@Validated @RequestBody GenreUpdateDTO updateRequestDTO) {
userService.update2ndGenre(userId, updateRequestDTO);
public BaseResponse update2ndLikedGenre(@Validated @RequestBody GenreUpdateDTO updateRequestDTO) {
userService.update2ndGenre(updateRequestDTO);
return BaseResponse.success("์„ฑ๊ณต์ ์œผ๋กœ 2์ˆœ์œ„ ์žฅ๋ฅด๊ฐ€ ์—…๋ฐ์ดํŠธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
}

@ApiOperation(value = "์ž‘์„ฑ ๋ฆฌ๋ทฐ ์กฐํšŒ api", notes = "์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", dataType = "long", value = "์œ ์ € id", required = true, paramType = "path"),
@ApiImplicitParam(name = "page", dataType = "int", value = "ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ(0๋ถ€ํ„ฐ ์‹œ์ž‘)", paramType = "query"),
@ApiImplicitParam(name = "direction", dataType = "String", value = "๋‚ด๋ฆผ์ฐจ์ˆœ๊ณผ ์˜ค๋ฆ„์ฐจ์ˆœ", paramType = "query"),
@ApiImplicitParam(name = "sort", dataType = "String", value = "์ •๋ ฌ๊ธฐ์ค€(createdAt, updatedAt)", paramType = "query"),
@ApiImplicitParam(name = "size", dataType = "int", value = "ํŽ˜์ด์ง€๋‹น ์•„์ดํ…œ ๊ฐฏ์ˆ˜", paramType = "query")
})
@GetMapping("/{userId}/reviews")
@GetMapping("/reviews")
@ResponseStatus(HttpStatus.OK)
public BaseResponse<List<MyReviewDto>> getMyReview(@PathVariable("userId") Long userId,
@PageableDefault(
size = 5,
sort = "createdAt",
direction = Sort.Direction.DESC,
page = 0) Pageable pageable) {
return BaseResponse.success(userService.getMyReview(userId, pageable));
public BaseResponse<List<MyReviewDto>> getMyReview(@PageableDefault(
size = 5,
sort = "createdAt",
direction = Sort.Direction.DESC,
page = 0) Pageable pageable) {
return BaseResponse.success(userService.getMyReview(pageable));
}

@ApiOperation(value = "์ข‹์•„์š”ํ•œ ๋ฆฌ๋ทฐ ์กฐํšŒ api", notes = "์œ ์ €๊ฐ€ ์ข‹์•„์š”ํ•œ ๋ฆฌ๋ทฐ๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", dataType = "long", value = "์œ ์ € id", required = true, paramType = "path"),
@ApiImplicitParam(name = "page", dataType = "int", value = "ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ(0๋ถ€ํ„ฐ ์‹œ์ž‘)", paramType = "query"),
@ApiImplicitParam(name = "size", dataType = "int", value = "ํŽ˜์ด์ง€๋‹น ์•„์ดํ…œ ๊ฐฏ์ˆ˜", paramType = "query")
})
@GetMapping("/{userId}/likedReviews")
@GetMapping("/likedReviews")
@ResponseStatus(HttpStatus.OK)
public BaseResponse<List<MyReviewDto>> getLikedReview(@PathVariable("userId") Long userId,
@PageableDefault(
size = 5,
page = 0) Pageable pageable) {
return BaseResponse.success(userService.getLikedReview(userId, pageable));
public BaseResponse<List<MyReviewDto>> getLikedReview(@PageableDefault(
size = 5,
page = 0) Pageable pageable) {
return BaseResponse.success(userService.getLikedReview(pageable));
}

@ApiOperation(value = "์ฃผ์ตœํ•œ ํ† ๋ก  ์กฐํšŒ api", notes = "์œ ์ €๊ฐ€ ์ฃผ์ตœํ•œ ํ† ๋ก ์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", dataType = "long", value = "์œ ์ € id", required = true, paramType = "path"),
@ApiImplicitParam(name = "page", dataType = "int", value = "ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ(0๋ถ€ํ„ฐ ์‹œ์ž‘)", paramType = "query"),
@ApiImplicitParam(name = "direction", dataType = "String", value = "๋‚ด๋ฆผ์ฐจ์ˆœ๊ณผ ์˜ค๋ฆ„์ฐจ์ˆœ", paramType = "query"),
@ApiImplicitParam(name = "sort", dataType = "String", value = "์ •๋ ฌ๊ธฐ์ค€(createdAt, updatedAt)", paramType = "query"),
@ApiImplicitParam(name = "size", dataType = "int", value = "ํŽ˜์ด์ง€๋‹น ์•„์ดํ…œ ๊ฐฏ์ˆ˜", paramType = "query")
})
@GetMapping("/{userId}/discussion/hosting")
@GetMapping("/discussion/hosting")
@ResponseStatus(HttpStatus.OK)
public BaseResponse<List<MyDiscussionDto>> getHostedDiscussion(
@PathVariable("userId") Long userId, @PageableDefault(
public BaseResponse<List<MyDiscussionDto>> getHostedDiscussion(@PageableDefault(
size = 5,
sort = "createdAt",
direction = Sort.Direction.DESC,
page = 0) Pageable pageable) {
return BaseResponse.success(userService.getHostedDiscussion(userId, pageable));
return BaseResponse.success(userService.getHostedDiscussion(pageable));
}

@ApiOperation(value = "์ฐธ์—ฌํ•œ ํ† ๋ก  ์กฐํšŒ api", notes = "์œ ์ €๊ฐ€ ์ฐธ์—ฌํ•œ ํ† ๋ก ์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", dataType = "long", value = "์œ ์ € id", required = true, paramType = "path"),
@ApiImplicitParam(name = "page", dataType = "int", value = "ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ(0๋ถ€ํ„ฐ ์‹œ์ž‘)", paramType = "query"),
@ApiImplicitParam(name = "size", dataType = "int", value = "ํŽ˜์ด์ง€๋‹น ์•„์ดํ…œ ๊ฐฏ์ˆ˜", paramType = "query")
})
@GetMapping("/{userId}/discussion/participating")
@GetMapping("/discussion/participating")
@ResponseStatus(HttpStatus.OK)
public BaseResponse<List<MyDiscussionDto>> getParticipatedDiscussion(
@PathVariable("userId") Long userId, @PageableDefault(
public BaseResponse<List<MyDiscussionDto>> getParticipatedDiscussion(@PageableDefault(
size = 5,
page = 0) Pageable pageable) {
return BaseResponse.success(userService.getParticipatedDiscussion(userId, pageable));
return BaseResponse.success(userService.getParticipatedDiscussion(pageable));
}
}
30 changes: 10 additions & 20 deletions src/main/java/tavebalak/OTTify/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,14 @@
import tavebalak.OTTify.user.dto.Response.UserProfileDTO;

public interface UserService {

UserProfileDTO getUserProfile(Long userId);

UserOttListDTO getUserOTT(Long userId);

void update1stGenre(Long userId, GenreUpdateDTO updateRequestDTO);

void update2ndGenre(Long userId, GenreUpdateDTO updateRequestDTO);

Long updateUserProfile(Long userId, String nickName, MultipartFile profilePhoto);

Long updateUserOTT(Long userId, UserOttUpdateDTO updateRequestDTO);

List<MyReviewDto> getMyReview(Long userId, Pageable pageable);

List<MyReviewDto> getLikedReview(Long userId, Pageable pageable);

List<MyDiscussionDto> getHostedDiscussion(Long userId, Pageable pageable);

List<MyDiscussionDto> getParticipatedDiscussion(Long userId, Pageable pageable);
UserProfileDTO getUserProfile();
UserOttListDTO getUserOTT();
void update1stGenre(GenreUpdateDTO updateRequestDTO);
void update2ndGenre(GenreUpdateDTO updateRequestDTO);
void updateUserProfile(String nickName, MultipartFile profilePhoto);
void updateUserOTT(UserOttUpdateDTO updateRequestDTO);
List<MyReviewDto> getMyReview(Pageable pageable);
List<MyReviewDto> getLikedReview(Pageable pageable);
List<MyDiscussionDto> getHostedDiscussion(Pageable pageable);
List<MyDiscussionDto> getParticipatedDiscussion(Pageable pageable);
}
Loading

0 comments on commit ff13b23

Please sign in to comment.