-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
567 additions
and
36 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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/swave/urnr/releasenote/controller/LikedController.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.swave.urnr.releasenote.controller; | ||
|
||
import com.swave.urnr.releasenote.responsedto.LikedCountResponseDTO; | ||
import com.swave.urnr.releasenote.service.LikedService; | ||
import com.swave.urnr.util.http.HttpResponse; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
정 |
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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/swave/urnr/releasenote/repository/LikedCustomRepository.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,5 @@ | ||
package com.swave.urnr.releasenote.repository; | ||
|
||
public interface LikedCustomRepository { | ||
long countByLiked(Long userInProjectId); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/swave/urnr/releasenote/repository/LikedCustomRepositoryImpl.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,26 @@ | ||
package com.swave.urnr.releasenote.repository; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import static com.swave.urnr.releasenote.domain.QLiked.liked; | ||
import static com.swave.urnr.releasenote.domain.QReleaseNote.releaseNote; | ||
import static com.swave.urnr.releasenote.domain.QSeenCheck.seenCheck; | ||
|
||
public class LikedCustomRepositoryImpl implements LikedCustomRepository { | ||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
public LikedCustomRepositoryImpl(JPAQueryFactory jpaQueryFactory) { | ||
this.jpaQueryFactory = jpaQueryFactory; | ||
} | ||
|
||
@Override | ||
public long countByLiked(Long releaseNoteId){ | ||
return jpaQueryFactory | ||
.select(liked.count()) | ||
.from(releaseNote) | ||
.join(seenCheck).on(seenCheck.releaseNote.id.eq(releaseNote.id)) | ||
.join(liked).on(liked.seenCheck.id.eq(seenCheck.id)) | ||
.where(seenCheck.isDeleted.eq(false), releaseNote.isDeleted.eq(false), releaseNote.id.eq(releaseNoteId), liked.isLiked.eq(true)) | ||
.fetchFirst(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/swave/urnr/releasenote/repository/LikedRepository.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.swave.urnr.releasenote.repository; | ||
|
||
import com.swave.urnr.releasenote.domain.Liked; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface LikedRepository extends JpaRepository<Liked, Long>, LikedCustomRepository { | ||
Liked findBySeenCheck_Id(Long Id); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/swave/urnr/releasenote/responsedto/LikedCountResponseDTO.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,14 @@ | ||
package com.swave.urnr.releasenote.responsedto; | ||
|
||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@ApiModel(value = "좋아요 개수 카운트 DTO") | ||
@NoArgsConstructor | ||
public class LikedCountResponseDTO { | ||
@ApiModelProperty(value="좋아요 개수", example = "2", required = true) | ||
private Long likedCount; | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/swave/urnr/releasenote/service/LikedService.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,14 @@ | ||
package com.swave.urnr.releasenote.service; | ||
|
||
import com.swave.urnr.releasenote.responsedto.LikedCountResponseDTO; | ||
import com.swave.urnr.util.http.HttpResponse; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
public interface LikedService { | ||
public HttpResponse createLiked(HttpServletRequest request, Long releaseNoteId); | ||
|
||
public HttpResponse cancelLiked(HttpServletRequest request, Long releaseNodeId); | ||
|
||
public LikedCountResponseDTO countLiked(Long releaseNodeId); | ||
} |
94 changes: 94 additions & 0 deletions
94
src/main/java/com/swave/urnr/releasenote/service/LikedServiceImpl.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,94 @@ | ||
package com.swave.urnr.releasenote.service; | ||
|
||
import com.swave.urnr.releasenote.domain.Liked; | ||
import com.swave.urnr.releasenote.domain.SeenCheck; | ||
import com.swave.urnr.releasenote.repository.LikedRepository; | ||
import com.swave.urnr.releasenote.repository.ReleaseNoteRepository; | ||
import com.swave.urnr.releasenote.repository.SeenCheckRepository; | ||
import com.swave.urnr.releasenote.responsedto.LikedCountResponseDTO; | ||
import com.swave.urnr.user.domain.UserInProject; | ||
import com.swave.urnr.util.http.HttpResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.access.AccessDeniedException; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.NoSuchElementException; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@EnableTransactionManagement | ||
public class LikedServiceImpl implements LikedService { | ||
|
||
private final ReleaseNoteRepository releaseNoteRepository; | ||
private final SeenCheckRepository seenCheckRepository; | ||
private final LikedRepository likedRepository; | ||
|
||
@Override | ||
@Transactional | ||
public HttpResponse createLiked(HttpServletRequest request, Long releaseNoteId){ | ||
UserInProject userInProject = releaseNoteRepository.findUserInProjectByUserIdAndReleaseNoteId((Long) request.getAttribute("id"), releaseNoteId); | ||
SeenCheck seenCheck; | ||
|
||
if(userInProject == null){ | ||
throw new AccessDeniedException("해당 프로젝트의 접근 권한이 없습니다."); | ||
}else{ | ||
seenCheck = seenCheckRepository.findByUserInProjectIdAndReleaseNoteId(userInProject.getId(), releaseNoteId); | ||
} | ||
|
||
if(null != likedRepository.findBySeenCheck_Id(seenCheck.getId())){ | ||
throw new RuntimeException("이미 좋아요 한 기록이 있습니다."); | ||
} | ||
|
||
Liked liked = Liked.builder() | ||
.isLiked(true) | ||
.seenCheck(seenCheck) | ||
.build(); | ||
|
||
likedRepository.saveAndFlush(liked); | ||
|
||
return HttpResponse.builder() | ||
.message("Liked Created") | ||
.description("Liked ID : " + liked.getId() + " Created") | ||
.build(); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public HttpResponse cancelLiked(HttpServletRequest request, Long releaseNoteId){ | ||
UserInProject userInProject = releaseNoteRepository.findUserInProjectByUserIdAndReleaseNoteId((Long) request.getAttribute("id"), releaseNoteId); | ||
SeenCheck seenCheck; | ||
|
||
if(userInProject == null){ | ||
throw new AccessDeniedException("해당 프로젝트의 접근 권한이 없습니다."); | ||
}else{ | ||
seenCheck = seenCheckRepository.findById(userInProject.getId()) | ||
.orElseThrow(NoSuchElementException::new); | ||
} | ||
|
||
Liked liked = likedRepository.findBySeenCheck_Id(seenCheck.getId()); | ||
if(null == liked){ | ||
throw new RuntimeException("좋아요 한 기록이 없습니다."); | ||
} | ||
|
||
liked.setIsLiked(false); | ||
|
||
likedRepository.flush(); | ||
|
||
return HttpResponse.builder() | ||
.message("Liked Cancelled") | ||
.description("Liked ID : " + liked.getId() + " Cancelled") | ||
.build(); | ||
} | ||
|
||
@Override | ||
public LikedCountResponseDTO countLiked(Long releaseNoteId){ | ||
LikedCountResponseDTO likedCountResponseDTO = new LikedCountResponseDTO(); | ||
likedCountResponseDTO.setLikedCount(likedRepository.countByLiked(releaseNoteId)); | ||
return likedCountResponseDTO; | ||
} | ||
} |
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
Oops, something went wrong.