-
Notifications
You must be signed in to change notification settings - Fork 7
member-api many commit #43
Changes from all commits
a028c06
9bc8f2e
9e0b4ba
4e30c63
6de5c78
2caa9ea
f2ac6bf
afd37ba
e197892
dc15595
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package io.codechobo.member.application; | ||
|
||
import io.codechobo.member.domain.Member; | ||
import io.codechobo.member.domain.Social; | ||
import io.codechobo.member.domain.repository.MemberRepository; | ||
import io.codechobo.member.domain.repository.SocialRepository; | ||
import io.codechobo.member.domain.support.SocialDto; | ||
import io.codechobo.member.domain.util.EntityDtoConverter; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import javax.persistence.EntityNotFoundException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author loustler | ||
* @since 10/24/2016 23:42 | ||
*/ | ||
@Service | ||
@Transactional | ||
public class SocialService { | ||
@Autowired | ||
private SocialRepository socialRepository; | ||
@Autowired | ||
private MemberRepository memberRepository; | ||
|
||
public List<SocialDto> all() { | ||
List<Social> socialList = socialRepository.findAll(); | ||
|
||
return EntityDtoConverter.socialListConvertToDtoList(socialList); | ||
} | ||
|
||
/** | ||
* Get multi social using member sequence. | ||
* | ||
* @param memberSequence | ||
* @return List if not found return empty size | ||
* @throws NullPointerException in case not found any social | ||
*/ | ||
public List<SocialDto> getSocials(final Long memberSequence) { | ||
List<Social> socialList = socialRepository.findByMemberSeq(Objects.requireNonNull(memberSequence)); | ||
|
||
if(Objects.isNull(socialList)) return null; | ||
|
||
return EntityDtoConverter.socialListConvertToDtoList(socialList); | ||
} | ||
|
||
/** | ||
* Get single social using social sequence. | ||
* | ||
* @param socialSequence | ||
* @return SocialDto | ||
*/ | ||
public SocialDto getSocial(final Long socialSequence) { | ||
Social foundSocial = socialRepository.findOne(Objects.requireNonNull(socialSequence)); | ||
|
||
return EntityDtoConverter.socialConvertToDto(foundSocial); | ||
} | ||
|
||
/** | ||
* Create SocialDto using member sequence in socialDto. | ||
* | ||
* @param socialDto | ||
* @return SocialDto | ||
* @throws NullPointerException in case socialDto's member sequence is null | ||
*/ | ||
public SocialDto createSocial(final SocialDto socialDto) { | ||
Member foundMember = memberRepository.findOne(Objects.requireNonNull(socialDto.getMemberSequence())); | ||
|
||
Social social = EntityDtoConverter.socialDtoConvertToEntity(socialDto); | ||
|
||
social.setMember(foundMember); | ||
|
||
Social created = socialRepository.save(social); | ||
|
||
return EntityDtoConverter.socialConvertToDto(created); | ||
} | ||
|
||
/** | ||
* Update Social using Social Sequence. | ||
* | ||
* @param socialDto | ||
* @return SocialDto | ||
* @throws EntityNotFoundException in case social sequence is null or not exist. | ||
* @throws NullPointerException in case social sequence is null. | ||
*/ | ||
public SocialDto updateSocial(final SocialDto socialDto) { | ||
if (!socialRepository.exists(Objects.requireNonNull(socialDto.getSequence()))) | ||
throw new EntityNotFoundException(socialDto.getSequence()+" is not exist."); | ||
|
||
Member foundMember = memberRepository.findOne(Objects.requireNonNull(socialDto.getMemberSequence())); | ||
|
||
Social updateSocial = new Social(socialDto); | ||
|
||
updateSocial.setMember(foundMember); | ||
|
||
Social updated = socialRepository.save(updateSocial); | ||
|
||
return EntityDtoConverter.socialConvertToDto(updated); | ||
} | ||
|
||
/** | ||
* Delete social using social sequence. | ||
* | ||
* @param socialSequence NotNull | ||
* @throws NullPointerException in case social sequence is null. | ||
*/ | ||
public void deleteSocial(final Long socialSequence) { | ||
socialRepository.delete(Objects.requireNonNull(socialSequence)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,24 +2,25 @@ | |
|
||
|
||
import io.codechobo.member.domain.support.SocialDto; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by Loustler on 8/7/16. | ||
*/ | ||
@Entity | ||
@NoArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Setter | ||
@Getter | ||
public class Social { | ||
|
@@ -35,8 +36,15 @@ public class Social { | |
@Column(name = "SOCIAL_ACCESS_TOKEN") | ||
private String token; // accessToken 등 token정보 | ||
|
||
@ManyToOne(optional = false, fetch = FetchType.LAZY) | ||
@JoinColumn(name = "MEMBER_SEQ") | ||
/** | ||
* Transactional 범위밖에서 벗어나서 LAZY에서 EAGER(default)로 수정 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lazy를 써야하는 순간이 어느순간인지 고민해보면 좋을거같네요. |
||
* Why? List일 때 proxy initialize fail | ||
* @see io.codechobo.member.domain.util.EntityDtoConverter#socialListConvertToDtoList(List) | ||
* | ||
* FK update 못하게 false 처리 | ||
*/ | ||
@ManyToOne | ||
@JoinColumn(name = "MEMBER_SEQ", updatable = false) | ||
private Member member; | ||
|
||
public Social(final SocialDto socialDto) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,11 @@ | |
|
||
|
||
/** | ||
* Created by Loustler on 8/21/16. | ||
* @author loustler | ||
* @since 08/21/2016 | ||
*/ | ||
@Repository | ||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
Member findByNickName(String nickname); | ||
Member findByEmail(String email); | ||
Member findByNickName(final String nickname); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. final 을 넣으신 이유가 있나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 굳이 필요없으려나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 일반적으로 Method 파라미터에는 final 은 선언해서 사용하면 실수에 의한 재 대입을 막을 수 있어서 좋은 패턴인데 인터페이스의 메소드는 파라미터를 사용하는 부분이 없어서 의미가 없긴합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 굳이 필요없군요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 굳이 삭제를 따로 할 필요도 없어 보입니다^^;; 바이트 코드가 미세하게 증가할려나;; 그건 class파일을 봐봐야 할 것 같고 저는 습관적으로 붙이는 편이라 가끔 인터페이스에도 붙이기도 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 통일성을 위해서 삭제를 하든지 추가를 하든지 해야될 것 같아서요 .. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 두 method 모두 final로 처리되어 있어서 그대로 놔두겠습니다
|
||
Member findByEmail(final String email); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
만약 Objects.requireNonNull이 널로 넘어오면 어떤식으로 동작하게 되나요?