package com.ekexiu.portal.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.jfw.apt.annotation.Autowrie;
import org.jfw.apt.web.annotation.Path;
import org.jfw.apt.web.annotation.operate.Delete;
import org.jfw.apt.web.annotation.operate.Get;
import org.jfw.apt.web.annotation.operate.Post;
import org.jfw.apt.web.annotation.operate.Put;
import org.jfw.apt.web.annotation.param.JdbcConn;
import org.jfw.apt.web.annotation.param.PathVar;
import org.jfw.apt.web.annotation.param.RequestBody;
import org.jfw.util.StringUtil;

import com.ekexiu.portal.dao.HonorDao;
import com.ekexiu.portal.po.Honor;

@Path("/honor")
public class HonorService {
	@Autowrie
	private HonorDao honorDao;
	
	public HonorDao getHonorDao() {
		return honorDao;
	}

	public void setHonorDao(HonorDao honorDao) {
		this.honorDao = honorDao;
	}

	@Get
	@Path("/{id}")
	public Honor query(@JdbcConn Connection con,@PathVar String id) throws SQLException
	{
		return this.honorDao.queryOne(con, id);
	}
	@Post
	@Path
	public void insert(@JdbcConn(true) Connection con, Honor honor) throws SQLException {
		String id = StringUtil.buildUUID();
		honor.setId(id);
		this.honorDao.insert(con, honor);
	}

	@Put
	@Path
	public void update(@JdbcConn(true) Connection con, @RequestBody Honor honor) throws SQLException {
		this.honorDao.update(con, honor);
	}

	@Get
	@Path("/professor")
	public List<Honor> queryByProfessor(@JdbcConn(false) Connection con, String professorId) throws SQLException {
		return this.honorDao.query(con, professorId);
	}

	@Delete
	@Path("/{id}")
	public void delete(@JdbcConn(true) Connection con, @PathVar String id) throws SQLException {
		this.honorDao.delete(con, id);
	}

}
