Skip to content

Commit

Permalink
Feat: 기록하기 기능 구현 추가
Browse files Browse the repository at this point in the history
- 패키지 구조 수정
- 기록하기 CQRS 패턴 적용
- 기록하기 유닛 테스트 추가

Fixes: #52
  • Loading branch information
한해용 committed Feb 28, 2024
1 parent 470ebd9 commit 38172a2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Record {
@Column(name = "record_date")
private LocalDateTime recordDate;

@OneToMany(cascade = CascadeType.ALL)
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "record_number")
private List<Image> images = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.dnd.gooding.record.query.dto.RecordData;
import com.dnd.gooding.user.command.domain.MemberId;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -32,6 +33,9 @@ public RecordData getRecord(RecordNo recordNo) {
public List<RecordData> getRecord(MemberId recorderMemberId) {
List<RecordData> records = recordDataDao.findByRecorderId(recorderMemberId.getId());
List<ImageData> images = imageDataDao.findByRecordNumberIn(toRecordIds(records));
Map<String, List<ImageData>> imageMap =
images.stream().collect(Collectors.groupingBy(ImageData::getRecordNumber));
records.forEach(record -> record.setImages(imageMap.get(record.getRecordNumber())));
return records;
}

Expand Down
19 changes: 7 additions & 12 deletions src/main/java/com/dnd/gooding/record/query/dto/RecordData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
import java.util.Collections;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.*;

import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.Subselect;
Expand Down Expand Up @@ -63,8 +57,7 @@ public class RecordData {
@Column(name = "description")
private String description;

@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "record_number")
@Transient
private List<ImageData> images = new ArrayList<>();

protected RecordData() {}
Expand All @@ -78,8 +71,7 @@ public RecordData(
String recorderId,
String recorderName,
String title,
String description,
List<ImageData> images) {
String description) {
this.recordNumber = recordNumber;
this.placeTitle = placeTitle;
this.placeLatitude = placeLatitude;
Expand All @@ -88,7 +80,6 @@ public RecordData(
this.recorderName = recorderName;
this.title = title;
this.description = description;
this.images.addAll(images);
}

public String getRecordNumber() {
Expand Down Expand Up @@ -120,4 +111,8 @@ public String getDescription() {
public List<ImageData> getImages() {
return Collections.unmodifiableList(images);
}

public void setImages(List<ImageData> images) {
this.images = images;
}
}

0 comments on commit 38172a2

Please sign in to comment.