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.ProjectDao;
import com.ekexiu.portal.po.Project;

@Path("/project")
public class ProjectService {

	@Autowrie
	private ProjectDao projectDao;

	public ProjectDao getProjectDao() {
		return projectDao;
	}

	public void setProjectDao(ProjectDao projectDao) {
		this.projectDao = projectDao;
	}

	@Get
	@Path("/{id}")
	public Project query(@JdbcConn(false) Connection con, @PathVar String id) throws SQLException {
		return this.projectDao.queryOne(con, id);
	}

	@Post
	@Path
	public void insert(@JdbcConn(true) Connection con, Project project) throws SQLException {
		String id = StringUtil.buildUUID();
		project.setId(id);
		this.projectDao.insert(con, project);
	}

	@Put
	@Path
	public void update(@JdbcConn(true) Connection con, @RequestBody Project project) throws SQLException {
		this.projectDao.update(con, project);
	}

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

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