From 1c14c81fd0dc1c48193323fc28f4029049aec046 Mon Sep 17 00:00:00 2001 From: yooonwodyd Date: Thu, 7 Nov 2024 15:03:27 +0900 Subject: [PATCH] feat:[#84]- refact Controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 반환타입 변경 --- .../user/controller/ArtistController.java | 25 ++++++---- .../user/controller/LoginController.java | 2 +- .../user/controller/UserController.java | 48 +++++++++---------- .../controller/apiDocs/ArtistApiDocs.java | 12 +++-- .../user/controller/apiDocs/UserApiDocs.java | 14 +++--- .../user/service/UserService.java | 6 --- 6 files changed, 55 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/helpmeCookies/user/controller/ArtistController.java b/src/main/java/com/helpmeCookies/user/controller/ArtistController.java index 0cf41f6..f9530ff 100644 --- a/src/main/java/com/helpmeCookies/user/controller/ArtistController.java +++ b/src/main/java/com/helpmeCookies/user/controller/ArtistController.java @@ -1,5 +1,7 @@ package com.helpmeCookies.user.controller; +import com.helpmeCookies.global.ApiResponse.ApiResponse; +import com.helpmeCookies.global.ApiResponse.SuccessCode; import com.helpmeCookies.global.jwt.JwtUser; import com.helpmeCookies.user.controller.apiDocs.ArtistApiDocs; import com.helpmeCookies.user.dto.ArtistInfoPage; @@ -24,44 +26,47 @@ public class ArtistController implements ArtistApiDocs { private final ArtistService artistService; @PostMapping("/v1/artists/students") - public ResponseEntity registerStudents( + public ResponseEntity> registerStudents( @RequestBody StudentArtistReq artistDetailsReq, @AuthenticationPrincipal JwtUser jwtUser ) { artistService.registerStudentsArtist(artistDetailsReq, jwtUser.getId()); - return ResponseEntity.ok().build(); + return ResponseEntity.ok((ApiResponse.success(SuccessCode.OK))); } @PostMapping("/v1/artists/bussinesses") - public ResponseEntity registerbussinsess( + public ResponseEntity> registerbussinsess( @RequestBody BusinessArtistReq businessArtistReq, @AuthenticationPrincipal JwtUser jwtUser ) { artistService.registerBusinessArtist(businessArtistReq, jwtUser.getId()); - return ResponseEntity.ok().build(); + return ResponseEntity.ok((ApiResponse.success(SuccessCode.OK))); } @GetMapping("/v1/artists/{userId}") - public ArtistDetailsRes getArtist( + public ResponseEntity> getArtist( @PathVariable Long userId ) { - return artistService.getArtistDetails(userId); + ArtistDetailsRes artistDetailsRes = artistService.getArtistDetails(userId); + return ResponseEntity.ok((ApiResponse.success(SuccessCode.OK, artistDetailsRes))); } @GetMapping("/v1/artist") - public ArtistDetailsRes getArtist( + public ResponseEntity> getArtist( @AuthenticationPrincipal JwtUser jwtUser ) { - return artistService.getArtistDetails(jwtUser.getId()); + ArtistDetailsRes artistDetailsRes = artistService.getArtistDetails(jwtUser.getId()); + return ResponseEntity.ok((ApiResponse.success(SuccessCode.OK, artistDetailsRes))); } @GetMapping("/v1/artists") - public ResponseEntity getArtistsByPage( + public ResponseEntity> getArtistsByPage( @RequestParam("query") String query, @RequestParam(name = "size", required = false, defaultValue = "20") int size, @RequestParam("page") int page ) { var pageable = PageRequest.of(page, size); - return ResponseEntity.ok(artistService.getArtistsByPage(query, pageable)); + ArtistInfoPage.Paging artistInfoPage = artistService.getArtistsByPage(query, pageable); + return ResponseEntity.ok((ApiResponse.success(SuccessCode.OK, artistInfoPage))); } } diff --git a/src/main/java/com/helpmeCookies/user/controller/LoginController.java b/src/main/java/com/helpmeCookies/user/controller/LoginController.java index 71e4391..03431cf 100644 --- a/src/main/java/com/helpmeCookies/user/controller/LoginController.java +++ b/src/main/java/com/helpmeCookies/user/controller/LoginController.java @@ -55,7 +55,7 @@ public JwtToken signup() { } @GetMapping("/oauth2/login/kakao") - public JwtToken ttt(@AuthenticationPrincipal OAuth2User oAuth2User) { + public JwtToken loginKakao(@AuthenticationPrincipal OAuth2User oAuth2User) { KakaoOAuth2Response kakaoUser = KakaoOAuth2Response.from(oAuth2User.getAttributes()); return jwtProvider.createToken(userDetailsService.loadUserByEmail(kakaoUser.email(), kakaoUser.nickname())); } diff --git a/src/main/java/com/helpmeCookies/user/controller/UserController.java b/src/main/java/com/helpmeCookies/user/controller/UserController.java index d4a1a0b..f7d0874 100644 --- a/src/main/java/com/helpmeCookies/user/controller/UserController.java +++ b/src/main/java/com/helpmeCookies/user/controller/UserController.java @@ -7,6 +7,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.web.PageableDefault; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.DeleteMapping; @@ -18,10 +19,11 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import com.helpmeCookies.global.ApiResponse.ApiResponse; +import com.helpmeCookies.global.ApiResponse.SuccessCode; import com.helpmeCookies.global.jwt.JwtUser; -import com.helpmeCookies.product.dto.FileUploadResponse; -import com.helpmeCookies.product.dto.ProductImageResponse; import com.helpmeCookies.user.controller.apiDocs.UserApiDocs; +import com.helpmeCookies.user.dto.UserDto; import com.helpmeCookies.user.dto.response.UserCommonInfoRes; import com.helpmeCookies.user.dto.request.UserReq; import com.helpmeCookies.user.dto.response.UserDetailsInfoRes; @@ -39,67 +41,65 @@ public class UserController implements UserApiDocs { @GetMapping("/v1/users") - public ResponseEntity getUsers( + public ResponseEntity> getUsers( @AuthenticationPrincipal JwtUser jwtUser ) { - return ResponseEntity.ok(UserCommonInfoRes.fromDto(userService.getUserInfo(jwtUser.getId()))); + UserCommonInfoRes userCommonInfoRes = UserCommonInfoRes.fromDto(userService.getUserInfo(jwtUser.getId())); + return ResponseEntity.ok(ApiResponse.success(SuccessCode.OK, userCommonInfoRes)); } @GetMapping("/v1/users/details") - public ResponseEntity getUserDetails( + public ResponseEntity> getUserDetails( @AuthenticationPrincipal JwtUser jwtUser ) { - return ResponseEntity.ok(UserDetailsInfoRes.fromDto(userService.getUserInfo(jwtUser.getId()))); + UserDetailsInfoRes userDetailsInfoRes = UserDetailsInfoRes.fromDto(userService.getUserInfo(jwtUser.getId())); + + return ResponseEntity.ok(ApiResponse.success(SuccessCode.OK, userDetailsInfoRes)); } @GetMapping("/v1/users/type") - public ResponseEntity getUserType( + public ResponseEntity> getUserType( @AuthenticationPrincipal JwtUser jwtUser ) { - return ResponseEntity.ok(userService.getUserType(jwtUser.getId())); - } - - @PostMapping("/images") - public ResponseEntity uploadImages(List files) throws - IOException { - List responses = userService.uploadMultiFiles(files); - return ResponseEntity.ok(new UserImageResponse(responses.stream().map(FileUploadResponse::photoUrl).toList())); + UserTypeDto userTypeDto = userService.getUserType(jwtUser.getId()); + return ResponseEntity.ok(ApiResponse.success(SuccessCode.OK, userTypeDto)); } @PutMapping("/v1/users") - public String updateUser( + public ResponseEntity> updateUser( @AuthenticationPrincipal JwtUser jwtUser, @RequestBody UserReq userReq ) { // UserInfoDto를 통해서 유저 정보를 수정한다. - userService.updateUser(userReq.toUserCommonInfoDto(), userReq.toUserInfoDto(), jwtUser.getId()); - return "ok"; + UserDto userDto = userService.updateUser(userReq.toUserCommonInfoDto(), userReq.toUserInfoDto(), jwtUser.getId()); + return ResponseEntity.ok(ApiResponse.success(SuccessCode.OK, userDto)); } @PostMapping("/v1/users/following/{artistId}") - public ResponseEntity followArtist( + public ResponseEntity> followArtist( @AuthenticationPrincipal JwtUser jwtUser, @PathVariable Long artistId ) { userService.followArtist(jwtUser.getId(), artistId); - return ResponseEntity.ok().build(); + return ResponseEntity.ok(ApiResponse.success(SuccessCode.OK)); } @DeleteMapping("/v1/users/following/{artistId}") - public ResponseEntity unfollowArtist( + public ResponseEntity> unfollowArtist( @AuthenticationPrincipal JwtUser jwtUser, @PathVariable Long artistId ) { userService.unfollowArtist(jwtUser.getId(), artistId); - return ResponseEntity.ok().build(); + return ResponseEntity.ok(ApiResponse.success(SuccessCode.OK)); } @GetMapping("/v1/users/following") - public ResponseEntity> getFollowingList( + public ResponseEntity>> getFollowingList( @AuthenticationPrincipal JwtUser jwtUser, @PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable ) { - return ResponseEntity.ok(userService.getFollowingWithPaging(jwtUser.getId(), pageable)); + Page followingList = userService.getFollowingWithPaging(jwtUser.getId(), pageable); + return ResponseEntity.ok(ApiResponse.success(SuccessCode.OK, followingList)); } @DeleteMapping("/v1/users") diff --git a/src/main/java/com/helpmeCookies/user/controller/apiDocs/ArtistApiDocs.java b/src/main/java/com/helpmeCookies/user/controller/apiDocs/ArtistApiDocs.java index 4df8e2d..95c6ea8 100644 --- a/src/main/java/com/helpmeCookies/user/controller/apiDocs/ArtistApiDocs.java +++ b/src/main/java/com/helpmeCookies/user/controller/apiDocs/ArtistApiDocs.java @@ -1,6 +1,8 @@ package com.helpmeCookies.user.controller.apiDocs; +import com.helpmeCookies.global.ApiResponse.ApiResponse; import com.helpmeCookies.global.jwt.JwtUser; +import com.helpmeCookies.user.dto.ArtistInfoPage; import com.helpmeCookies.user.dto.ArtistInfoPage.Paging; import com.helpmeCookies.user.dto.request.BusinessArtistReq; import com.helpmeCookies.user.dto.request.StudentArtistReq; @@ -20,32 +22,32 @@ public interface ArtistApiDocs { @Operation(summary = "학생 작가 등록", description = "학생 작가 등록") @PostMapping("/v1/artists/students") - ResponseEntity registerStudents( + ResponseEntity> registerStudents( @RequestBody StudentArtistReq artistDetailsReq, @AuthenticationPrincipal JwtUser jwtUser ); @Operation(summary = "사업자 작가 등록", description = "사업자 작가 등록") @PostMapping("/v1/artists/bussinesses") - ResponseEntity registerbussinsess( + ResponseEntity> registerbussinsess( @RequestBody BusinessArtistReq businessArtistReq, @AuthenticationPrincipal JwtUser jwtUser ); @Operation(summary = "작가 프로필 조회", description = "작가 프로필 조회") @GetMapping("/v1/artists/{userId}") - ArtistDetailsRes getArtist( + ResponseEntity> getArtist( @PathVariable Long userId ); @Operation(summary = "작가 자신의 프로필 조회", description = "작가 자신의 프로필 조회") @GetMapping("/v1/artist") - ArtistDetailsRes getArtist( + ResponseEntity> getArtist( @AuthenticationPrincipal JwtUser jwtUser ); @Operation(summary = "작가 검색") - ResponseEntity getArtistsByPage( + ResponseEntity> getArtistsByPage( String query, @Parameter(description = "default value 20") int size, int page diff --git a/src/main/java/com/helpmeCookies/user/controller/apiDocs/UserApiDocs.java b/src/main/java/com/helpmeCookies/user/controller/apiDocs/UserApiDocs.java index 1eaff9c..06987f7 100644 --- a/src/main/java/com/helpmeCookies/user/controller/apiDocs/UserApiDocs.java +++ b/src/main/java/com/helpmeCookies/user/controller/apiDocs/UserApiDocs.java @@ -11,7 +11,9 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import com.helpmeCookies.global.ApiResponse.ApiResponse; import com.helpmeCookies.global.jwt.JwtUser; +import com.helpmeCookies.user.dto.UserDto; import com.helpmeCookies.user.dto.UserTypeDto; import com.helpmeCookies.user.dto.response.UserCommonInfoRes; import com.helpmeCookies.user.dto.response.UserDetailsInfoRes; @@ -25,32 +27,32 @@ public interface UserApiDocs { @Operation(summary = "유저 일반 정보 조회", description = "로그인한 유저의 username, imageUrl, hashtag를 조회한다.") @GetMapping("/v1/users") - ResponseEntity getUsers(@AuthenticationPrincipal JwtUser jwtUser); + ResponseEntity> getUsers(@AuthenticationPrincipal JwtUser jwtUser); @Operation(summary = "유저 상세 정보 조회", description = "로그인한 유저의 상세 정보를 조회한다. 유저의 모든 정보를 조회 할 수 있다.") @GetMapping("/v1/users/details") - ResponseEntity getUserDetails(@AuthenticationPrincipal JwtUser jwtUser); + ResponseEntity> getUserDetails(@AuthenticationPrincipal JwtUser jwtUser); @Operation(summary = "유저 타입 조회", description = "로그인한 유저의 타입과 권한을 조회한다.") @GetMapping("/v1/users/type") - public ResponseEntity getUserType(@AuthenticationPrincipal JwtUser jwtUser); + ResponseEntity> getUserType(@AuthenticationPrincipal JwtUser jwtUser); @Operation(summary = "아티스트 팔로우하기", description = "로그인한 유저가 특정 아티스트를 팔로우한다.") @PostMapping("/v1/users/following/{artistId}") - public ResponseEntity followArtist( + ResponseEntity> followArtist( @AuthenticationPrincipal JwtUser jwtUser, @PathVariable Long artistId ); @Operation(summary = "아티스트 팔로우 취소하기", description = "로그인한 유저가 특정 아티스트를 팔로우 취소한다.") @DeleteMapping("/v1/users/following/{artistId}") - public ResponseEntity unfollowArtist( + ResponseEntity> unfollowArtist( @AuthenticationPrincipal JwtUser jwtUser, @PathVariable Long artistId ); @Operation(summary = "팔로잉 목록 조회", description = "로그인한 유저의 팔로우한 아티스트 목록을 조회한다.") @GetMapping("/v1/users/following") - public ResponseEntity> getFollowingList( + ResponseEntity>> getFollowingList( @AuthenticationPrincipal JwtUser jwtUser, @PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable ); diff --git a/src/main/java/com/helpmeCookies/user/service/UserService.java b/src/main/java/com/helpmeCookies/user/service/UserService.java index 39f26a4..1c0bc12 100644 --- a/src/main/java/com/helpmeCookies/user/service/UserService.java +++ b/src/main/java/com/helpmeCookies/user/service/UserService.java @@ -11,7 +11,6 @@ import com.helpmeCookies.global.exception.user.ResourceNotFoundException; import com.helpmeCookies.global.utils.AwsS3FileUtils; -import com.helpmeCookies.product.dto.FileUploadResponse; import com.helpmeCookies.user.dto.UserCommonInfoDto; import com.helpmeCookies.user.dto.UserDto; import com.helpmeCookies.user.dto.UserInfoDto; @@ -64,11 +63,6 @@ public UserDto updateUser(UserCommonInfoDto userCommonInfoDto, UserInfoDto userI return UserDto.fromEntity(userRepository.save(existingUser)); } - @Transactional - public List uploadMultiFiles(List files) throws IOException { - return awsS3FileUtils.uploadMultiImages(files); - } - @Transactional public UserTypeDto getUserType(Long userId) {