-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # bp-app-api/build.gradle # bp-app-api/src/main/java/com/beautify_project/bp_app_api/bean/ImageRepositoryBean.java # bp-app-api/src/main/java/com/beautify_project/bp_app_api/bean/JasyptConfigBean.java # bp-app-api/src/main/java/com/beautify_project/bp_app_api/config/IOBoundAsyncThreadPoolConfiguration.java # bp-app-api/src/main/java/com/beautify_project/bp_app_api/config/JasyptConfigBean.java # bp-app-api/src/main/java/com/beautify_project/bp_app_api/config/JasyptConfiguration.java # bp-app-api/src/main/java/com/beautify_project/bp_app_api/config/properties/NaverCloudPlatformObjectStorageConfig.java # bp-app-api/src/main/java/com/beautify_project/bp_app_api/controller/ShopController.java # bp-app-api/src/main/java/com/beautify_project/bp_app_api/repository/image/NaverCloudPlatformObjectStorageRepository.java # bp-app-api/src/main/java/com/beautify_project/bp_app_api/service/ShopLikeService.java # bp-app-api/src/main/java/com/beautify_project/bp_app_api/service/ShopService.java # bp-app-api/src/main/resources/application-local.yml # bp-app-api/src/main/resources/application-test.yml # bp-app-api/src/test/java/com/beautify_project/bp_app_api/integration/ShopServiceRepositoryIntegrationTest.java # bp-domain-mysql/src/main/java/com/beautify_project/bp_mysql/entity/BaseEntity.java # bp-domain-mysql/src/main/java/com/beautify_project/bp_mysql/entity/CustomEntityListener.java # bp-domain-mysql/src/main/java/com/beautify_project/bp_mysql/repository/ShopLikeRepositoryCustom.java # bp-domain-mysql/src/main/java/com/beautify_project/bp_mysql/repository/ShopLikeRepositoryImpl.java # bp-domain-mysql/src/main/java/com/beautify_project/bp_mysql/repository/ShopRepository.java # bp-utils/src/main/java/com/beautify_project/bp_utils/UUIDGenerator.java # bp-utils/src/main/java/com/beautify_project/bp_utils/Validator.java # settings.gradle
- Loading branch information
Showing
62 changed files
with
3,424 additions
and
2,374 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
52 changes: 52 additions & 0 deletions
52
bp-app-api/src/main/java/com/beautify_project/bp_app_api/config/KafkaProducerConfig.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,52 @@ | ||
package com.beautify_project.bp_app_api.config; | ||
|
||
import com.beautify_project.bp_app_api.config.properties.KafkaProducerConfigProperties; | ||
import com.beautify_project.bp_app_api.dto.event.ShopLikeCancelEvent; | ||
import com.beautify_project.bp_app_api.dto.event.ShopLikeEvent; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.kafka.clients.producer.ProducerConfig; | ||
import org.apache.kafka.common.serialization.StringSerializer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.kafka.annotation.EnableKafka; | ||
import org.springframework.kafka.core.DefaultKafkaProducerFactory; | ||
import org.springframework.kafka.core.KafkaTemplate; | ||
import org.springframework.kafka.core.ProducerFactory; | ||
import org.springframework.kafka.support.serializer.JsonSerializer; | ||
|
||
@EnableKafka | ||
@Configuration | ||
@RequiredArgsConstructor | ||
public class KafkaProducerConfig { | ||
|
||
private final KafkaProducerConfigProperties configProperties; | ||
|
||
@Bean | ||
public Map<String, Object> producerConfig() { | ||
return Map.of( | ||
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, configProperties.getBroker(), | ||
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class, | ||
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class); | ||
} | ||
|
||
@Bean(name = "ShopLikeEventProducerFactory") | ||
public ProducerFactory<String, ShopLikeEvent> shopLikeEventProducerFactory() { | ||
return new DefaultKafkaProducerFactory<>(producerConfig()); | ||
} | ||
|
||
@Bean(name = "ShopLikeEventKafkaTemplate") | ||
public KafkaTemplate<String, ShopLikeEvent> shopLikeEventKafkaTemplate() { | ||
return new KafkaTemplate<>(shopLikeEventProducerFactory()); | ||
} | ||
|
||
@Bean(name = "ShopLikeCancelEventProducerFactory") | ||
public ProducerFactory<String, ShopLikeCancelEvent> shopLikeCancelEventProducerFactory() { | ||
return new DefaultKafkaProducerFactory<>(producerConfig()); | ||
} | ||
|
||
@Bean(name = "ShopLikeCancelEventKafkaTemplate") | ||
public KafkaTemplate<String, ShopLikeCancelEvent> shopLikeCancelEventKafkaTemplate() { | ||
return new KafkaTemplate<>(shopLikeCancelEventProducerFactory()); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...beautify_project/bp_app_api/config/properties/AsyncThreadPoolConfigurationProperties.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,8 @@ | ||
package com.beautify_project.bp_app_api.config.properties; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "thread-pool.async" ) | ||
public record AsyncThreadPoolConfigurationProperties(Integer corePoolSize, Integer maxPoolSize, | ||
Integer queueCapacity, String threadNamePrefix) { | ||
} |
60 changes: 60 additions & 0 deletions
60
...java/com/beautify_project/bp_app_api/config/properties/KafkaProducerConfigProperties.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,60 @@ | ||
package com.beautify_project.bp_app_api.config.properties; | ||
|
||
import com.beautify_project.bp_app_api.exception.BpCustomException; | ||
import com.beautify_project.bp_app_api.response.ErrorResponseMessage.ErrorCode; | ||
import com.beautify_project.bp_utils.Validator; | ||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "kafka.producer") | ||
@Slf4j | ||
@Getter | ||
public class KafkaProducerConfigProperties { | ||
|
||
private String broker; | ||
private Topic topic; | ||
|
||
public void setBroker(final String broker) { | ||
if (Validator.isEmptyOrBlank(broker)) { | ||
throw new BpCustomException("broker 설정값이 올바르지 않습니다.", ErrorCode.IS001); | ||
} | ||
this.broker = broker; | ||
} | ||
|
||
public void setTopic(final Topic topic) { | ||
if (topic == null) { | ||
throw new BpCustomException("topic 설정값이 올바르지 않습니다.", ErrorCode.IS001); | ||
} | ||
this.topic = topic; | ||
} | ||
|
||
@Getter | ||
public static class Topic { | ||
private String shopLikeEvent; | ||
private String shopLikeCancelEvent; | ||
private String signUpCertificationMailEvent; | ||
|
||
public void setShopLikeEvent(final String shopLikeEvent) { | ||
if (Validator.isEmptyOrBlank(shopLikeEvent)) { | ||
throw new BpCustomException("shop-like-event 설정값이 올바르지 않습니다.", ErrorCode.IS001); | ||
} | ||
this.shopLikeEvent = shopLikeEvent; | ||
} | ||
|
||
public void setShopLikeCancelEvent(final String shopLikeCancelEvent) { | ||
if (Validator.isEmptyOrBlank(shopLikeCancelEvent)) { | ||
throw new BpCustomException("shop-like-cancel-event 설정값이 올바르지 않습니다.", ErrorCode.IS001); | ||
} | ||
this.shopLikeCancelEvent = shopLikeCancelEvent; | ||
} | ||
|
||
public void setSignUpCertificationMailEvent(final String signUpCertificationMailEvent) { | ||
if (Validator.isEmptyOrBlank(signUpCertificationMailEvent)) { | ||
throw new BpCustomException("sign-up-certification-mail 설정값이 올바르지 않습니다.", | ||
ErrorCode.IS001); | ||
} | ||
this.signUpCertificationMailEvent = signUpCertificationMailEvent; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.beautify_project.bp_app_api.controller; | ||
|
||
import com.beautify_project.bp_app_api.dto.event.ShopLikeCancelEvent; | ||
import com.beautify_project.bp_app_api.dto.event.ShopLikeEvent; | ||
import com.beautify_project.bp_app_api.request.shop.ShopListFindRequestParameters; | ||
import com.beautify_project.bp_app_api.request.shop.ShopRegistrationRequest; | ||
import com.beautify_project.bp_app_api.response.ResponseMessage; | ||
|
@@ -8,6 +10,7 @@ | |
import com.beautify_project.bp_app_api.service.ShopService; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotBlank; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
|
@@ -56,22 +59,38 @@ public ResponseMessage findShopList(@RequestParam(name = "type") final String se | |
// TODO: 샵 삭제 구현 | ||
|
||
/** | ||
* Shop 좋아요 | ||
* Shop 좋아요 이벤트 producer | ||
*/ | ||
@PostMapping("/v1/shops/likes/{id}") | ||
@ResponseStatus(code = HttpStatus.NO_CONTENT) | ||
@ResponseStatus(code = HttpStatus.OK) | ||
public void likeShop(@PathVariable(value = "id") @NotBlank final String shopId) { | ||
// TODO: spring security 통해서 토큰 넘겨주는 방식으로 개선 필요 | ||
shopService.likeShop(shopId, "[email protected]"); | ||
shopService.produceShopLikeEvent(shopId, "[email protected]"); | ||
} | ||
|
||
/** | ||
* Shop 좋아요 취소 | ||
* Shop 좋아요 이벤트 처리 (consumer 는 bp-kafka-consumer 에서 처리) | ||
*/ | ||
@DeleteMapping("/v1/shops/likes/{id}") | ||
@PostMapping("/v1/shops/likes") | ||
@ResponseStatus(code = HttpStatus.NO_CONTENT) | ||
public void batchShopLikes(@Valid @RequestBody final List<ShopLikeEvent> shopLikeEvents) { | ||
shopService.batchShopLikes(shopLikeEvents); | ||
} | ||
|
||
/** | ||
* Shop 좋아요 취소 이벤트 producer | ||
*/ | ||
@DeleteMapping("/v1/shops/likes/{id}") | ||
@ResponseStatus(code = HttpStatus.OK) | ||
public void cancelLikeShop(@PathVariable(value = "id") @NotBlank final String shopId) { | ||
// TODO: spring security 통해서 토큰 넘겨주는 방식으로 개선 필요 | ||
shopService.cancelLikeShop(shopId, "[email protected]"); | ||
shopService.produceShopLikeCancelEvent(shopId, "[email protected]"); | ||
} | ||
|
||
/** | ||
* Shop 좋아요 취소 이벤트 처리 (consumer 는 bp-kafka-consumer 에서 처리) | ||
*/ | ||
@DeleteMapping("/v1/shops/likes") | ||
@ResponseStatus(code = HttpStatus.NO_CONTENT) | ||
public void batchShopLikeCancel(@Valid @RequestBody final List<ShopLikeCancelEvent> shopLikeCancelEvents) { | ||
shopService.batchShopLikesCancel(shopLikeCancelEvents); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
bp-app-api/src/main/java/com/beautify_project/bp_app_api/dto/event/ShopLikeCancelEvent.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,24 @@ | ||
package com.beautify_project.bp_app_api.dto.event; | ||
|
||
|
||
import com.beautify_project.bp_utils.Validator; | ||
|
||
public record ShopLikeCancelEvent(String shopId, String memberEmail) { | ||
|
||
public ShopLikeCancelEvent(final String shopId, final String memberEmail) { | ||
validate(shopId, memberEmail); | ||
this.shopId = shopId; | ||
this.memberEmail = memberEmail; | ||
} | ||
|
||
private void validate(final String shopId, final String memberEmail) { | ||
if (Validator.isEmptyOrBlank(shopId)) { | ||
throw new UnsupportedOperationException("shopId 파라미터는 필수값 입니다."); | ||
} | ||
|
||
if (Validator.isEmptyOrBlank(memberEmail)) { | ||
throw new UnsupportedOperationException("memberEmail 파라미터는 필수값 입니다."); | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
bp-app-api/src/main/java/com/beautify_project/bp_app_api/dto/event/ShopLikeEvent.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,23 @@ | ||
package com.beautify_project.bp_app_api.dto.event; | ||
|
||
import com.beautify_project.bp_utils.Validator; | ||
|
||
public record ShopLikeEvent (String shopId, String memberEmail){ | ||
|
||
public ShopLikeEvent(final String shopId, final String memberEmail) { | ||
validate(shopId, memberEmail); | ||
this.shopId = shopId; | ||
this.memberEmail = memberEmail; | ||
} | ||
|
||
private void validate(final String shopId, final String memberEmail) { | ||
|
||
if (Validator.isEmptyOrBlank(shopId)) { | ||
throw new UnsupportedOperationException("shopId 파라미터는 필수값 입니다."); | ||
} | ||
|
||
if (Validator.isEmptyOrBlank(memberEmail)) { | ||
throw new UnsupportedOperationException("memberEmail 파라미터는 필수값 입니다."); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
bp-app-api/src/main/java/com/beautify_project/bp_app_api/producer/KafkaEventProducer.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,27 @@ | ||
package com.beautify_project.bp_app_api.producer; | ||
|
||
import com.beautify_project.bp_app_api.config.properties.KafkaProducerConfigProperties; | ||
import com.beautify_project.bp_app_api.dto.event.ShopLikeCancelEvent; | ||
import com.beautify_project.bp_app_api.dto.event.ShopLikeEvent; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.kafka.core.KafkaTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class KafkaEventProducer { | ||
|
||
private final KafkaTemplate<String, ShopLikeEvent> shopLikeEventKafkaTemplate; | ||
private final KafkaTemplate<String, ShopLikeCancelEvent> shopLikeCancelEventKafkaTemplate; | ||
private final KafkaProducerConfigProperties configProperties; | ||
|
||
public void publishShopLikeEvent(final ShopLikeEvent event) { | ||
shopLikeEventKafkaTemplate.send(configProperties.getTopic().getShopLikeEvent(), event); | ||
} | ||
|
||
public void publishShopLikeCancelEvent(final ShopLikeCancelEvent event) { | ||
shopLikeCancelEventKafkaTemplate.send(configProperties.getTopic().getShopLikeCancelEvent(), event); | ||
} | ||
} |
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
Oops, something went wrong.