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

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.

主站蜘蛛池模板: 贡觉县| 文水县| 昭觉县| 额敏县| 沈阳市| 和龙市| 三江| 茌平县| 河东区| 溧水县| 峡江县| 北京市| 福建省| 宜昌市| 曲沃县| 资兴市| 祁连县| 鹿泉市| 法库县| 措勤县| 长垣县| 鹤山市| 萨嘎县| 鄂尔多斯市| 洪江市| 章丘市| 白城市| 五寨县| 安多县| 东莞市| 土默特右旗| 额尔古纳市| 嘉黎县| 霞浦县| 高阳县| 满城县| 凤阳县| 城口县| 武陟县| 湖北省| 宁蒗|