Skip to content

Commit

Permalink
admin/receipt/get/id endpoint with attachments and all other receiptinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
akselsf committed Sep 22, 2024
1 parent 6200fab commit b4f2655
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AdminReceiptController {

return ResponseEntity.ok(receiptAdminService.getAll(from, count))
}
/*

@GetMapping("/get/{id}")
fun getReceipt(@PathVariable id: Int): ResponseEntity<CompleteReceipt> {
if (!authenticationService.checkBankomMembership()) {
Expand All @@ -43,6 +43,6 @@ class AdminReceiptController {

return ResponseEntity.ok(receiptAdminService.getReceipt(id))
}
*/


}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ data class CompleteReceipt(

val attachmentCount: Int,

val latestReviewStatus: String,
val latestReviewStatus: String?,

val latestReviewCreatedAt: LocalDateTime,
val latestReviewCreatedAt: LocalDateTime?,

val paymentAccountNumber: String,

Expand All @@ -39,4 +39,5 @@ data class CompleteReceipt(
val attachments: List<String>



)
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ class AttachmentService {
return attachmentRepository.findByReceiptId(id);
}


}
2 changes: 2 additions & 0 deletions src/main/kotlin/com/example/autobank/service/ImageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.autobank.service
import com.azure.storage.blob.BlobContainerClient
import com.azure.storage.blob.BlobServiceClientBuilder
import net.coobird.thumbnailator.Thumbnails
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import java.io.ByteArrayInputStream
Expand Down Expand Up @@ -60,4 +61,5 @@ class ImageService(
}



}
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
package com.example.autobank.service

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import com.example.autobank.repository.receipt.CardRepository
import com.example.autobank.repository.receipt.PaymentRepository
import com.example.autobank.data.receipt.Card
import com.example.autobank.data.receipt.Payment

@Service
class PaymentCardService {
}

@Autowired
lateinit var paymentRepository: PaymentRepository

@Autowired
lateinit var cardRepository: CardRepository

fun getCardByReceiptId(receiptId: Int): Card {
val card = cardRepository.findFirstByReceiptId(receiptId)
if (card == null) {
throw Exception("Card not found")
}
return card

}

fun getPaymentByReceiptId(receiptId: Int): Payment {
val payment = paymentRepository.findFirstByReceiptId(receiptId)
if (payment == null) {
throw Exception("Payment not found")
}
return payment
}


}





51 changes: 27 additions & 24 deletions src/main/kotlin/com/example/autobank/service/ReceiptAdminService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class ReceiptAdminService {
@Autowired
lateinit var receiptInfoViewRepository: ReceiptInfoViewRepository

@Autowired
lateinit var paymentCardService: PaymentCardService

@Autowired
lateinit var imageService: ImageService

@Autowired
lateinit var attachmentService: AttachmentService

fun getAll(from: Int, count: Int): List<ReceiptInfo>? {
try {
Expand All @@ -26,34 +34,28 @@ class ReceiptAdminService {
return receiptInfoViewRepository.findAll().subList(0, 5)
}
}
/*

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

if (receipt.paymentOrCard == "PAYMENT") {
val payment = receiptRepository.findByReceiptId(id)
return CompleteReceipt(
receipt.receiptId,
receipt.amount,
receipt.receiptName,
receipt.receiptDescription,
receipt.receiptCreatedAt,
receipt.committeeName,
receipt.userFullname,
receipt.paymentOrCard,
receipt.attachmentCount,
receipt.latestReviewStatus,
receipt.latestReviewCreatedAt,
payment.paymentAccountNumber,
"",
emptyList()
)
var card: Card = Card(0, 0, "")
var payment: Payment = Payment(0, 0, "")

if (receipt.paymentOrCard == "Card") {
card = paymentCardService.getCardByReceiptId(receipt.receiptId)
} else if (receipt.paymentOrCard == "Payment") {
payment = paymentCardService.getPaymentByReceiptId(receipt.receiptId)
}
println(receipt.paymentOrCard)

// Get images
val attachments = attachmentService.getAttachmentsByReceiptId(receipt.receiptId)
val images = attachments.map { attachment -> imageService.downloadImage(attachment.name) }

CompleteReceipt(
return CompleteReceipt(
receipt.receiptId,
receipt.amount,
receipt.receiptName,
Expand All @@ -64,10 +66,11 @@ class ReceiptAdminService {
receipt.paymentOrCard,
receipt.attachmentCount,
receipt.latestReviewStatus,
receipt.latestReviewCreatedAt
receipt.latestReviewCreatedAt,
payment.account_number,
card.card_number,
images
)

}*/
}
}

0 comments on commit b4f2655

Please sign in to comment.