From eb4165757a684e48e8d16e7edfbdc59cf85f1265 Mon Sep 17 00:00:00 2001 From: Mi Date: Mon, 25 Sep 2023 21:34:14 +0900 Subject: [PATCH 1/5] [ADD] CORS config --- .../mini_project/config/CorsConfig.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/com/alttalttal/mini_project/config/CorsConfig.java diff --git a/src/main/java/com/alttalttal/mini_project/config/CorsConfig.java b/src/main/java/com/alttalttal/mini_project/config/CorsConfig.java new file mode 100644 index 0000000..b381dac --- /dev/null +++ b/src/main/java/com/alttalttal/mini_project/config/CorsConfig.java @@ -0,0 +1,28 @@ +package com.alttalttal.mini_project.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +@Configuration +public class CorsConfig { + + // cors 설정 필터 + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + + config.setAllowCredentials(true); + config.addAllowedOriginPattern("*"); // 배포시 cors 적용할 주소 입력: secrets + config.addAllowedHeader("*"); // 클라이언트가 보낸 헤더 중 서버에서 허용할 것 + config.addAllowedMethod("*"); + config.addExposedHeader("*"); // 응답시 클라이언트가 엑세스 할 수 있는 헤더 + config.setMaxAge(600L); + source.registerCorsConfiguration("/**", config); // OriginPattern 의 모든 하위경로 cors 허용 + + return new CorsFilter(source); + } +} From 36efce61d104273577c40eaf783fe4f613e2567b Mon Sep 17 00:00:00 2001 From: Mi Date: Mon, 25 Sep 2023 21:35:16 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[ADD]=20Spring=20Security=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/WebSecurityConfig.java | 78 +++++++++++++ .../controller/UserController.java | 16 +-- .../jwt/JwtAuthenticationFilter.java | 103 ++++++++++++++++++ .../jwt/JwtAuthorizationFilter.java | 68 ++++++++++++ .../alttalttal/mini_project/jwt/JwtUtil.java | 25 ++++- .../security/UserDetailsImpl.java | 62 +++++++++++ .../security/UserDetailsServiceImpl.java | 24 ++++ .../mini_project/service/UserService.java | 32 ------ 8 files changed, 364 insertions(+), 44 deletions(-) create mode 100644 src/main/java/com/alttalttal/mini_project/config/WebSecurityConfig.java create mode 100644 src/main/java/com/alttalttal/mini_project/jwt/JwtAuthenticationFilter.java create mode 100644 src/main/java/com/alttalttal/mini_project/jwt/JwtAuthorizationFilter.java create mode 100644 src/main/java/com/alttalttal/mini_project/security/UserDetailsImpl.java create mode 100644 src/main/java/com/alttalttal/mini_project/security/UserDetailsServiceImpl.java diff --git a/src/main/java/com/alttalttal/mini_project/config/WebSecurityConfig.java b/src/main/java/com/alttalttal/mini_project/config/WebSecurityConfig.java new file mode 100644 index 0000000..6e08687 --- /dev/null +++ b/src/main/java/com/alttalttal/mini_project/config/WebSecurityConfig.java @@ -0,0 +1,78 @@ +package com.alttalttal.mini_project.config; + +import com.alttalttal.mini_project.jwt.JwtAuthenticationFilter; +import com.alttalttal.mini_project.jwt.JwtAuthorizationFilter; +import com.alttalttal.mini_project.jwt.JwtUtil; +import com.alttalttal.mini_project.security.UserDetailsServiceImpl; +import com.alttalttal.mini_project.service.RedisService; +import io.swagger.v3.oas.models.PathItem; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; + +@Configuration +@EnableWebSecurity +@RequiredArgsConstructor +public class WebSecurityConfig{ + private final JwtUtil jwtUtil; + private final CorsConfig corsConfig; + private final UserDetailsServiceImpl userDetailsService; + private final RedisService redisService; + private final AuthenticationConfiguration authenticationConfiguration; + + @Bean + public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception{ + return configuration.getAuthenticationManager(); + } + + @Bean + public JwtAuthenticationFilter jwtAuthenticationFilter() throws Exception { + JwtAuthenticationFilter filter = new JwtAuthenticationFilter(jwtUtil, redisService); + filter.setAuthenticationManager(authenticationManager(authenticationConfiguration)); + return filter; + } + + @Bean + public JwtAuthorizationFilter jwtAuthorizationFilter() { + return new JwtAuthorizationFilter(jwtUtil, userDetailsService); + } + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + // CSRF 설정 + http.csrf((csrf) -> csrf.disable()); + + // 기본 설정인 Session 방식은 사용하지 않고 JWT 방식을 사용하기 위한 설정 + http.sessionManagement((sessionManagement) -> + sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS) + ); + http.authorizeHttpRequests((authorizeHttpRequests) -> + authorizeHttpRequests + .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() // resources 접근 허용 설정 + .requestMatchers(new AntPathRequestMatcher("/")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/api/users/**")).permitAll() +// .requestMatchers(new AntPathRequestMatcher("/api/news", HttpMethod.GET.name())).permitAll() + .requestMatchers(new AntPathRequestMatcher("/main")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/recipes/**", PathItem.HttpMethod.GET.name())).permitAll() + .anyRequest().authenticated() // 그 외 요청은 인증 필요 + ); + + // 필터 관리 + http.addFilterBefore(jwtAuthorizationFilter(), JwtAuthenticationFilter.class); + http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); + http.addFilterBefore(corsConfig.corsFilter(), JwtAuthorizationFilter.class); + + return http.build(); + } +} diff --git a/src/main/java/com/alttalttal/mini_project/controller/UserController.java b/src/main/java/com/alttalttal/mini_project/controller/UserController.java index 18651ed..3fc76d7 100644 --- a/src/main/java/com/alttalttal/mini_project/controller/UserController.java +++ b/src/main/java/com/alttalttal/mini_project/controller/UserController.java @@ -11,7 +11,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -@RequestMapping("/users") +@RequestMapping("/api") @CrossOrigin(exposedHeaders = "*") @RestController public class UserController { @@ -23,23 +23,23 @@ public UserController(UserService userService, JwtUtil jwtUtil) { } - @PostMapping("/signup") + @PostMapping("/users/signup") public ResponseEntity createUser(@RequestBody SignUpRequestDto signUpRequestDto) { return userService.createUser(signUpRequestDto); } - @PostMapping("/login") - public ResponseEntity loginUser(@RequestBody LoginRequestDto loginRequestDto, HttpServletResponse response){ - return userService.loginUser(loginRequestDto, response); - } +// @PostMapping("/users/login") +// public ResponseEntity loginUser(@RequestBody LoginRequestDto loginRequestDto, HttpServletResponse response){ +// return userService.loginUser(loginRequestDto, response); +// } - @GetMapping("/logout") + @GetMapping("/users/logout") public ResponseEntity logoutUser(@RequestHeader(JwtUtil.ACCESS_HEADER) String accessToken, @RequestHeader(JwtUtil.REFRESH_HEADER) String refreshToken){ return userService.logoutUser(accessToken, refreshToken); } - @GetMapping("/info") + @GetMapping("/users/info") public UserInfoResponseDto userInfo(HttpServletRequest request, HttpServletResponse response){ return userService.userInfo(request, response); } diff --git a/src/main/java/com/alttalttal/mini_project/jwt/JwtAuthenticationFilter.java b/src/main/java/com/alttalttal/mini_project/jwt/JwtAuthenticationFilter.java new file mode 100644 index 0000000..9348bfe --- /dev/null +++ b/src/main/java/com/alttalttal/mini_project/jwt/JwtAuthenticationFilter.java @@ -0,0 +1,103 @@ +package com.alttalttal.mini_project.jwt; + +import com.alttalttal.mini_project.dto.LoginRequestDto; +import com.alttalttal.mini_project.entity.UserRoleEnum; +import com.alttalttal.mini_project.security.UserDetailsImpl; +import com.alttalttal.mini_project.service.RedisService; +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * 로그인 및 JWT 생성 + */ +@Slf4j(topic = "로그인 및 JWT 생성") +public class JwtAuthenticationFilter extends UsernamePasswordAuthenticationFilter { + private final JwtUtil jwtUtil; + private final RedisService redisService; + + public JwtAuthenticationFilter(JwtUtil jwtUtil, RedisService redisService) { + this.jwtUtil = jwtUtil; + this.redisService = redisService; + setFilterProcessesUrl("/api/users/login"); + } + + @Override + public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException{ + log.info("로그인 시도"); + try{ + LoginRequestDto requestDto = new ObjectMapper().readValue(request.getInputStream(), LoginRequestDto.class); + + return getAuthenticationManager().authenticate( + new UsernamePasswordAuthenticationToken( + requestDto.getEmail(), + requestDto.getPassword(), + null + ) + ); + }catch (IOException e){ + log.error(e.getMessage()); + throw new RuntimeException(e.getMessage()); + } + } + + @Override + protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException { + log.info("로그인 성공 및 JWT 생성"); + String email = ((UserDetailsImpl) authResult.getPrincipal()).getUsername(); + UserRoleEnum role = ((UserDetailsImpl) authResult.getPrincipal()).getRole(); + + //JWT Token 생성 + String accessToken = jwtUtil.createAccessToken(email, role); + String refreshToken = jwtUtil.createRefreshToken(email, role); + + response.addHeader(JwtUtil.ACCESS_HEADER, accessToken); + response.addHeader(JwtUtil.REFRESH_HEADER, refreshToken); + + //Refresh Token 저장 + redisService.setValues(jwtUtil.substringToken(refreshToken), email, 60 * 60 * 24 * 30 * 1000L); + Map data = new LinkedHashMap<>(); + data.put("success", true); + data.put("statusCode", HttpServletResponse.SC_OK); + data.put("msg", "로그인 성공"); + + ObjectMapper mapper = new ObjectMapper(); + String jsonString = mapper.writeValueAsString(data); + + response.setContentType("application/json"); + response.setCharacterEncoding("UTF-8"); + response.getWriter().write(jsonString); + } + + @Override + protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException, ServletException { + log.info("로그인 실패"); + + Map data = new LinkedHashMap<>(); + data.put("success", false); + data.put("statusCode", HttpServletResponse.SC_BAD_REQUEST); + data.put("msg", failed.getMessage()); + + // 에러 메시지를 JSON 형식으로 생성 + ObjectMapper objectMapper = new ObjectMapper(); + String errorJson = objectMapper.writeValueAsString(data); + + // 응답에 에러 메시지 전송 + response.setContentType("application/json"); + response.setCharacterEncoding("UTF-8"); + response.getWriter().write(errorJson); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + } +} diff --git a/src/main/java/com/alttalttal/mini_project/jwt/JwtAuthorizationFilter.java b/src/main/java/com/alttalttal/mini_project/jwt/JwtAuthorizationFilter.java new file mode 100644 index 0000000..3c28193 --- /dev/null +++ b/src/main/java/com/alttalttal/mini_project/jwt/JwtAuthorizationFilter.java @@ -0,0 +1,68 @@ +package com.alttalttal.mini_project.jwt; + +import com.alttalttal.mini_project.security.UserDetailsServiceImpl; +import io.jsonwebtoken.Claims; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.util.StringUtils; +import org.springframework.web.filter.OncePerRequestFilter; + +import java.io.IOException; + +@Slf4j(topic = "JWT 검증 및 인가") +public class JwtAuthorizationFilter extends OncePerRequestFilter { + private final JwtUtil jwtUtil; + private final UserDetailsServiceImpl userDetailsService; + + public JwtAuthorizationFilter(JwtUtil jwtUtil, UserDetailsServiceImpl userDetailsService) { + this.jwtUtil = jwtUtil; + this.userDetailsService = userDetailsService; + } + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { + String accessTokenValue = jwtUtil.getAccessJwtFromHeader(request); + String refreshTokenValue = jwtUtil.getRefreshJwtFromHeader(request); + + if(StringUtils.hasText(accessTokenValue)){ + log.info(accessTokenValue); + + if (!jwtUtil.validateAllToken(accessTokenValue, refreshTokenValue, response)) { + log.error("Token Error"); + return; + } + + Claims info = jwtUtil.getUserInfoFromToken(accessTokenValue.split(" ")[1].trim()); + + try { + setAuthentication(info.getSubject()); + } catch (Exception e) { + log.error(e.getMessage()); + return; + } + } + filterChain.doFilter(request, response); + } + + public void setAuthentication(String email) { + SecurityContext context = SecurityContextHolder.createEmptyContext(); + Authentication authentication = createAuthentication(email); + context.setAuthentication(authentication); + + SecurityContextHolder.setContext(context); + } + + // 인증 객체 생성 + private Authentication createAuthentication(String email) { + UserDetails userDetails = userDetailsService.loadUserByUsername(email); + return new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); + } +} diff --git a/src/main/java/com/alttalttal/mini_project/jwt/JwtUtil.java b/src/main/java/com/alttalttal/mini_project/jwt/JwtUtil.java index a3dfa75..fa8d57c 100644 --- a/src/main/java/com/alttalttal/mini_project/jwt/JwtUtil.java +++ b/src/main/java/com/alttalttal/mini_project/jwt/JwtUtil.java @@ -112,7 +112,7 @@ public void addJwtToCookie(String token, String tokenValue, HttpServletResponse // 받아온 Cookie의 Value인 JWT 토큰 substring public String substringToken(String tokenValue){ if(StringUtils.hasText(tokenValue) && tokenValue.startsWith(BEARER_PREFIX)){ - return tokenValue.substring(7); + return tokenValue.substring("Bearer ".length()); } logger.error("Not Found Token"); throw new IllegalArgumentException("Not Found Token"); @@ -135,6 +135,24 @@ public String getTokenFromRequest(String tokenValue, HttpServletRequest req) { return null; } + // header 에서 Access JWT 가져오기 + public String getAccessJwtFromHeader(HttpServletRequest request) { + String bearerToken = request.getHeader(ACCESS_HEADER); + if (StringUtils.hasText(bearerToken) && bearerToken.startsWith(BEARER_PREFIX)) { + return bearerToken; + } + return null; + } + + // header 에서 Refresh JWT 가져오기 + public String getRefreshJwtFromHeader(HttpServletRequest request) { + String bearerToken = request.getHeader(REFRESH_HEADER); + if (StringUtils.hasText(bearerToken) && bearerToken.startsWith(BEARER_PREFIX)) { + return bearerToken; + } + return null; + } + // Token 검증 public boolean validateToken(String token) { try { @@ -155,9 +173,8 @@ public boolean validateToken(String token) { public boolean validateAllToken(String accessToken, String refreshToken, HttpServletResponse response) { - - accessToken = substringToken(accessToken); - refreshToken = substringToken(refreshToken); + accessToken = accessToken.substring("Bearer ".length()); + refreshToken = refreshToken.substring("Bearer ".length()); if(accessToken != null){ // accessToken 비어있지 않고 if(validateToken(accessToken) && redisService.getValue(accessToken) == null){ // access 검증, 로그아웃하지 않았다 diff --git a/src/main/java/com/alttalttal/mini_project/security/UserDetailsImpl.java b/src/main/java/com/alttalttal/mini_project/security/UserDetailsImpl.java new file mode 100644 index 0000000..d8e565e --- /dev/null +++ b/src/main/java/com/alttalttal/mini_project/security/UserDetailsImpl.java @@ -0,0 +1,62 @@ +package com.alttalttal.mini_project.security; + +import com.alttalttal.mini_project.entity.User; +import com.alttalttal.mini_project.entity.UserRoleEnum; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Collection; + +public class UserDetailsImpl implements UserDetails { + private final User user; + + public UserDetailsImpl(User user){ + this.user = user; + } + + public User getUser() { + return user; + } + + @Override + public Collection getAuthorities() { + return null; + } + + @Override + public String getPassword() { + return user.getPassword(); + } + + @Override + public String getUsername() { + return user.getEmail(); + } + + public String getNickname(){ + return user.getNickname(); + } + + public UserRoleEnum getRole(){ + return user.getRole(); + } + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return true; + } +} diff --git a/src/main/java/com/alttalttal/mini_project/security/UserDetailsServiceImpl.java b/src/main/java/com/alttalttal/mini_project/security/UserDetailsServiceImpl.java new file mode 100644 index 0000000..9284990 --- /dev/null +++ b/src/main/java/com/alttalttal/mini_project/security/UserDetailsServiceImpl.java @@ -0,0 +1,24 @@ +package com.alttalttal.mini_project.security; + +import com.alttalttal.mini_project.entity.User; +import com.alttalttal.mini_project.repository.UserRepository; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +@Service +public class UserDetailsServiceImpl implements UserDetailsService { + private final UserRepository userRepository; + + public UserDetailsServiceImpl(UserRepository userRepository) { + this.userRepository = userRepository; + } + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + User user = userRepository.findByEmail(username).orElseThrow(() -> new UsernameNotFoundException("없는 user입니다.")); + return new UserDetailsImpl(user); + } + +} diff --git a/src/main/java/com/alttalttal/mini_project/service/UserService.java b/src/main/java/com/alttalttal/mini_project/service/UserService.java index 81f7751..e421be5 100644 --- a/src/main/java/com/alttalttal/mini_project/service/UserService.java +++ b/src/main/java/com/alttalttal/mini_project/service/UserService.java @@ -66,38 +66,6 @@ public ResponseEntity createUser(SignUpRequestDto signUpRequ return new ResponseEntity<>(new MessageResponseDto("회원가입 성공!" , HttpStatus.OK.toString()), HttpStatus.OK); } - - public ResponseEntity loginUser(@RequestBody LoginRequestDto requestDto, HttpServletResponse res) { - String email = requestDto.getEmail(); - String password = requestDto.getPassword(); - - // 사용자 확인 - User user = userRepository.findByEmail(email).orElseThrow( - () -> new IllegalArgumentException("회원을 찾을 수 없습니다.") - ); - log.info("user = {}", user.getId()); - // 비밀번호 확인 - if(!passwordEncoder.matches(password, user.getPassword())){ - throw new IllegalArgumentException("비밀번호가 틀렸습니다."); - } - log.info("email = {}", user.getEmail()); - - // JWT 생성 - String acessToken = jwtUtil.createAccessToken(user.getEmail(), user.getRole()); - String refreshToken = jwtUtil.createRefreshToken(user.getEmail(), user.getRole()); - log.info("acessToken = {}", acessToken); - log.info("refreshToken = {}", refreshToken); - - res.addHeader(JwtUtil.ACCESS_HEADER, acessToken); - res.addHeader(JwtUtil.REFRESH_HEADER, refreshToken); - - - // Refresh Token 저장 - redisService.setValues(jwtUtil.substringToken(refreshToken), user.getEmail(), 60 * 60 * 24 * 30 * 1000L); - return new ResponseEntity<>(new MessageResponseDto("로그인 성공!", HttpStatus.OK.toString()), HttpStatus.OK); - } - - public ResponseEntity logoutUser(String accessToken, String refreshToken) { Long expiration = jwtUtil.getExpiration(jwtUtil.substringToken(refreshToken)); From d932f91185a9edaf06a592fa9b9d8cb04d0ed67b Mon Sep 17 00:00:00 2001 From: Mi Date: Mon, 25 Sep 2023 21:35:57 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[REFACTOR]=20=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F?= =?UTF-8?q?=20=ED=95=84=EC=9A=94=ED=95=9C=20=EB=B6=80=EB=B6=84=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alttalttal/mini_project/service/MainPageService.java | 2 ++ .../java/com/alttalttal/mini_project/service/RedisService.java | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/alttalttal/mini_project/service/MainPageService.java b/src/main/java/com/alttalttal/mini_project/service/MainPageService.java index 8577a51..9697514 100644 --- a/src/main/java/com/alttalttal/mini_project/service/MainPageService.java +++ b/src/main/java/com/alttalttal/mini_project/service/MainPageService.java @@ -8,6 +8,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.Collections; +import java.util.Comparator; import java.util.List; @Service diff --git a/src/main/java/com/alttalttal/mini_project/service/RedisService.java b/src/main/java/com/alttalttal/mini_project/service/RedisService.java index d9bcb31..c88153a 100644 --- a/src/main/java/com/alttalttal/mini_project/service/RedisService.java +++ b/src/main/java/com/alttalttal/mini_project/service/RedisService.java @@ -1,6 +1,5 @@ package com.alttalttal.mini_project.service; -import com.alttalttal.mini_project.jwt.JwtUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.RedisTemplate; From 17ed8d74eaa15b759b6ab760e9ba6f1fdb0fa496 Mon Sep 17 00:00:00 2001 From: Mi Date: Tue, 26 Sep 2023 17:56:29 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[REFACTOR]=20domain=EC=9D=84=20=EA=B8=B0?= =?UTF-8?q?=EC=A4=80=EC=9C=BC=EB=A1=9C=20Refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mini_project/MiniProjectApplication.java | 3 +- .../lounge}/controller/LoungeController.java | 12 ++++---- .../lounge}/dto/LoungeRequestDto.java | 2 +- .../lounge}/dto/LoungeResponseDto.java | 3 +- .../lounge/entity}/LoungeEntity.java | 7 +++-- .../lounge}/repository/LoungeRepository.java | 4 +-- .../lounge}/service/LoungeService.java | 17 ++++++----- .../main}/controller/MainPageController.java | 6 ++-- .../main}/dto/MainPageResponseDto.java | 4 ++- .../domain/main/service/MainPageService.java | 29 +++++++++++++++++++ .../mypage}/controller/MypageController.java | 10 +++---- .../mypage}/dto/MypageRequestDto.java | 2 +- .../mypage}/dto/MypageResponseDto.java | 6 ++-- .../mypage}/service/MypageService.java | 17 ++++++----- .../recipe}/controller/RecipeController.java | 13 ++++----- .../recipe}/dto/IngredientResponseDto.java | 4 +-- .../recipe}/dto/MakingDetailResponseDto.java | 4 +-- .../recipe}/dto/RecipeResponseDto.java | 4 +-- .../recipe}/dto/simpleRecipesResponseDto.java | 4 +-- .../recipe}/entity/MongoRecipe.java | 8 ++--- .../entity/recipe_component/Ingredient.java | 2 +- .../entity/recipe_component/MakingDetail.java | 2 +- .../recipe}/entity/recipe_component/Zzim.java | 2 +- .../repository/MongoRecipeRepository.java | 4 +-- .../recipe}/service/RecipeService.java | 15 +++++----- .../user}/controller/UserController.java | 15 +++++----- .../user}/dto/LoginRequestDto.java | 2 +- .../user}/dto/SignUpRequestDto.java | 2 +- .../user}/dto/UserInfoResponseDto.java | 2 +- .../{ => domain/user}/entity/User.java | 6 ++-- .../user}/entity/UserRoleEnum.java | 2 +- .../user}/repository/UserRepository.java | 4 +-- .../user}/service/RedisService.java | 2 +- .../user}/service/UserService.java | 19 ++++++------ .../{ => global}/config/CorsConfig.java | 2 +- .../{ => global}/config/MongoConfig.java | 2 +- .../{ => global}/config/PasswordConfig.java | 2 +- .../{ => global}/config/RedisConfig.java | 2 +- .../config/WebSecurityConfig.java | 14 ++++----- .../{ => global}/dto/MessageResponseDto.java | 2 +- .../{ => global}/entity/Timestamped.java | 2 +- .../handler/ExceptionCustomHandler.java | 4 +-- .../jwt/JwtAuthenticationFilter.java | 11 ++++--- .../jwt/JwtAuthorizationFilter.java | 4 +-- .../{ => global}/jwt/JwtUtil.java | 8 ++--- .../security/UserDetailsImpl.java | 6 ++-- .../security/UserDetailsServiceImpl.java | 6 ++-- .../token}/ServiceManager.java | 4 +-- .../token}/ServiceManagerImpl.java | 8 ++--- .../mini_project/service/MainPageService.java | 25 ---------------- 50 files changed, 173 insertions(+), 167 deletions(-) rename src/main/java/com/alttalttal/mini_project/{ => domain/lounge}/controller/LoungeController.java (77%) rename src/main/java/com/alttalttal/mini_project/{ => domain/lounge}/dto/LoungeRequestDto.java (87%) rename src/main/java/com/alttalttal/mini_project/{ => domain/lounge}/dto/LoungeResponseDto.java (81%) rename src/main/java/com/alttalttal/mini_project/{dto => domain/lounge/entity}/LoungeEntity.java (81%) rename src/main/java/com/alttalttal/mini_project/{ => domain/lounge}/repository/LoungeRepository.java (76%) rename src/main/java/com/alttalttal/mini_project/{ => domain/lounge}/service/LoungeService.java (84%) rename src/main/java/com/alttalttal/mini_project/{ => domain/main}/controller/MainPageController.java (74%) rename src/main/java/com/alttalttal/mini_project/{ => domain/main}/dto/MainPageResponseDto.java (68%) create mode 100644 src/main/java/com/alttalttal/mini_project/domain/main/service/MainPageService.java rename src/main/java/com/alttalttal/mini_project/{ => domain/mypage}/controller/MypageController.java (75%) rename src/main/java/com/alttalttal/mini_project/{ => domain/mypage}/dto/MypageRequestDto.java (72%) rename src/main/java/com/alttalttal/mini_project/{ => domain/mypage}/dto/MypageResponseDto.java (73%) rename src/main/java/com/alttalttal/mini_project/{ => domain/mypage}/service/MypageService.java (81%) rename src/main/java/com/alttalttal/mini_project/{ => domain/recipe}/controller/RecipeController.java (78%) rename src/main/java/com/alttalttal/mini_project/{ => domain/recipe}/dto/IngredientResponseDto.java (66%) rename src/main/java/com/alttalttal/mini_project/{ => domain/recipe}/dto/MakingDetailResponseDto.java (60%) rename src/main/java/com/alttalttal/mini_project/{ => domain/recipe}/dto/RecipeResponseDto.java (89%) rename src/main/java/com/alttalttal/mini_project/{ => domain/recipe}/dto/simpleRecipesResponseDto.java (81%) rename src/main/java/com/alttalttal/mini_project/{ => domain/recipe}/entity/MongoRecipe.java (63%) rename src/main/java/com/alttalttal/mini_project/{ => domain/recipe}/entity/recipe_component/Ingredient.java (66%) rename src/main/java/com/alttalttal/mini_project/{ => domain/recipe}/entity/recipe_component/MakingDetail.java (63%) rename src/main/java/com/alttalttal/mini_project/{ => domain/recipe}/entity/recipe_component/Zzim.java (86%) rename src/main/java/com/alttalttal/mini_project/{mongo => domain/recipe}/repository/MongoRecipeRepository.java (75%) rename src/main/java/com/alttalttal/mini_project/{ => domain/recipe}/service/RecipeService.java (88%) rename src/main/java/com/alttalttal/mini_project/{ => domain/user}/controller/UserController.java (78%) rename src/main/java/com/alttalttal/mini_project/{ => domain/user}/dto/LoginRequestDto.java (69%) rename src/main/java/com/alttalttal/mini_project/{ => domain/user}/dto/SignUpRequestDto.java (82%) rename src/main/java/com/alttalttal/mini_project/{ => domain/user}/dto/UserInfoResponseDto.java (82%) rename src/main/java/com/alttalttal/mini_project/{ => domain/user}/entity/User.java (84%) rename src/main/java/com/alttalttal/mini_project/{ => domain/user}/entity/UserRoleEnum.java (87%) rename src/main/java/com/alttalttal/mini_project/{ => domain/user}/repository/UserRepository.java (68%) rename src/main/java/com/alttalttal/mini_project/{ => domain/user}/service/RedisService.java (95%) rename src/main/java/com/alttalttal/mini_project/{ => domain/user}/service/UserService.java (86%) rename src/main/java/com/alttalttal/mini_project/{ => global}/config/CorsConfig.java (95%) rename src/main/java/com/alttalttal/mini_project/{ => global}/config/MongoConfig.java (96%) rename src/main/java/com/alttalttal/mini_project/{ => global}/config/PasswordConfig.java (88%) rename src/main/java/com/alttalttal/mini_project/{ => global}/config/RedisConfig.java (96%) rename src/main/java/com/alttalttal/mini_project/{ => global}/config/WebSecurityConfig.java (88%) rename src/main/java/com/alttalttal/mini_project/{ => global}/dto/MessageResponseDto.java (84%) rename src/main/java/com/alttalttal/mini_project/{ => global}/entity/Timestamped.java (92%) rename src/main/java/com/alttalttal/mini_project/{ => global}/handler/ExceptionCustomHandler.java (86%) rename src/main/java/com/alttalttal/mini_project/{ => global}/jwt/JwtAuthenticationFilter.java (92%) rename src/main/java/com/alttalttal/mini_project/{ => global}/jwt/JwtAuthorizationFilter.java (95%) rename src/main/java/com/alttalttal/mini_project/{ => global}/jwt/JwtUtil.java (97%) rename src/main/java/com/alttalttal/mini_project/{ => global}/security/UserDetailsImpl.java (86%) rename src/main/java/com/alttalttal/mini_project/{ => global}/security/UserDetailsServiceImpl.java (81%) rename src/main/java/com/alttalttal/mini_project/{service => global/token}/ServiceManager.java (71%) rename src/main/java/com/alttalttal/mini_project/{service => global/token}/ServiceManagerImpl.java (82%) delete mode 100644 src/main/java/com/alttalttal/mini_project/service/MainPageService.java diff --git a/src/main/java/com/alttalttal/mini_project/MiniProjectApplication.java b/src/main/java/com/alttalttal/mini_project/MiniProjectApplication.java index 2a12459..6f92ce5 100644 --- a/src/main/java/com/alttalttal/mini_project/MiniProjectApplication.java +++ b/src/main/java/com/alttalttal/mini_project/MiniProjectApplication.java @@ -11,8 +11,7 @@ @EnableJpaAuditing @SpringBootApplication(exclude = SecurityAutoConfiguration.class) // mysql repository와 mongodb repository의 package로 나눔 -@EnableJpaRepositories(basePackages = "com.alttalttal.mini_project.repository") -@EnableMongoRepositories(basePackages = "com.alttalttal.mini_project.mongo.repository") + public class MiniProjectApplication { public static void main(String[] args) { diff --git a/src/main/java/com/alttalttal/mini_project/controller/LoungeController.java b/src/main/java/com/alttalttal/mini_project/domain/lounge/controller/LoungeController.java similarity index 77% rename from src/main/java/com/alttalttal/mini_project/controller/LoungeController.java rename to src/main/java/com/alttalttal/mini_project/domain/lounge/controller/LoungeController.java index 97ef1f9..69868e7 100644 --- a/src/main/java/com/alttalttal/mini_project/controller/LoungeController.java +++ b/src/main/java/com/alttalttal/mini_project/domain/lounge/controller/LoungeController.java @@ -1,10 +1,10 @@ -package com.alttalttal.mini_project.controller; +package com.alttalttal.mini_project.domain.lounge.controller; -import com.alttalttal.mini_project.dto.LoungeRequestDto; -import com.alttalttal.mini_project.dto.LoungeResponseDto; -import com.alttalttal.mini_project.dto.MessageResponseDto; -import com.alttalttal.mini_project.jwt.JwtUtil; -import com.alttalttal.mini_project.service.LoungeService; +import com.alttalttal.mini_project.domain.lounge.dto.LoungeRequestDto; +import com.alttalttal.mini_project.domain.lounge.dto.LoungeResponseDto; +import com.alttalttal.mini_project.global.dto.MessageResponseDto; +import com.alttalttal.mini_project.global.jwt.JwtUtil; +import com.alttalttal.mini_project.domain.lounge.service.LoungeService; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/com/alttalttal/mini_project/dto/LoungeRequestDto.java b/src/main/java/com/alttalttal/mini_project/domain/lounge/dto/LoungeRequestDto.java similarity index 87% rename from src/main/java/com/alttalttal/mini_project/dto/LoungeRequestDto.java rename to src/main/java/com/alttalttal/mini_project/domain/lounge/dto/LoungeRequestDto.java index 478b6ea..0b95019 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/LoungeRequestDto.java +++ b/src/main/java/com/alttalttal/mini_project/domain/lounge/dto/LoungeRequestDto.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.lounge.dto; import lombok.*; diff --git a/src/main/java/com/alttalttal/mini_project/dto/LoungeResponseDto.java b/src/main/java/com/alttalttal/mini_project/domain/lounge/dto/LoungeResponseDto.java similarity index 81% rename from src/main/java/com/alttalttal/mini_project/dto/LoungeResponseDto.java rename to src/main/java/com/alttalttal/mini_project/domain/lounge/dto/LoungeResponseDto.java index c9b5403..42763a0 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/LoungeResponseDto.java +++ b/src/main/java/com/alttalttal/mini_project/domain/lounge/dto/LoungeResponseDto.java @@ -1,5 +1,6 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.lounge.dto; +import com.alttalttal.mini_project.domain.lounge.entity.LoungeEntity; import lombok.Getter; import java.time.LocalDateTime; diff --git a/src/main/java/com/alttalttal/mini_project/dto/LoungeEntity.java b/src/main/java/com/alttalttal/mini_project/domain/lounge/entity/LoungeEntity.java similarity index 81% rename from src/main/java/com/alttalttal/mini_project/dto/LoungeEntity.java rename to src/main/java/com/alttalttal/mini_project/domain/lounge/entity/LoungeEntity.java index a6b1d10..46f04c4 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/LoungeEntity.java +++ b/src/main/java/com/alttalttal/mini_project/domain/lounge/entity/LoungeEntity.java @@ -1,8 +1,9 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.lounge.entity; -import com.alttalttal.mini_project.entity.Timestamped; -import com.alttalttal.mini_project.entity.User; +import com.alttalttal.mini_project.domain.lounge.dto.LoungeRequestDto; +import com.alttalttal.mini_project.global.entity.Timestamped; +import com.alttalttal.mini_project.domain.user.entity.User; import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/alttalttal/mini_project/repository/LoungeRepository.java b/src/main/java/com/alttalttal/mini_project/domain/lounge/repository/LoungeRepository.java similarity index 76% rename from src/main/java/com/alttalttal/mini_project/repository/LoungeRepository.java rename to src/main/java/com/alttalttal/mini_project/domain/lounge/repository/LoungeRepository.java index 153dfd3..f78a111 100644 --- a/src/main/java/com/alttalttal/mini_project/repository/LoungeRepository.java +++ b/src/main/java/com/alttalttal/mini_project/domain/lounge/repository/LoungeRepository.java @@ -1,6 +1,6 @@ -package com.alttalttal.mini_project.repository; +package com.alttalttal.mini_project.domain.lounge.repository; -import com.alttalttal.mini_project.dto.LoungeEntity; +import com.alttalttal.mini_project.domain.lounge.entity.LoungeEntity; import org.springframework.data.jpa.repository.JpaRepository; public interface LoungeRepository extends JpaRepository { diff --git a/src/main/java/com/alttalttal/mini_project/service/LoungeService.java b/src/main/java/com/alttalttal/mini_project/domain/lounge/service/LoungeService.java similarity index 84% rename from src/main/java/com/alttalttal/mini_project/service/LoungeService.java rename to src/main/java/com/alttalttal/mini_project/domain/lounge/service/LoungeService.java index c7fc696..f7e9a8e 100644 --- a/src/main/java/com/alttalttal/mini_project/service/LoungeService.java +++ b/src/main/java/com/alttalttal/mini_project/domain/lounge/service/LoungeService.java @@ -1,17 +1,18 @@ -package com.alttalttal.mini_project.service; +package com.alttalttal.mini_project.domain.lounge.service; -import com.alttalttal.mini_project.dto.LoungeRequestDto; -import com.alttalttal.mini_project.dto.LoungeResponseDto; -import com.alttalttal.mini_project.dto.LoungeEntity; -import com.alttalttal.mini_project.entity.User; -import com.alttalttal.mini_project.jwt.JwtUtil; -import com.alttalttal.mini_project.repository.LoungeRepository; +import com.alttalttal.mini_project.domain.lounge.dto.LoungeRequestDto; +import com.alttalttal.mini_project.domain.lounge.dto.LoungeResponseDto; +import com.alttalttal.mini_project.domain.lounge.entity.LoungeEntity; +import com.alttalttal.mini_project.domain.user.entity.User; +import com.alttalttal.mini_project.global.jwt.JwtUtil; +import com.alttalttal.mini_project.domain.lounge.repository.LoungeRepository; +import com.alttalttal.mini_project.global.token.ServiceManagerImpl; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import com.alttalttal.mini_project.dto.MessageResponseDto; +import com.alttalttal.mini_project.global.dto.MessageResponseDto; import java.util.List; diff --git a/src/main/java/com/alttalttal/mini_project/controller/MainPageController.java b/src/main/java/com/alttalttal/mini_project/domain/main/controller/MainPageController.java similarity index 74% rename from src/main/java/com/alttalttal/mini_project/controller/MainPageController.java rename to src/main/java/com/alttalttal/mini_project/domain/main/controller/MainPageController.java index 58faea2..7c628b9 100644 --- a/src/main/java/com/alttalttal/mini_project/controller/MainPageController.java +++ b/src/main/java/com/alttalttal/mini_project/domain/main/controller/MainPageController.java @@ -1,7 +1,7 @@ -package com.alttalttal.mini_project.controller; +package com.alttalttal.mini_project.domain.main.controller; -import com.alttalttal.mini_project.dto.MainPageResponseDto; -import com.alttalttal.mini_project.service.MainPageService; +import com.alttalttal.mini_project.domain.main.dto.MainPageResponseDto; +import com.alttalttal.mini_project.domain.main.service.MainPageService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; diff --git a/src/main/java/com/alttalttal/mini_project/dto/MainPageResponseDto.java b/src/main/java/com/alttalttal/mini_project/domain/main/dto/MainPageResponseDto.java similarity index 68% rename from src/main/java/com/alttalttal/mini_project/dto/MainPageResponseDto.java rename to src/main/java/com/alttalttal/mini_project/domain/main/dto/MainPageResponseDto.java index 2d9ee08..ecde902 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/MainPageResponseDto.java +++ b/src/main/java/com/alttalttal/mini_project/domain/main/dto/MainPageResponseDto.java @@ -1,5 +1,7 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.main.dto; +import com.alttalttal.mini_project.domain.lounge.dto.LoungeResponseDto; +import com.alttalttal.mini_project.domain.recipe.dto.simpleRecipesResponseDto; import lombok.Getter; import java.util.List; diff --git a/src/main/java/com/alttalttal/mini_project/domain/main/service/MainPageService.java b/src/main/java/com/alttalttal/mini_project/domain/main/service/MainPageService.java new file mode 100644 index 0000000..298b686 --- /dev/null +++ b/src/main/java/com/alttalttal/mini_project/domain/main/service/MainPageService.java @@ -0,0 +1,29 @@ +package com.alttalttal.mini_project.domain.main.service; + +import com.alttalttal.mini_project.domain.lounge.dto.LoungeResponseDto; +import com.alttalttal.mini_project.domain.main.dto.MainPageResponseDto; +import com.alttalttal.mini_project.domain.recipe.dto.simpleRecipesResponseDto; +import com.alttalttal.mini_project.domain.recipe.entity.MongoRecipe; +import com.alttalttal.mini_project.domain.recipe.repository.MongoRecipeRepository; +import com.alttalttal.mini_project.domain.lounge.repository.LoungeRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class MainPageService { + private final MongoRecipeRepository mongoRecipeRepository; + private final LoungeRepository loungeRepository; + public MainPageResponseDto getMainPage() { + List mongoRecipeList = mongoRecipeRepository.findAll(); + mongoRecipeList.sort(Comparator.comparingInt(mongoRecipe -> mongoRecipe.getZzimUserIdList().size())); + Collections.reverse(mongoRecipeList); + List simpleRecipesResponseDtoList = mongoRecipeList.stream().limit(9).map(simpleRecipesResponseDto::new).toList(); + List loungeResponseDtoList = loungeRepository.findAll().stream().map(LoungeResponseDto::new).toList(); + return new MainPageResponseDto(simpleRecipesResponseDtoList, loungeResponseDtoList); + } +} diff --git a/src/main/java/com/alttalttal/mini_project/controller/MypageController.java b/src/main/java/com/alttalttal/mini_project/domain/mypage/controller/MypageController.java similarity index 75% rename from src/main/java/com/alttalttal/mini_project/controller/MypageController.java rename to src/main/java/com/alttalttal/mini_project/domain/mypage/controller/MypageController.java index 34fbc37..3d3baee 100644 --- a/src/main/java/com/alttalttal/mini_project/controller/MypageController.java +++ b/src/main/java/com/alttalttal/mini_project/domain/mypage/controller/MypageController.java @@ -1,9 +1,9 @@ -package com.alttalttal.mini_project.controller; +package com.alttalttal.mini_project.domain.mypage.controller; -import com.alttalttal.mini_project.dto.MypageRequestDto; -import com.alttalttal.mini_project.dto.MypageResponseDto; -import com.alttalttal.mini_project.jwt.JwtUtil; -import com.alttalttal.mini_project.service.MypageService; +import com.alttalttal.mini_project.domain.mypage.dto.MypageRequestDto; +import com.alttalttal.mini_project.domain.mypage.dto.MypageResponseDto; +import com.alttalttal.mini_project.global.jwt.JwtUtil; +import com.alttalttal.mini_project.domain.mypage.service.MypageService; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/com/alttalttal/mini_project/dto/MypageRequestDto.java b/src/main/java/com/alttalttal/mini_project/domain/mypage/dto/MypageRequestDto.java similarity index 72% rename from src/main/java/com/alttalttal/mini_project/dto/MypageRequestDto.java rename to src/main/java/com/alttalttal/mini_project/domain/mypage/dto/MypageRequestDto.java index 733bd16..6c68b82 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/MypageRequestDto.java +++ b/src/main/java/com/alttalttal/mini_project/domain/mypage/dto/MypageRequestDto.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.mypage.dto; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/alttalttal/mini_project/dto/MypageResponseDto.java b/src/main/java/com/alttalttal/mini_project/domain/mypage/dto/MypageResponseDto.java similarity index 73% rename from src/main/java/com/alttalttal/mini_project/dto/MypageResponseDto.java rename to src/main/java/com/alttalttal/mini_project/domain/mypage/dto/MypageResponseDto.java index 913ddc1..994c6ab 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/MypageResponseDto.java +++ b/src/main/java/com/alttalttal/mini_project/domain/mypage/dto/MypageResponseDto.java @@ -1,6 +1,8 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.mypage.dto; -import com.alttalttal.mini_project.entity.User; +import com.alttalttal.mini_project.domain.lounge.dto.LoungeResponseDto; +import com.alttalttal.mini_project.domain.user.entity.User; +import com.alttalttal.mini_project.domain.recipe.dto.simpleRecipesResponseDto; import lombok.Getter; import java.util.List; diff --git a/src/main/java/com/alttalttal/mini_project/service/MypageService.java b/src/main/java/com/alttalttal/mini_project/domain/mypage/service/MypageService.java similarity index 81% rename from src/main/java/com/alttalttal/mini_project/service/MypageService.java rename to src/main/java/com/alttalttal/mini_project/domain/mypage/service/MypageService.java index 7bebaaf..2b40d93 100644 --- a/src/main/java/com/alttalttal/mini_project/service/MypageService.java +++ b/src/main/java/com/alttalttal/mini_project/domain/mypage/service/MypageService.java @@ -1,11 +1,12 @@ -package com.alttalttal.mini_project.service; - -import com.alttalttal.mini_project.dto.MypageRequestDto; -import com.alttalttal.mini_project.dto.MypageResponseDto; -import com.alttalttal.mini_project.dto.simpleRecipesResponseDto; -import com.alttalttal.mini_project.entity.User; -import com.alttalttal.mini_project.jwt.JwtUtil; -import com.alttalttal.mini_project.mongo.repository.MongoRecipeRepository; +package com.alttalttal.mini_project.domain.mypage.service; + +import com.alttalttal.mini_project.domain.mypage.dto.MypageRequestDto; +import com.alttalttal.mini_project.domain.mypage.dto.MypageResponseDto; +import com.alttalttal.mini_project.domain.recipe.dto.simpleRecipesResponseDto; +import com.alttalttal.mini_project.domain.user.entity.User; +import com.alttalttal.mini_project.global.jwt.JwtUtil; +import com.alttalttal.mini_project.domain.recipe.repository.MongoRecipeRepository; +import com.alttalttal.mini_project.global.token.ServiceManagerImpl; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/alttalttal/mini_project/controller/RecipeController.java b/src/main/java/com/alttalttal/mini_project/domain/recipe/controller/RecipeController.java similarity index 78% rename from src/main/java/com/alttalttal/mini_project/controller/RecipeController.java rename to src/main/java/com/alttalttal/mini_project/domain/recipe/controller/RecipeController.java index a5488ac..d5a4beb 100644 --- a/src/main/java/com/alttalttal/mini_project/controller/RecipeController.java +++ b/src/main/java/com/alttalttal/mini_project/domain/recipe/controller/RecipeController.java @@ -1,11 +1,10 @@ -package com.alttalttal.mini_project.controller; +package com.alttalttal.mini_project.domain.recipe.controller; -import com.alttalttal.mini_project.dto.MessageResponseDto; -import com.alttalttal.mini_project.dto.RecipeResponseDto; -import com.alttalttal.mini_project.dto.simpleRecipesResponseDto; -import com.alttalttal.mini_project.jwt.JwtUtil; -import com.alttalttal.mini_project.repository.UserRepository; -import com.alttalttal.mini_project.service.RecipeService; +import com.alttalttal.mini_project.global.dto.MessageResponseDto; +import com.alttalttal.mini_project.domain.recipe.dto.RecipeResponseDto; +import com.alttalttal.mini_project.domain.recipe.dto.simpleRecipesResponseDto; +import com.alttalttal.mini_project.global.jwt.JwtUtil; +import com.alttalttal.mini_project.domain.recipe.service.RecipeService; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/alttalttal/mini_project/dto/IngredientResponseDto.java b/src/main/java/com/alttalttal/mini_project/domain/recipe/dto/IngredientResponseDto.java similarity index 66% rename from src/main/java/com/alttalttal/mini_project/dto/IngredientResponseDto.java rename to src/main/java/com/alttalttal/mini_project/domain/recipe/dto/IngredientResponseDto.java index 9668ce4..781f43b 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/IngredientResponseDto.java +++ b/src/main/java/com/alttalttal/mini_project/domain/recipe/dto/IngredientResponseDto.java @@ -1,6 +1,6 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.recipe.dto; -import com.alttalttal.mini_project.entity.recipe_component.Ingredient; +import com.alttalttal.mini_project.domain.recipe.entity.recipe_component.Ingredient; import lombok.Getter; @Getter diff --git a/src/main/java/com/alttalttal/mini_project/dto/MakingDetailResponseDto.java b/src/main/java/com/alttalttal/mini_project/domain/recipe/dto/MakingDetailResponseDto.java similarity index 60% rename from src/main/java/com/alttalttal/mini_project/dto/MakingDetailResponseDto.java rename to src/main/java/com/alttalttal/mini_project/domain/recipe/dto/MakingDetailResponseDto.java index 4c57fc4..cdc8963 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/MakingDetailResponseDto.java +++ b/src/main/java/com/alttalttal/mini_project/domain/recipe/dto/MakingDetailResponseDto.java @@ -1,6 +1,6 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.recipe.dto; -import com.alttalttal.mini_project.entity.recipe_component.MakingDetail; +import com.alttalttal.mini_project.domain.recipe.entity.recipe_component.MakingDetail; import lombok.Getter; @Getter diff --git a/src/main/java/com/alttalttal/mini_project/dto/RecipeResponseDto.java b/src/main/java/com/alttalttal/mini_project/domain/recipe/dto/RecipeResponseDto.java similarity index 89% rename from src/main/java/com/alttalttal/mini_project/dto/RecipeResponseDto.java rename to src/main/java/com/alttalttal/mini_project/domain/recipe/dto/RecipeResponseDto.java index 415afeb..30b2dbf 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/RecipeResponseDto.java +++ b/src/main/java/com/alttalttal/mini_project/domain/recipe/dto/RecipeResponseDto.java @@ -1,6 +1,6 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.recipe.dto; -import com.alttalttal.mini_project.entity.MongoRecipe; +import com.alttalttal.mini_project.domain.recipe.entity.MongoRecipe; import lombok.Getter; import java.util.List; diff --git a/src/main/java/com/alttalttal/mini_project/dto/simpleRecipesResponseDto.java b/src/main/java/com/alttalttal/mini_project/domain/recipe/dto/simpleRecipesResponseDto.java similarity index 81% rename from src/main/java/com/alttalttal/mini_project/dto/simpleRecipesResponseDto.java rename to src/main/java/com/alttalttal/mini_project/domain/recipe/dto/simpleRecipesResponseDto.java index 2a3125d..de78343 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/simpleRecipesResponseDto.java +++ b/src/main/java/com/alttalttal/mini_project/domain/recipe/dto/simpleRecipesResponseDto.java @@ -1,6 +1,6 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.recipe.dto; -import com.alttalttal.mini_project.entity.MongoRecipe; +import com.alttalttal.mini_project.domain.recipe.entity.MongoRecipe; import lombok.Getter; @Getter diff --git a/src/main/java/com/alttalttal/mini_project/entity/MongoRecipe.java b/src/main/java/com/alttalttal/mini_project/domain/recipe/entity/MongoRecipe.java similarity index 63% rename from src/main/java/com/alttalttal/mini_project/entity/MongoRecipe.java rename to src/main/java/com/alttalttal/mini_project/domain/recipe/entity/MongoRecipe.java index 917862d..d8222fe 100644 --- a/src/main/java/com/alttalttal/mini_project/entity/MongoRecipe.java +++ b/src/main/java/com/alttalttal/mini_project/domain/recipe/entity/MongoRecipe.java @@ -1,8 +1,8 @@ -package com.alttalttal.mini_project.entity; +package com.alttalttal.mini_project.domain.recipe.entity; -import com.alttalttal.mini_project.entity.recipe_component.Ingredient; -import com.alttalttal.mini_project.entity.recipe_component.MakingDetail; -import com.alttalttal.mini_project.entity.recipe_component.Zzim; +import com.alttalttal.mini_project.domain.recipe.entity.recipe_component.Ingredient; +import com.alttalttal.mini_project.domain.recipe.entity.recipe_component.MakingDetail; +import com.alttalttal.mini_project.domain.recipe.entity.recipe_component.Zzim; import jakarta.persistence.Id; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/alttalttal/mini_project/entity/recipe_component/Ingredient.java b/src/main/java/com/alttalttal/mini_project/domain/recipe/entity/recipe_component/Ingredient.java similarity index 66% rename from src/main/java/com/alttalttal/mini_project/entity/recipe_component/Ingredient.java rename to src/main/java/com/alttalttal/mini_project/domain/recipe/entity/recipe_component/Ingredient.java index 8ff9819..e6aaad1 100644 --- a/src/main/java/com/alttalttal/mini_project/entity/recipe_component/Ingredient.java +++ b/src/main/java/com/alttalttal/mini_project/domain/recipe/entity/recipe_component/Ingredient.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.entity.recipe_component; +package com.alttalttal.mini_project.domain.recipe.entity.recipe_component; import jakarta.persistence.Embeddable; import lombok.Getter; diff --git a/src/main/java/com/alttalttal/mini_project/entity/recipe_component/MakingDetail.java b/src/main/java/com/alttalttal/mini_project/domain/recipe/entity/recipe_component/MakingDetail.java similarity index 63% rename from src/main/java/com/alttalttal/mini_project/entity/recipe_component/MakingDetail.java rename to src/main/java/com/alttalttal/mini_project/domain/recipe/entity/recipe_component/MakingDetail.java index 4874e41..284cc7f 100644 --- a/src/main/java/com/alttalttal/mini_project/entity/recipe_component/MakingDetail.java +++ b/src/main/java/com/alttalttal/mini_project/domain/recipe/entity/recipe_component/MakingDetail.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.entity.recipe_component; +package com.alttalttal.mini_project.domain.recipe.entity.recipe_component; import jakarta.persistence.Embeddable; import lombok.Getter; diff --git a/src/main/java/com/alttalttal/mini_project/entity/recipe_component/Zzim.java b/src/main/java/com/alttalttal/mini_project/domain/recipe/entity/recipe_component/Zzim.java similarity index 86% rename from src/main/java/com/alttalttal/mini_project/entity/recipe_component/Zzim.java rename to src/main/java/com/alttalttal/mini_project/domain/recipe/entity/recipe_component/Zzim.java index f5dc7e8..fa95e17 100644 --- a/src/main/java/com/alttalttal/mini_project/entity/recipe_component/Zzim.java +++ b/src/main/java/com/alttalttal/mini_project/domain/recipe/entity/recipe_component/Zzim.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.entity.recipe_component; +package com.alttalttal.mini_project.domain.recipe.entity.recipe_component; import jakarta.persistence.*; import lombok.Getter; diff --git a/src/main/java/com/alttalttal/mini_project/mongo/repository/MongoRecipeRepository.java b/src/main/java/com/alttalttal/mini_project/domain/recipe/repository/MongoRecipeRepository.java similarity index 75% rename from src/main/java/com/alttalttal/mini_project/mongo/repository/MongoRecipeRepository.java rename to src/main/java/com/alttalttal/mini_project/domain/recipe/repository/MongoRecipeRepository.java index f91ba50..bb376ff 100644 --- a/src/main/java/com/alttalttal/mini_project/mongo/repository/MongoRecipeRepository.java +++ b/src/main/java/com/alttalttal/mini_project/domain/recipe/repository/MongoRecipeRepository.java @@ -1,6 +1,6 @@ -package com.alttalttal.mini_project.mongo.repository; +package com.alttalttal.mini_project.domain.recipe.repository; -import com.alttalttal.mini_project.entity.MongoRecipe; +import com.alttalttal.mini_project.domain.recipe.entity.MongoRecipe; import org.springframework.data.mongodb.repository.MongoRepository; import java.util.List; diff --git a/src/main/java/com/alttalttal/mini_project/service/RecipeService.java b/src/main/java/com/alttalttal/mini_project/domain/recipe/service/RecipeService.java similarity index 88% rename from src/main/java/com/alttalttal/mini_project/service/RecipeService.java rename to src/main/java/com/alttalttal/mini_project/domain/recipe/service/RecipeService.java index 6112045..2349e0b 100644 --- a/src/main/java/com/alttalttal/mini_project/service/RecipeService.java +++ b/src/main/java/com/alttalttal/mini_project/domain/recipe/service/RecipeService.java @@ -1,11 +1,12 @@ -package com.alttalttal.mini_project.service; +package com.alttalttal.mini_project.domain.recipe.service; -import com.alttalttal.mini_project.dto.MessageResponseDto; -import com.alttalttal.mini_project.dto.RecipeResponseDto; -import com.alttalttal.mini_project.dto.simpleRecipesResponseDto; -import com.alttalttal.mini_project.entity.MongoRecipe; -import com.alttalttal.mini_project.jwt.JwtUtil; -import com.alttalttal.mini_project.mongo.repository.MongoRecipeRepository; +import com.alttalttal.mini_project.global.dto.MessageResponseDto; +import com.alttalttal.mini_project.domain.recipe.dto.RecipeResponseDto; +import com.alttalttal.mini_project.domain.recipe.dto.simpleRecipesResponseDto; +import com.alttalttal.mini_project.domain.recipe.entity.MongoRecipe; +import com.alttalttal.mini_project.global.jwt.JwtUtil; +import com.alttalttal.mini_project.global.token.ServiceManagerImpl; +import com.alttalttal.mini_project.domain.recipe.repository.MongoRecipeRepository; import com.mongodb.BasicDBObject; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; diff --git a/src/main/java/com/alttalttal/mini_project/controller/UserController.java b/src/main/java/com/alttalttal/mini_project/domain/user/controller/UserController.java similarity index 78% rename from src/main/java/com/alttalttal/mini_project/controller/UserController.java rename to src/main/java/com/alttalttal/mini_project/domain/user/controller/UserController.java index 3fc76d7..c6f8dac 100644 --- a/src/main/java/com/alttalttal/mini_project/controller/UserController.java +++ b/src/main/java/com/alttalttal/mini_project/domain/user/controller/UserController.java @@ -1,11 +1,10 @@ -package com.alttalttal.mini_project.controller; - -import com.alttalttal.mini_project.dto.LoginRequestDto; -import com.alttalttal.mini_project.dto.MessageResponseDto; -import com.alttalttal.mini_project.dto.SignUpRequestDto; -import com.alttalttal.mini_project.dto.UserInfoResponseDto; -import com.alttalttal.mini_project.jwt.JwtUtil; -import com.alttalttal.mini_project.service.UserService; +package com.alttalttal.mini_project.domain.user.controller; + +import com.alttalttal.mini_project.global.dto.MessageResponseDto; +import com.alttalttal.mini_project.domain.user.dto.SignUpRequestDto; +import com.alttalttal.mini_project.domain.user.dto.UserInfoResponseDto; +import com.alttalttal.mini_project.global.jwt.JwtUtil; +import com.alttalttal.mini_project.domain.user.service.UserService; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/com/alttalttal/mini_project/dto/LoginRequestDto.java b/src/main/java/com/alttalttal/mini_project/domain/user/dto/LoginRequestDto.java similarity index 69% rename from src/main/java/com/alttalttal/mini_project/dto/LoginRequestDto.java rename to src/main/java/com/alttalttal/mini_project/domain/user/dto/LoginRequestDto.java index 008db84..fdf4587 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/LoginRequestDto.java +++ b/src/main/java/com/alttalttal/mini_project/domain/user/dto/LoginRequestDto.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.user.dto; import lombok.Getter; diff --git a/src/main/java/com/alttalttal/mini_project/dto/SignUpRequestDto.java b/src/main/java/com/alttalttal/mini_project/domain/user/dto/SignUpRequestDto.java similarity index 82% rename from src/main/java/com/alttalttal/mini_project/dto/SignUpRequestDto.java rename to src/main/java/com/alttalttal/mini_project/domain/user/dto/SignUpRequestDto.java index 442fbea..db9dae2 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/SignUpRequestDto.java +++ b/src/main/java/com/alttalttal/mini_project/domain/user/dto/SignUpRequestDto.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.user.dto; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/alttalttal/mini_project/dto/UserInfoResponseDto.java b/src/main/java/com/alttalttal/mini_project/domain/user/dto/UserInfoResponseDto.java similarity index 82% rename from src/main/java/com/alttalttal/mini_project/dto/UserInfoResponseDto.java rename to src/main/java/com/alttalttal/mini_project/domain/user/dto/UserInfoResponseDto.java index 29f0723..1eee9b3 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/UserInfoResponseDto.java +++ b/src/main/java/com/alttalttal/mini_project/domain/user/dto/UserInfoResponseDto.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.domain.user.dto; import lombok.Getter; diff --git a/src/main/java/com/alttalttal/mini_project/entity/User.java b/src/main/java/com/alttalttal/mini_project/domain/user/entity/User.java similarity index 84% rename from src/main/java/com/alttalttal/mini_project/entity/User.java rename to src/main/java/com/alttalttal/mini_project/domain/user/entity/User.java index 9f41ae8..1ebfce7 100644 --- a/src/main/java/com/alttalttal/mini_project/entity/User.java +++ b/src/main/java/com/alttalttal/mini_project/domain/user/entity/User.java @@ -1,8 +1,8 @@ -package com.alttalttal.mini_project.entity; +package com.alttalttal.mini_project.domain.user.entity; -import com.alttalttal.mini_project.dto.LoungeEntity; -import com.alttalttal.mini_project.dto.MypageRequestDto; +import com.alttalttal.mini_project.domain.lounge.entity.LoungeEntity; +import com.alttalttal.mini_project.domain.mypage.dto.MypageRequestDto; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/alttalttal/mini_project/entity/UserRoleEnum.java b/src/main/java/com/alttalttal/mini_project/domain/user/entity/UserRoleEnum.java similarity index 87% rename from src/main/java/com/alttalttal/mini_project/entity/UserRoleEnum.java rename to src/main/java/com/alttalttal/mini_project/domain/user/entity/UserRoleEnum.java index 9f0c7f6..2f20b37 100644 --- a/src/main/java/com/alttalttal/mini_project/entity/UserRoleEnum.java +++ b/src/main/java/com/alttalttal/mini_project/domain/user/entity/UserRoleEnum.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.entity; +package com.alttalttal.mini_project.domain.user.entity; public enum UserRoleEnum { USER(Authority.USER), // 사용자 권한 diff --git a/src/main/java/com/alttalttal/mini_project/repository/UserRepository.java b/src/main/java/com/alttalttal/mini_project/domain/user/repository/UserRepository.java similarity index 68% rename from src/main/java/com/alttalttal/mini_project/repository/UserRepository.java rename to src/main/java/com/alttalttal/mini_project/domain/user/repository/UserRepository.java index 7ab4205..475fd60 100644 --- a/src/main/java/com/alttalttal/mini_project/repository/UserRepository.java +++ b/src/main/java/com/alttalttal/mini_project/domain/user/repository/UserRepository.java @@ -1,6 +1,6 @@ -package com.alttalttal.mini_project.repository; +package com.alttalttal.mini_project.domain.user.repository; -import com.alttalttal.mini_project.entity.User; +import com.alttalttal.mini_project.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; diff --git a/src/main/java/com/alttalttal/mini_project/service/RedisService.java b/src/main/java/com/alttalttal/mini_project/domain/user/service/RedisService.java similarity index 95% rename from src/main/java/com/alttalttal/mini_project/service/RedisService.java rename to src/main/java/com/alttalttal/mini_project/domain/user/service/RedisService.java index c88153a..276e0e6 100644 --- a/src/main/java/com/alttalttal/mini_project/service/RedisService.java +++ b/src/main/java/com/alttalttal/mini_project/domain/user/service/RedisService.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.service; +package com.alttalttal.mini_project.domain.user.service; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/alttalttal/mini_project/service/UserService.java b/src/main/java/com/alttalttal/mini_project/domain/user/service/UserService.java similarity index 86% rename from src/main/java/com/alttalttal/mini_project/service/UserService.java rename to src/main/java/com/alttalttal/mini_project/domain/user/service/UserService.java index e421be5..8769bf4 100644 --- a/src/main/java/com/alttalttal/mini_project/service/UserService.java +++ b/src/main/java/com/alttalttal/mini_project/domain/user/service/UserService.java @@ -1,13 +1,13 @@ -package com.alttalttal.mini_project.service; +package com.alttalttal.mini_project.domain.user.service; -import com.alttalttal.mini_project.dto.LoginRequestDto; -import com.alttalttal.mini_project.dto.MessageResponseDto; -import com.alttalttal.mini_project.dto.SignUpRequestDto; -import com.alttalttal.mini_project.dto.UserInfoResponseDto; -import com.alttalttal.mini_project.entity.User; -import com.alttalttal.mini_project.entity.UserRoleEnum; -import com.alttalttal.mini_project.jwt.JwtUtil; -import com.alttalttal.mini_project.repository.UserRepository; +import com.alttalttal.mini_project.global.dto.MessageResponseDto; +import com.alttalttal.mini_project.domain.user.dto.SignUpRequestDto; +import com.alttalttal.mini_project.domain.user.dto.UserInfoResponseDto; +import com.alttalttal.mini_project.domain.user.entity.User; +import com.alttalttal.mini_project.domain.user.entity.UserRoleEnum; +import com.alttalttal.mini_project.global.jwt.JwtUtil; +import com.alttalttal.mini_project.domain.user.repository.UserRepository; +import com.alttalttal.mini_project.global.token.ServiceManagerImpl; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; @@ -18,7 +18,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.RequestBody; import java.util.Optional; diff --git a/src/main/java/com/alttalttal/mini_project/config/CorsConfig.java b/src/main/java/com/alttalttal/mini_project/global/config/CorsConfig.java similarity index 95% rename from src/main/java/com/alttalttal/mini_project/config/CorsConfig.java rename to src/main/java/com/alttalttal/mini_project/global/config/CorsConfig.java index b381dac..79d6eca 100644 --- a/src/main/java/com/alttalttal/mini_project/config/CorsConfig.java +++ b/src/main/java/com/alttalttal/mini_project/global/config/CorsConfig.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.config; +package com.alttalttal.mini_project.global.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/com/alttalttal/mini_project/config/MongoConfig.java b/src/main/java/com/alttalttal/mini_project/global/config/MongoConfig.java similarity index 96% rename from src/main/java/com/alttalttal/mini_project/config/MongoConfig.java rename to src/main/java/com/alttalttal/mini_project/global/config/MongoConfig.java index 427d738..d771c61 100644 --- a/src/main/java/com/alttalttal/mini_project/config/MongoConfig.java +++ b/src/main/java/com/alttalttal/mini_project/global/config/MongoConfig.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.config; +package com.alttalttal.mini_project.global.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/com/alttalttal/mini_project/config/PasswordConfig.java b/src/main/java/com/alttalttal/mini_project/global/config/PasswordConfig.java similarity index 88% rename from src/main/java/com/alttalttal/mini_project/config/PasswordConfig.java rename to src/main/java/com/alttalttal/mini_project/global/config/PasswordConfig.java index 7506bdc..4c6e8de 100644 --- a/src/main/java/com/alttalttal/mini_project/config/PasswordConfig.java +++ b/src/main/java/com/alttalttal/mini_project/global/config/PasswordConfig.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.config; +package com.alttalttal.mini_project.global.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/com/alttalttal/mini_project/config/RedisConfig.java b/src/main/java/com/alttalttal/mini_project/global/config/RedisConfig.java similarity index 96% rename from src/main/java/com/alttalttal/mini_project/config/RedisConfig.java rename to src/main/java/com/alttalttal/mini_project/global/config/RedisConfig.java index 331e0c6..875606a 100644 --- a/src/main/java/com/alttalttal/mini_project/config/RedisConfig.java +++ b/src/main/java/com/alttalttal/mini_project/global/config/RedisConfig.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.config; +package com.alttalttal.mini_project.global.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/com/alttalttal/mini_project/config/WebSecurityConfig.java b/src/main/java/com/alttalttal/mini_project/global/config/WebSecurityConfig.java similarity index 88% rename from src/main/java/com/alttalttal/mini_project/config/WebSecurityConfig.java rename to src/main/java/com/alttalttal/mini_project/global/config/WebSecurityConfig.java index 6e08687..226d769 100644 --- a/src/main/java/com/alttalttal/mini_project/config/WebSecurityConfig.java +++ b/src/main/java/com/alttalttal/mini_project/global/config/WebSecurityConfig.java @@ -1,10 +1,10 @@ -package com.alttalttal.mini_project.config; +package com.alttalttal.mini_project.global.config; -import com.alttalttal.mini_project.jwt.JwtAuthenticationFilter; -import com.alttalttal.mini_project.jwt.JwtAuthorizationFilter; -import com.alttalttal.mini_project.jwt.JwtUtil; -import com.alttalttal.mini_project.security.UserDetailsServiceImpl; -import com.alttalttal.mini_project.service.RedisService; +import com.alttalttal.mini_project.global.jwt.JwtAuthenticationFilter; +import com.alttalttal.mini_project.global.jwt.JwtAuthorizationFilter; +import com.alttalttal.mini_project.global.jwt.JwtUtil; +import com.alttalttal.mini_project.global.security.UserDetailsServiceImpl; +import com.alttalttal.mini_project.domain.user.service.RedisService; import io.swagger.v3.oas.models.PathItem; import lombok.RequiredArgsConstructor; import org.springframework.boot.autoconfigure.security.servlet.PathRequest; @@ -15,8 +15,6 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.http.SessionCreationPolicy; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; diff --git a/src/main/java/com/alttalttal/mini_project/dto/MessageResponseDto.java b/src/main/java/com/alttalttal/mini_project/global/dto/MessageResponseDto.java similarity index 84% rename from src/main/java/com/alttalttal/mini_project/dto/MessageResponseDto.java rename to src/main/java/com/alttalttal/mini_project/global/dto/MessageResponseDto.java index 8b511c7..d7b59e1 100644 --- a/src/main/java/com/alttalttal/mini_project/dto/MessageResponseDto.java +++ b/src/main/java/com/alttalttal/mini_project/global/dto/MessageResponseDto.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.dto; +package com.alttalttal.mini_project.global.dto; import lombok.Getter; diff --git a/src/main/java/com/alttalttal/mini_project/entity/Timestamped.java b/src/main/java/com/alttalttal/mini_project/global/entity/Timestamped.java similarity index 92% rename from src/main/java/com/alttalttal/mini_project/entity/Timestamped.java rename to src/main/java/com/alttalttal/mini_project/global/entity/Timestamped.java index 21fb555..6e84938 100644 --- a/src/main/java/com/alttalttal/mini_project/entity/Timestamped.java +++ b/src/main/java/com/alttalttal/mini_project/global/entity/Timestamped.java @@ -1,4 +1,4 @@ -package com.alttalttal.mini_project.entity; +package com.alttalttal.mini_project.global.entity; import jakarta.persistence.*; import lombok.Getter; diff --git a/src/main/java/com/alttalttal/mini_project/handler/ExceptionCustomHandler.java b/src/main/java/com/alttalttal/mini_project/global/handler/ExceptionCustomHandler.java similarity index 86% rename from src/main/java/com/alttalttal/mini_project/handler/ExceptionCustomHandler.java rename to src/main/java/com/alttalttal/mini_project/global/handler/ExceptionCustomHandler.java index 9f27e9c..837c801 100644 --- a/src/main/java/com/alttalttal/mini_project/handler/ExceptionCustomHandler.java +++ b/src/main/java/com/alttalttal/mini_project/global/handler/ExceptionCustomHandler.java @@ -1,10 +1,10 @@ -package com.alttalttal.mini_project.handler; +package com.alttalttal.mini_project.global.handler; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -import com.alttalttal.mini_project.dto.MessageResponseDto; +import com.alttalttal.mini_project.global.dto.MessageResponseDto; @RestControllerAdvice public class ExceptionCustomHandler { diff --git a/src/main/java/com/alttalttal/mini_project/jwt/JwtAuthenticationFilter.java b/src/main/java/com/alttalttal/mini_project/global/jwt/JwtAuthenticationFilter.java similarity index 92% rename from src/main/java/com/alttalttal/mini_project/jwt/JwtAuthenticationFilter.java rename to src/main/java/com/alttalttal/mini_project/global/jwt/JwtAuthenticationFilter.java index 9348bfe..43ef6d3 100644 --- a/src/main/java/com/alttalttal/mini_project/jwt/JwtAuthenticationFilter.java +++ b/src/main/java/com/alttalttal/mini_project/global/jwt/JwtAuthenticationFilter.java @@ -1,16 +1,15 @@ -package com.alttalttal.mini_project.jwt; +package com.alttalttal.mini_project.global.jwt; -import com.alttalttal.mini_project.dto.LoginRequestDto; -import com.alttalttal.mini_project.entity.UserRoleEnum; -import com.alttalttal.mini_project.security.UserDetailsImpl; -import com.alttalttal.mini_project.service.RedisService; +import com.alttalttal.mini_project.domain.user.dto.LoginRequestDto; +import com.alttalttal.mini_project.domain.user.entity.UserRoleEnum; +import com.alttalttal.mini_project.global.security.UserDetailsImpl; +import com.alttalttal.mini_project.domain.user.service.RedisService; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; -import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; diff --git a/src/main/java/com/alttalttal/mini_project/jwt/JwtAuthorizationFilter.java b/src/main/java/com/alttalttal/mini_project/global/jwt/JwtAuthorizationFilter.java similarity index 95% rename from src/main/java/com/alttalttal/mini_project/jwt/JwtAuthorizationFilter.java rename to src/main/java/com/alttalttal/mini_project/global/jwt/JwtAuthorizationFilter.java index 3c28193..b51170d 100644 --- a/src/main/java/com/alttalttal/mini_project/jwt/JwtAuthorizationFilter.java +++ b/src/main/java/com/alttalttal/mini_project/global/jwt/JwtAuthorizationFilter.java @@ -1,6 +1,6 @@ -package com.alttalttal.mini_project.jwt; +package com.alttalttal.mini_project.global.jwt; -import com.alttalttal.mini_project.security.UserDetailsServiceImpl; +import com.alttalttal.mini_project.global.security.UserDetailsServiceImpl; import io.jsonwebtoken.Claims; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; diff --git a/src/main/java/com/alttalttal/mini_project/jwt/JwtUtil.java b/src/main/java/com/alttalttal/mini_project/global/jwt/JwtUtil.java similarity index 97% rename from src/main/java/com/alttalttal/mini_project/jwt/JwtUtil.java rename to src/main/java/com/alttalttal/mini_project/global/jwt/JwtUtil.java index fa8d57c..57527b8 100644 --- a/src/main/java/com/alttalttal/mini_project/jwt/JwtUtil.java +++ b/src/main/java/com/alttalttal/mini_project/global/jwt/JwtUtil.java @@ -1,8 +1,8 @@ -package com.alttalttal.mini_project.jwt; +package com.alttalttal.mini_project.global.jwt; -import com.alttalttal.mini_project.entity.UserRoleEnum; -import com.alttalttal.mini_project.repository.UserRepository; -import com.alttalttal.mini_project.service.RedisService; +import com.alttalttal.mini_project.domain.user.entity.UserRoleEnum; +import com.alttalttal.mini_project.domain.user.repository.UserRepository; +import com.alttalttal.mini_project.domain.user.service.RedisService; import io.jsonwebtoken.*; import io.jsonwebtoken.security.Keys; import jakarta.annotation.PostConstruct; diff --git a/src/main/java/com/alttalttal/mini_project/security/UserDetailsImpl.java b/src/main/java/com/alttalttal/mini_project/global/security/UserDetailsImpl.java similarity index 86% rename from src/main/java/com/alttalttal/mini_project/security/UserDetailsImpl.java rename to src/main/java/com/alttalttal/mini_project/global/security/UserDetailsImpl.java index d8e565e..2d705ae 100644 --- a/src/main/java/com/alttalttal/mini_project/security/UserDetailsImpl.java +++ b/src/main/java/com/alttalttal/mini_project/global/security/UserDetailsImpl.java @@ -1,7 +1,7 @@ -package com.alttalttal.mini_project.security; +package com.alttalttal.mini_project.global.security; -import com.alttalttal.mini_project.entity.User; -import com.alttalttal.mini_project.entity.UserRoleEnum; +import com.alttalttal.mini_project.domain.user.entity.User; +import com.alttalttal.mini_project.domain.user.entity.UserRoleEnum; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; diff --git a/src/main/java/com/alttalttal/mini_project/security/UserDetailsServiceImpl.java b/src/main/java/com/alttalttal/mini_project/global/security/UserDetailsServiceImpl.java similarity index 81% rename from src/main/java/com/alttalttal/mini_project/security/UserDetailsServiceImpl.java rename to src/main/java/com/alttalttal/mini_project/global/security/UserDetailsServiceImpl.java index 9284990..db09773 100644 --- a/src/main/java/com/alttalttal/mini_project/security/UserDetailsServiceImpl.java +++ b/src/main/java/com/alttalttal/mini_project/global/security/UserDetailsServiceImpl.java @@ -1,7 +1,7 @@ -package com.alttalttal.mini_project.security; +package com.alttalttal.mini_project.global.security; -import com.alttalttal.mini_project.entity.User; -import com.alttalttal.mini_project.repository.UserRepository; +import com.alttalttal.mini_project.domain.user.entity.User; +import com.alttalttal.mini_project.domain.user.repository.UserRepository; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; diff --git a/src/main/java/com/alttalttal/mini_project/service/ServiceManager.java b/src/main/java/com/alttalttal/mini_project/global/token/ServiceManager.java similarity index 71% rename from src/main/java/com/alttalttal/mini_project/service/ServiceManager.java rename to src/main/java/com/alttalttal/mini_project/global/token/ServiceManager.java index 559149a..29a6e0b 100644 --- a/src/main/java/com/alttalttal/mini_project/service/ServiceManager.java +++ b/src/main/java/com/alttalttal/mini_project/global/token/ServiceManager.java @@ -1,6 +1,6 @@ -package com.alttalttal.mini_project.service; +package com.alttalttal.mini_project.global.token; -import com.alttalttal.mini_project.entity.User; +import com.alttalttal.mini_project.domain.user.entity.User; import jakarta.servlet.http.HttpServletRequest; public interface ServiceManager { diff --git a/src/main/java/com/alttalttal/mini_project/service/ServiceManagerImpl.java b/src/main/java/com/alttalttal/mini_project/global/token/ServiceManagerImpl.java similarity index 82% rename from src/main/java/com/alttalttal/mini_project/service/ServiceManagerImpl.java rename to src/main/java/com/alttalttal/mini_project/global/token/ServiceManagerImpl.java index be9b534..a08aa75 100644 --- a/src/main/java/com/alttalttal/mini_project/service/ServiceManagerImpl.java +++ b/src/main/java/com/alttalttal/mini_project/global/token/ServiceManagerImpl.java @@ -1,8 +1,8 @@ -package com.alttalttal.mini_project.service; +package com.alttalttal.mini_project.global.token; -import com.alttalttal.mini_project.entity.User; -import com.alttalttal.mini_project.jwt.JwtUtil; -import com.alttalttal.mini_project.repository.UserRepository; +import com.alttalttal.mini_project.domain.user.entity.User; +import com.alttalttal.mini_project.global.jwt.JwtUtil; +import com.alttalttal.mini_project.domain.user.repository.UserRepository; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/alttalttal/mini_project/service/MainPageService.java b/src/main/java/com/alttalttal/mini_project/service/MainPageService.java deleted file mode 100644 index 9697514..0000000 --- a/src/main/java/com/alttalttal/mini_project/service/MainPageService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.alttalttal.mini_project.service; - -import com.alttalttal.mini_project.dto.LoungeResponseDto; -import com.alttalttal.mini_project.dto.MainPageResponseDto; -import com.alttalttal.mini_project.dto.simpleRecipesResponseDto; -import com.alttalttal.mini_project.mongo.repository.MongoRecipeRepository; -import com.alttalttal.mini_project.repository.LoungeRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -@Service -@RequiredArgsConstructor -public class MainPageService { - private final MongoRecipeRepository mongoRecipeRepository; - private final LoungeRepository loungeRepository; - public MainPageResponseDto getMainPage() { - List simpleRecipesResponseDtoList = mongoRecipeRepository.findAll().stream().limit(9).map(simpleRecipesResponseDto::new).toList(); - List loungeResponseDtoList = loungeRepository.findAll().stream().map(LoungeResponseDto::new).toList(); - return new MainPageResponseDto(simpleRecipesResponseDtoList, loungeResponseDtoList); - } -} From bc0864f079cdd522c9b070a7b4b1bdbb2225e165 Mon Sep 17 00:00:00 2001 From: klettermi <95194606+klettermi@users.noreply.github.com> Date: Fri, 3 Nov 2023 20:02:46 +0900 Subject: [PATCH 5/5] Update README.md --- README.md | 120 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 102 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0520aef..2eb262f 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,102 @@ -# 🍸12조 알딸딸 -### 📝 코드 컨벤션 -- ENCODING: UTF-8 -- FORMAT: 중괄호 필수 작성(if, else..) -- 어노테이션: 1줄씩 작성 -- 패키지명: 소문자 -- 클래스명: UpperCamelCase, 명사 -- 매소드명: LowerCamelCase, 동사 -- 상수: CONSTANT_CASE ---- -### 🐾 커밋 컨벤션 -- [INITIAL] — repository를 생성하고 최초에 파일을 업로드 할 때 -- [ADD] — 신규 파일 추가 -- [UPDATE] — 코드 변경이 일어날때 -- [REFACTOR] — 코드를 리팩토링 했을때 -- [FIX] — 잘못된 링크 정보 변경, 필요한 모듈 추가 및 삭제 -- [REMOVE] — 파일 제거 -- [STYLE] — 디자인 관련 변경사항 \ No newline at end of file +# 🍸 01 | 프로젝트 소개 [알딸딸] +
+ +
+
+ + +``` +🍸 모두가 함께 공유할 수 있는 칵테일 플랫폼 +- 모든 사람이 칵테일 레시피를 조회할 수 있는 서비스 +- 원하는 레시피를 찜할 수 있는 서비스 +- 신뢰되는 사용자들의 의견 나눔 서비스 +``` +- 모든 사람이 인증 과정 없이 칵테일 레시피를 조회할 수 있습니다. +- 회원은 원하는 레시피를 찜하여 마이페이지에서 볼 수 있습니다. +- 회원은 모두와 소통할 수 있는 라운지를 이용할 수 있습니다. +- 회원가입, 로그인 및 로그아웃을 통해 회원 관리가 가능합니다. +- 마이페이지에서 닉네임을 수정하거나 찜목록을 볼 수 있습니다. + + +# 🥂 02 | 프로젝트 목표 + +1️⃣ **레시피 조회** +
+ +
+
+ +2️⃣ **원하는 레시피를 찜하고 해제하기** +
+ +
+
+ +3️⃣ **라운지** +
+ +
+
+ +4️⃣ **회원가입, 로그인 및 로그아웃** +- 회원가입/로그인 +
+ +
+ +- 로그아웃 +
+ +
+ +5️⃣ **마이페이지** +
+ +
+ +# ⚙️ 03 | 아키텍쳐 +## 서비스 아키텍쳐 +
+ +
+ +## ERD +
+ +
+
+ +
+ + +## API 명세서 (swagger) +image +image + + +# 🎯 04 | 트러블 슈팅 + +- 로그아웃 구현 + - 문제: Front-end에서 토큰을 삭제해주는 방식이 보안상 문제가 될 수 있다고 판단 + - 해결 방안: Back-end에서도 보안 유지를 위해 로그아웃 로직을 구현 + 로그아웃 요청이 오면 Refresh Token을 Redis에서 삭제 시킨 후 AccessToken을 BlackList로 Redis에 저장 + 로그아웃 후 해당 유저가 요청을 보낼 때 접근이 불가능하도록 구현 +- 기존의 파일 구조를 도메인 별로 변경 + - 문제: 비즈니스 도메인을 명확하게 구분하고 확정성, 유지보수성을 향상시킬 수 있도록 파일 구조 변경 필요 + - 해결 방안: 도메인 별로 리팩토링 진행 + 불필요한 @EnableJpaRepositories, @EnableMongoRepositoies 삭제 +- Spring Security 적용 + - 문제: Spring Security가 적용되어 있지 않아 + 웹 응용 프로그램 및 서비스에서 보안을 효과적으로 관리하고 강화하기 위해 적용 필요 + - 해결 방안: Spring Security 적용 + +# 🛠️ 05 | 기술 스택 + +| Backend | Tech | Spring Boot Spring JPA Spring Security | +| --- | --- | --- | +| | Platform | Ubuntu | +| | DB | AWS RDS(Mysql) Redis MongoDB | +| | DevOps | AWS EC2 Docker | + + +