<repo_name>PuyaAlemirad/TeacherRestService<file_sep>/test/JUnitTest/NewEmptyJUnitTest.java
///*
// * To change this license header, choose License Headers in Project Properties.
// * To change this template file, choose Tools | Templates
// * and open the template in the editor.
// */
//package JUnitTest;
//
//import dao.TeacherDAOInterface;
//import entity.Teacher;
//import java.util.ArrayList;
//import java.util.List;
//import org.junit.Before;
//import org.junit.Test;
//import service.DaoRest;
//
//public class NewEmptyJUnitTest {
//
//    MockPairDAO mock;
//    DaoRest daoRest;
//    Teacher t;
//
//    @Before
//    public void setUp() {
//        mock = new MockPairDAO();
//        daoRest = new DaoRest();
//        t = new Teacher();
//    }
//
//    @Test
//    public void createTeacher() {
//        mock.addTeacher(t);
//
//    }
//
//    class MockPairDAO implements TeacherDAOInterface {
//
//        @Override
//        public void addTeacher(Teacher t) {
//
//        }
//
//        @Override
//        public void editTeacher(Teacher t) {
//
//        }
//
//        @Override
//        public void removeTeacher(Long id) {
//
//        }
//
//        @Override
//        public Teacher findById(Long id) {
//
//            if (t.getId().equals(id)) {
//                return t;
//            } else {
//                return null;
//            }
//
//        }
//
//        @Override
//        public List<Teacher> getAllTeacher() {
//            List<Teacher> list = new ArrayList<>();
//            return list;
//        }
//
//    }
//}
<file_sep>/README.md
# TeacherRestService
Rest service API that has all the features for a CRUD. 
Project was done in februari 2019. 
<file_sep>/src/java/dao/TeacherDAO.java
package dao;

import entity.Teacher;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
public class TeacherDAO implements TeacherDAOInterface {

    @PersistenceContext
    EntityManager em;

    @Override
    public void addTeacher(Teacher t) {
        em.persist(t);
    }

    @Override
    public void editTeacher(Teacher t) {
        em.merge(t);
    }

    @Override
    public void removeTeacher(int id) {

        em.remove(em.find(Teacher.class, id));

    }

    @Override
    public Teacher findById(int id) {
        return em.find(Teacher.class, id);
    }

    @Override
    public List<Teacher> getAllTeacher() {

        return em.createQuery("SELECT t FROM Teacher t").getResultList();
    }
}
