Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
akselsf committed Sep 22, 2024
1 parent cf9ca17 commit 6200fab
Show file tree
Hide file tree
Showing 20 changed files with 348 additions and 15 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
Empty file modified gradlew
100644 → 100755
Empty file.
56 changes: 50 additions & 6 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ CREATE TABLE committee

);


CREATE TABLE receipt
(
id INT NOT NULL PRIMARY KEY IDENTITY (1,1),
amount DECIMAL(10, 2) NOT NULL,
committee_id INT NOT NULL references committee (id),
name VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
description VARCHAR(500) NOT NULL,
createdat DATETIME NOT NULL,
onlineuser_id INT NOT NULL references onlineuser (id),
);
Expand Down Expand Up @@ -54,15 +53,60 @@ CREATE TABLE economicrequest
(
id INT NOT NULL PRIMARY KEY IDENTITY (1,1),
subject VARCHAR(55) NOT NULL,
purpose TEXT NOT NULL,
purpose VARCHAR(500) NOT NULL,
date DATE NOT NULL,
duration VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
description VARCHAR(500) NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
personcount INT NOT NULL,
names varchar(max) NOT NULL,
names VARCHAR(500) NOT NULL,
paymentdescription varchar(255) NOT NULL,
otherinformation varchar(max) NOT NULL,
otherinformation VARCHAR(500) NOT NULL,
createdat DATETIME NOT NULL,
onlineuser_id INT NOT NULL references onlineuser (id),
);

CREATE TABLE receiptreview
(
id INT NOT NULL PRIMARY KEY IDENTITY (1,1),
receipt_id INT NOT NULL references receipt (id),
status VARCHAR(55) NOT NULL,
comment VARCHAR(500) NOT NULL,
createdat DATETIME NOT NULL,
onlineuser_id INT NOT NULL references onlineuser (id),
);

CREATE VIEW receipt_info AS
SELECT
r.id AS receipt_id,
r.amount,
MAX(r.name) AS receipt_name,
MAX(r.description) AS receipt_description,
MAX(r.createdat) AS receipt_created_at,
MAX(c.name) AS committee_name,
MAX(ou.fullname) AS user_fullname,

CASE
WHEN MAX(p.id) IS NOT NULL THEN 'Payment'
WHEN MAX(ca.id) IS NOT NULL THEN 'Card'
ELSE 'None'
END AS payment_or_card,

COUNT(a.id) AS attachment_count

FROM
receipt r
LEFT JOIN
committee c ON r.committee_id = c.id
LEFT JOIN
onlineuser ou ON r.onlineuser_id = ou.id
LEFT JOIN
payment p ON r.id = p.receipt_id
LEFT JOIN
card ca ON r.id = ca.receipt_id
LEFT JOIN
attachment a ON r.id = a.receipt_id
GROUP BY
r.id, r.amount;


Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.autobank.controller;

import com.example.autobank.data.receipt.CompleteReceipt
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import com.example.autobank.data.receipt.Receipt;
import com.example.autobank.service.ReceiptAdminService;
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PathVariable
import com.example.autobank.data.receipt.ReceiptInfo
import com.example.autobank.service.AuthenticationService
import org.springframework.web.bind.annotation.RequestParam


@RestController
@RequestMapping("/api/admin/receipt")
class AdminReceiptController {

@Autowired
lateinit var receiptAdminService: ReceiptAdminService

@Autowired
lateinit var authenticationService: AuthenticationService

@GetMapping("/all")
fun getAllReceipts( @RequestParam from: Int, @RequestParam count: Int)
: ResponseEntity<List<ReceiptInfo>> {
if (!authenticationService.checkBankomMembership()) {
return ResponseEntity.status(403).build()
}

return ResponseEntity.ok(receiptAdminService.getAll(from, count))
}
/*
@GetMapping("/get/{id}")
fun getReceipt(@PathVariable id: Int): ResponseEntity<CompleteReceipt> {
if (!authenticationService.checkBankomMembership()) {
return ResponseEntity.status(403).build()
}
return ResponseEntity.ok(receiptAdminService.getReceipt(id))
}
*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ReceiptController() {
val res = receiptService.createReceipt(receipt)
ResponseEntity.ok(res)
} catch (e: Exception) {
println(e)
ResponseEntity.badRequest().build()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.autobank.data.receipt


import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import java.math.BigDecimal
import java.time.LocalDateTime

data class CompleteReceipt(
val receiptId: Int,

val amount: BigDecimal,

val receiptName: String,

val receiptDescription: String,

val receiptCreatedAt: LocalDateTime,

val committeeName: String,

val userFullname: String,

val paymentOrCard: String,

val attachmentCount: Int,

val latestReviewStatus: String,

val latestReviewCreatedAt: LocalDateTime,

val paymentAccountNumber: String,


val cardCardNumber: String,

val attachments: List<String>


)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.autobank.data.receipt

import jakarta.persistence.Column
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import org.hibernate.annotations.CreationTimestamp
import org.jetbrains.annotations.NotNull
import java.time.LocalDateTime


class ReceiptAndReview (
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@NotNull
val id: Int,


)
46 changes: 46 additions & 0 deletions src/main/kotlin/com/example/autobank/data/receipt/ReceiptInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.example.autobank.data.receipt

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import java.math.BigDecimal
import java.time.LocalDateTime

@Entity
@Table(name = "receipt_info")
class ReceiptInfo(
@Id
@Column(name = "receipt_id")
val receiptId: Int,

@Column(name = "amount")
val amount: BigDecimal,

@Column(name = "receipt_name")
val receiptName: String,

@Column(name = "receipt_description")
val receiptDescription: String,

@Column(name = "receipt_created_at")
val receiptCreatedAt: LocalDateTime,

@Column(name = "committee_name")
val committeeName: String,

@Column(name = "user_fullname")
val userFullname: String,

@Column(name = "payment_or_card")
val paymentOrCard: String,

@Column(name = "attachment_count")
val attachmentCount: Int,

@Column(name = "latest_review_status")
val latestReviewStatus: String,

@Column(name = "latest_review_created_at")
val latestReviewCreatedAt: LocalDateTime
)
32 changes: 32 additions & 0 deletions src/main/kotlin/com/example/autobank/data/receipt/ReceiptReview.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.autobank.data.receipt

import jakarta.persistence.*
import org.hibernate.annotations.CreationTimestamp
import org.jetbrains.annotations.NotNull
import java.time.LocalDateTime

@Entity
@Table(name = "receiptreview")
class ReceiptReview (
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@NotNull
val id: Int,

@Column(name = "receipt_id")
val receiptId: Int,

@Column(name = "status")
val status: String,

@Column(name = "comment")
val comment: String,

@Column(name = "onlineuser_id")
var onlineUserId: Int?,

@CreationTimestamp
@Column(name = "createdat")
val createdat: LocalDateTime?,
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.repository
package com.example.autobank.repository.receipt

import com.example.autobank.data.receipt.Attachment
import org.springframework.data.jpa.repository.JpaRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.repository
package com.example.autobank.repository.receipt

import com.example.autobank.data.receipt.Card
import org.springframework.data.jpa.repository.JpaRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.repository
package com.example.autobank.repository.receipt

import com.example.autobank.data.receipt.Card
import com.example.autobank.data.receipt.Payment
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.autobank.repository.receipt

import com.example.autobank.data.receipt.ReceiptInfo
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface ReceiptInfoViewRepository : JpaRepository<ReceiptInfo, Int> {

fun findByReceiptId(id: Int): ReceiptInfo

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.repository
package com.example.autobank.repository.receipt

import com.example.autobank.data.receipt.Receipt
import org.springframework.data.jpa.repository.JpaRepository
Expand All @@ -9,4 +9,5 @@ interface ReceiptRepository : JpaRepository<Receipt, Int> {
fun findAllByOnlineUserId(onlineUserId: Int): List<Receipt>



}
1 change: 1 addition & 0 deletions src/main/kotlin/com/example/autobank/security/WebConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class WebConfig : WebMvcConfigurer {
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true)

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

import com.example.autobank.data.receipt.Attachment
import com.example.autobank.repository.AttachmentRepository
import com.example.autobank.repository.receipt.AttachmentRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ImageService(

val blobClient = blobContainerClient.getBlobClient(filename)
blobClient.upload(resized.inputStream(), resized.size.toLong())

println("Uploaded image to $filename")
return filename
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.autobank.service

import org.springframework.stereotype.Service
@Service
class PaymentCardService {
}
Loading

0 comments on commit 6200fab

Please sign in to comment.