diff --git a/src/main/java/com/loafle/overflow/email/dao/EmailAuthDAO.java b/src/main/java/com/loafle/overflow/email/dao/EmailAuthDAO.java index 5d333ef..292f15e 100644 --- a/src/main/java/com/loafle/overflow/email/dao/EmailAuthDAO.java +++ b/src/main/java/com/loafle/overflow/email/dao/EmailAuthDAO.java @@ -3,8 +3,13 @@ package com.loafle.overflow.email.dao; import com.loafle.overflow.commons.dao.BaseDAO; import com.loafle.overflow.email.model.EmailAuth; +import java.util.List; + /** * Created by geek@loafle.com on 17. 6. 6. */ public interface EmailAuthDAO extends BaseDAO { + public EmailAuth findByAuthToken(EmailAuth emailAuth); + + public List findByMemberId(EmailAuth emailAuth); } diff --git a/src/main/java/com/loafle/overflow/email/dao/JPAEmailAuthDAO.java b/src/main/java/com/loafle/overflow/email/dao/JPAEmailAuthDAO.java index b643643..30f06e5 100644 --- a/src/main/java/com/loafle/overflow/email/dao/JPAEmailAuthDAO.java +++ b/src/main/java/com/loafle/overflow/email/dao/JPAEmailAuthDAO.java @@ -3,8 +3,42 @@ package com.loafle.overflow.email.dao; import com.loafle.overflow.commons.dao.JPABaseDAO; import com.loafle.overflow.email.model.EmailAuth; +import javax.persistence.Query; +import java.util.List; + /** * Created by geek@loafle.com on 17. 6. 6. */ public class JPAEmailAuthDAO extends JPABaseDAO 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 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 auths = null; + + try { + auths = (List)query.getResultList(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + return auths; + } + } } diff --git a/src/test/java/com/loafle/overflow/email/dao/JPAEmailAuthDAOTest.java b/src/test/java/com/loafle/overflow/email/dao/JPAEmailAuthDAOTest.java index 4bbefd3..36605a0 100644 --- a/src/test/java/com/loafle/overflow/email/dao/JPAEmailAuthDAOTest.java +++ b/src/test/java/com/loafle/overflow/email/dao/JPAEmailAuthDAOTest.java @@ -2,11 +2,13 @@ package com.loafle.overflow.email.dao; import com.loafle.overflow.email.model.EmailAuth; import com.loafle.overflow.member.model.Member; +import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import java.util.Date; +import java.util.List; /** * Created by root on 17. 6. 6. @@ -23,6 +25,7 @@ public class JPAEmailAuthDAOTest { } @Test + @Ignore public void createEmailAuth() { EmailAuth auth = new EmailAuth(); @@ -36,6 +39,7 @@ public class JPAEmailAuthDAOTest { } @Test + @Ignore public void updateEmailAuth() { EmailAuth auth = this.emailAuthDAO.find("1"); @@ -46,4 +50,27 @@ public class JPAEmailAuthDAOTest { this.emailAuthDAO.update(auth); 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 ems = this.emailAuthDAO.findByMemberId(auth); + + System.out.println(ems.get(0).getMember().getEmail()); + Assert.assertEquals((long)1, (long)ems.size()); + } } \ No newline at end of file