-
Notifications
You must be signed in to change notification settings - Fork 0
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
6 changed files
with
89 additions
and
1 deletion.
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
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/example/autobank/data/ReceiptReviewRequestBody.kt
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,10 @@ | ||
package com.example.autobank.data | ||
|
||
import jakarta.persistence.Entity | ||
|
||
|
||
data class ReceiptReviewRequestBody ( | ||
val receiptId: Int, | ||
val status: String, | ||
val comment: String, | ||
) |
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
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/example/autobank/repository/receipt/ReceiptReviewRepository.kt
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,19 @@ | ||
package com.example.autobank.repository.receipt | ||
|
||
|
||
import com.example.autobank.data.receipt.ReceiptInfo | ||
import com.example.autobank.data.receipt.ReceiptReview | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.stereotype.Repository | ||
import org.springframework.data.jpa.repository.Modifying | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Repository | ||
interface ReceiptReviewRepository : JpaRepository<ReceiptReview, Int> { | ||
fun findFirstByReceiptId(receiptId: Int): ReceiptReview? | ||
|
||
@Modifying | ||
@Transactional | ||
fun deleteByReceiptId(receiptId: Int) | ||
|
||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/com/example/autobank/service/ReceiptReviewService.kt
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,31 @@ | ||
package com.example.autobank.service | ||
|
||
import com.example.autobank.data.ReceiptReviewRequestBody | ||
import com.example.autobank.data.receipt.ReceiptRequestBody | ||
import com.example.autobank.data.receipt.ReceiptReview | ||
import com.example.autobank.repository.receipt.ReceiptReviewRepository | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ReceiptReviewService { | ||
|
||
@Autowired | ||
lateinit var receiptReviewRepository: ReceiptReviewRepository | ||
|
||
@Autowired | ||
lateinit var onlineUserService: OnlineUserService | ||
|
||
fun createReceiptReview(receiptReview: ReceiptReviewRequestBody): ReceiptReview { | ||
val onlineuserid = onlineUserService.getOnlineUser()?.id ?: throw Exception("User not found") | ||
if (receiptReview.status != "APPROVED" && receiptReview.status != "DENIED") { | ||
throw Exception("Invalid status") | ||
} | ||
if (receiptReviewRepository.findFirstByReceiptId(receiptReview.receiptId) != null) { | ||
println("Updating review") | ||
receiptReviewRepository.deleteByReceiptId(receiptReview.receiptId) | ||
} | ||
return receiptReviewRepository.save(ReceiptReview(0, receiptReview.receiptId, receiptReview.status, receiptReview.comment, onlineuserid, null)) | ||
|
||
} | ||
} |