package com.itranswarp.shici.web;

import java.io.IOException;
import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.itranswarp.shici.bean.Dynasty;
import com.itranswarp.shici.bean.Poem;
import com.itranswarp.shici.bean.Poet;

/**
 * Provide REST API.
 * 
 * @author liaoxuefeng
 */
@RestController
public class ApiController extends AbstractController {

	@GetMapping("/api/dynasties")
	public List<Dynasty> getDynasties() {
		return this.poemService.getDynasties();
	}

	@GetMapping("/api/dynasties/{id}")
	public Dynasty getDynasty(@PathVariable("id") long id) {
		return this.poemService.getDynasty(id);
	}

	@GetMapping("/api/dynasties/{id}/poets")
	public List<Poet> getPoets(@PathVariable("id") long id) {
		return this.poemService.getPoets(id);
	}

	@GetMapping("/api/poets/{id}")
	public Poet getPoet(@PathVariable("id") long id) {
		return this.poemService.getPoet(id);
	}

	@GetMapping("/api/poet/{id}/poems")
	public List<Poem> getPoems(@PathVariable("id") long id) {
		return this.poemService.getPoems(id);
	}

	@GetMapping("/api/poems/{id}")
	public Poem getPoem(@PathVariable("id") long id) {
		return this.poemService.getPoem(id);
	}

	@GetMapping("/api/suggest")
	public String[] suggest(@RequestParam(value = "q", defaultValue = "") String q) throws IOException {
		if (q.trim().isEmpty()) {
			return EMPTY_SUGGUESTS;
		}
		return this.searchService.suggest(q);
	}

	static final String[] EMPTY_SUGGUESTS = new String[0];
}

@@ -1362,32 +1362,140 @@
 etPoem(id);%0A%09%7D%0A%0A
+%09@GetMapping(%22/api/poems/today%22)%0A%09public Poem getTodayPoem() %7B%0A%09%09return this.poemService.getFeatured();%0A%09%7D%0A%0A
 %09@GetMapping(%22/a

add today poem 4 api