package com.yihu.hos.arbiter.controllers;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.hos.arbiter.models.ArbiterServer;
import com.yihu.hos.arbiter.services.ArbiterServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author Airhead
 * @since 2016/12/9.
 */
@RestController
@RequestMapping("/arbiter")
public class ArbiterServerController {
    @Autowired
    private ArbiterServerService arbiterServerService;
    @Autowired
    private ObjectMapper objectMapper;

    @RequestMapping()
    public void register(@RequestBody String body) {
        try {
            ArbiterServer arbiterServer = objectMapper.readValue(body, ArbiterServer.class);
            arbiterServerService.save(arbiterServer);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
