Skip to content

Commit

Permalink
feat:[kakao-tech-campus-2nd-step3#84]- refact Controller
Browse files Browse the repository at this point in the history
반환타입 변경
  • Loading branch information
yooonwodyd committed Nov 7, 2024
1 parent 1a7da80 commit 1c14c81
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,44 +26,47 @@ public class ArtistController implements ArtistApiDocs {
private final ArtistService artistService;

@PostMapping("/v1/artists/students")
public ResponseEntity<String> registerStudents(
public ResponseEntity<ApiResponse<Void>> 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<String> registerbussinsess(
public ResponseEntity<ApiResponse<Void>> 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<ApiResponse<ArtistDetailsRes>> 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<ApiResponse<ArtistDetailsRes>> 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<ArtistInfoPage.Paging> getArtistsByPage(
public ResponseEntity<ApiResponse<ArtistInfoPage.Paging>> 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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
48 changes: 24 additions & 24 deletions src/main/java/com/helpmeCookies/user/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -39,67 +41,65 @@ public class UserController implements UserApiDocs {


@GetMapping("/v1/users")
public ResponseEntity<UserCommonInfoRes> getUsers(
public ResponseEntity<ApiResponse<UserCommonInfoRes>> 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<UserDetailsInfoRes> getUserDetails(
public ResponseEntity<ApiResponse<UserDetailsInfoRes>> 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<UserTypeDto> getUserType(
public ResponseEntity<ApiResponse<UserTypeDto>> getUserType(
@AuthenticationPrincipal JwtUser jwtUser
) {
return ResponseEntity.ok(userService.getUserType(jwtUser.getId()));
}

@PostMapping("/images")
public ResponseEntity<UserImageResponse> uploadImages(List<MultipartFile> files) throws
IOException {
List<FileUploadResponse> 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<ApiResponse<UserDto>> 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<String> followArtist(
public ResponseEntity<ApiResponse<Void>> 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<String> unfollowArtist(
public ResponseEntity<ApiResponse<Void>> 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<Page<UserFollowingRes>> getFollowingList(
public ResponseEntity<ApiResponse<Page<UserFollowingRes>>> getFollowingList(
@AuthenticationPrincipal JwtUser jwtUser,
@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
) {
return ResponseEntity.ok(userService.getFollowingWithPaging(jwtUser.getId(), pageable));
Page<UserFollowingRes> followingList = userService.getFollowingWithPaging(jwtUser.getId(), pageable);
return ResponseEntity.ok(ApiResponse.success(SuccessCode.OK, followingList));
}

@DeleteMapping("/v1/users")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,32 +22,32 @@ public interface ArtistApiDocs {

@Operation(summary = "학생 작가 등록", description = "학생 작가 등록")
@PostMapping("/v1/artists/students")
ResponseEntity<String> registerStudents(
ResponseEntity<ApiResponse<Void>> registerStudents(
@RequestBody StudentArtistReq artistDetailsReq,
@AuthenticationPrincipal JwtUser jwtUser
);

@Operation(summary = "사업자 작가 등록", description = "사업자 작가 등록")
@PostMapping("/v1/artists/bussinesses")
ResponseEntity<String> registerbussinsess(
ResponseEntity<ApiResponse<Void>> registerbussinsess(
@RequestBody BusinessArtistReq businessArtistReq,
@AuthenticationPrincipal JwtUser jwtUser
);

@Operation(summary = "작가 프로필 조회", description = "작가 프로필 조회")
@GetMapping("/v1/artists/{userId}")
ArtistDetailsRes getArtist(
ResponseEntity<ApiResponse<ArtistDetailsRes>> getArtist(
@PathVariable Long userId
);

@Operation(summary = "작가 자신의 프로필 조회", description = "작가 자신의 프로필 조회")
@GetMapping("/v1/artist")
ArtistDetailsRes getArtist(
ResponseEntity<ApiResponse<ArtistDetailsRes>> getArtist(
@AuthenticationPrincipal JwtUser jwtUser
);

@Operation(summary = "작가 검색")
ResponseEntity<Paging> getArtistsByPage(
ResponseEntity<ApiResponse<ArtistInfoPage.Paging>> getArtistsByPage(
String query,
@Parameter(description = "default value 20") int size,
int page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,32 +27,32 @@ public interface UserApiDocs {

@Operation(summary = "유저 일반 정보 조회", description = "로그인한 유저의 username, imageUrl, hashtag를 조회한다.")
@GetMapping("/v1/users")
ResponseEntity<UserCommonInfoRes> getUsers(@AuthenticationPrincipal JwtUser jwtUser);
ResponseEntity<ApiResponse<UserCommonInfoRes>> getUsers(@AuthenticationPrincipal JwtUser jwtUser);

@Operation(summary = "유저 상세 정보 조회", description = "로그인한 유저의 상세 정보를 조회한다. 유저의 모든 정보를 조회 할 수 있다.")
@GetMapping("/v1/users/details")
ResponseEntity<UserDetailsInfoRes> getUserDetails(@AuthenticationPrincipal JwtUser jwtUser);
ResponseEntity<ApiResponse<UserDetailsInfoRes>> getUserDetails(@AuthenticationPrincipal JwtUser jwtUser);

@Operation(summary = "유저 타입 조회", description = "로그인한 유저의 타입과 권한을 조회한다.")
@GetMapping("/v1/users/type")
public ResponseEntity<UserTypeDto> getUserType(@AuthenticationPrincipal JwtUser jwtUser);
ResponseEntity<ApiResponse<UserTypeDto>> getUserType(@AuthenticationPrincipal JwtUser jwtUser);

@Operation(summary = "아티스트 팔로우하기", description = "로그인한 유저가 특정 아티스트를 팔로우한다.")
@PostMapping("/v1/users/following/{artistId}")
public ResponseEntity<String> followArtist(
ResponseEntity<ApiResponse<Void>> followArtist(
@AuthenticationPrincipal JwtUser jwtUser, @PathVariable Long artistId
);

@Operation(summary = "아티스트 팔로우 취소하기", description = "로그인한 유저가 특정 아티스트를 팔로우 취소한다.")
@DeleteMapping("/v1/users/following/{artistId}")
public ResponseEntity<String> unfollowArtist(
ResponseEntity<ApiResponse<Void>> unfollowArtist(
@AuthenticationPrincipal JwtUser jwtUser,
@PathVariable Long artistId
);

@Operation(summary = "팔로잉 목록 조회", description = "로그인한 유저의 팔로우한 아티스트 목록을 조회한다.")
@GetMapping("/v1/users/following")
public ResponseEntity<Page<UserFollowingRes>> getFollowingList(
ResponseEntity<ApiResponse<Page<UserFollowingRes>>> getFollowingList(
@AuthenticationPrincipal JwtUser jwtUser,
@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
);
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/helpmeCookies/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,11 +63,6 @@ public UserDto updateUser(UserCommonInfoDto userCommonInfoDto, UserInfoDto userI
return UserDto.fromEntity(userRepository.save(existingUser));
}

@Transactional
public List<FileUploadResponse> uploadMultiFiles(List<MultipartFile> files) throws IOException {
return awsS3FileUtils.uploadMultiImages(files);
}


@Transactional
public UserTypeDto getUserType(Long userId) {
Expand Down

0 comments on commit 1c14c81

Please sign in to comment.