diff --git a/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryCustom.java b/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryCustom.java index 48ca1a8a..f62c7612 100644 --- a/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryCustom.java +++ b/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryCustom.java @@ -7,5 +7,6 @@ public interface PortfolioRepositoryCustom { List findByMemberAndDeletedAtIsNull(Member member); - Boolean hasExistPortfolioByMember(Member member,String condition); + Boolean hasExistPortfolioByMember(Member member); + Boolean hasExistPortfolioById(Member member,Long id); } diff --git a/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryImpl.java b/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryImpl.java index 4fbb54c5..66182615 100644 --- a/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryImpl.java +++ b/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryImpl.java @@ -22,21 +22,24 @@ public List findByMemberAndDeletedAtIsNull(Member member) { .fetch(); } - public Boolean hasExistPortfolioByMember(Member member,String condition){ + public Boolean hasExistPortfolioByMember(Member member){ return queryFactory .selectFrom(portfolio) .where(portfolio.member.eq(member) - .and(conditionEq(condition)) + .and(portfolio.fileUri.isNotNull().or(portfolio.notionUri.isNotNull())) .and(portfolio.deletedAt.isNull())) .fetchFirst()!=null; } - public BooleanExpression conditionEq(String condition){ - if(condition.equals("or")){ - return portfolio.fileUri.isNotNull().or(portfolio.notionUri.isNotNull()); - }else if (condition.equals("and")){ - return portfolio.fileUri.isNull().and(portfolio.notionUri.isNull()); - } - return null; + public Boolean hasExistPortfolioById(Member member,Long id){ + return queryFactory + .selectFrom(portfolio) + .where(portfolio.member.eq(member) + .and(portfolio.id.eq(id)) + .and(portfolio.fileUri.isNull()) + .and(portfolio.notionUri.isNull()) + .and(portfolio.portfolioData.isNull()) + .and(portfolio.deletedAt.isNull())) + .fetchFirst()!=null; } } diff --git a/src/main/java/com/gongjakso/server/domain/portfolio/service/PortfolioService.java b/src/main/java/com/gongjakso/server/domain/portfolio/service/PortfolioService.java index d748cd8e..07ad04ca 100644 --- a/src/main/java/com/gongjakso/server/domain/portfolio/service/PortfolioService.java +++ b/src/main/java/com/gongjakso/server/domain/portfolio/service/PortfolioService.java @@ -181,7 +181,7 @@ public List getMyPortfolios(Member member) { public void saveExistPortfolio(Member member, MultipartFile file, String notionUri){ //등록된 파일이나 노션 링크 있는지 확인 //Validation - Boolean isExist = portfolioRepository.hasExistPortfolioByMember(member,"or"); + Boolean isExist = portfolioRepository.hasExistPortfolioByMember(member); if (isExist){ throw new ApplicationException(ErrorCode.ALREADY_EXIST_EXCEPTION); } @@ -212,20 +212,20 @@ public void deleteExistPortfolio(Member member, Long id, String dataType){ s3Client.delete(portfolio.getFileUri()); portfolio.setFileUri(null); //file,notion all null - if(portfolioRepository.hasExistPortfolioByMember(member,"and")){ + if(portfolioRepository.hasExistPortfolioById(member,id)){ portfolioRepository.delete(portfolio); } - } else if (type.equals(DataType.NOTION)) { + }else if (type.equals(DataType.NOTION)) { //notion delete if(portfolio.getNotionUri()==null){ throw new ApplicationException(ErrorCode.NOTION_NOT_FOUND_EXCEPTION); } portfolio.setNotionUri(null); //file,notion all null - if(portfolioRepository.hasExistPortfolioByMember(member,"and")){ + if(portfolioRepository.hasExistPortfolioById(member,id)){ portfolioRepository.delete(portfolio); } - }else { + }else if(type.equals(DataType.HYBRID)) { //file,notion delete if(portfolio.getFileUri()==null || portfolio.getNotionUri()==null){ throw new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION);