Skip to content

Commit

Permalink
Merge pull request #207 from Gongjakso/feat/portfolio
Browse files Browse the repository at this point in the history
fix: PortfolioData에서 필드 분리, Education 데이터 타입 변경
  • Loading branch information
jinnxyoung authored Sep 20, 2024
2 parents c9f09c6 + e5a9118 commit fb1d79d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static ApplyRes of(Apply apply) {
.memberId(apply.getMember().getId())
.leaderName(apply.getTeam().getMember().getName())
.portfolioId(apply.getPortfolioInfo().getPortfolio() != null ? apply.getPortfolioInfo().getPortfolio().getId() : null)
.portfolioName(apply.getPortfolioInfo().getPortfolio() != null ? apply.getPortfolioInfo().getPortfolio().getPortfolioData().portfolioName() : null)
.portfolioName(apply.getPortfolioInfo().getPortfolio() != null ? apply.getPortfolioInfo().getPortfolio().getPortfolioName() : null)
.isPrivate(apply.getPortfolioInfo().isPrivate())
.body(apply.getBody())
.status(apply.getStatus().getDescription())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public record PortfolioReq (
public record Education (
String school,
String grade,
Boolean isActive
String state
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static PortfolioRes from(Portfolio portfolio) {
PortfolioData portfolioData = portfolio.getPortfolioData();
return new PortfolioRes(
portfolio.getId(),
portfolioData.portfolioName(),
portfolio.getPortfolioName(),
portfolioData.educationList(),
portfolioData.workList(),
portfolioData.activityList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record SimplePortfolioRes(
public static SimplePortfolioRes of(Portfolio portfolio) {
return new SimplePortfolioRes(
portfolio.getId(),
portfolio.getPortfolioData().portfolioName(),
portfolio.getPortfolioName(),
portfolio.getModifiedAt()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class Portfolio extends BaseTimeEntity {
@Column(name = "portfolio_id", nullable = false, columnDefinition = "bigint")
private Long id;

@Column(name = "portfolio_name", nullable = false, columnDefinition = "varchar(50)")
private String portfolioName;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;
Expand All @@ -34,12 +37,17 @@ public class Portfolio extends BaseTimeEntity {
private PortfolioData portfolioData;

@Builder
public Portfolio(Member member, PortfolioData portfolioData) {
public Portfolio(Member member, String portfolioName, PortfolioData portfolioData) {
this.member = member;
this.portfolioName = portfolioName;
this.portfolioData = portfolioData;
}

public void update(PortfolioData updatedData) {
public void updateName(String updatedName) {
this.portfolioName = updatedName;
}

public void updateData(PortfolioData updatedData) {
this.portfolioData = updatedData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ public class PortfolioService {

private final PortfolioRepository portfolioRepository;

// PortfolioReq -> PortfolioData 변환
private PortfolioData convertToPortfolioData(PortfolioReq portfolioReq) {
String portfolioName = portfolioReq.portfolioName();
// PortfolioName 생성 로직을 분리
private String generatePortfolioName(String portfolioName) {
if (portfolioName == null || portfolioName.isEmpty()) {
long existingPortfolioCount = portfolioRepository.countByDeletedAtIsNull();
portfolioName = "포트폴리오 " + (existingPortfolioCount + 1);
return "포트폴리오 " + (existingPortfolioCount + 1);
}
return portfolioName;
}

// PortfolioReq -> PortfolioData 변환
private PortfolioData convertToPortfolioData(PortfolioReq portfolioReq) {
List<PortfolioData.Education> educationList = portfolioReq.educationList() != null
? portfolioReq.educationList().stream()
.map(education -> new PortfolioData.Education(
education.school(),
education.grade(),
education.isActive()
education.state()
))
.toList()
: List.of();
Expand Down Expand Up @@ -89,19 +92,24 @@ private PortfolioData convertToPortfolioData(PortfolioReq portfolioReq) {
.toList()
: List.of();

return new PortfolioData(portfolioName, educationList, workList, activityList, awardList, certificateList, snsList);
return new PortfolioData(educationList, workList, activityList, awardList, certificateList, snsList);
}

@Transactional
public PortfolioRes registerPortfolio(Member member, PortfolioReq portfolioReq) {
if (member == null) {
throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION);
}

String portfolioName = generatePortfolioName(portfolioReq.portfolioName());
PortfolioData portfolioData = convertToPortfolioData(portfolioReq);

Portfolio portfolio = Portfolio.builder()
.member(member)
.portfolioName(portfolioName)
.portfolioData(portfolioData)
.build();

Portfolio savedPortfolio = portfolioRepository.save(portfolio);

return PortfolioRes.from(savedPortfolio);
Expand All @@ -124,8 +132,15 @@ public PortfolioRes updatePortfolio(Member member, Long portfolioId, PortfolioRe
if (!portfolio.getMember().getId().equals(member.getId())) {
throw new ApplicationException(ErrorCode.FORBIDDEN_EXCEPTION);
}

if (portfolioReq.portfolioName() != null) {
String portfolioName = generatePortfolioName(portfolioReq.portfolioName());
portfolio.updateName(portfolioName);
}

PortfolioData updatedPortfolioData = convertToPortfolioData(portfolioReq);
portfolio.update(updatedPortfolioData);
portfolio.updateData(updatedPortfolioData);

Portfolio updatedPortfolio = portfolioRepository.save(portfolio);

return PortfolioRes.from(updatedPortfolio);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;

public record PortfolioData (
String portfolioName,
List<Education> educationList,
List<Work> workList,
List<Activity> activityList,
Expand All @@ -15,7 +14,7 @@ public record PortfolioData (
public record Education (
String school,
String grade,
Boolean isActive
String state
) {
}

Expand Down

0 comments on commit fb1d79d

Please sign in to comment.