package com.goafanti.fragment.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.goafanti.common.controller.BaseApiController;
import com.goafanti.common.utils.StringUtils;
import com.goafanti.fragment.service.FragmentService;

@RestController
@RequestMapping(value = "/open/html/")
public class FragmentController extends BaseApiController {

	@Autowired
	FragmentService fragmentService;

	@RequestMapping(value = "/get/{id}", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
	public String get(@PathVariable String id, String noCache) {
		if (StringUtils.isNotBlank(noCache)) {
			fragmentService.clean(id);
		}
		return fragmentService.selectById(id);
	}

	@RequestMapping(value = "/json/{id}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	public String json(@PathVariable String id) {
		return fragmentService.selectById(id);
	}

}
