Skip to content

Commit

Permalink
refactor: 멤버 패키지 리팩토링
Browse files Browse the repository at this point in the history
- domain -> entity로 패키지명 변경
- mapping 메서드 mapper클래스에서 수행하도록 변경
  • Loading branch information
parksangchu committed May 20, 2024
1 parent a3fb446 commit 0696eda
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 35 deletions.
1 change: 1 addition & 0 deletions be/issue-tracker/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ out/
### VS Code ###
.vscode/

src/main/resources/application.properties

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.issuetracker.member.dto.MemberCreateDto;
import com.issuetracker.member.dto.SimpleMemberDto;
import com.issuetracker.member.model.Member;
import com.issuetracker.member.entity.Member;
import com.issuetracker.member.service.MemberService;
import jakarta.validation.Valid;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.issuetracker.member.model;
package com.issuetracker.member.entity;

import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -17,7 +17,7 @@ public class Member {
private final String nickname;
private final String email;
private final Long fileId;

public boolean hasSamePassword(String password) {
return this.password.equals(password);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.issuetracker.member.repository;

import com.issuetracker.global.repository.WithInsert;
import com.issuetracker.member.model.Member;
import com.issuetracker.member.entity.Member;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.issuetracker.member.dto.LoginMemberDto;
import com.issuetracker.member.dto.LoginTryDto;
import com.issuetracker.member.entity.Member;
import com.issuetracker.member.exception.LoginFailException;
import com.issuetracker.member.model.Member;
import com.issuetracker.member.repository.MemberRepository;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import com.issuetracker.file.service.FileService;
import com.issuetracker.member.dto.MemberCreateDto;
import com.issuetracker.member.dto.SimpleMemberDto;
import com.issuetracker.member.entity.Member;
import com.issuetracker.member.exception.MemberNotFoundException;
import com.issuetracker.member.model.Member;
import com.issuetracker.member.repository.MemberRepository;
import com.issuetracker.member.util.MemberMapper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -28,7 +29,7 @@ public class MemberService {
*/
@Transactional
public Member create(MemberCreateDto memberCreateDto) {
Member member = toMember(memberCreateDto);
Member member = MemberMapper.toMember(memberCreateDto);
Member created = memberRepository.insert(member);

log.info("새로운 유저가 생성되었습니다. {}", created);
Expand All @@ -52,7 +53,7 @@ public List<SimpleMemberDto> getMembers() {
public SimpleMemberDto getSimpleMemberById(String id) {
Member member = getMemberOrThrow(id);
String imgUrl = getImgUrl(member);
return new SimpleMemberDto(id, imgUrl);
return MemberMapper.toSimpleMemberDto(member, imgUrl);
}

/**
Expand All @@ -62,7 +63,7 @@ public SimpleMemberDto getSimpleMemberById(String id) {
public List<SimpleMemberDto> findSimpleMembersById(List<String> issueAssigneeIds) {
List<Member> members = (List<Member>) memberRepository.findAllById(issueAssigneeIds);
return members.stream()
.map(member -> new SimpleMemberDto(member.getId(), fileService.getImgUrlById(member.getFileId())))
.map(member -> MemberMapper.toSimpleMemberDto(member, fileService.getImgUrlById(member.getFileId())))
.toList();
}

Expand All @@ -81,16 +82,11 @@ private Member getMemberOrThrow(String id) {
return memberRepository.findById(id).orElseThrow(MemberNotFoundException::new);
}

private Member toMember(MemberCreateDto memberCreateDto) {
return new Member(memberCreateDto.getId(), memberCreateDto.getPassword(),
memberCreateDto.getNickname(), memberCreateDto.getEmail(), null);
}

private List<SimpleMemberDto> toSimpleMemberDtos(List<Member> members) {
List<SimpleMemberDto> simpleMemberDtos = new ArrayList<>();
for (Member member : members) {
String imgUrl = getImgUrl(member);
simpleMemberDtos.add(new SimpleMemberDto(member.getId(), imgUrl));
simpleMemberDtos.add(MemberMapper.toSimpleMemberDto(member, imgUrl));
}
return simpleMemberDtos;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.issuetracker.member.util;

import com.issuetracker.member.dto.MemberCreateDto;
import com.issuetracker.member.dto.SimpleMemberDto;
import com.issuetracker.member.entity.Member;

public class MemberMapper {

public static Member toMember(MemberCreateDto memberCreateDto) {
return new Member(memberCreateDto.getId(), memberCreateDto.getPassword(),
memberCreateDto.getNickname(), memberCreateDto.getEmail(), null);
}

public static SimpleMemberDto toSimpleMemberDto(Member member, String imgUrl) {
return new SimpleMemberDto(member.getId(), imgUrl);
}
}
15 changes: 0 additions & 15 deletions be/issue-tracker/src/main/resources/application.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.issuetracker.member.dto.LoginMemberDto;
import com.issuetracker.member.dto.LoginTryDto;
import com.issuetracker.member.entity.Member;
import com.issuetracker.member.exception.LoginFailException;
import com.issuetracker.member.model.Member;
import com.issuetracker.member.service.LoginService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.issuetracker.member.dto.MemberCreateDto;
import com.issuetracker.member.model.Member;
import com.issuetracker.member.entity.Member;
import com.issuetracker.member.service.MemberService;
import java.net.URI;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.issuetracker.member.model.Member;
import com.issuetracker.member.entity.Member;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import com.issuetracker.member.dto.LoginMemberDto;
import com.issuetracker.member.dto.LoginTryDto;
import com.issuetracker.member.entity.Member;
import com.issuetracker.member.exception.LoginFailException;
import com.issuetracker.member.model.Member;
import com.issuetracker.member.repository.MemberRepository;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import static org.mockito.Mockito.when;

import com.issuetracker.member.dto.MemberCreateDto;
import com.issuetracker.member.model.Member;
import com.issuetracker.member.entity.Member;
import com.issuetracker.member.repository.MemberRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand Down

0 comments on commit 0696eda

Please sign in to comment.