com.mycompany.geocoordinate.controller.PointController.java Source code

Java tutorial

Introduction

Here is the source code for com.mycompany.geocoordinate.controller.PointController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.geocoordinate.controller;

import com.mycompany.geocoordinate.mappers.CoordinateMapper;

import com.mycompany.geocoordinate.model.GeoObject;
import com.mycompany.geocoordinate.model.GeoType;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jettison.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author andrey
 */
@Controller
@RequestMapping("/")
@Configuration
public class PointController {

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView main() {
        return new ModelAndView("index");
    }

    @Autowired
    private CoordinateMapper coordinateMapper;

    @ResponseStatus(HttpStatus.CREATED)
    @PostMapping(value = "/point", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody ResponseEntity<List<Integer>> point(@RequestBody GeoObject geoObject)
            throws IOException, JSONException {

        boolean check = coordinateMapper.isThereGeoObjectFromCircleType(GeoType.GEOPOINT) != null
                & coordinateMapper.selectCoordinateForLineorCircle(geoObject.getCoordinate()) != null;

        coordinateMapper.insertCoordinateForLineorCircle(GeoType.GEOPOINT, geoObject.getCoordinate());

        List<Integer> responseType = coordinateMapper.selectIdGeo(geoObject.getCoordinate());

        return ResponseEntity.created(URI.create("/point/id")).body(responseType);

    }
};