-
Notifications
You must be signed in to change notification settings - Fork 0
/
InitDaoImpl.java
84 lines (70 loc) · 3.1 KB
/
InitDaoImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.hiit.api.domain.dao.it.in;
import com.hiit.api.domain.dao.AbstractDataConverter;
import com.hiit.api.domain.dao.AbstractJpaDao;
import com.hiit.api.domain.dao.exception.DataNotFoundException;
import com.hiit.api.repository.dao.bussiness.InItRepository;
import com.hiit.api.repository.entity.business.it.InItEntity;
import com.hiit.api.repository.entity.business.it.ItStatus;
import com.hiit.api.repository.entity.business.member.HiitMemberEntity;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public class InitDaoImpl extends AbstractJpaDao<InItEntity, Long, InItData> implements InItDao {
private final InItRepository repository;
public InitDaoImpl(
JpaRepository<InItEntity, Long> jpaRepository,
AbstractDataConverter<InItEntity, InItData> converter,
InItRepository repository) {
super(jpaRepository, converter);
this.repository = repository;
}
@Override
public List<InItData> findAllActiveStatusByMember(Long memberId) {
return findStatusByMember(memberId, ItStatus.ACTIVE);
}
@Override
public List<InItData> findAllEndStatusByMember(Long memberId) {
return findStatusByMember(memberId, ItStatus.END);
}
private List<InItData> findStatusByMember(Long memberId, ItStatus status) {
HiitMemberEntity member = HiitMemberEntity.builder().id(memberId).build();
List<InItEntity> sources = repository.findAllByHiitMemberAndStatus(member, status);
return sources.stream().map(converter::from).collect(Collectors.toList());
}
@Override
public InItData findActiveStatusByIdAndMember(Long inItId, Long memberId) {
return findStatusByIdAndMember(memberId, inItId, ItStatus.ACTIVE);
}
@Override
public InItData findEndStatusByIdAndMember(Long inItId, Long memberId) {
return findStatusByIdAndMember(memberId, inItId, ItStatus.END);
}
private InItData findStatusByIdAndMember(Long memberId, Long inItId, ItStatus active) {
HiitMemberEntity member = HiitMemberEntity.builder().id(memberId).build();
Optional<InItEntity> source = repository.findByIdAndHiitMemberAndStatus(inItId, member, active);
if (source.isEmpty()) {
throw new DataNotFoundException("InIt id : " + inItId + " Member id : " + memberId);
}
return converter.from(source.get());
}
@Override
public InItData findActiveStatusByTargetIdAndMember(Long targetId, Long memberId) {
return findStatusByTargetIdAndMember(targetId, memberId, ItStatus.ACTIVE);
}
@Override
public InItData findEndStatusByTargetIdAndMember(Long targetId, Long memberId) {
return findStatusByTargetIdAndMember(targetId, memberId, ItStatus.END);
}
private InItData findStatusByTargetIdAndMember(Long targetId, Long memberId, ItStatus status) {
HiitMemberEntity member = HiitMemberEntity.builder().id(memberId).build();
Optional<InItEntity> source =
repository.findByTargetIdAndStatusAndHiitMember(targetId, status, member);
if (source.isEmpty()) {
throw new DataNotFoundException("Target id : " + targetId + " Member id : " + memberId);
}
return converter.from(source.get());
}
}