mirror of
https://github.com/dalbodeule/sh0rt.kr-pdns.git
synced 2025-12-18 06:11:59 +09:00
add powerdns client codes.
This commit is contained in:
@@ -8,7 +8,6 @@ import io.swagger.v3.oas.annotations.media.Schema
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.web.ErrorResponse
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import space.mori.dnsapi.db.Domain
|
||||
import space.mori.dnsapi.dto.DomainResponseDTO
|
||||
@@ -68,5 +67,5 @@ class DomainController {
|
||||
domainService!!.deleteDomain(cfid!!)
|
||||
}
|
||||
|
||||
private fun Domain.toDTO() = DomainResponseDTO(cfid = cfid!!, domainName = domainName!!)
|
||||
private fun Domain.toDTO() = DomainResponseDTO(id = cfid, name = name)
|
||||
}
|
||||
|
||||
@@ -7,20 +7,23 @@ import io.swagger.v3.oas.annotations.media.Schema
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable_.id
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import space.mori.dnsapi.service.RecordService
|
||||
import space.mori.dnsapi.db.Record
|
||||
import space.mori.dnsapi.db.Domain
|
||||
import space.mori.dnsapi.db.Record as DomainRecord
|
||||
import space.mori.dnsapi.dto.RecordRequestDTO
|
||||
import space.mori.dnsapi.dto.RecordResponseDTO
|
||||
import space.mori.dnsapi.getISOFormat
|
||||
import space.mori.dnsapi.service.RecordService
|
||||
import java.util.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/record")
|
||||
class RecordController {
|
||||
@RequestMapping("/zones")
|
||||
class RecordController(
|
||||
@Autowired
|
||||
private val recordService: RecordService? = null
|
||||
|
||||
@GetMapping
|
||||
private val recordService: RecordService,
|
||||
) {
|
||||
@GetMapping("{zone_id}/dns_records")
|
||||
@Operation(summary = "Get all records", tags=["record"])
|
||||
@ApiResponses(value = [
|
||||
ApiResponse(responseCode = "200", description = "Return All Records",
|
||||
@@ -28,11 +31,11 @@ class RecordController {
|
||||
ApiResponse(responseCode = "400", description = "Bad request",
|
||||
content = [Content(schema = Schema(implementation = Void::class))]),
|
||||
])
|
||||
fun allRecords(@PathVariable cfid: String?): List<RecordResponseDTO?> {
|
||||
return recordService!!.getAllRecords(cfid!!).map{ it?.toDTO() }
|
||||
fun allRecords(@PathVariable zone_id: String): List<RecordResponseDTO> {
|
||||
return recordService.getRecordsByDomain(zone_id)?.map{ it } ?: listOf()
|
||||
}
|
||||
|
||||
@GetMapping("/{cfid}")
|
||||
@GetMapping("{zone_id}/dns_records/{dns_record_id}")
|
||||
@Operation(summary = "Get Record by ID", tags=["record"])
|
||||
@ApiResponses(value = [
|
||||
ApiResponse(responseCode = "200", description = "Return Record",
|
||||
@@ -40,11 +43,11 @@ class RecordController {
|
||||
ApiResponse(responseCode = "400", description = "Bad request",
|
||||
content = [Content(schema = Schema(implementation = Void::class))])
|
||||
])
|
||||
fun getRecordByCfid(@PathVariable cfid: String?): Optional<RecordResponseDTO> {
|
||||
return recordService!!.getRecordById(cfid!!).map { it.toDTO() }
|
||||
fun getRecordByCfid(@PathVariable zone_id: String, @PathVariable dns_record_id: String): RecordResponseDTO {
|
||||
return recordService.getRecord(zone_id, dns_record_id)
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@PostMapping("{zone_id}/dns_records")
|
||||
@Operation(summary = "Add Record by ID", tags=["record"])
|
||||
@ApiResponses(value = [
|
||||
ApiResponse(responseCode = "200", description = "Return Record",
|
||||
@@ -52,11 +55,11 @@ class RecordController {
|
||||
ApiResponse(responseCode = "400", description = "Bad request",
|
||||
content = [Content(schema = Schema(implementation = Void::class))]),
|
||||
])
|
||||
fun createRecord(@RequestBody record: RecordRequestDTO): RecordResponseDTO {
|
||||
return recordService!!.createRecord(record).toDTO()
|
||||
fun createRecord(@PathVariable zone_id: String, @RequestBody record: RecordRequestDTO): RecordResponseDTO {
|
||||
return recordService.createRecord(zone_id, record)
|
||||
}
|
||||
|
||||
@DeleteMapping("/{cfid}")
|
||||
@DeleteMapping("{zone_id}/dns_records/{dns_record_id}")
|
||||
@Operation(summary = "Remove Record by ID", tags=["record"])
|
||||
@ApiResponses(value = [
|
||||
ApiResponse(responseCode = "200", description = "Return Record",
|
||||
@@ -64,19 +67,33 @@ class RecordController {
|
||||
ApiResponse(responseCode = "400", description = "Bad request",
|
||||
content = [Content(schema = Schema(implementation = Void::class))]),
|
||||
])
|
||||
fun deleteRecord(@PathVariable cfid: String?) {
|
||||
recordService!!.deleteRecord(cfid!!)
|
||||
fun deleteRecord(@PathVariable zone_id: String, @PathVariable dns_record_id: String) {
|
||||
recordService.deleteRecord(zone_id, dns_record_id)
|
||||
}
|
||||
|
||||
private fun Record.toDTO() = RecordResponseDTO(
|
||||
cfid = cfid!!,
|
||||
name = name!!,
|
||||
type = type!!,
|
||||
content = content!!,
|
||||
prio = prio!!,
|
||||
ttl = ttl!!,
|
||||
changeDate = changeDate!!,
|
||||
auth = auth,
|
||||
disabled = disabled
|
||||
@PatchMapping("{zone_id}/dns_records/{dns_record_id}")
|
||||
@Operation(summary = "Update Record by ID", tags=["record"])
|
||||
@ApiResponses(value = [
|
||||
ApiResponse(responseCode = "200", description = "Return Record",
|
||||
content = [Content(schema = Schema(implementation = RecordResponseDTO::class))]),
|
||||
ApiResponse(responseCode = "400", description = "Bad request",
|
||||
content = [Content(schema = Schema(implementation = Void::class))]),
|
||||
])
|
||||
fun updateRecord(@PathVariable zone_id: String, @PathVariable dns_record_id: String, @RequestBody record: RecordRequestDTO): RecordResponseDTO {
|
||||
return recordService.updateRecord(zone_id, dns_record_id, record)
|
||||
}
|
||||
|
||||
private fun DomainRecord.toDTO() = RecordResponseDTO(
|
||||
id = cfid,
|
||||
type = type,
|
||||
name = name,
|
||||
content = content,
|
||||
zoneId = domain.cfid,
|
||||
zoneName = domain.name,
|
||||
priority = prio,
|
||||
ttl = ttl,
|
||||
createdOn = createdOn.getISOFormat(),
|
||||
modifiedOn = modifiedOn.getISOFormat(),
|
||||
comment = comment
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user