-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
๐ :: (Meogo-44) bookmark #45
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package org.meogo.domain.bookmark | ||
package org.meogo.domain.bookmark.domain | ||
|
||
import org.meogo.domain.user.domain.User | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import java.util.UUID | ||
|
||
interface BookmarkRepository : JpaRepository<Bookmark, UUID> { | ||
fun findAllBySchoolId(schoolId: Int): List<Bookmark>? | ||
fun findAllByUser(user: User): List<Bookmark>? | ||
|
||
fun existsBySchoolIdAndUser(schoolId: Int, user: User): Boolean | ||
fun findBySchoolIdAndUser(schoolId: Int, user: User): Bookmark? | ||
|
||
fun deleteBySchoolIdAndUser(schoolId: Int, user: User) | ||
fun existsBySchoolIdAndUser(schoolId: Int, user: User): Boolean | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.meogo.domain.bookmark.exception | ||
|
||
import org.meogo.global.error.exception.ErrorCode | ||
import org.meogo.global.error.exception.MeogoException | ||
|
||
object BookmarkNotFoundException : MeogoException( | ||
ErrorCode.BOOKMARK_NOT_FOUND | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.meogo.domain.bookmark.presentation | ||
|
||
import org.meogo.domain.bookmark.service.BookmarkService | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.web.bind.annotation.DeleteMapping | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.ResponseStatus | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/bookmark") | ||
class BookmarkController( | ||
private val bookmarkService: BookmarkService | ||
) { | ||
|
||
@ResponseStatus(HttpStatus.OK) | ||
@PostMapping | ||
fun create(@RequestParam(name = "school_id")schoolId: Int) = | ||
bookmarkService.execute(schoolId) | ||
|
||
@GetMapping("/query/my") | ||
fun myBookmarks() = | ||
bookmarkService.queryBookmarkedSchool() | ||
|
||
@GetMapping("/query") | ||
fun isBookmarked(@RequestParam(name = "school_id")schoolId: Int) = | ||
bookmarkService.queryIsBookmarked(schoolId) | ||
|
||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
@DeleteMapping | ||
fun delete(@RequestParam(name = "school_id")schoolId: Int) = | ||
bookmarkService.deleteBookmark(schoolId) | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,19 +1,22 @@ | ||||||
package org.meogo.domain.bookmark | ||||||
package org.meogo.domain.bookmark.service | ||||||
|
||||||
import org.meogo.domain.bookmark.domain.Bookmark | ||||||
import org.meogo.domain.bookmark.domain.BookmarkRepository | ||||||
import org.meogo.domain.bookmark.exception.BookmarkNotFoundException | ||||||
import org.meogo.domain.post.domain.PostRepository | ||||||
import org.meogo.domain.user.exception.UserNotFoundException | ||||||
import org.meogo.domain.user.facade.UserFacade | ||||||
import org.springframework.stereotype.Service | ||||||
import org.springframework.transaction.annotation.Transactional | ||||||
|
||||||
@Transactional | ||||||
@Service | ||||||
class BookmarkService( | ||||||
private val bookmarkRepository: BookmarkRepository, | ||||||
private val userFacade: UserFacade, | ||||||
private val postRepository: PostRepository | ||||||
) { | ||||||
|
||||||
@Transactional | ||||||
fun execute(schoolId: Int) { | ||||||
val user = userFacade.currentUser() ?: throw UserNotFoundException | ||||||
|
||||||
|
@@ -25,9 +28,11 @@ class BookmarkService( | |||||
) | ||||||
} | ||||||
|
||||||
fun queryBookmarkedPost(schoolId: Int): Int { | ||||||
val posts = bookmarkRepository.findAllBySchoolId(schoolId) | ||||||
return posts?.size ?: 0 | ||||||
fun queryBookmarkedSchool(): List<Int> { | ||||||
val user = userFacade.currentUser() ?: throw UserNotFoundException | ||||||
|
||||||
val posts = bookmarkRepository.findAllByUser(user) | ||||||
return posts?.map { it.schoolId } ?: emptyList() | ||||||
} | ||||||
|
||||||
fun queryIsBookmarked(schoolId: Int): Boolean { | ||||||
|
@@ -37,6 +42,7 @@ class BookmarkService( | |||||
|
||||||
fun deleteBookmark(schoolId: Int) { | ||||||
val user = userFacade.currentUser() ?: throw UserNotFoundException | ||||||
bookmarkRepository.deleteBySchoolIdAndUser(schoolId, user) | ||||||
val bookmark = bookmarkRepository.findBySchoolIdAndUser(schoolId, user) ?: throw BookmarkNotFoundException | ||||||
bookmarkRepository.delete(bookmark) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์์ธ ์ธ์คํด์คํ ์ ๊ดํธ ์ถ๊ฐ ํ์
์ ์ฉ ๊ฐ๋ฅํ ์์ ์ฌํญ: -val bookmark = bookmarkRepository.findBySchoolIdAndUser(schoolId, user) ?: throw BookmarkNotFoundException
+val bookmark = bookmarkRepository.findBySchoolIdAndUser(schoolId, user) ?: throw BookmarkNotFoundException() ๐ Committable suggestion
Suggested change
|
||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์์ธ ์ธ์คํด์คํ ์ ๊ดํธ ์ถ๊ฐ ํ์
throw UserNotFoundException
๋์throw UserNotFoundException()
์ฒ๋ผ ์์ธ๋ฅผ ์ธ์คํด์คํํ ๋ ๊ดํธ๋ฅผ ์ถ๊ฐํด์ผ ํฉ๋๋ค.์ ์ฉ ๊ฐ๋ฅํ ์์ ์ฌํญ:
๐ Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UserNotFoundException๊ฐ object๋ก ๋์ด์์ด์ ๊ด์ฐฎใด์ ๊ฒ ๊ฐ์
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@meltapplee, ์๊ฒ ์ต๋๋ค.
UserNotFoundException
์ด ๊ฐ์ฒด๋ก ์ ์๋์ด ์์ด์ ๊ดํธ ์์ด๋ ์ฌ์ฉ ๊ฐ๋ฅํ๊ตฐ์. ์๋ ค์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.๐ฐโ
โ๏ธ Learnings added