Skip to content

Commit

Permalink
add total to responsebody
Browse files Browse the repository at this point in the history
  • Loading branch information
akselsf committed Dec 24, 2024
1 parent 5a08d38 commit 47306ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.example.autobank.service.AuthenticationService
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import com.example.autobank.data.ReceiptReviewRequestBody
import com.example.autobank.data.receipt.ReceiptListResponseBody
import com.example.autobank.data.receipt.ReceiptReview
import com.example.autobank.service.ReceiptReviewService
import org.springframework.data.repository.query.Param
Expand All @@ -33,7 +34,7 @@ class AdminReceiptController {


@GetMapping("/all")
fun getAllReceipts(@Param("page") from: Int, @Param("count") count: Int, @Param("status") status: String?, @Param("committee") committee: String?, @Param("search") search: String?, @Param("sortOrder") sortOrder: String?, @Param("sortField") sortField: String?): ResponseEntity<List<ReceiptInfo>> {
fun getAllReceipts(@Param("page") from: Int, @Param("count") count: Int, @Param("status") status: String?, @Param("committee") committee: String?, @Param("search") search: String?, @Param("sortOrder") sortOrder: String?, @Param("sortField") sortField: String?): ResponseEntity<ReceiptListResponseBody> {
if (!authenticationService.checkBankomMembership()) {
return ResponseEntity.status(403).build()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.autobank.data.receipt

class ReceiptListResponseBody(
val receipts: Array<ReceiptInfo>,
val total: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,7 @@ class ReceiptAdminService {
@Autowired
lateinit var receiptService: ReceiptService

@Autowired
lateinit var paymentCardService: PaymentCardService

@Autowired
lateinit var imageService: ImageService

@Autowired
lateinit var attachmentService: AttachmentService

fun getAll(from: Int, count: Int, status: String?, committeeName: String?, search: String?, sortField: String?, sortOrder: String?): List<ReceiptInfo>? {
fun getAll(from: Int, count: Int, status: String?, committeeName: String?, search: String?, sortField: String?, sortOrder: String?): ReceiptListResponseBody? {


val sort = if (!sortField.isNullOrEmpty()) {
Expand All @@ -43,21 +34,19 @@ class ReceiptAdminService {

val pageable = PageRequest.of(from, count, sort)

return if (status != null || committeeName != null || search != null) {
receiptInfoViewRepository.findAll(
ReceiptInfoSpecification(status, committeeName, search), pageable
).toList()
} else {
receiptInfoViewRepository.findAll(pageable).toList()
}
val specification = ReceiptInfoSpecification(status, committeeName, search)

val receipts: List<ReceiptInfo> = receiptInfoViewRepository.findAll(specification, pageable).toList()

val total: Long = receiptInfoViewRepository.count(specification)

return ReceiptListResponseBody(receipts.toTypedArray(), total)


}

fun getReceipt(id: Int): CompleteReceipt? {
val receipt = receiptInfoViewRepository.findByReceiptId(id)
if (receipt == null) {
return null
}

return receiptService.getCompleteReceipt(receipt)

Expand Down

0 comments on commit 47306ef

Please sign in to comment.