46 lines
1.5 KiB
Kotlin
46 lines
1.5 KiB
Kotlin
package space.luminic.finance.api
|
|
|
|
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType
|
|
import io.swagger.v3.oas.annotations.security.SecurityScheme
|
|
import org.springframework.web.bind.annotation.*
|
|
import space.luminic.finance.dtos.CurrencyDTO
|
|
import space.luminic.finance.mappers.CurrencyMapper.toDto
|
|
import space.luminic.finance.services.CurrencyService
|
|
|
|
@RestController
|
|
@RequestMapping("/references")
|
|
@SecurityScheme(
|
|
name = "bearerAuth",
|
|
type = SecuritySchemeType.HTTP,
|
|
bearerFormat = "JWT",
|
|
scheme = "bearer"
|
|
)
|
|
class ReferenceController(
|
|
private val currencyService: CurrencyService
|
|
) {
|
|
|
|
@GetMapping("/currencies")
|
|
fun getCurrencies(): List<CurrencyDTO> {
|
|
return currencyService.getCurrencies().map { it.toDto() }
|
|
}
|
|
|
|
@GetMapping("/currencies/{currencyCode}")
|
|
fun getCurrency(@PathVariable currencyCode: String): CurrencyDTO {
|
|
return currencyService.getCurrency(currencyCode).toDto()
|
|
}
|
|
|
|
@PostMapping("/currencies")
|
|
fun createCurrency(@RequestBody currencyDTO: CurrencyDTO): CurrencyDTO {
|
|
return currencyService.createCurrency(currencyDTO).toDto()
|
|
}
|
|
|
|
@PutMapping("/currencies/{currencyCode}")
|
|
fun updateCurrency(@PathVariable currencyCode: String, @RequestBody currencyDTO: CurrencyDTO): CurrencyDTO {
|
|
return currencyService.updateCurrency(currencyDTO).toDto()
|
|
}
|
|
|
|
@DeleteMapping("/currencies/{currencyCode}")
|
|
fun deleteCurrency(@PathVariable currencyCode: String) {
|
|
currencyService.deleteCurrency(currencyCode)
|
|
}
|
|
} |