Skip to content

Commit

Permalink
Merge pull request #48 from appKom/47-receipt-filters-in-requests
Browse files Browse the repository at this point in the history
47 receipt filters in requests
  • Loading branch information
akselsf authored Jan 19, 2025
2 parents 4fc78fc + dcdf6c5 commit db6040d
Show file tree
Hide file tree
Showing 41 changed files with 132 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.autobank.controller

import com.example.autobank.data.Economicrequest
import com.example.autobank.data.models.Economicrequest
import com.example.autobank.data.user.OnlineUser
import com.example.autobank.service.AdminService
import com.example.autobank.service.EconomicRequestReviewService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
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.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestParam
import com.example.autobank.data.ReceiptReviewRequestBody
import com.example.autobank.data.receipt.ReceiptReview
import com.example.autobank.data.receipt.ReceiptListResponseBody
import com.example.autobank.data.models.ReceiptReview
import com.example.autobank.service.ReceiptReviewService
import org.springframework.data.repository.query.Param

Expand All @@ -36,13 +33,12 @@ class AdminReceiptController {


@GetMapping("/all")
fun getAllReceipts(@Param("page") from: Int, @Param("count") count: Int)
: 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()
}

return ResponseEntity.ok(receiptAdminService.getAll(from, count))
return ResponseEntity.ok(receiptAdminService.getAll(from, count, status, committee, search, sortField, sortOrder))
}

@GetMapping("/get/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class AuthenticationController {
return try {
ResponseEntity.ok(onlineUserService.checkUser())
} catch (e: Exception) {
print(e)
ResponseEntity.badRequest().build();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package com.example.autobank.controller

import com.example.autobank.data.Committee
import com.example.autobank.data.Economicrequest
import com.example.autobank.data.user.OnlineUser
import com.example.autobank.data.models.Committee
import com.example.autobank.data.user.UserCommitteeResponseBody
import com.example.autobank.repository.CommitteeRepository
import com.example.autobank.service.AdminService
import com.example.autobank.service.CommitteeService
import com.example.autobank.service.EconomicRequestReviewService
import com.example.autobank.service.EconomicrequestService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.autobank.controller

import com.example.autobank.data.Economicrequest
import com.example.autobank.data.models.Economicrequest
import com.example.autobank.service.AuthenticationService
import com.example.autobank.service.EconomicrequestService
import org.springframework.beans.factory.annotation.Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.autobank.controller

import com.example.autobank.data.models.ReceiptInfo
import com.example.autobank.data.receipt.*
import com.example.autobank.service.ImageService
import com.example.autobank.service.ReceiptService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.autobank.data.authentication;

import java.time.Instant

class AuthenticatedUserResponse(
val success: Boolean,
val isadmin: Boolean,
val issuperadmin: Boolean
val issuperadmin: Boolean,
val expiresat: Instant?
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.data.receipt
package com.example.autobank.data.models

import jakarta.persistence.*
import org.jetbrains.annotations.NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.data.receipt
package com.example.autobank.data.models

import jakarta.persistence.*
import org.jetbrains.annotations.NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.data
package com.example.autobank.data.models

import jakarta.persistence.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.data
package com.example.autobank.data.models

import jakarta.persistence.*
import java.time.LocalDateTime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.data
package com.example.autobank.data.models

import jakarta.persistence.*
import org.hibernate.annotations.CreationTimestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.data.receipt
package com.example.autobank.data.models

import jakarta.persistence.*
import org.jetbrains.annotations.NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.data.receipt
package com.example.autobank.data.models


import jakarta.persistence.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.data.receipt
package com.example.autobank.data.models

import jakarta.persistence.Column
import jakarta.persistence.Entity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.autobank.data.receipt
package com.example.autobank.data.models

import jakarta.persistence.*
import org.hibernate.annotations.CreationTimestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
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

Expand Down

This file was deleted.

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

import com.example.autobank.data.models.ReceiptInfo

class ReceiptListResponseBody(
val receipts: Array<ReceiptInfo>,
val total: Long,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.autobank.data.receipt

import com.example.autobank.data.receipt.Receipt
import jakarta.persistence.Entity
import com.example.autobank.data.models.Receipt


class ReceiptRequestBody {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.autobank.data.receipt

import com.example.autobank.data.receipt.Receipt
import jakarta.persistence.Entity
import com.example.autobank.data.models.Receipt


class ReceiptResponseBody {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.autobank.repository;

import com.example.autobank.data.Committee
import com.example.autobank.data.Economicrequest
import com.example.autobank.data.models.Committee
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

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

import com.example.autobank.data.EconomicRequestReview
import com.example.autobank.data.models.EconomicRequestReview
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.autobank.repository;

import com.example.autobank.data.Economicrequest
import com.example.autobank.data.models.Economicrequest
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.autobank.repository.receipt

import com.example.autobank.data.receipt.Card
import com.example.autobank.data.receipt.Payment
import com.example.autobank.data.models.Payment
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.example.autobank.repository.receipt

import com.example.autobank.data.receipt.ReceiptInfo
import com.example.autobank.data.models.ReceiptInfo
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.JpaSpecificationExecutor
import org.springframework.stereotype.Repository

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

fun findByReceiptId(id: Int): ReceiptInfo

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

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

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

import com.example.autobank.data.receipt.ReceiptReview
import com.example.autobank.data.models.ReceiptReview
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
import org.springframework.data.jpa.repository.Modifying
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.autobank.repository.receipt.specification

import com.example.autobank.data.models.ReceiptInfo
import org.springframework.data.jpa.domain.Specification
import jakarta.persistence.criteria.Predicate

class ReceiptInfoSpecification(
private val status: String?,
private val committeeName: String?,
private val search: String?
) : Specification<ReceiptInfo> {
override fun toPredicate(
root: jakarta.persistence.criteria.Root<ReceiptInfo>,
query: jakarta.persistence.criteria.CriteriaQuery<*>,
criteriaBuilder: jakarta.persistence.criteria.CriteriaBuilder
): Predicate? {
val predicates = mutableListOf<Predicate>()


if (status == "NONE") {
predicates.add(criteriaBuilder.isNull(root.get<String>("latestReviewStatus")))
} else if (status == "DONE") {
predicates.add(criteriaBuilder.isNotNull(root.get<String>("latestReviewStatus")))
}else if (status != null) {
predicates.add(criteriaBuilder.equal(root.get<String>("latestReviewStatus"), status))
}

if (committeeName != null) {
val committeeNames = committeeName.split(",").map { it.trim() }
predicates.add(root.get<String>("committeeName").`in`(committeeNames))
}

if (search != null) {
predicates.add(criteriaBuilder.like(root.get<String>("receiptName"), "%$search%"))
}


return criteriaBuilder.and(*predicates.toTypedArray())
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.autobank.service

import com.example.autobank.data.receipt.Attachment
import com.example.autobank.data.models.Attachment
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 @@ -12,6 +12,7 @@ import org.springframework.security.oauth2.server.resource.authentication.JwtAut
import org.springframework.stereotype.Service
import org.springframework.web.client.RestTemplate
import org.springframework.web.client.exchange
import java.time.Instant


@Service
Expand Down Expand Up @@ -134,6 +135,16 @@ class AuthenticationService {
return superadminEmails.split(",").contains(getUserDetails().email)
}

fun getExpiresAt(): Instant? {
val authentication = SecurityContextHolder.getContext().authentication
return if (authentication is JwtAuthenticationToken) {
val token = authentication.token
token.getClaim("exp")
} else {
null
}
}

data class Result(
val name_long: String = ""
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.autobank.service;

import com.example.autobank.data.Committee
import com.example.autobank.data.models.Committee
import com.example.autobank.data.user.UserCommitteeResponseBody
import com.example.autobank.repository.CommitteeRepository
import org.springframework.beans.factory.annotation.Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.autobank.service

import com.example.autobank.data.EconomicRequestReview
import com.example.autobank.data.Economicrequest
import com.example.autobank.data.models.EconomicRequestReview
import com.example.autobank.data.models.Economicrequest
import com.example.autobank.data.user.OnlineUser
import com.example.autobank.repository.EconomicRequestReviewRepository
import org.springframework.beans.factory.annotation.Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.autobank.service

import com.example.autobank.data.Economicrequest
import com.example.autobank.data.models.Economicrequest
import com.example.autobank.repository.EconomicrequestRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
Expand Down
Loading

0 comments on commit db6040d

Please sign in to comment.