find method added

This commit is contained in:
geek 2017-06-07 16:34:37 +09:00
parent 66de3e3d07
commit 43f0673463
3 changed files with 66 additions and 0 deletions

View File

@ -3,8 +3,13 @@ package com.loafle.overflow.email.dao;
import com.loafle.overflow.commons.dao.BaseDAO; import com.loafle.overflow.commons.dao.BaseDAO;
import com.loafle.overflow.email.model.EmailAuth; import com.loafle.overflow.email.model.EmailAuth;
import java.util.List;
/** /**
* Created by geek@loafle.com on 17. 6. 6. * Created by geek@loafle.com on 17. 6. 6.
*/ */
public interface EmailAuthDAO extends BaseDAO<EmailAuth> { public interface EmailAuthDAO extends BaseDAO<EmailAuth> {
public EmailAuth findByAuthToken(EmailAuth emailAuth);
public List<EmailAuth> findByMemberId(EmailAuth emailAuth);
} }

View File

@ -3,8 +3,42 @@ package com.loafle.overflow.email.dao;
import com.loafle.overflow.commons.dao.JPABaseDAO; import com.loafle.overflow.commons.dao.JPABaseDAO;
import com.loafle.overflow.email.model.EmailAuth; import com.loafle.overflow.email.model.EmailAuth;
import javax.persistence.Query;
import java.util.List;
/** /**
* Created by geek@loafle.com on 17. 6. 6. * Created by geek@loafle.com on 17. 6. 6.
*/ */
public class JPAEmailAuthDAO extends JPABaseDAO<EmailAuth> implements EmailAuthDAO { public class JPAEmailAuthDAO extends JPABaseDAO<EmailAuth> implements EmailAuthDAO {
public EmailAuth findByAuthToken(EmailAuth emailAuth) {
Query query = getEntityManager().createNativeQuery("SELECT e.* FROM EMAIL_AUTH e WHERE e.auth_token = :auth_token", EmailAuth.class);
query.setParameter("auth_token", emailAuth.getAuthToken());
EmailAuth auth = null;
try {
auth = (EmailAuth)query.getSingleResult();
} catch (Exception e) {
e.printStackTrace();
} finally {
return auth;
}
}
@Override
public List<EmailAuth> findByMemberId(EmailAuth emailAuth) {
Query query = getEntityManager().createNativeQuery("SELECT e.* FROM EMAIL_AUTH e WHERE e.member_id = :member_id", EmailAuth.class);
query.setParameter("member_id", emailAuth.getMember().getId());
List<EmailAuth> auths = null;
try {
auths = (List<EmailAuth>)query.getResultList();
} catch (Exception e) {
e.printStackTrace();
} finally {
return auths;
}
}
} }

View File

@ -2,11 +2,13 @@ package com.loafle.overflow.email.dao;
import com.loafle.overflow.email.model.EmailAuth; import com.loafle.overflow.email.model.EmailAuth;
import com.loafle.overflow.member.model.Member; import com.loafle.overflow.member.model.Member;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* Created by root on 17. 6. 6. * Created by root on 17. 6. 6.
@ -23,6 +25,7 @@ public class JPAEmailAuthDAOTest {
} }
@Test @Test
@Ignore
public void createEmailAuth() { public void createEmailAuth() {
EmailAuth auth = new EmailAuth(); EmailAuth auth = new EmailAuth();
@ -36,6 +39,7 @@ public class JPAEmailAuthDAOTest {
} }
@Test @Test
@Ignore
public void updateEmailAuth() { public void updateEmailAuth() {
EmailAuth auth = this.emailAuthDAO.find("1"); EmailAuth auth = this.emailAuthDAO.find("1");
@ -46,4 +50,27 @@ public class JPAEmailAuthDAOTest {
this.emailAuthDAO.update(auth); this.emailAuthDAO.update(auth);
System.out.println(auth.getConfirmDate()); System.out.println(auth.getConfirmDate());
} }
@Test
@Ignore
public void TestFindByAuthToken() {
EmailAuth auth = new EmailAuth();
auth.setAuthToken("3C03F8AB-1D4D-4C8A-8C36-EE2D644988B5");
EmailAuth temp = this.emailAuthDAO.findByAuthToken(auth);
System.out.println(temp.getId());
Assert.assertNotNull(temp);
}
@Test
@Ignore
public void TestFindByMemberId() {
EmailAuth auth = new EmailAuth();
auth.setMember(new Member((long)4));
List<EmailAuth> ems = this.emailAuthDAO.findByMemberId(auth);
System.out.println(ems.get(0).getMember().getEmail());
Assert.assertEquals((long)1, (long)ems.size());
}
} }