From 162fa61d3ca8c046d667f2dddfa32525ad92587c Mon Sep 17 00:00:00 2001 From: snoop Date: Wed, 27 Sep 2017 14:46:59 +0900 Subject: [PATCH] added read List By Apkey, ProbeKey, Domain --- .../module/domain/dao/DomainMemberDAO.java | 9 ++++ .../domain/service/DomainMemberService.java | 8 ++++ .../module/member/service/MemberService.java | 44 +++++++++++++++++++ src/main/resources/local/init.sql | 2 + .../service/DomainMemberServiceTest.java | 18 ++++++++ .../member/service/MemberServiceTest.java | 34 +++++++++++++- 6 files changed, 114 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/loafle/overflow/module/domain/dao/DomainMemberDAO.java b/src/main/java/com/loafle/overflow/module/domain/dao/DomainMemberDAO.java index 3f9257b..a5fe331 100644 --- a/src/main/java/com/loafle/overflow/module/domain/dao/DomainMemberDAO.java +++ b/src/main/java/com/loafle/overflow/module/domain/dao/DomainMemberDAO.java @@ -1,12 +1,21 @@ package com.loafle.overflow.module.domain.dao; +import com.loafle.overflow.module.domain.model.Domain; import com.loafle.overflow.module.domain.model.DomainMember; +import com.loafle.overflow.module.member.model.Member; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.List; + /** * Created by root on 17. 6. 23. */ @Repository public interface DomainMemberDAO extends JpaRepository { + + @Query("SELECT dm.member from DomainMember dm where dm.domain = (:domain)") + List findAllMemberByDomain(@Param("domain") Domain domain); } diff --git a/src/main/java/com/loafle/overflow/module/domain/service/DomainMemberService.java b/src/main/java/com/loafle/overflow/module/domain/service/DomainMemberService.java index 71fc2fe..08d19e7 100644 --- a/src/main/java/com/loafle/overflow/module/domain/service/DomainMemberService.java +++ b/src/main/java/com/loafle/overflow/module/domain/service/DomainMemberService.java @@ -1,10 +1,14 @@ package com.loafle.overflow.module.domain.service; import com.loafle.overflow.module.domain.dao.DomainMemberDAO; +import com.loafle.overflow.module.domain.model.Domain; import com.loafle.overflow.module.domain.model.DomainMember; +import com.loafle.overflow.module.member.model.Member; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + /** * Created by snoop on 17. 6. 28. */ @@ -18,4 +22,8 @@ public class DomainMemberService { this.domainMemberDAO.save(domainMember); } + public List readAllMemberByDomain(Domain domain) { + return this.domainMemberDAO.findAllMemberByDomain(domain); + } + } diff --git a/src/main/java/com/loafle/overflow/module/member/service/MemberService.java b/src/main/java/com/loafle/overflow/module/member/service/MemberService.java index 41f792e..0ff766d 100644 --- a/src/main/java/com/loafle/overflow/module/member/service/MemberService.java +++ b/src/main/java/com/loafle/overflow/module/member/service/MemberService.java @@ -2,11 +2,18 @@ package com.loafle.overflow.module.member.service; import com.loafle.overflow.commons.model.SessionMetadata; import com.loafle.overflow.commons.utils.EmailSender; +import com.loafle.overflow.module.apikey.model.ApiKey; +import com.loafle.overflow.module.apikey.service.ApiKeyService; +import com.loafle.overflow.module.domain.model.Domain; +import com.loafle.overflow.module.domain.model.DomainMember; +import com.loafle.overflow.module.domain.service.DomainMemberService; import com.loafle.overflow.module.email.service.EmailAuthService; import com.loafle.overflow.module.member.dao.MemberDAO; import com.loafle.overflow.module.member.exception.*; import com.loafle.overflow.module.member.model.Member; import com.loafle.overflow.module.meta.model.MetaMemberStatus; +import com.loafle.overflow.module.probe.model.Probe; +import com.loafle.overflow.module.probe.service.ProbeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mail.MailException; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -15,6 +22,7 @@ import org.springframework.stereotype.Service; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; +import java.util.List; /** * Created by geek on 17. 6. 28. @@ -31,6 +39,15 @@ public class MemberService { @Autowired private EmailSender emailSender; + @Autowired + private ApiKeyService apiKeyService; + + @Autowired + private DomainMemberService domainMemberService; + + @Autowired + private ProbeService probeService; + private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); public Member signin(String signinId, String signinPw) throws SignInIdNotExistException, EmailNotConfirmedException, SignInPwNotMatchException { @@ -184,4 +201,31 @@ public class MemberService { public void emailConfirm(Member member) { } + + public List readAllByProbeKey(String probeKey) { + + Probe probe = this.probeService.readByProbeKey(probeKey); + + if(probe == null) { + return null; + } + + return this.domainMemberService.readAllMemberByDomain(probe.getDomain()); + } + + public List readAllByApiKey(String apikey) { + + ApiKey apiKey = this.apiKeyService.readByApiKey(apikey); + + if(apiKey == null) { + return null; + } + + return this.domainMemberService.readAllMemberByDomain(apiKey.getDomain()); + } + + public List readAllByDomain(Domain domain) { + + return this.domainMemberService.readAllMemberByDomain(domain); + } } diff --git a/src/main/resources/local/init.sql b/src/main/resources/local/init.sql index d13ffd1..5f0589b 100644 --- a/src/main/resources/local/init.sql +++ b/src/main/resources/local/init.sql @@ -952,6 +952,8 @@ INSERT INTO public."domain" (create_date,"name") VALUES ( INSERT INTO public.domain_member (create_date,domain_id,member_id) VALUES ( '2017-06-26 11:27:43.023',1,1); +INSERT INTO public.domain_member (create_date,domain_id,member_id) VALUES ( +'2017-06-26 11:27:43.023',1,2); INSERT INTO public.api_key (api_key,create_date,domain_id) VALUES ( '52abd6fd57e511e7ac52080027658d13','2017-06-26 13:02:28.347',1); diff --git a/src/test/java/com/loafle/overflow/module/domain/service/DomainMemberServiceTest.java b/src/test/java/com/loafle/overflow/module/domain/service/DomainMemberServiceTest.java index e0e5987..0317c8b 100644 --- a/src/test/java/com/loafle/overflow/module/domain/service/DomainMemberServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/domain/service/DomainMemberServiceTest.java @@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.util.List; + import static org.junit.Assert.*; /** @@ -45,4 +47,20 @@ public class DomainMemberServiceTest { } + @Test + public void readAllMemberByDomain() { + + Domain domain = new Domain(); + domain.setId(1); + + List members = this.domainMemberService.readAllMemberByDomain(domain); + + Assert.assertNotEquals(members.size(), 0); + + for(Member member : members) { + System.out.println(member.getEmail()); + } + + } + } \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/module/member/service/MemberServiceTest.java b/src/test/java/com/loafle/overflow/module/member/service/MemberServiceTest.java index 0800be0..32d36cb 100644 --- a/src/test/java/com/loafle/overflow/module/member/service/MemberServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/member/service/MemberServiceTest.java @@ -1,5 +1,6 @@ package com.loafle.overflow.module.member.service; +import com.loafle.overflow.module.domain.model.Domain; import com.loafle.overflow.module.member.model.Member; import com.loafle.overflow.module.meta.model.MetaMemberStatus; import com.loafle.overflow.spring.AppConfigTest; @@ -13,11 +14,12 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Date; +import java.util.List; /** * Created by insanity on 17. 6. 28. */ -@Ignore + @RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles("test") @ContextConfiguration(classes = {AppConfigTest.class}) @@ -47,5 +49,35 @@ public class MemberServiceTest { Assert.assertNotNull(m); } + @Test + public void readAllMemberByProbeKey() { + + List members = this.memberService.readAllByProbeKey("95d8bcdc739741dca74c4a0e489e0774"); + + Assert.assertNotEquals(members.size(), 0); + + } + + @Test + public void readAllMemberByApiKey() { + + List members = this.memberService.readAllByApiKey("52abd6fd57e511e7ac52080027658d13"); + + Assert.assertNotEquals(members.size(), 0); + } + + @Test + public void readAllMemberByDomain() { + + Domain domain = new Domain(); + + domain.setId(1); + + List members = this.memberService.readAllByDomain(domain); + + Assert.assertNotEquals(members.size(), 0); + + } + }