mirror of
https://github.com/dalbodeule/sh0rt.kr-pdns.git
synced 2025-12-18 06:11:59 +09:00
initialized
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package space.mori.dnsapi.controller
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation
|
||||
import io.swagger.v3.oas.annotations.Parameter
|
||||
import io.swagger.v3.oas.annotations.media.ArraySchema
|
||||
import io.swagger.v3.oas.annotations.media.Content
|
||||
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
|
||||
import space.mori.dnsapi.service.DomainService
|
||||
import java.util.*
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/domain")
|
||||
class DomainController {
|
||||
@Autowired
|
||||
private val domainService: DomainService? = null
|
||||
|
||||
@get:GetMapping
|
||||
@get:Operation(summary = "Get all domains", tags = ["domain"])
|
||||
@get:ApiResponse(responseCode = "200", description = "Returns all domains",
|
||||
content = [Content(array = ArraySchema(schema = Schema(implementation = DomainResponseDTO::class)))])
|
||||
val allDomains: List<DomainResponseDTO?>
|
||||
get() = domainService!!.getAllDomains().map { it?.toDTO() }
|
||||
|
||||
@Operation(summary = "Get domain", tags = ["domain"])
|
||||
@ApiResponses(value = [
|
||||
ApiResponse(responseCode = "200", description = "Returns domain",
|
||||
content = [Content(schema = Schema(implementation = DomainResponseDTO::class))]),
|
||||
ApiResponse(responseCode = "404", description = "Returns not found",
|
||||
content = [Content(schema = Schema(implementation = Void::class))])
|
||||
])
|
||||
@GetMapping("/{cfid}")
|
||||
fun getDomainByCfid(
|
||||
@Parameter(description = "CFID", required = true)
|
||||
@PathVariable cfid: String?
|
||||
): Optional<DomainResponseDTO> {
|
||||
return domainService!!.getDomainById(cfid!!).map { it.toDTO() }
|
||||
}
|
||||
|
||||
@Operation(summary = "Create domain", tags = ["domain"])
|
||||
@ApiResponses(value = [
|
||||
ApiResponse(responseCode = "200", description = "Created domain",
|
||||
content = [Content(schema = Schema(implementation = DomainResponseDTO::class))]),
|
||||
ApiResponse(responseCode = "400", description = "Bad request",
|
||||
content = [Content(schema = Schema(implementation = Void::class))])
|
||||
])
|
||||
@PostMapping
|
||||
fun createDomain(@RequestBody domain: Domain?): DomainResponseDTO {
|
||||
return domainService!!.createDomain(domain!!).toDTO()
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete domain", tags = ["domain"])
|
||||
@ApiResponses(value = [
|
||||
ApiResponse(responseCode = "200", description = "Deleted domain",
|
||||
content = [Content(schema = Schema(implementation = Void::class))]),
|
||||
ApiResponse(responseCode = "400", description = "Bad request",
|
||||
content = [Content(schema = Schema(implementation = Void::class))])
|
||||
])
|
||||
@DeleteMapping("/{cfid}")
|
||||
fun deleteDomain(@PathVariable cfid: String?) {
|
||||
domainService!!.deleteDomain(cfid!!)
|
||||
}
|
||||
|
||||
private fun Domain.toDTO() = DomainResponseDTO(cfid = cfid!!, domainName = domainName!!)
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package space.mori.dnsapi.controller
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation
|
||||
import io.swagger.v3.oas.annotations.media.ArraySchema
|
||||
import io.swagger.v3.oas.annotations.media.Content
|
||||
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.bind.annotation.*
|
||||
import space.mori.dnsapi.service.RecordService
|
||||
import space.mori.dnsapi.db.Record
|
||||
import space.mori.dnsapi.dto.RecordRequestDTO
|
||||
import space.mori.dnsapi.dto.RecordResponseDTO
|
||||
import java.util.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/record")
|
||||
class RecordController {
|
||||
@Autowired
|
||||
private val recordService: RecordService? = null
|
||||
|
||||
@GetMapping
|
||||
@Operation(summary = "Get all records", tags=["record"])
|
||||
@ApiResponses(value = [
|
||||
ApiResponse(responseCode = "200", description = "Return All Records",
|
||||
content = [Content(array = ArraySchema(schema = Schema(implementation = RecordResponseDTO::class)))]),
|
||||
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() }
|
||||
}
|
||||
|
||||
@GetMapping("/{cfid}")
|
||||
@Operation(summary = "Get 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 getRecordByCfid(@PathVariable cfid: String?): Optional<RecordResponseDTO> {
|
||||
return recordService!!.getRecordById(cfid!!).map { it.toDTO() }
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "Add 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 createRecord(@RequestBody record: RecordRequestDTO): RecordResponseDTO {
|
||||
return recordService!!.createRecord(record).toDTO()
|
||||
}
|
||||
|
||||
@DeleteMapping("/{cfid}")
|
||||
@Operation(summary = "Remove Record by ID", tags=["record"])
|
||||
@ApiResponses(value = [
|
||||
ApiResponse(responseCode = "200", description = "Return Record",
|
||||
content = [Content(schema = Schema(implementation = Void::class))]),
|
||||
ApiResponse(responseCode = "400", description = "Bad request",
|
||||
content = [Content(schema = Schema(implementation = Void::class))]),
|
||||
])
|
||||
fun deleteRecord(@PathVariable cfid: String?) {
|
||||
recordService!!.deleteRecord(cfid!!)
|
||||
}
|
||||
|
||||
private fun Record.toDTO() = RecordResponseDTO(
|
||||
cfid = cfid!!,
|
||||
name = name!!,
|
||||
type = type!!,
|
||||
content = content!!,
|
||||
prio = prio!!,
|
||||
ttl = ttl!!,
|
||||
changeDate = changeDate!!,
|
||||
auth = auth,
|
||||
disabled = disabled
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user