001package com.lucidtech.puttingalltogether.controller;
002
003import com.lucidtech.puttingalltogether.model.Greeting;
004import org.springframework.web.bind.annotation.GetMapping;
005import org.springframework.web.bind.annotation.RequestParam;
006import org.springframework.web.bind.annotation.RestController;
007
008import java.util.concurrent.atomic.AtomicLong;
009
010import static java.lang.String.format;
011
012@RestController
013public class GreetingController {
014
015    private static final String template = "Hello, %s!";
016    private final AtomicLong counter = new AtomicLong();
017
018    @GetMapping("/greeting")
019    public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
020        return new Greeting(counter.incrementAndGet(), format(template, name));
021    }
022}