Skip to content

Commit

Permalink
Merge pull request #260 from Gongjakso/fix/portfolio
Browse files Browse the repository at this point in the history
fix : 존재하는 포트폴리오 삭제 오류 수정
  • Loading branch information
sycuuui authored Sep 30, 2024
2 parents 1592fb2 + 8aeff0a commit ff3eae8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@

public interface PortfolioRepositoryCustom {
List<Portfolio> findByMemberAndDeletedAtIsNull(Member member);
Boolean hasExistPortfolioByMember(Member member,String condition);
Boolean hasExistPortfolioByMember(Member member);
Boolean hasExistPortfolioById(Member member,Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,24 @@ public List<Portfolio> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public List<SimplePortfolioRes> 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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ff3eae8

Please sign in to comment.