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.PaperDao;
import com.ekexiu.portal.po.Paper;

@Path("/paper")
public class PaperService {
	@Autowrie
	private PaperDao paperDao;
	
	public PaperDao getPaperDao() {
		return paperDao;
	}

	public void setPaperDao(PaperDao paperDao) {
		this.paperDao = paperDao;
	}

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

	@Put
	@Path
	public void update(@JdbcConn(true) Connection con, @RequestBody Paper paper) throws SQLException {
		this.paperDao.update(con, paper);
	}

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

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