/*
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package com.mpalourdio.springboottemplate.controllers;

import com.mpalourdio.springboottemplate.mediatype.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Running a GET request here with ACCEPT header = application/vnd.api.v1+json;q=0.9, application/json
 * will receive response from processV2.
 *
 * The same thing will happen if no ACCEPT header is specified
 *
 * @link https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
 * @link http://allegro.tech/2015/01/Content-headers-or-how-to-version-api.html
 */


@RestController
@RequestMapping("/http")
public class HttpVersionedApiController {


    @GetMapping(value = "/test", produces = MediaType.APPLICATION_VND_API_V1_VALUE)
    public String processV1() {
        return "v1";
    }

    @GetMapping(value = "/test", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_VND_API_V2_VALUE})
    public String processV2() {
        return "v2";
    }

    @PostMapping(
            value = "/test",
            consumes = MediaType.APPLICATION_VND_API_V1_VALUE,
            produces = MediaType.APPLICATION_VND_API_V1_VALUE
    )
    public String processV1Post() {
        return "v1-post";
    }

    @PostMapping(
            value = "/test",
            consumes = MediaType.APPLICATION_VND_API_V2_VALUE,
            produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_VND_API_V2_VALUE}
    )
    public String processV2Post() {
        return "v2-post";
    }

    @PostMapping(value = "/test", consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_VND_API_V1_VALUE)
    public String processV1PostConsumeAll() {
        return "v1-post-consumes-all";
    }

    @PostMapping(
            value = "/test",
            consumes = MediaType.ALL_VALUE,
            produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_VND_API_V2_VALUE}
    )
    public String processV2PostConsumeAll() {
        return "v2-post-consumes-all";
    }
}



@@ -844,16 +844,70 @@
 oller;%0A%0A
+import java.util.Collections;%0Aimport java.util.List;%0A%0A
 /**%0A * R
@@ -1438,38 +1438,44 @@
 LUE)%0A    public 
+List%3C
 String
+%3E
  processV1() %7B%0A 
@@ -1492,12 +1492,39 @@
 urn 
+Collections.singletonList(
 %22v1%22
+)
 ;%0A  
@@ -1651,38 +1651,44 @@
 UE%7D)%0A    public 
+List%3C
 String
+%3E
  processV2() %7B%0A 
@@ -1705,12 +1705,39 @@
 urn 
+Collections.singletonList(
 %22v2%22
+)
 ;%0A  
@@ -1922,38 +1922,44 @@
    )%0A    public 
+List%3C
 String
+%3E
  processV1Post()
@@ -1968,32 +1968,58 @@
 %0A        return 
+Collections.singletonList(
 %22v1-post%22;%0A    %7D
@@ -2007,24 +2007,25 @@
 st(%22v1-post%22
+)
 ;%0A    %7D%0A%0A   
@@ -2238,38 +2238,44 @@
    )%0A    public 
+List%3C
 String
+%3E
  processV2Post()
@@ -2284,32 +2284,58 @@
 %0A        return 
+Collections.singletonList(
 %22v2-post%22;%0A    %7D
@@ -2327,16 +2327,17 @@
 v2-post%22
+)
 ;%0A    %7D%0A
@@ -2457,38 +2457,44 @@
 LUE)%0A    public 
+List%3C
 String
+%3E
  processV1PostCo
@@ -2521,16 +2521,42 @@
  return 
+Collections.singletonList(
 %22v1-post
@@ -2561,32 +2561,33 @@
 st-consumes-all%22
+)
 ;%0A    %7D%0A%0A    @Po
@@ -2785,22 +2785,28 @@
  public 
+List%3C
 String
+%3E
  process
@@ -2841,16 +2841,42 @@
  return 
+Collections.singletonList(
 %22v2-post
@@ -2889,16 +2889,17 @@
 mes-all%22
+)
 ;%0A    %7D%0A

Return valid JSON