diff --git a/src/main/java/com/example/healthylife/config/CorsConfig.java b/src/main/java/com/example/healthylife/config/CorsConfig.java index ef734fb..819383f 100644 --- a/src/main/java/com/example/healthylife/config/CorsConfig.java +++ b/src/main/java/com/example/healthylife/config/CorsConfig.java @@ -1,6 +1,9 @@ package com.example.healthylife.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; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -8,17 +11,17 @@ public class CorsConfig { @Bean - public WebMvcConfigurer corsConfigurer() { - return new WebMvcConfigurer() { - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedOrigins("http://localhost:3000", - "https://trendy-healthy.store") // 허용할 도메인 - .allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD") - .allowedHeaders("*") - .allowCredentials(true); - } - }; + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.addAllowedOriginPattern("http://localhost:8081/swagger-ui/index.html"); // 특정 origin 허용 + config.addAllowedOriginPattern("https://trendy-healthy-backend.store/swagger-ui/"); // 특정 origin 허용 + config.addAllowedOriginPattern("http://localhost:3000"); + config.addAllowedOriginPattern("https://trendy-healthy.store/"); + config.addAllowedMethod("*"); // 모든 HTTP 메서드 허용 + config.addAllowedHeader("*"); // 모든 헤더 허용 + config.setAllowCredentials(true); // 자격 증명 허용 + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); } } diff --git a/src/main/java/com/example/healthylife/config/security/MyUserDetailsService.java b/src/main/java/com/example/healthylife/config/security/MyUserDetailsService.java index 9713fe0..57c6fb6 100644 --- a/src/main/java/com/example/healthylife/config/security/MyUserDetailsService.java +++ b/src/main/java/com/example/healthylife/config/security/MyUserDetailsService.java @@ -6,7 +6,6 @@ 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.Component; import org.springframework.stereotype.Service; import java.util.Optional; diff --git a/src/main/java/com/example/healthylife/controller/CommunityController.java b/src/main/java/com/example/healthylife/controller/CommunityController.java index 197d8ac..ef31c47 100644 --- a/src/main/java/com/example/healthylife/controller/CommunityController.java +++ b/src/main/java/com/example/healthylife/controller/CommunityController.java @@ -3,10 +3,7 @@ import com.example.healthylife.entity.CommunityEntity; import com.example.healthylife.service.CommunityService; import io.swagger.annotations.ApiOperation; -import lombok.Getter; -import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.List; diff --git a/src/main/java/com/example/healthylife/controller/JwtLoginAuthController.java b/src/main/java/com/example/healthylife/controller/JwtLoginAuthController.java index 3964280..96ec8ac 100644 --- a/src/main/java/com/example/healthylife/controller/JwtLoginAuthController.java +++ b/src/main/java/com/example/healthylife/controller/JwtLoginAuthController.java @@ -2,9 +2,10 @@ import com.example.healthylife.config.jwt.JwtUtil; import com.example.healthylife.entity.UserEntity; -import com.example.healthylife.service.Impl.JwtAuthService; +import com.example.healthylife.service.JwtAuthService; import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -19,19 +20,16 @@ import java.util.Map; @Slf4j +@RequiredArgsConstructor @RequestMapping("/jwt") @RestController @ApiOperation("로그인 컨트롤러") public class JwtLoginAuthController { - @Autowired - private AuthenticationManager authenticationManager; - @Autowired - private JwtUtil jwtUtil; - @Autowired - private JwtAuthService jwtAuthService; - @Autowired - private ObjectMapper objectMapper; + private final AuthenticationManager authenticationManager; + private final JwtUtil jwtUtil; + private final JwtAuthService jwtAuthService; + private final ObjectMapper objectMapper; @ApiOperation("로그인 컨트롤러") @PostMapping("/authenticate") diff --git a/src/main/java/com/example/healthylife/controller/TodayController.java b/src/main/java/com/example/healthylife/controller/TodayController.java index 97ca5ac..60b87ce 100644 --- a/src/main/java/com/example/healthylife/controller/TodayController.java +++ b/src/main/java/com/example/healthylife/controller/TodayController.java @@ -4,7 +4,6 @@ import com.example.healthylife.service.TodayService; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; -import org.checkerframework.checker.units.qual.A; import org.springframework.web.bind.annotation.*; import java.util.List; diff --git a/src/main/java/com/example/healthylife/controller/UserController.java b/src/main/java/com/example/healthylife/controller/UserController.java index 3f86ac3..bb109fa 100644 --- a/src/main/java/com/example/healthylife/controller/UserController.java +++ b/src/main/java/com/example/healthylife/controller/UserController.java @@ -1,18 +1,13 @@ package com.example.healthylife.controller; -import com.example.healthylife.config.security.MyUserDetailsService; import com.example.healthylife.entity.UserEntity; import com.example.healthylife.service.UserService; -import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.stereotype.Repository; import org.springframework.web.bind.annotation.*; import java.util.List; -import java.util.Map; import java.util.Optional; @RequestMapping("/user") diff --git a/src/main/java/com/example/healthylife/entity/UserEntity.java b/src/main/java/com/example/healthylife/entity/UserEntity.java index b2d24c7..22bfc8d 100644 --- a/src/main/java/com/example/healthylife/entity/UserEntity.java +++ b/src/main/java/com/example/healthylife/entity/UserEntity.java @@ -1,8 +1,6 @@ package com.example.healthylife.entity; import lombok.*; -import org.springframework.data.annotation.LastModifiedBy; -import org.springframework.data.annotation.LastModifiedDate; import javax.persistence.*; import java.io.Serializable; @@ -12,48 +10,40 @@ @Getter @Table(name = "user") @NoArgsConstructor +@AllArgsConstructor +@Builder public class UserEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name ="user_sq", unique = true, nullable = false) - // user sequence + @Column(name = "user_sq", unique = true, nullable = false) private Long userSq; - // user id - @Column(name ="user_id", unique = true, nullable = false, length = 100) + @Column(name = "user_id", unique = true, nullable = false, length = 100) private String userId; - // user password - @LastModifiedDate - @Column(name ="user_pw", length = 100) + @Column(name = "user_pw", length = 100) private String userPw; - // user name @Column(name = "user_name", length = 200) private String userName; - - // user email - @Column(name = "user_email",length = 300) + @Column(name = "user_email", length = 300) private String userEmail; - // user address @Column(name = "user_address", length = 400) private String userAddress; - // user age - @Column(name = "user_age", length = 50) + @Column(name = "user_age") private Long userAge; - // user phone number @Column(name = "user_phone", length = 100) - private Long userPhone; + private String userPhone; // builder @Builder(toBuilder = true) public UserEntity(long userSq,String userId, String userPw,String userName,String userEmail,String userAddress, long userAge, - long userPhone){ + String userPhone){ this.userSq = userSq; this.userId = userId; this.userPw = userPw; @@ -65,7 +55,8 @@ public UserEntity(long userSq,String userId, String userPw,String userName,Strin this.userPhone = userPhone; } + //비밀번호 암호화 public UserEntity withUserPw(String userPw) { return this.toBuilder().userPw(userPw).build(); } -} \ No newline at end of file +} diff --git a/src/main/java/com/example/healthylife/exception/ErrorCode.java b/src/main/java/com/example/healthylife/exception/ErrorCode.java deleted file mode 100644 index 35e8076..0000000 --- a/src/main/java/com/example/healthylife/exception/ErrorCode.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.example.healthylife.exception; - -public class ErrorCode { -} diff --git a/src/main/java/com/example/healthylife/exception/S3Exception.java b/src/main/java/com/example/healthylife/exception/S3Exception.java deleted file mode 100644 index 35fb0f2..0000000 --- a/src/main/java/com/example/healthylife/exception/S3Exception.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.example.healthylife.exception; - -public class S3Exception { -} diff --git a/src/main/java/com/example/healthylife/health/CustomHealthIndicator b/src/main/java/com/example/healthylife/health/CustomHealthIndicator deleted file mode 100644 index 760fa7d..0000000 --- a/src/main/java/com/example/healthylife/health/CustomHealthIndicator +++ /dev/null @@ -1,23 +0,0 @@ -package com.example.healthylife.health; - -import org.springframework.boot.actuate.health.Health; -import org.springframework.boot.actuate.health.HealthIndicator; -import org.springframework.stereotype.Component; - -@Component -public class CustomHealthIndicator implements HealthIndicator { - - @Override - public Health health() { - int errorCode = check(); // 애플리케이션의 상태를 확인하는 로직 - if (errorCode != 0) { - return Health.down().withDetail("Error Code", errorCode).build(); - } - return Health.up().build(); - } - - private int check() { - // 애플리케이션의 상태를 확인하는 로직 - return 0; - } -} diff --git a/src/main/java/com/example/healthylife/service/CommunityCommentsService.java b/src/main/java/com/example/healthylife/service/CommunityCommentsService.java index 1ab0a13..cbf63a2 100644 --- a/src/main/java/com/example/healthylife/service/CommunityCommentsService.java +++ b/src/main/java/com/example/healthylife/service/CommunityCommentsService.java @@ -1,21 +1,36 @@ package com.example.healthylife.service; import com.example.healthylife.entity.CommunityCommentsEntity; +import com.example.healthylife.repository.CommunityCommentsRepository; import org.springframework.stereotype.Service; import java.util.List; @Service -public interface CommunityCommentsService { +public class CommunityCommentsService { + private final CommunityCommentsRepository communityCommentsRepository; + + public CommunityCommentsService(CommunityCommentsRepository communityCommentsRepository){ + this.communityCommentsRepository=communityCommentsRepository; + } //댓글 전체 리스트 - List communityCommentsList(); + public List communityCommentsList() { + return communityCommentsRepository.findAll(); + } + //댓글등록 - CommunityCommentsEntity insertComments(CommunityCommentsEntity communityCommentsEntity); + public CommunityCommentsEntity insertComments(CommunityCommentsEntity communityCommentsEntity) { + return communityCommentsRepository.save(communityCommentsEntity); + } //댓글삭제 - void deleteBySq(long commentsSq); + public void deleteBySq(long commentsSq) { + + communityCommentsRepository.deleteById(commentsSq); + } - //커뮤니티 내가 쓴 댓글 - List findMyCommunityComments(String userId); + public List findMyCommunityComments(String userId) { + return communityCommentsRepository.findByUserUserId(userId); + } } diff --git a/src/main/java/com/example/healthylife/service/CommunityService.java b/src/main/java/com/example/healthylife/service/CommunityService.java index 4ef4e84..6b021ec 100644 --- a/src/main/java/com/example/healthylife/service/CommunityService.java +++ b/src/main/java/com/example/healthylife/service/CommunityService.java @@ -1,24 +1,60 @@ package com.example.healthylife.service; - import com.example.healthylife.entity.CommunityEntity; -import com.example.healthylife.entity.UserEntity; +import com.example.healthylife.repository.CommunityRepository; +import com.example.healthylife.repository.UserRepository; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import java.util.List; -import java.util.Optional; +@RequiredArgsConstructor +@Service +public class CommunityService { + + private final CommunityRepository communityRepository; + private final UserRepository userRepository; + -public interface CommunityService { //글전체조회 - List communityList(); - //글등록 - CommunityEntity registerCommunity(CommunityEntity communityEntity); - //글 수정 - CommunityEntity updateCommunity(CommunityEntity communityEntity); - //글삭제 - void deleteBySq(long communitySq); + public List communityList() { + return communityRepository.findAll(); + } + + + //커뮤니티 글 작성 + public CommunityEntity registerCommunity(CommunityEntity communityEntity) { + return communityRepository.save(communityEntity); + } + + + //커뮤니티 글 수정 + @Transactional + public CommunityEntity updateCommunity(CommunityEntity communityEntity) { - List findMyContents(String userId); + return communityRepository.save(communityEntity); + } + //커뮤니티 글 삭제 + public void deleteBySq(long communitySq) { + + communityRepository.deleteById(communitySq); + } + + public List findMyContents(String userId) { + return communityRepository.findByUserUserId(userId); + } } + //커뮤니티 내가 쓴 글 조회 +// @Override +// public List findMyContents(long userSq) { +// return communityRepository.findByUserUserId(userSq); +// } + + + + + + diff --git a/src/main/java/com/example/healthylife/service/Impl/CommunityCommentsImpl.java b/src/main/java/com/example/healthylife/service/Impl/CommunityCommentsImpl.java deleted file mode 100644 index ac8b0e9..0000000 --- a/src/main/java/com/example/healthylife/service/Impl/CommunityCommentsImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.example.healthylife.service.Impl; - -import com.example.healthylife.entity.CommunityCommentsEntity; -import com.example.healthylife.repository.CommunityCommentsRepository; -import com.example.healthylife.service.CommunityCommentsService; -import com.example.healthylife.service.CommunityService; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class CommunityCommentsImpl implements CommunityCommentsService { - private final CommunityCommentsRepository communityCommentsRepository; - - public CommunityCommentsImpl(CommunityCommentsRepository communityCommentsRepository){ - this.communityCommentsRepository=communityCommentsRepository; - } - - //댓글 전체 리스트 - @Override - public List communityCommentsList() { - return communityCommentsRepository.findAll(); - } - - //댓글등록 - @Override - public CommunityCommentsEntity insertComments(CommunityCommentsEntity communityCommentsEntity) { - return communityCommentsRepository.save(communityCommentsEntity); - } - - //댓글삭제 - @Override - public void deleteBySq(long commentsSq) { - - communityCommentsRepository.deleteById(commentsSq); - } - - @Override - public List findMyCommunityComments(String userId) { - return communityCommentsRepository.findByUserUserId(userId); - } -} diff --git a/src/main/java/com/example/healthylife/service/Impl/CommunityServiceImpl.java b/src/main/java/com/example/healthylife/service/Impl/CommunityServiceImpl.java deleted file mode 100644 index a452635..0000000 --- a/src/main/java/com/example/healthylife/service/Impl/CommunityServiceImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.example.healthylife.service.Impl; - -import com.example.healthylife.entity.CommunityEntity; -import com.example.healthylife.repository.CommunityRepository; -import com.example.healthylife.repository.UserRepository; -import com.example.healthylife.service.CommunityService; -import io.swagger.annotations.ApiOperation; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - - -import java.util.Date; -import java.util.List; - -@Service -public class CommunityServiceImpl implements CommunityService { - - private final CommunityRepository communityRepository; - private final UserRepository userRepository; - - public CommunityServiceImpl(CommunityRepository communityRepository, UserRepository userRepository, UserRepository userRepository1) { - - this.communityRepository = communityRepository; - - - this.userRepository = userRepository; - } - - //글전체조회 - @Override - public List communityList() { - return communityRepository.findAll(); - } - - - //커뮤니티 글 작성 - @Override - public CommunityEntity registerCommunity(CommunityEntity communityEntity) { - return communityRepository.save(communityEntity); - } - - - //커뮤니티 글 수정 - @Override - @Transactional - public CommunityEntity updateCommunity(CommunityEntity communityEntity) { - - return communityRepository.save(communityEntity); - } - - //커뮤니티 글 삭제 - @Override - public void deleteBySq(long communitySq) { - - communityRepository.deleteById(communitySq); - } - - @Override - public List findMyContents(String userId) { - return communityRepository.findByUserUserId(userId); - } -} - //커뮤니티 내가 쓴 글 조회 -// @Override -// public List findMyContents(long userSq) { -// return communityRepository.findByUserUserId(userSq); -// } - - - - - - diff --git a/src/main/java/com/example/healthylife/service/Impl/TodayCommentsServiceImpl.java b/src/main/java/com/example/healthylife/service/Impl/TodayCommentsServiceImpl.java deleted file mode 100644 index b28cf47..0000000 --- a/src/main/java/com/example/healthylife/service/Impl/TodayCommentsServiceImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.example.healthylife.service.Impl; - -import com.example.healthylife.entity.TodayCommentsEntity; -import com.example.healthylife.repository.TodayCommentsRepository; -import com.example.healthylife.repository.UserRepository; -import com.example.healthylife.service.TodayCommentsService; -import org.springframework.stereotype.Service; - -import java.util.List; -@Service -public class TodayCommentsServiceImpl implements TodayCommentsService { - private final TodayCommentsRepository todayCommentsRepository; - private final UserRepository userRepository; - public TodayCommentsServiceImpl(TodayCommentsRepository todayCommentsRepository, UserRepository userRepository) { - this.todayCommentsRepository = todayCommentsRepository; - this.userRepository = userRepository; - } - - @Override - public List todayCommentsList() { - return todayCommentsRepository.findAll(); - } - - @Override - public TodayCommentsEntity insertTodayComments(TodayCommentsEntity todayCommentsEntity) { - return todayCommentsRepository.save(todayCommentsEntity); - } - - @Override - public void deleteByTodayCommentsSq(long todayCommentsSq) { - todayCommentsRepository.deleteById(todayCommentsSq); - - } - - @Override - public List findMyTodayComments(String userId) { - return todayCommentsRepository.findByUserUserId(userId); - } -} diff --git a/src/main/java/com/example/healthylife/service/Impl/TodayServiceImpl.java b/src/main/java/com/example/healthylife/service/Impl/TodayServiceImpl.java deleted file mode 100644 index a436aec..0000000 --- a/src/main/java/com/example/healthylife/service/Impl/TodayServiceImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.example.healthylife.service.Impl; - -import com.example.healthylife.entity.TodayEntity; -import com.example.healthylife.repository.TodayRepository; -import com.example.healthylife.repository.UserRepository; -import com.example.healthylife.service.TodayService; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class TodayServiceImpl implements TodayService { - - private final TodayRepository todayRepository; - private final UserRepository userRepository; - public TodayServiceImpl(TodayRepository todayRepository, UserRepository userRepository){ - this.todayRepository = todayRepository; - this.userRepository = userRepository; - } - - @Override - public List todayList() { - return todayRepository.findAll(); - } - - @Override - public List findMyTodayContents(String userId) { - return todayRepository.findByUserUserId(userId); - } - - //오운완 내가 쓴 글 찾기 -// @Override -// public List findMyToday(String userId) { -// return todayRepository.findByUserToday(userId); -// } - - @Override - public TodayEntity registerToday(TodayEntity todayEntity) { - return todayRepository.save(todayEntity); - } - - @Override - public TodayEntity updateEntity(TodayEntity todayEntity) { - return todayRepository.save(todayEntity); - } - - @Override - public void deleteByTodaySq(long todaySq) { -todayRepository.deleteById(todaySq); - } - - -} diff --git a/src/main/java/com/example/healthylife/service/Impl/UserServiceImpl.java b/src/main/java/com/example/healthylife/service/Impl/UserServiceImpl.java deleted file mode 100644 index db0ddce..0000000 --- a/src/main/java/com/example/healthylife/service/Impl/UserServiceImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.example.healthylife.service.Impl; - -import com.example.healthylife.entity.UserEntity; -import com.example.healthylife.repository.UserRepository; -import com.example.healthylife.service.UserService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Objects; -import java.util.Optional; - -@Service -@Slf4j -public class UserServiceImpl implements UserService { - - private final UserRepository userRepository; - private final PasswordEncoder passwordEncoder; - - @Autowired - public UserServiceImpl(UserRepository userRepository, PasswordEncoder passwordEncoder) { - this.userRepository = userRepository; - this.passwordEncoder = passwordEncoder; - } - - //회원 전체조회 - @Override - @Transactional(readOnly = true) - public List userList() { - return (List) userRepository.findAll(); - } - - //회원 단일조회 - @Override - public Optional findUserById(String userId) { - return userRepository.findByUserId(userId); - } - - //회원 등록 - @Override - @Transactional - public UserEntity signUpUser(UserEntity userEntity) { - String encodedPassword = passwordEncoder.encode(userEntity.getUserPw()); - userEntity = userEntity.withUserPw(encodedPassword); - return userRepository.save(userEntity); - } - - //회원 수정 - @Override - @Transactional - public UserEntity updateUser(UserEntity userEntity) { - UserEntity user = userRepository.findById(userEntity.getUserSq()).orElseThrow(() -> new RuntimeException("User not found")); - - UserEntity.UserEntityBuilder resultEntityBuilder = user.toBuilder(); - - if (Objects.nonNull(userEntity.getUserName()) && !"".equalsIgnoreCase(userEntity.getUserName())) { - resultEntityBuilder.userName(userEntity.getUserName()); - } - - if (Objects.nonNull(userEntity.getUserEmail()) && !"".equalsIgnoreCase(userEntity.getUserEmail())) { - resultEntityBuilder.userEmail(userEntity.getUserEmail()); - } - - if (Objects.nonNull(userEntity.getUserPw()) && !"".equalsIgnoreCase(userEntity.getUserPw())) { - resultEntityBuilder.userPw(passwordEncoder.encode(userEntity.getUserPw())); - } - - UserEntity resultEntity = resultEntityBuilder.build(); - - return userRepository.save(resultEntity); - } - - //회원 삭제 - @Override - @Transactional - public void deleteUserBySq(long userSq) { - userRepository.deleteById(userSq); - } -} diff --git a/src/main/java/com/example/healthylife/service/Impl/JwtAuthService.java b/src/main/java/com/example/healthylife/service/JwtAuthService.java similarity index 91% rename from src/main/java/com/example/healthylife/service/Impl/JwtAuthService.java rename to src/main/java/com/example/healthylife/service/JwtAuthService.java index 11652e6..9768b0e 100644 --- a/src/main/java/com/example/healthylife/service/Impl/JwtAuthService.java +++ b/src/main/java/com/example/healthylife/service/JwtAuthService.java @@ -1,8 +1,9 @@ -package com.example.healthylife.service.Impl; +package com.example.healthylife.service; import com.example.healthylife.config.jwt.JwtUtil; import com.example.healthylife.entity.UserEntity; import io.jsonwebtoken.Claims; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.AuthenticationException; import org.springframework.stereotype.Service; @@ -11,10 +12,12 @@ import java.util.Map; import java.util.Objects; +@RequiredArgsConstructor @Service public class JwtAuthService { - @Autowired - private JwtUtil jwtUtil; + + private final JwtUtil jwtUtil; + private Map refreshTokenMap = new HashMap<>(); private Map usernameTokenMap = new HashMap<>(); diff --git a/src/main/java/com/example/healthylife/service/Impl/S3ImageService.java b/src/main/java/com/example/healthylife/service/S3ImageService.java similarity index 100% rename from src/main/java/com/example/healthylife/service/Impl/S3ImageService.java rename to src/main/java/com/example/healthylife/service/S3ImageService.java diff --git a/src/main/java/com/example/healthylife/service/TodayCommentsService.java b/src/main/java/com/example/healthylife/service/TodayCommentsService.java index acb3f29..5c46784 100644 --- a/src/main/java/com/example/healthylife/service/TodayCommentsService.java +++ b/src/main/java/com/example/healthylife/service/TodayCommentsService.java @@ -1,14 +1,33 @@ package com.example.healthylife.service; import com.example.healthylife.entity.TodayCommentsEntity; +import com.example.healthylife.repository.TodayCommentsRepository; +import com.example.healthylife.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; import java.util.List; +@RequiredArgsConstructor +@Service +public class TodayCommentsService { + private final TodayCommentsRepository todayCommentsRepository; + private final UserRepository userRepository; -public interface TodayCommentsService { - List todayCommentsList(); - TodayCommentsEntity insertTodayComments(TodayCommentsEntity todayCommentsEntity); - void deleteByTodayCommentsSq(long todayCommentsSq); - //오운완 내가 쓴 댓글 확인하기 - List findMyTodayComments(String userId); + public List todayCommentsList() { + return todayCommentsRepository.findAll(); + } + + public TodayCommentsEntity insertTodayComments(TodayCommentsEntity todayCommentsEntity) { + return todayCommentsRepository.save(todayCommentsEntity); + } + + public void deleteByTodayCommentsSq(long todayCommentsSq) { + todayCommentsRepository.deleteById(todayCommentsSq); + + } + + public List findMyTodayComments(String userId) { + return todayCommentsRepository.findByUserUserId(userId); + } } diff --git a/src/main/java/com/example/healthylife/service/TodayService.java b/src/main/java/com/example/healthylife/service/TodayService.java index 45628c3..0368997 100644 --- a/src/main/java/com/example/healthylife/service/TodayService.java +++ b/src/main/java/com/example/healthylife/service/TodayService.java @@ -1,23 +1,45 @@ package com.example.healthylife.service; import com.example.healthylife.entity.TodayEntity; +import com.example.healthylife.repository.TodayRepository; +import com.example.healthylife.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; import java.util.List; +@RequiredArgsConstructor +@Service +public class TodayService { -public interface TodayService { - //오운완 전체조회 - List todayList(); + private final TodayRepository todayRepository; + private final UserRepository userRepository; - //오운완 내가 쓴 글 조회 - List findMyTodayContents(String userId); - //오운완 등록 - TodayEntity registerToday(TodayEntity todayEntity); - //오운완 수정 - TodayEntity updateEntity(TodayEntity todayEntity); - //오운완 삭제 - void deleteByTodaySq(long todaySq); + public List todayList() { + return todayRepository.findAll(); + } + public List findMyTodayContents(String userId) { + return todayRepository.findByUserUserId(userId); + } + + //오운완 내가 쓴 글 찾기 +// @Override +// public List findMyToday(String userId) { +// return todayRepository.findByUserToday(userId); +// } + + public TodayEntity registerToday(TodayEntity todayEntity) { + return todayRepository.save(todayEntity); + } + + public TodayEntity updateEntity(TodayEntity todayEntity) { + return todayRepository.save(todayEntity); + } + + public void deleteByTodaySq(long todaySq) { +todayRepository.deleteById(todaySq); + } } diff --git a/src/main/java/com/example/healthylife/service/UserService.java b/src/main/java/com/example/healthylife/service/UserService.java index bc4e0c8..e4404f6 100644 --- a/src/main/java/com/example/healthylife/service/UserService.java +++ b/src/main/java/com/example/healthylife/service/UserService.java @@ -1,23 +1,70 @@ package com.example.healthylife.service; import com.example.healthylife.entity.UserEntity; +import com.example.healthylife.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Objects; import java.util.Optional; - +@RequiredArgsConstructor @Service -public interface UserService { +@Slf4j +public class UserService { + + private final UserRepository userRepository; + private final PasswordEncoder passwordEncoder; + //회원 전체조회 - List userList(); - // 회원 단일조회 - Optional findUserById(String userId); + @Transactional(readOnly = true) + public List userList() { + return (List) userRepository.findAll(); + } + + //회원 단일조회 + public Optional findUserById(String userId) { + return userRepository.findByUserId(userId); + } + //회원 등록 - UserEntity signUpUser(UserEntity userEntity); + @Transactional + public UserEntity signUpUser(UserEntity userEntity) { + String encodedPassword = passwordEncoder.encode(userEntity.getUserPw()); + userEntity = userEntity.withUserPw(encodedPassword); + return userRepository.save(userEntity); + } + //회원 수정 - UserEntity updateUser(UserEntity userEntity); - //회원 삭제 - void deleteUserBySq(long userSq); + @Transactional + public UserEntity updateUser(UserEntity userEntity) { + UserEntity user = userRepository.findById(userEntity.getUserSq()).orElseThrow(() -> new RuntimeException("User not found")); + UserEntity.UserEntityBuilder resultEntityBuilder = user.toBuilder(); + if (Objects.nonNull(userEntity.getUserName()) && !"".equalsIgnoreCase(userEntity.getUserName())) { + resultEntityBuilder.userName(userEntity.getUserName()); + } + + if (Objects.nonNull(userEntity.getUserEmail()) && !"".equalsIgnoreCase(userEntity.getUserEmail())) { + resultEntityBuilder.userEmail(userEntity.getUserEmail()); + } + + if (Objects.nonNull(userEntity.getUserPw()) && !"".equalsIgnoreCase(userEntity.getUserPw())) { + resultEntityBuilder.userPw(passwordEncoder.encode(userEntity.getUserPw())); + } + + UserEntity resultEntity = resultEntityBuilder.build(); + + return userRepository.save(resultEntity); + } + + //회원 삭제 + @Transactional + public void deleteUserBySq(long userSq) { + userRepository.deleteById(userSq); + } }