-
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-42) post good #43
Conversation
Walkthroughμ΄λ² λ³κ²½ μ¬νμ Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 13
π§Ή Outside diff range and nitpick comments (4)
src/main/kotlin/org/meogo/domain/bookmark/BookmarkRepository.kt (2)
7-7
: μΈν°νμ΄μ€ μ μΈμ΄ μ μ ν©λλ€. μμ κ°μ μ μμ΄ μμ΅λλ€.
BookmarkRepository
μΈν°νμ΄μ€κ°JpaRepository<Bookmark, UUID>
λ₯Ό μ¬λ°λ₯΄κ² νμ₯νκ³ μμ΄Bookmark
μν°ν°μ λν κΈ°λ³Έμ μΈ CRUD μμ μ΄ κ°λ₯ν©λλ€.κ°λ μ±μ λμ΄κΈ° μν΄
Bookmark
μUUID
μ λν import λ¬Έμ μΆκ°νλ κ²μ΄ μ’μ΅λλ€. λ€μκ³Ό κ°μ΄ λ³κ²½ν΄ 보μΈμ:import org.meogo.domain.bookmark.Bookmark import java.util.UUID interface BookmarkRepository : JpaRepository<Bookmark, UUID> { // ... }
8-12
: μ¬μ©μ μ μ λ©μλλ€μ΄ μ ꡬνλμ΄ μμ΅λλ€. μμ κ°μ μ μμ΄ μμ΅λλ€.μΈ κ°μ§ μ¬μ©μ μ μ λ©μλ(
findAllBySchoolId
,existsBySchoolIdAndUser
,deleteBySchoolIdAndUser
)κ° Spring Data JPA λͺ λͺ κ·μΉμ λ°λ₯΄κ³ μμΌλ©°, λΆλ§ν¬ κ΄λ¦¬μ νμν μμ λ€μ μ μ ν λ€λ£¨κ³ μμ΅λλ€.
findAllBySchoolId
λ©μλμ λ°ν νμ μ κ°μ ν μ μμ΅λλ€. λ€μκ³Ό κ°μ΄ λ³κ²½νλ κ²μ΄ μ’μ΅λλ€:fun findAllBySchoolId(schoolId: Int): List<Bookmark>μ΄λ κ² νλ©΄ λΉ λ¦¬μ€νΈλ₯Ό λ°νν μ μμ΄ null 체ν¬λ₯Ό μ€μΌ μ μμ΅λλ€. JPAλ κ²°κ³Όκ° μμ λ λΉ μ»¬λ μ μ λ°ννλ―λ‘, μ΄ λ°©μμ΄ λ Kotlinμ€λ¬μ΄ μ κ·Όλ²μ λλ€.
src/main/kotlin/org/meogo/domain/good/domain/Good.kt (1)
13-24
: ν΄λμ€ μ΄λ¦μ μ¬κ³ ν΄ λ³΄μΈμ.
Bookmark
μμGood
μΌλ‘μ ν΄λμ€ μ΄λ¦ λ³κ²½μ΄ μλλ₯Ό λͺ νν μ λ¬νμ§ μμ μ μμ΅λλ€. ν΄λμ€μ λͺ©μ μ λ μ μ€λͺ νλ μ΄λ¦μ κ³ λ €ν΄ λ³΄μΈμ. μλ₯Ό λ€μ΄,Like
λλFavorite
κ³Ό κ°μ μ΄λ¦μ΄ λ μ μ ν μ μμ΅λλ€.κ·Έ μΈμ ν΄λμ€ κ΅¬μ‘°μ κ΄κ³ μ€μ μ μ μ ν©λλ€:
Post
μUser
μν°ν°μμ κ΄κ³κ° μ μ μλμ΄ μμ΅λλ€.- μ§μ° λ‘λ©(LAZY)μ μ¬μ©νμ¬ μ±λ₯μ μ΅μ ννκ³ μμ΅λλ€.
BaseUUIDEntity
λ₯Ό μμλ°μ κ³΅ν΅ κΈ°λ₯μ μ¬μ¬μ©νκ³ μμ΅λλ€.src/main/kotlin/org/meogo/domain/good/presentation/GoodController.kt (1)
1-28
: λ¬Έμν κ°μ μ μμ½λμ κ°λ μ±κ³Ό μ μ§λ³΄μμ±μ λμ΄κΈ° μν΄ KDoc μ£Όμμ μΆκ°νλ κ²μ΄ μ’μ΅λλ€. 컨νΈλ‘€λ¬μ κ° λ©μλμ λͺ©μ μ μ€λͺ νλ μ£Όμμ μΆκ°ν΄μ£ΌμΈμ.
λ€μκ³Ό κ°μ΄ KDoc μ£Όμμ μΆκ°ν΄λ³΄μΈμ:
/** * κ²μλ¬Όμ λν 'μ’μμ' κΈ°λ₯μ κ΄λ¦¬νλ 컨νΈλ‘€λ¬μ λλ€. * * @property goodService μ’μμ κ΄λ ¨ λΉμ¦λμ€ λ‘μ§μ μ²λ¦¬νλ μλΉμ€ */ @RestController @RequestMapping("/good") class GoodController( private val goodService: GoodService ) { /** * νΉμ κ²μλ¬Όμ μ’μμλ₯Ό μΆκ°ν©λλ€. * * @param postId μ’μμλ₯Ό μΆκ°ν κ²μλ¬Όμ ID * @return μ’μμ μΆκ° κ²°κ³Ό */ @PostMapping fun addGoodToPost(@RequestParam(name = "post_id") postId: Long): ResponseEntity<Any> { // ... (μ΄μ μ μ μν ꡬν) } /** * νΉμ κ²μλ¬Όμμ μ’μμλ₯Ό μ κ±°ν©λλ€. * * @param postId μ’μμλ₯Ό μ κ±°ν κ²μλ¬Όμ ID * @return μ’μμ μ κ±° κ²°κ³Ό */ @DeleteMapping fun removeGoodFromPost(@RequestParam(name = "post_id") postId: Long): ResponseEntity<Any> { // ... (μ΄μ μ μ μν ꡬν) } }
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
π Files selected for processing (8)
- src/main/kotlin/org/meogo/domain/bookmark/Bookmark.kt (1 hunks)
- src/main/kotlin/org/meogo/domain/bookmark/BookmarkRepository.kt (1 hunks)
- src/main/kotlin/org/meogo/domain/bookmark/BookmarkService.kt (1 hunks)
- src/main/kotlin/org/meogo/domain/good/domain/Good.kt (1 hunks)
- src/main/kotlin/org/meogo/domain/good/domain/GoodRepository.kt (1 hunks)
- src/main/kotlin/org/meogo/domain/good/presentation/GoodController.kt (1 hunks)
- src/main/kotlin/org/meogo/domain/good/service/GoodService.kt (1 hunks)
- src/main/kotlin/org/meogo/domain/post/domain/Post.kt (1 hunks)
π Additional comments (10)
src/main/kotlin/org/meogo/domain/good/domain/GoodRepository.kt (1)
1-10
: μ λ°μ μΈ κ΅¬μ‘°κ° μ ꡬμ±λμ΄ μμ΅λλ€.ν¨ν€μ§ μ μΈ, μν¬νΈ, κ·Έλ¦¬κ³ μΈν°νμ΄μ€ μ μκ° μ μ νκ² μ΄λ£¨μ΄μ Έ μμ΅λλ€.
JpaRepository
λ₯Ό μμλ°μGood
μν°ν°μ λν κΈ°λ³Έμ μΈ CRUD μμ μ μνν μ μλλ‘ μ μ€κ³λμμ΅λλ€.src/main/kotlin/org/meogo/domain/bookmark/BookmarkRepository.kt (1)
1-6
: ν¨ν€μ§ μ μΈκ³Ό μν¬νΈκ° μ μ ν©λλ€.ν¨ν€μ§ μ μΈκ³Ό μν¬νΈκ°
BookmarkRepository
μΈν°νμ΄μ€μ κΈ°λ₯μ λ§κ² μ ꡬμ±λμ΄ μμ΅λλ€.src/main/kotlin/org/meogo/domain/bookmark/Bookmark.kt (2)
1-10
: ν¨ν€μ§ μ μΈκ³Ό μν¬νΈκ° μ μ ν©λλ€.ν¨ν€μ§ μ μΈκ³Ό μν¬νΈλ ν΄λμ€λ€μ΄
Bookmark
μν°ν°μ ꡬνμ νμν μμλ€μ μ ν¬ν¨νκ³ μμ΅λλ€. λΆνμν μν¬νΈλ μμ΄ κΉλν΄ λ³΄μ λλ€.
17-20
: User μν°ν°μμ κ΄κ³ μ€μ μ΄ μ μ ν©λλ€.
User
μν°ν°μμ λ€λμΌ κ΄κ³κ° μ μ€μ λμ΄ μμ΅λλ€.FetchType.LAZY
λ₯Ό μ¬μ©νμ¬ μ±λ₯ μ΅μ νλ₯Ό κ³ λ €ν μ κ³Όuser_id
λ₯Όnullable = false
λ‘ μ€μ νμ¬ λ°μ΄ν° 무결μ±μ 보μ₯ν μ μ΄ μ’μ΅λλ€.src/main/kotlin/org/meogo/domain/good/domain/Good.kt (2)
3-10
: import λ¬Έμ΄ μ μ ν©λλ€.νμν λͺ¨λ ν΄λμ€κ° μ¬λ°λ₯΄κ² importλμμΌλ©°, λΆνμν importλ μμ΅λλ€.
1-1
: ν¨ν€μ§ λ³κ²½μ΄ μ μ ν©λλ€.ν¨ν€μ§ κ΅¬μ‘°κ° κ°μ λμμ΅λλ€. μ΄λ μ½λ ꡬ쑰λ₯Ό λ λͺ ννκ² λ§λλλ€.
λ€λ₯Έ νμΌμμ μ΄ ν΄λμ€λ₯Ό importνλ λΆλΆμ νμΈνκΈ° μν΄ λ€μ μ€ν¬λ¦½νΈλ₯Ό μ€ννμΈμ:
β Verification successful
Good ν΄λμ€μ ν¨ν€μ§ λ³κ²½μ΄ μ¬λ°λ₯΄κ² μλ£λμμ΅λλ€.
λͺ¨λ import λ¬Έμ΄ μλ‘μ΄ ν¨ν€μ§ κ²½λ‘λ₯Ό μ¬μ©νκ³ μμ΅λλ€.
π Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # μ€λͺ : Good ν΄λμ€μ import λ¬Έμ κ²μν©λλ€. # ν μ€νΈ: Good ν΄λμ€μ import λ¬Έμ κ²μν©λλ€. μμ κ²°κ³Ό: μλ‘μ΄ ν¨ν€μ§ κ²½λ‘λ₯Ό μ¬μ©νλ import λ¬Έλ§ λνλμΌ ν©λλ€. rg --type kotlin "import.*org\.meogo\.domain\.good\..*Good"Length of output: 393
src/main/kotlin/org/meogo/domain/good/presentation/GoodController.kt (1)
14-18
: ν΄λμ€ μ μΈμ΄ μ μ ν©λλ€
GoodController
ν΄λμ€μ μ μΈμ΄ Spring νλ μμν¬μ λͺ¨λ² μ¬λ‘λ₯Ό μ λ°λ₯΄κ³ μμ΅λλ€.@RestController
μ@RequestMapping("/good")
μ΄λ Έν μ΄μ μ΄ μ¬λ°λ₯΄κ² μ¬μ©λμμΌλ©°, μμ±μλ₯Ό ν΅ν μμ‘΄μ± μ£Όμ λ μ ꡬνλμ΄ μμ΅λλ€.src/main/kotlin/org/meogo/domain/good/service/GoodService.kt (2)
1-10
: ν¨ν€μ§ μ μΈ λ° μν¬νΈκ° μ μ ν©λλ€.ν¨ν€μ§ μ μΈκ³Ό νμν λͺ¨λ ν΄λμ€λ€μ μν¬νΈκ° μ¬λ°λ₯΄κ² λμ΄ μμ΅λλ€. μ½λ κ΅¬μ‘°κ° μ μ 리λμ΄ μμ΅λλ€.
11-16
: ν΄λμ€ μ μΈκ³Ό μμ‘΄μ± μ£Όμ μ΄ μ μ ν©λλ€.
@Service
μ΄λ Έν μ΄μ κ³Ό μμ±μλ₯Ό ν΅ν μμ‘΄μ± μ£Όμ μ΄ μ¬λ°λ₯΄κ² ꡬνλμ΄ μμ΅λλ€. μ’μ ꡬ쑰μ λλ€.λ€μ μ€ν¬λ¦½νΈλ₯Ό μ€ννμ¬ μμ‘΄μ±λ€μ΄ νλ‘μ νΈμ μ¬λ°λ₯΄κ² μ μλμ΄ μλμ§ νμΈνμΈμ:
β Verification successful
μμ‘΄μ± νμΈ μλ£
GoodRepository, UserFacade, PostRepositoryκ° νλ‘μ νΈ λ΄μ μ¬λ°λ₯΄κ² μ μλμ΄ μμ΅λλ€.
π Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # μμ‘΄μ± ν΄λμ€λ€μ΄ νλ‘μ νΈμ μ‘΄μ¬νλμ§ νμΈ echo "Checking GoodRepository..." rg --type kotlin "interface GoodRepository" echo "Checking UserFacade..." rg --type kotlin "class UserFacade" echo "Checking PostRepository..." rg --type kotlin "interface PostRepository"Length of output: 620
src/main/kotlin/org/meogo/domain/post/domain/Post.kt (1)
Line range hint
52-58
: null κ° μ²λ¦¬μ λν κ³ λ € νμ
update
λ©μλμμschoolId
,keyWord
,image
μ λν΄ null κ°μ νμ©νλλ‘ λ³κ²½λμμ΅λλ€. μ΄λ μ μ°μ±μ μ 곡νμ§λ§, μ μ¬μ μΈ λ¬Έμ λ₯Ό μΌκΈ°ν μ μμ΅λλ€.λ€μ μ¬νμ κ³ λ €ν΄λ³΄μΈμ:
- null κ°μ΄ μλμ μΌλ‘ νμ©λλμ§ νμΈ
- νμν κ²½μ° null κ°μ λν μ ν¨μ± κ²μ¬ μΆκ°
- μ΄λ¬ν λ³κ²½μ΄ μ ν리μΌμ΄μ μ λ€λ₯Έ λΆλΆμ λ―ΈμΉλ μν₯ κ²ν
λ€μ μ€ν¬λ¦½νΈλ₯Ό μ€ννμ¬
Post
ν΄λμ€μ μ¬μ©μ νμΈνμΈμ:
import java.util.UUID | ||
|
||
interface GoodRepository : JpaRepository<Good, UUID> { | ||
fun findByUserAndPost(user: User, post: Post): Good |
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.
findByUserAndPost
λ©μλμ λ°ν νμ
κ³Ό μ΄λ¦μ μ¬κ³ ν΄ λ³΄μΈμ.
νμ¬ λ©μλ μ μμλ λ κ°μ§ μ μ¬μ μΈ λ¬Έμ κ° μμ΅λλ€:
- λ°ν νμ
μ΄ non-nullable
Good
μ λλ€. λ§μ½ μΌμΉνλ μν°ν°κ° μμ κ²½μ° μ΄λ μμΈλ₯Ό λ°μμν¬ μ μμ΅λλ€. - λ©μλ μ΄λ¦μ΄ λ¨μΌ μν°ν°λ₯Ό λ°νν κ²μμ μμνμ§λ§, μ€μ λ‘λ μ¬μ©μμ κ²μλ¬Ό μ‘°ν©μ λν΄ μ¬λ¬ "μ’μμ"κ° μ‘΄μ¬ν μ μμ΅λλ€.
λ€μκ³Ό κ°μ΄ μμ νλ κ²μ κ³ λ €ν΄λ³΄μΈμ:
-fun findByUserAndPost(user: User, post: Post): Good
+fun findByUserAndPost(user: User, post: Post): Good?
λλ μ¬λ¬ μν°ν°λ₯Ό λ°ννλλ‘ λ³κ²½:
-fun findByUserAndPost(user: User, post: Post): Good
+fun findAllByUserAndPost(user: User, post: Post): List<Good>
μ νν μ κ·Ό λ°©μμ λ°λΌ μλΉμ€ λ μ΄μ΄μμ μ μ ν μ²λ¦¬ν΄μΌ ν©λλ€.
Committable suggestion was skipped due to low confidence.
@Entity | ||
class Bookmark( | ||
id: UUID? = null, | ||
|
||
val schoolId: Int? = 0, |
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.
schoolId
μμ±μ λ νμ© μ¬λΆμ κΈ°λ³Έκ°μ μ¬κ³ ν΄ λ³΄μΈμ.
schoolId
κ° λμ νμ©νκ³ κΈ°λ³Έκ°μΌλ‘ 0μ μ¬μ©νλ κ²μ΄ μλλ μ€κ³μΈμ§ νμΈν΄ μ£ΌμΈμ. λ§μ½ schoolId
κ° νμ νλλΌλ©΄, λμ νμ©νμ§ μλλ‘ λ³κ²½νκ³ μλ―Έ μλ κΈ°λ³Έκ°μ μ€μ νκ±°λ κΈ°λ³Έκ° μμ΄ νμ νλΌλ―Έν°λ‘ λ§λλ κ²μ΄ μ’μ΅λλ€.
λ€μκ³Ό κ°μ΄ λ³κ²½μ κ³ λ €ν΄ λ³΄μΈμ:
- val schoolId: Int? = 0,
+ val schoolId: Int,
λλ μλ―Έ μλ κΈ°λ³Έκ°μ΄ μλ€λ©΄:
- val schoolId: Int? = 0,
+ val schoolId: Int,
κ·Έλ¦¬κ³ μμ±μμμ schoolId
λ₯Ό νμ νλΌλ―Έν°λ‘ λ°λλ‘ λ³κ²½νμΈμ.
π Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
@Entity | |
class Bookmark( | |
id: UUID? = null, | |
val schoolId: Int? = 0, | |
@Entity | |
class Bookmark( | |
id: UUID? = null, | |
val schoolId: Int, |
@@ -0,0 +1,28 @@ | |||
package org.meogo.domain.good.presentation | |||
|
|||
import lombok.RequiredArgsConstructor |
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.
Lombok μ΄λ Έν μ΄μ μ κ±° νμ
Kotlinμμλ Lombokμ΄ νμνμ§ μμ΅λλ€. @RequiredArgsConstructor
μ΄λ
Έν
μ΄μ
κ³Ό importλ₯Ό μ κ±°ν΄μ£ΌμΈμ. Kotlinμ μ΄λ―Έ μ£Ό μμ±μμμ νλ‘νΌν°λ₯Ό μ μΈν λ μλμΌλ‘ μμ±μ 맀κ°λ³μλ₯Ό λ§λ€μ΄μ€λλ€.
λ€μκ³Ό κ°μ΄ μμ ν΄μ£ΌμΈμ:
-import lombok.RequiredArgsConstructor
-
import org.meogo.domain.good.service.GoodService
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.DeleteMapping
@@ -10,7 +9,6 @@ import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
-@RequiredArgsConstructor
@RestController
@RequestMapping("/good")
class GoodController(
Also applies to: 13-13
@ResponseStatus(HttpStatus.CREATED) | ||
@PostMapping | ||
fun addGood(@RequestParam(name = "post_id")postId: Long) = | ||
goodService.addGood(postId) |
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.
π οΈ Refactor suggestion
addGood λ©μλ κ°μ μ μ
addGood
λ©μλμ ꡬνμ λμ²΄λ‘ μ¬λ°λ₯΄μ§λ§, λ€μκ³Ό κ°μ κ°μ μ¬νμ μ μν©λλ€:
@RequestParam
μ΄λ Έν μ΄μ μ 곡백μ μΌκ΄μ± μκ² μμ ν΄μ£ΌμΈμ.- λ©μλ μ΄λ¦μ λ ꡬ체μ μΌλ‘ λ³κ²½νλ κ²μ΄ μ’μ΅λλ€ (μ:
addGoodToPost
). - μ€λ₯ μ²λ¦¬ λ‘μ§μ μΆκ°νλ κ²μ΄ μ’μ΅λλ€.
λ€μκ³Ό κ°μ΄ μμ ν΄λ³΄μΈμ:
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
fun addGoodToPost(@RequestParam(name = "post_id") postId: Long): ResponseEntity<Any> {
return try {
goodService.addGood(postId)
ResponseEntity.status(HttpStatus.CREATED).build()
} catch (e: Exception) {
ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Failed to add good: ${e.message}")
}
}
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
@DeleteMapping | ||
fun deleteGood(@RequestParam(name = "post_id")postId: Long) = | ||
goodService.deleteGood(postId) |
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.
π οΈ Refactor suggestion
deleteGood λ©μλ κ°μ μ μ
deleteGood
λ©μλλ addGood
λ©μλμ μ μ¬ν κ°μ μ΄ νμν©λλ€:
@RequestParam
μ΄λ Έν μ΄μ μ 곡백μ μΌκ΄μ± μκ² μμ ν΄μ£ΌμΈμ.- λ©μλ μ΄λ¦μ λ ꡬ체μ μΌλ‘ λ³κ²½νλ κ²μ΄ μ’μ΅λλ€ (μ:
removeGoodFromPost
). - μ€λ₯ μ²λ¦¬ λ‘μ§μ μΆκ°νλ κ²μ΄ μ’μ΅λλ€.
λ€μκ³Ό κ°μ΄ μμ ν΄λ³΄μΈμ:
@DeleteMapping
fun removeGoodFromPost(@RequestParam(name = "post_id") postId: Long): ResponseEntity<Any> {
return try {
goodService.deleteGood(postId)
ResponseEntity.noContent().build()
} catch (e: Exception) {
ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Failed to remove good: ${e.message}")
}
}
μ΄λ κ² μμ νλ©΄ @ResponseStatus
μ΄λ
Έν
μ΄μ
μ΄ νμ μμ΄μ§λ―λ‘ μ κ±°ν μ μμ΅λλ€.
fun queryBookmarkedPost(schoolId: Int): Int { | ||
val posts = bookmarkRepository.findAllBySchoolId(schoolId) | ||
return posts?.size ?: 0 | ||
} |
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.
π οΈ Refactor suggestion
λ©μλ μ΄λ¦ λ³κ²½ λ° μΏΌλ¦¬ μ΅μ ν νμ
νμ¬ λ©μλ μ΄λ¦ queryBookmarkedPost
λ λΆλ§ν¬λ κ²μλ¬Όμ μ‘°ννλ κ²μ²λΌ 보μ΄μ§λ§, μ€μ λ‘λ λΆλ§ν¬ μλ₯Ό λ°νν©λλ€. λν, λͺ¨λ λΆλ§ν¬λ₯Ό μ‘°νν ν ν¬κΈ°λ₯Ό κ³μ°νλ κ²μ λΉν¨μ¨μ μΌ μ μμ΅λλ€.
λ€μκ³Ό κ°μ΄ κ°μ ν μ μμ΅λλ€:
- λ©μλ μ΄λ¦μ
countBookmarksBySchoolId
λ‘ λ³κ²½νμ¬ μλλ₯Ό λͺ νν ν©λλ€. - 쿼리λ₯Ό μ΅μ ννμ¬ μ§μ κ°μλ₯Ό λ°ννλλ‘ ν©λλ€.
fun countBookmarksBySchoolId(schoolId: Int): Int {
return bookmarkRepository.countBySchoolId(schoolId)
}
BookmarkRepository
μ countBySchoolId
λ©μλλ₯Ό μΆκ°νκ³ , μ΄λ₯Ό ν΅ν΄ λ°μ΄ν°λ² μ΄μ€ λ 벨μμ ν¨μ¨μ μΌλ‘ κ°μλ₯Ό κ³μ°ν μ μμ΅λλ€.
fun queryIsBookmarked(schoolId: Int): Boolean { | ||
val user = userFacade.currentUser() ?: throw UserNotFoundException | ||
return bookmarkRepository.existsBySchoolIdAndUser(schoolId, user) | ||
} |
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.
π οΈ Refactor suggestion
μμΈ μ²λ¦¬ μΌκ΄μ± κ°μ νμ
UserNotFoundException
μ λ©μλ λ΄λΆμμ μ§μ μ²λ¦¬νλ κ²μ μΌκ΄μ± μλ μμΈ μ²λ¦¬λ₯Ό μΌκΈ°ν μ μμ΅λλ€.
μμΈ μ²λ¦¬λ₯Ό μλΉμ€ λ 벨 μμμμ ν΅μΌμ μΌλ‘ μ²λ¦¬νλ κ²μ΄ μ’μ΅λλ€. μλ₯Ό λ€μ΄:
fun queryIsBookmarked(schoolId: Int): Boolean {
val user = userFacade.currentUser()
return bookmarkRepository.existsBySchoolIdAndUser(schoolId, user)
}
κ·Έλ¦¬κ³ UserFacade
μμ currentUser()
κ° nullμ λ°ννμ§ μκ³ νμ UserNotFoundException
μ λμ§λλ‘ μμ νμΈμ. μ΄λ κ² νλ©΄ λͺ¨λ λ©μλμμ μΌκ΄λ λ°©μμΌλ‘ μ¬μ©μ μ‘΄μ¬ μ¬λΆλ₯Ό μ²λ¦¬ν μ μμ΅λλ€.
fun deleteBookmark(schoolId: Int) { | ||
val user = userFacade.currentUser() ?: throw UserNotFoundException | ||
bookmarkRepository.deleteBySchoolIdAndUser(schoolId, user) | ||
} |
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.
νΈλμμ μ²λ¦¬ λ° μμΈ μν© κ³ λ € νμ
deleteBookmark
λ©μλμ λͺ κ°μ§ κ°μ μ΄ νμν©λλ€:
@Transactional
μ΄λ Έν μ΄μ μ΄ λλ½λμ΄ μμ΅λλ€.- μμ νλ €λ λΆλ§ν¬κ° μ‘΄μ¬νμ§ μλ κ²½μ°μ λν μ²λ¦¬κ° μμ΅λλ€.
λ€μκ³Ό κ°μ΄ μμ νλ κ²μ΄ μ’μ΅λλ€:
@Transactional
fun deleteBookmark(schoolId: Int) {
val user = userFacade.currentUser()
val deleted = bookmarkRepository.deleteBySchoolIdAndUser(schoolId, user)
if (deleted == 0) {
// λΆλ§ν¬κ° μ‘΄μ¬νμ§ μλ κ²½μ°μ λν μ²λ¦¬
// μ: throw BookmarkNotFoundException(schoolId, user.id)
}
}
μ΄λ κ² νλ©΄ νΈλμμ μ²λ¦¬κ° 보μ₯λκ³ , μ‘΄μ¬νμ§ μλ λΆλ§ν¬λ₯Ό μμ νλ €λ μλλ₯Ό μ μ ν μ²λ¦¬ν μ μμ΅λλ€.
@Service | ||
class BookmarkService( | ||
private val bookmarkRepository: BookmarkRepository, | ||
private val userFacade: UserFacade, | ||
private val postRepository: PostRepository | ||
) { |
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.
μ¬μ©λμ§ μλ μμ‘΄μ± μ κ±° νμ
PostRepository
κ° μ£Όμ
λμμ§λ§ ν΄λμ€ λ΄μμ μ¬μ©λμ§ μκ³ μμ΅λλ€. μ΄λ λΆνμν μμ‘΄μ±μ μΌκΈ°ν μ μμ΅λλ€.
λ€μκ³Ό κ°μ΄ μμ νλ κ²μ΄ μ’μ΅λλ€:
@Service
class BookmarkService(
private val bookmarkRepository: BookmarkRepository,
- private val userFacade: UserFacade,
- private val postRepository: PostRepository
+ private val userFacade: UserFacade
) {
λ§μ½ PostRepository
κ° ν₯ν μ¬μ©λ μμ μ΄λΌλ©΄, μ£Όμμ μΆκ°νμ¬ κ·Έ μλλ₯Ό λͺ
νν ν΄μ£ΌμΈμ.
π Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
@Service | |
class BookmarkService( | |
private val bookmarkRepository: BookmarkRepository, | |
private val userFacade: UserFacade, | |
private val postRepository: PostRepository | |
) { | |
@Service | |
class BookmarkService( | |
private val bookmarkRepository: BookmarkRepository, | |
private val userFacade: UserFacade | |
) { |
fun deleteGood() { | ||
this.good -= 1 | ||
} |
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.
μμ κ° μ²΄ν¬ μΆκ° νμ
deleteGood()
λ©μλμμ good
μμ±μ΄ 0 μ΄νλ‘ λ΄λ €κ°μ§ μλλ‘ μ²΄ν¬νλ κ²μ΄ μ’μ΅λλ€. μ΄λ μλͺ»λ μνλ₯Ό λ°©μ§νλ λ° λμμ΄ λ©λλ€.
λ€μκ³Ό κ°μ΄ μμ νλ κ²μ κ³ λ €ν΄λ³΄μΈμ:
fun deleteGood() {
- this.good -= 1
+ if (this.good > 0) {
+ this.good -= 1
+ }
}
π Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
fun deleteGood() { | |
this.good -= 1 | |
} | |
fun deleteGood() { | |
if (this.good > 0) { | |
this.good -= 1 | |
} | |
} |
close #42
Summary by CodeRabbit