added read List<Memeber>

By Apkey, ProbeKey, Domain
This commit is contained in:
snoop 2017-09-27 14:46:59 +09:00
parent d9a352e32f
commit 162fa61d3c
6 changed files with 114 additions and 1 deletions

View File

@ -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<DomainMember, Long> {
@Query("SELECT dm.member from DomainMember dm where dm.domain = (:domain)")
List<Member> findAllMemberByDomain(@Param("domain") Domain domain);
}

View File

@ -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<Member> readAllMemberByDomain(Domain domain) {
return this.domainMemberDAO.findAllMemberByDomain(domain);
}
}

View File

@ -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<Member> readAllByProbeKey(String probeKey) {
Probe probe = this.probeService.readByProbeKey(probeKey);
if(probe == null) {
return null;
}
return this.domainMemberService.readAllMemberByDomain(probe.getDomain());
}
public List<Member> readAllByApiKey(String apikey) {
ApiKey apiKey = this.apiKeyService.readByApiKey(apikey);
if(apiKey == null) {
return null;
}
return this.domainMemberService.readAllMemberByDomain(apiKey.getDomain());
}
public List<Member> readAllByDomain(Domain domain) {
return this.domainMemberService.readAllMemberByDomain(domain);
}
}

View File

@ -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);

View File

@ -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<Member> members = this.domainMemberService.readAllMemberByDomain(domain);
Assert.assertNotEquals(members.size(), 0);
for(Member member : members) {
System.out.println(member.getEmail());
}
}
}

View File

@ -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<Member> members = this.memberService.readAllByProbeKey("95d8bcdc739741dca74c4a0e489e0774");
Assert.assertNotEquals(members.size(), 0);
}
@Test
public void readAllMemberByApiKey() {
List<Member> members = this.memberService.readAllByApiKey("52abd6fd57e511e7ac52080027658d13");
Assert.assertNotEquals(members.size(), 0);
}
@Test
public void readAllMemberByDomain() {
Domain domain = new Domain();
domain.setId(1);
List<Member> members = this.memberService.readAllByDomain(domain);
Assert.assertNotEquals(members.size(), 0);
}
}