diff --git a/module-api/src/main/java/kernel/jdon/coffeechat/service/CoffeeChatService.java b/module-api/src/main/java/kernel/jdon/coffeechat/service/CoffeeChatService.java index 98a9104f9..1147d974b 100644 --- a/module-api/src/main/java/kernel/jdon/coffeechat/service/CoffeeChatService.java +++ b/module-api/src/main/java/kernel/jdon/coffeechat/service/CoffeeChatService.java @@ -50,12 +50,12 @@ private void increaseViewCount(CoffeeChat coffeeChat) { coffeeChat.increaseViewCount(); } - public CustomPageResponse findHostCoffeeChatList(Long memberId, Pageable pageable) { + public CustomPageResponse findHostCoffeeChatList(Long memberId, Pageable pageable) { Page findCoffeeChatPage = coffeeChatRepository.findAllByMemberIdAndIsDeletedFalse( memberId, pageable) .map(FindCoffeeChatListResponse::of); - return new CustomPageResponse<>(findCoffeeChatPage); + return CustomPageResponse.of(findCoffeeChatPage); } @Transactional diff --git a/module-api/src/main/java/kernel/jdon/config/auth/OAuth2SecurityConfig.java b/module-api/src/main/java/kernel/jdon/config/auth/OAuth2SecurityConfig.java index 54883d383..6e87e7372 100644 --- a/module-api/src/main/java/kernel/jdon/config/auth/OAuth2SecurityConfig.java +++ b/module-api/src/main/java/kernel/jdon/config/auth/OAuth2SecurityConfig.java @@ -27,7 +27,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.cors(corsCustomizer -> corsCustomizer.configurationSource(request -> { CorsConfiguration config = new CorsConfiguration(); - config.setAllowedOrigins(List.of("http://localhost:3000")); + config.setAllowedOrigins(List.of("http://localhost:3000", "https://peaceful-sopapillas-36c089.netlify.app")); config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE")); config.setAllowedHeaders(List.of("*")); config.setMaxAge(3600L); diff --git a/module-api/src/main/java/kernel/jdon/favorite/service/FavoriteService.java b/module-api/src/main/java/kernel/jdon/favorite/service/FavoriteService.java index 9da841933..1035298ac 100644 --- a/module-api/src/main/java/kernel/jdon/favorite/service/FavoriteService.java +++ b/module-api/src/main/java/kernel/jdon/favorite/service/FavoriteService.java @@ -40,10 +40,16 @@ public UpdateFavoriteResponse create(Long memberId, UpdateFavoriteRequest update InflearnCourse findInflearnCourse = inflearnCourseRepository.findById( updateFavoriteRequest.getLectureId()) .orElseThrow(() -> new ApiException(InflearncourseErrorCode.NOT_FOUND_INFLEARN_COURSE)); + + return favoriteRepository.findFavoriteByMemberIdAndInflearnCourseId(memberId, + updateFavoriteRequest.getLectureId()) + .map(favorite -> UpdateFavoriteResponse.of(favorite.getId())) + .orElseGet(() -> createNewFavorite(findMember, findInflearnCourse)); + } - Favorite favorite = new Favorite(findMember, findInflearnCourse); + private UpdateFavoriteResponse createNewFavorite(Member member, InflearnCourse inflearnCourse) { + Favorite favorite = new Favorite(member, inflearnCourse); Favorite savedFavorite = favoriteRepository.save(favorite); - return UpdateFavoriteResponse.of(savedFavorite.getId()); } diff --git a/module-api/src/main/java/kernel/jdon/global/page/CustomPageResponse.java b/module-api/src/main/java/kernel/jdon/global/page/CustomPageResponse.java index c1edc7005..8d5584668 100644 --- a/module-api/src/main/java/kernel/jdon/global/page/CustomPageResponse.java +++ b/module-api/src/main/java/kernel/jdon/global/page/CustomPageResponse.java @@ -5,21 +5,22 @@ import org.springframework.data.domain.Page; +import lombok.AllArgsConstructor; import lombok.Getter; @Getter +@AllArgsConstructor public class CustomPageResponse { private List content; private PageInfo pageInfo; - public CustomPageResponse(Page page) { - this.content = page.getContent(); - this.pageInfo = new PageInfo(page); + public static CustomPageResponse of(Page page) { + return new CustomPageResponse(page.getContent(), new PageInfo(page)); } @Getter - public class PageInfo implements Serializable { + public static class PageInfo implements Serializable { private Integer pageNumber; private Integer pageSize; diff --git a/module-domain/src/main/java/kernel/jdon/skillhistory/domain/SkillHistory.java b/module-domain/src/main/java/kernel/jdon/skillhistory/domain/SkillHistory.java index 3c6a65afe..c72b3c8dd 100644 --- a/module-domain/src/main/java/kernel/jdon/skillhistory/domain/SkillHistory.java +++ b/module-domain/src/main/java/kernel/jdon/skillhistory/domain/SkillHistory.java @@ -9,7 +9,6 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; -import jakarta.persistence.UniqueConstraint; import kernel.jdon.jobcategory.domain.JobCategory; import kernel.jdon.wantedjd.domain.WantedJd; import lombok.AccessLevel; @@ -20,10 +19,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -@Table(name = "skill_history", - uniqueConstraints = { - @UniqueConstraint(columnNames = {"job_category_id", "wanted_jd_id", "keyword"}) - }) +@Table(name = "skill_history") public class SkillHistory { @Id @GeneratedValue(strategy = GenerationType.IDENTITY)