diff --git a/src/main/kotlin/com/deterior/domain/member/dto/ScrapCheckResponse.kt b/src/main/kotlin/com/deterior/domain/member/dto/ScrapCheckResponse.kt new file mode 100644 index 0000000..369a91f --- /dev/null +++ b/src/main/kotlin/com/deterior/domain/member/dto/ScrapCheckResponse.kt @@ -0,0 +1,6 @@ +package com.deterior.domain.member.dto + +data class ScrapCheckResponse( + val check: Boolean, + val username: String, +) \ No newline at end of file diff --git a/src/main/kotlin/com/deterior/domain/scrap/controller/ScrapController.kt b/src/main/kotlin/com/deterior/domain/scrap/controller/ScrapController.kt index fd8cf7c..1748932 100644 --- a/src/main/kotlin/com/deterior/domain/scrap/controller/ScrapController.kt +++ b/src/main/kotlin/com/deterior/domain/scrap/controller/ScrapController.kt @@ -1,14 +1,18 @@ package com.deterior.domain.scrap.controller +import com.deterior.domain.member.dto.ScrapCheckResponse +import com.deterior.domain.scrap.dto.ScrapHandleDto import com.deterior.domain.scrap.dto.ScrapRequest import com.deterior.domain.scrap.dto.ScrapResponse import com.deterior.domain.scrap.service.ScrapService import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.ResponseEntity import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam @RequestMapping("/api") @Controller @@ -21,4 +25,13 @@ class ScrapController @Autowired constructor( val dto = scrapService.doLike(scrapRequest.toHandleDto()) return ResponseEntity.ok(dto.toResponse()) } + + @GetMapping("/scrap/check") + override fun checkScrap( + @RequestParam boardId: Long, + @RequestParam username: String + ): ResponseEntity { + val result = scrapService.isLike(ScrapHandleDto(boardId, username)) + return ResponseEntity.ok(ScrapCheckResponse(result, username)) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/deterior/domain/scrap/controller/ScrapControllerSwagger.kt b/src/main/kotlin/com/deterior/domain/scrap/controller/ScrapControllerSwagger.kt index 39b357d..ad0b386 100644 --- a/src/main/kotlin/com/deterior/domain/scrap/controller/ScrapControllerSwagger.kt +++ b/src/main/kotlin/com/deterior/domain/scrap/controller/ScrapControllerSwagger.kt @@ -1,11 +1,14 @@ package com.deterior.domain.scrap.controller +import com.deterior.domain.member.dto.ScrapCheckResponse import com.deterior.domain.scrap.dto.ScrapRequest import com.deterior.domain.scrap.dto.ScrapResponse import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.Parameter import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestParam @Tag(name = "스크랩 API") interface ScrapControllerSwagger { @@ -14,4 +17,15 @@ interface ScrapControllerSwagger { fun pushScrap( @RequestBody scrapRequest: ScrapRequest ): ResponseEntity + + @Operation(summary = "스크랩 여부 확인 \uD83D\uDD12", + parameters = [ + Parameter(name = "boardId", description = "게시글 아이디", required = true), + Parameter(name = "username", description = "사용자 아이디", required = true), + ] + ) + fun checkScrap( + @RequestParam boardId: Long, + @RequestParam username: String + ): ResponseEntity } \ No newline at end of file diff --git a/src/main/kotlin/com/deterior/domain/scrap/service/ScrapService.kt b/src/main/kotlin/com/deterior/domain/scrap/service/ScrapService.kt index 3f498dd..268042a 100644 --- a/src/main/kotlin/com/deterior/domain/scrap/service/ScrapService.kt +++ b/src/main/kotlin/com/deterior/domain/scrap/service/ScrapService.kt @@ -7,4 +7,5 @@ interface ScrapService { // fun pushLike(scrapHandleDto: ScrapHandleDto): ScrapDto // fun undoLike(scrapHandleDto: ScrapHandleDto): ScrapDto fun doLike(scrapHandleDto: ScrapHandleDto): ScrapDto + fun isLike(scrapHandleDto: ScrapHandleDto): Boolean } \ No newline at end of file diff --git a/src/main/kotlin/com/deterior/domain/scrap/service/ScrapServiceImpl.kt b/src/main/kotlin/com/deterior/domain/scrap/service/ScrapServiceImpl.kt index e400043..a7c08ff 100644 --- a/src/main/kotlin/com/deterior/domain/scrap/service/ScrapServiceImpl.kt +++ b/src/main/kotlin/com/deterior/domain/scrap/service/ScrapServiceImpl.kt @@ -22,6 +22,11 @@ class ScrapServiceImpl @Autowired constructor( scrapRepository.isScrapExists(scrapHandleDto) .let { if (it) return undoLike(scrapHandleDto) else return pushLike(scrapHandleDto) } + @Transactional + override fun isLike(scrapHandleDto: ScrapHandleDto): Boolean { + return scrapRepository.isScrapExists(scrapHandleDto) + } + private fun pushLike(scrapHandleDto: ScrapHandleDto): ScrapDto { val board = boardRepository.findById(scrapHandleDto.boardId).get() val member = memberRepository.findByUsername(scrapHandleDto.username)