Skip to content

Commit

Permalink
Merge pull request #30 from Mojacknong/feature_29/코드-정리
Browse files Browse the repository at this point in the history
Feature 29/코드 정리
  • Loading branch information
Ryeolee authored Nov 20, 2023
2 parents e0e8449 + 5245dd8 commit 59ab095
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 210 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD

on:
push:
branches: ["feature_27/파이어베이스-관리"]
branches: ["feature_29/코드-정리"]

pull_request:
branches: ["dev"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public RedisConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(redisHost);
redisStandaloneConfiguration.setPort(Integer.parseInt(redisPort));
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(redisStandaloneConfiguration);
return lettuceConnectionFactory;
return new LettuceConnectionFactory(redisStandaloneConfiguration);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public enum ErrorMessage {
INTERVAL_SERVER_ERROR(1001, "요청을 처리하는 과정에서 서버가 예상하지 못한 오류가 발생하였습니다."),
REFRESH_NOTIFICATION_ERROR(1002, "Refresh Token 인증 오류"),
NO_USER_DATA(1003, "유저에 대한 정보가 없습니다."),
NO_MOTIVATION_DATA(1004, "동기에 대한 정보가 없습니다.");
NO_MOTIVATION_DATA(1004, "동기에 대한 정보가 없습니다."),
FAIL_GET_INFORMATION(1005, "소셜에서 정보를 가져오는데 실패했습니다.");



Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,40 @@
package modernfarmer.server.farmususer.user.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto;
import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto;
import modernfarmer.server.farmususer.user.service.AuthService;
import modernfarmer.server.farmususer.user.util.JwtTokenProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;


@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/user/auth")
public class AuthController {
private final Logger LOGGER = LoggerFactory.getLogger(AuthController.class);

private final AuthService authService;
private final JwtTokenProvider jwtTokenProvider;

@PostMapping(value = "/kakao-login")
public BaseResponseDto kakaoLogin(HttpServletRequest request) {
public BaseResponseDto<TokenResponseDto> kakaoLogin(HttpServletRequest request) {

String accessToken = jwtTokenProvider.resolveToken(request);

BaseResponseDto reissueTokenResponseDto = authService.kakaoLogin(accessToken);

LOGGER.info("카카오 로그인 완료");

return reissueTokenResponseDto;
return authService.kakaoLogin(accessToken);
}


@PostMapping(value = "/google-login")
public BaseResponseDto googleLogin(HttpServletRequest request) {
public BaseResponseDto<TokenResponseDto> googleLogin(HttpServletRequest request) {

String accessToken = jwtTokenProvider.resolveToken(request);

BaseResponseDto tokenResponseDto = authService.googleLogin(accessToken);

LOGGER.info("구글 로그인 완료");

return tokenResponseDto;
return authService.googleLogin(accessToken);
}





}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FirebaseController {


@PostMapping(value = "/firebase-token")
public BaseResponseDto insertFirebaseToken(HttpServletRequest request) {
public BaseResponseDto<Void> insertFirebaseToken(HttpServletRequest request) {

String userId = jwtTokenProvider.getUserId(request);
String fireBaseToken = jwtTokenProvider.getFirebaseToken(request);
Expand All @@ -33,7 +33,7 @@ public BaseResponseDto insertFirebaseToken(HttpServletRequest request) {


@DeleteMapping(value = "/firebase-token")
public BaseResponseDto deleteFirebaseToken(HttpServletRequest request) {
public BaseResponseDto<Void> deleteFirebaseToken(HttpServletRequest request) {

String userId = jwtTokenProvider.getUserId(request);
String fireBaseToken = jwtTokenProvider.getFirebaseToken(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import modernfarmer.server.farmususer.user.dto.request.OnBoardingLevelRequest;
import modernfarmer.server.farmususer.user.dto.request.OnBoardingMotivationRequest;
import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto;
import modernfarmer.server.farmususer.user.dto.response.OnBoardingLevelResponse;
import modernfarmer.server.farmususer.user.service.OnBoardingService;
import modernfarmer.server.farmususer.user.util.JwtTokenProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -27,22 +27,18 @@ public class OnBoardingController {


@PostMapping(value = "/motivation")
public BaseResponseDto onBoardingMotivation(HttpServletRequest request, @Validated @RequestBody OnBoardingMotivationRequest onBoardingMotivationRequest) {
public BaseResponseDto<Void> onBoardingMotivation(HttpServletRequest request, @Validated @RequestBody OnBoardingMotivationRequest onBoardingMotivationRequest) {

String userId = jwtTokenProvider.getUserId(request);

BaseResponseDto responseDto = onBoardingService.onBoardingMotivation(Long.valueOf(userId),onBoardingMotivationRequest);

return responseDto;
return onBoardingService.onBoardingMotivation(Long.valueOf(userId),onBoardingMotivationRequest);
}

@PostMapping(value = "/level")
public BaseResponseDto onBoardingLevel(HttpServletRequest request, @Validated @RequestBody OnBoardingLevelRequest onBoardingLevelRequest) {
public BaseResponseDto<OnBoardingLevelResponse> onBoardingLevel(HttpServletRequest request, @Validated @RequestBody OnBoardingLevelRequest onBoardingLevelRequest) {

String userId = jwtTokenProvider.getUserId(request);

BaseResponseDto responseDto = onBoardingService.onBoardingLevel(Long.valueOf(userId), onBoardingLevelRequest);

return responseDto;
return onBoardingService.onBoardingLevel(Long.valueOf(userId), onBoardingLevelRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import modernfarmer.server.farmususer.user.dto.request.ProduceNicknameRequest;
import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto;
import modernfarmer.server.farmususer.user.dto.response.*;

import modernfarmer.server.farmususer.user.service.UserService;
import modernfarmer.server.farmususer.user.util.JwtTokenProvider;
Expand Down Expand Up @@ -36,7 +36,7 @@ public class UserController {
// }

@GetMapping
public BaseResponseDto getUser(HttpServletRequest request){
public BaseResponseDto<GetUserResponseDto> getUser(HttpServletRequest request){

String userId = jwtTokenProvider.getUserId(request);

Expand All @@ -45,90 +45,68 @@ public BaseResponseDto getUser(HttpServletRequest request){




@PostMapping(value = "/nickname")
public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){
public BaseResponseDto<Void> emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){

String userId = jwtTokenProvider.getUserId(request);

BaseResponseDto responseDto = userService.emitNickname(Long.valueOf(userId), produceNicknameRequest.getNickName());

return responseDto;
return userService.emitNickname(Long.valueOf(userId), produceNicknameRequest.getNickName());
}

@PostMapping(value = "/select-information", produces = MediaType.APPLICATION_JSON_VALUE)
public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, @RequestPart(value = "file", required = false) MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException {
public BaseResponseDto<Void> selectProfileImageAndNickname(HttpServletRequest request, @RequestPart(value = "file", required = false) MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException {

String userId = jwtTokenProvider.getUserId(request);

BaseResponseDto responseDto = userService.selectProfileImageAndNickname(Long.valueOf(userId), multipartFile,nickName);

return responseDto;
return userService.selectProfileImageAndNickname(Long.valueOf(userId), multipartFile,nickName);

}

@PatchMapping(value = "/sign-up/complete", produces = MediaType.APPLICATION_JSON_VALUE)
public BaseResponseDto signUpComplete(HttpServletRequest request) {
public BaseResponseDto<Void> signUpComplete(HttpServletRequest request) {

String userId = jwtTokenProvider.getUserId(request);


BaseResponseDto responseDto = userService.signUpComlete(Long.valueOf(userId));

return responseDto;
return userService.signUpComlete(Long.valueOf(userId));

}

@GetMapping(value = "/profileImage")
public BaseResponseDto selectProfileImage(HttpServletRequest request){
public BaseResponseDto<ProfileImageResponseDto> selectProfileImage(HttpServletRequest request){

String userId = jwtTokenProvider.getUserId(request);


BaseResponseDto profileImageResponseDto = userService.selectProfileImage(Long.valueOf(userId));

return profileImageResponseDto;
return userService.selectProfileImage(Long.valueOf(userId));
}


@DeleteMapping(value = "/delete")
public BaseResponseDto deleteUser(HttpServletRequest request){
public BaseResponseDto<Void> deleteUser(HttpServletRequest request){

String userId = jwtTokenProvider.getUserId(request);

BaseResponseDto responseDto = userService.deleteUser(Long.valueOf(userId));

return responseDto;
return userService.deleteUser(Long.valueOf(userId));
}

@DeleteMapping("/logout")
public BaseResponseDto logout(HttpServletRequest request) {

public BaseResponseDto<Void> logout(HttpServletRequest request) {

String userId = jwtTokenProvider.getUserId(request);

BaseResponseDto logoutResponseDto = userService.logout(Long.valueOf(userId));

log.info("로그아웃 완료");

return logoutResponseDto;
return userService.logout(Long.valueOf(userId));
}

@GetMapping(value = "/reissue-token")
public BaseResponseDto reissueToken(HttpServletRequest request) {
public BaseResponseDto<RefreshTokenResponseDto> reissueToken(HttpServletRequest request) {

String userId = jwtTokenProvider.getUserId(request);
String refreshToken = jwtTokenProvider.resolveToken(request);

BaseResponseDto reissueTokenResponseDto = userService.reissueToken(refreshToken, Long.valueOf(userId));

log.info("토큰 재발급 완료");

return reissueTokenResponseDto;
return userService.reissueToken(refreshToken, Long.valueOf(userId));
}

@PatchMapping(value = "/delete/user-profile")
public BaseResponseDto deleteUserProfile(HttpServletRequest request) {
public BaseResponseDto<Void> deleteUserProfile(HttpServletRequest request) {

String userId = jwtTokenProvider.getUserId(request);

Expand All @@ -137,14 +115,13 @@ public BaseResponseDto deleteUserProfile(HttpServletRequest request) {


@GetMapping(value = "/all-user")
public BaseResponseDto allUser() {
public BaseResponseDto<AllUserResponseDto> allUser() {

return userService.allUser();
}

@GetMapping(value = "/specific-user")
public BaseResponseDto specificUser(@RequestParam("userId") Long userId) {

public BaseResponseDto<SpecificUserResponseDto> specificUser(@RequestParam("userId") Long userId) {

return userService.specificUser(userId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ public class BaseResponseDto<T> {
@JsonInclude(JsonInclude.Include.NON_NULL)
private T data;

public static <T> BaseResponseDto of(SuccessMessage successMessage, T data){
public static <T> BaseResponseDto<T> of(SuccessMessage successMessage, T data){

return BaseResponseDto.builder()
return BaseResponseDto.<T>builder()
.code(successMessage.getCode())
.message(successMessage.getMessage())
.data(data)
.build();
}

public static <T> BaseResponseDto of(ErrorMessage errorMessage){
public static <T> BaseResponseDto<T> of(ErrorMessage errorMessage){

return BaseResponseDto.builder()
return BaseResponseDto.<T>builder()
.code(errorMessage.getCode())
.message(errorMessage.getMessage())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@Builder
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Entity
@Table(name = "motivation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Getter
@Entity
@Builder
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Table(name = "users")
public class User extends BaseEntity{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@Builder
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Setter
@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Builder
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Setter
@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.lettuce.core.dynamic.annotation.Param;
import modernfarmer.server.farmususer.user.entity.User;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand Down Expand Up @@ -55,7 +56,8 @@ public interface UserRepository extends JpaRepository<User, Long> {

List<User> findAllBy();

Optional<User> findById(Long userId);
@NotNull
Optional<User> findById(@NotNull Long userId);



Expand Down
Loading

0 comments on commit 59ab095

Please sign in to comment.