-
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.
type: feat, change, test body: 따봉 기능을 추가 하였습니다. 기존 릴리즈 노트 정보에 따봉 갯수가 추가됩니다.
- Loading branch information
Showing
15 changed files
with
477 additions
and
32 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
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; | ||
|
||
@Api(tags = "LikedController") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@CrossOrigin(origins = "http://localhost:3000", allowedHeaders = "*", allowCredentials = "true") | ||
public class LikedController { | ||
|
||
private final LikedService likedService; | ||
|
||
@Operation(summary = "내 이름 좋아요 하나 생성", description = "releaseNoteId의 릴리즈 노트에 내 이름으로 좋아요를 하나 생성합니다. 중복은 불가능 합니다. 유저 정보는 JWT로부터 가져옵니다.") | ||
@PostMapping("/api/project/release-note/{releaseNoteId}/Liked") | ||
public HttpResponse createLiked(HttpServletRequest request,@PathVariable Long releaseNoteId){ | ||
return likedService.createLiked(request, releaseNoteId); | ||
} | ||
|
||
@Operation(summary = "내 이름 좋아요 하나 취소", description = "releaseNoteId의 릴리즈 노트에 내 이름으로된 좋아요를 하나 취소합니다. 유저 정보는 JWT로부터 가져옵니다.") | ||
@PutMapping("/api/project/release-note/{releaseNoteId}/Liked") | ||
public HttpResponse cancelLiked(HttpServletRequest request,@PathVariable Long releaseNoteId){ | ||
return likedService.cancelLiked(request, releaseNoteId); | ||
} | ||
|
||
@Operation(summary = "좋아요 갯수 세기", description = "releaseNoteId의 릴리즈 노트에 달린 좋아요의 갯수를 반환합니다.") | ||
@GetMapping("/api/project/release-note/{releaseNoteId}/Liked") | ||
public LikedCountResponseDTO countLiked(@PathVariable Long releaseNoteId){ | ||
return likedService.countLiked(releaseNoteId); | ||
} | ||
} |
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
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.