-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from kakao-tech-campus-2nd-step3/Master
9조 BE 코드리뷰 5회차
- Loading branch information
Showing
44 changed files
with
1,873 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/helpmeCookies/global/ApiResponse/ApiResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.helpmeCookies.global.ApiResponse; | ||
|
||
import jakarta.annotation.Nullable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@RequiredArgsConstructor | ||
public class ApiResponse<T> { | ||
|
||
private final int code; | ||
private final String message; | ||
private T data; | ||
|
||
public static<T> ApiResponse<T> success(SuccessCode successCode, T data) { | ||
return new ApiResponse<T>(successCode.getCode(), successCode.getMessage(),data); | ||
} | ||
|
||
public static ApiResponse<Void> success(SuccessCode successCode) { | ||
return new ApiResponse<>(successCode.getCode(), successCode.getMessage(),null); | ||
} | ||
|
||
public static ApiResponse<Void> error(HttpStatus errorCode, String message) { | ||
return new ApiResponse<>(errorCode.value(), message,null); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/helpmeCookies/global/ApiResponse/SuccessCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.helpmeCookies.global.ApiResponse; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public enum SuccessCode { | ||
OK(200, "OK"), | ||
CREATED_SUCCESS(201, "저장에 성공했습니다"), | ||
NO_CONTENT(204, "삭제에 성공했습니다."); | ||
|
||
private final int code; | ||
private final String message; | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/helpmeCookies/global/config/ProPertyConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.helpmeCookies.global.config; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.helpmeCookies.global.jwt.JwtProperties; | ||
|
||
@Configuration | ||
@EnableConfigurationProperties(JwtProperties.class) | ||
public class ProPertyConfig { | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/helpmeCookies/global/config/RedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.helpmeCookies.global.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@Configuration | ||
@EnableRedisRepositories | ||
public class RedisConfig { | ||
|
||
@Value("${spring.data.redis.host}") | ||
private String host; | ||
|
||
@Value("${spring.data.redis.port}") | ||
private int port; | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
return new LettuceConnectionFactory(host, port); | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<?, ?> redisTemplate() { | ||
RedisTemplate<byte[], byte[]> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new StringRedisSerializer()); | ||
redisTemplate.setHashKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setHashValueSerializer(new StringRedisSerializer()); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory()); | ||
return redisTemplate; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/com/helpmeCookies/global/jwt/JwtProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.helpmeCookies.global.jwt; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Component | ||
@ConfigurationProperties(prefix = "jwt") | ||
@Getter | ||
@Setter | ||
public class JwtProperties { | ||
private String secret; | ||
private long accessTokenExpireTime; | ||
private long refreshTokenExpireTime; | ||
|
||
public JwtProperties() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/helpmeCookies/product/repository/ProductLikeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.helpmeCookies.product.repository; | ||
|
||
import com.helpmeCookies.product.entity.Like; | ||
import com.helpmeCookies.product.entity.Product; | ||
import com.helpmeCookies.user.entity.User; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ProductLikeRepository extends JpaRepository<Like, Long> { | ||
Optional<Like> findDistinctFirstByUserAndProduct(User user, Product product); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/helpmeCookies/product/service/ProductLikeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.helpmeCookies.product.service; | ||
|
||
import com.helpmeCookies.product.entity.Like; | ||
import com.helpmeCookies.product.entity.Product; | ||
import com.helpmeCookies.product.repository.ProductLikeRepository; | ||
import com.helpmeCookies.product.repository.ProductRepository; | ||
import com.helpmeCookies.user.entity.User; | ||
import com.helpmeCookies.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ProductLikeService { | ||
private final ProductLikeRepository productLikeRepository; | ||
private final UserRepository userRepository; | ||
private final ProductRepository productRepository; | ||
|
||
@Transactional | ||
public void productLike(Long userId, Long productId) { | ||
User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("유효하지 않은 유저Id입니다." + userId)); | ||
Product product = productRepository.findById(productId).orElseThrow(() -> new IllegalArgumentException("유효하지 않은 상품Id입니다." + productId)); | ||
Like like = new Like(user, product); | ||
productLikeRepository.save(like); | ||
} | ||
|
||
@Transactional | ||
public void deleteProductLike(Long userId, Long productId) { | ||
User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("유효하지 않은 유저Id입니다." + userId)); | ||
Product product = productRepository.findById(productId).orElseThrow(() -> new IllegalArgumentException("유효하지 않은 상품Id입니다." + productId)); | ||
|
||
Like like = productLikeRepository.findDistinctFirstByUserAndProduct(user,product).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 상품 찜 항목입니다.")); | ||
productLikeRepository.delete(like); | ||
} | ||
} |
Oops, something went wrong.