官术网_书友最值得收藏!

Service/Controller

The MessageController handles all the URLs, or you can say operations, related to messages. To have a separation of concern in our code. The actual job of saving the message, that is the database operations, is delegated to the respective Repository class (MessageRepository):

    /**
* Exposes the operations related to creating and showing
* messages through URLs using REST
*/
@RestController
@RequestMapping("/message")
class MessageController(val repository: MessageRepository) {

val broadcaster = ReactiveBroadcaster()

/**
* Creates new message and saves it into DB
*/
@PostMapping
@ResponseStatus(CREATED)
fun create(@RequestBody message: Message): Message {
val msg = repository.insert(message)
broadcaster.send(msg)
return msg
}

/**
* Get list of all the messages
*/
@GetMapping
fun list() = repository.findAll()

/**
* Get list of messages in the given bounds
*/
@GetMapping("/bbox/{xMin},{yMin},{xMax},{yMax}")
fun findByBoundingBox(@PathVariable xMin: Double, @PathVariable
yMin: Double,
@PathVariable xMax: Double, @PathVariable
yMax: Double)
= repository.findByBoundingBox(PGbox2d(Point(xMin, yMin),
Point(xMax, yMax)))

/**
* Subscribes to receive the updates regarding the messages
*/
@GetMapping("/subscribe")
fun subscribe()= broadcaster.subscribe()
}

@GetMapping and @PostMapping annotations are just method-specific shortcuts for @RequestMapping annotations available since Spring Framework 4.3.

主站蜘蛛池模板: 洛南县| 普兰县| 乐东| 龙门县| 福州市| 衡阳县| 咸宁市| 潞城市| 阳谷县| 保定市| 汉寿县| 桓台县| 金寨县| 乡城县| 射阳县| 济宁市| 明星| 广水市| 郯城县| 广西| 嘉祥县| 酉阳| 边坝县| 绥江县| 高邑县| 清河县| 浙江省| 宣城市| 临澧县| 保定市| 化德县| 嘉峪关市| 兴隆县| 乌拉特后旗| 深圳市| 本溪市| 泰宁县| 西吉县| 法库县| 平昌县| 屏南县|