Skip to content

Commit

Permalink
Added committee GET /all , service/repository/controller
Browse files Browse the repository at this point in the history
  • Loading branch information
akselsf committed Sep 16, 2024
1 parent cc56a28 commit b9ee16c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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.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.*

@RestController
@RequestMapping("/api/committee")
class CommitteeController(
) {

@Autowired
lateinit var committeeService: CommitteeService

@GetMapping("/all")
fun getAllCommittees(): ResponseEntity<List<Committee>> {
return try {
val committees = committeeService.getAllCommittees()
ResponseEntity.ok(committees)
} catch (e: Exception) {
ResponseEntity.badRequest().build()
}

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

import jakarta.persistence.*

@Entity
@Table(name = "committee")
class Committee (
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Int,
val name: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.autobank.repository;

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

@Repository
interface CommitteeRepository : JpaRepository<Committee, Int> {


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

import com.example.autobank.data.Committee
import com.example.autobank.repository.CommitteeRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class CommitteeService() {

@Autowired
lateinit var committeeRepository: CommitteeRepository

fun getAllCommittees(): List<Committee> {
return committeeRepository.findAll()
}
}

0 comments on commit b9ee16c

Please sign in to comment.