package com.github.hronom.words.counter.controllers;

import com.github.hronom.words.counter.controllers.pojos.WordStatistic;
import com.github.hronom.words.counter.services.WordsService;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@RestController
public class RootController {
    private final WordsService wordsService;

    @Autowired
    public RootController(WordsService wordsServiceArg) {
        wordsService = wordsServiceArg;
    }

    @ApiOperation(value = "Return statistic for specified word.")
    @ApiResponses(
        value = {
            @ApiResponse(code = 200, message = "Successful."),
            @ApiResponse(code = 400, message = "Something bad happens.")
        })
    @RequestMapping(value = "/ask", method = {RequestMethod.POST}, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public ResponseEntity ask(
        @ApiParam(name = "word", value = "must be an English word (case sensitive)", required = true)
        @RequestParam(value = "word", required = true) String word
    ) {
        try {
            WordStatistic wordStatistic = new WordStatistic(
                wordsService.getWordTextsCount(word),
                wordsService.getWordRequestsCount(word)
            );
            return ResponseEntity.ok(wordStatistic);
        } catch (Exception exception){
            return ResponseEntity.badRequest().body(ExceptionUtils.getStackTrace(exception));
        }
    }
}

@@ -1088,16 +1088,504 @@
 %0A    %7D%0A%0A
+    @ApiOperation(value = %22Return link to the SWAGGER UI.%22)%0A    @ApiResponses(%0A        value = %7B%0A            @ApiResponse(code = 200, message = %22Successful.%22),%0A            @ApiResponse(code = 400, message = %22Something bad happens.%22)%0A        %7D)%0A    @RequestMapping(value = %22/%22, method = %7BRequestMethod.GET%7D, produces = MediaType.TEXT_HTML_VALUE)%0A    @ResponseBody%0A    public ResponseEntity root() %7B%0A        return ResponseEntity.ok(%22%3Ca href=%5C%22/swagger-ui.html#!%5C%22%3ESWAGGER UI%3C/a%3E%22);%0A    %7D%0A%0A
     @Api

Add response for root