Skip to content

Commit b2ff5aa

Browse files
Fix: 이미지 변경 수정
Fix: 이미지 변경 수정
2 parents a5b8fe4 + bf9a165 commit b2ff5aa

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

src/main/java/flipnote/image/adapter/out/persistence/ImageRefRepositoryAdapter.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void activate(Long imageRefId, ReferenceType referenceType, Long referenc
5656
() -> new IllegalArgumentException("ImageRef is Blank")
5757
);
5858

59-
imageRef.getReference().activate(referenceType, referenceId);
59+
imageRef.activate(referenceType, referenceId);
6060

6161
imageRefRepository.save(imageRef);
6262

@@ -92,9 +92,22 @@ public void delete(Long id) {
9292

9393
@Override
9494
public ImageRefRow findById(Long imageRefId) {
95-
ImageRef imageRef = imageRefRepository.findById(imageRefId).orElseThrow(
96-
() -> new IllegalArgumentException("Image")
97-
);
95+
96+
log.debug("{}", imageRefId);
97+
98+
Optional<ImageRef> imageRefOptional = imageRefRepository.findById(imageRefId);
99+
100+
log.debug("{}", imageRefOptional.get().getId());
101+
102+
ImageRef imageRef = imageRefOptional.get();
103+
104+
// ImageRef imageRef = imageRefRepository.findById(imageRefId).orElseThrow(
105+
// () -> new IllegalArgumentException("error")
106+
// );
107+
108+
if(imageRef.getReference()==null) {
109+
return new ImageRefRow(imageRef.getId(), null, null);
110+
}
98111

99112
ReferenceType type = imageRef.getReference().getType();
100113
Long referenceId = imageRef.getReference().getId();

src/main/java/flipnote/image/application/service/ChangeImageService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public ChangeImageResult changeImage(Long newImageRefId, ReferenceType type, Lon
3535
if(newImageRefId == null) {
3636
current.ifPresent(id -> imageRefPort.delete(id));
3737

38+
log.debug("다른 대상일 경우");
3839
return ChangeImageResult.from(null, defaultImagePort.defaultUrl(type));
40+
3941
}
4042

4143
//2. 신규 이미지로 변경할 경우
@@ -45,12 +47,16 @@ public ChangeImageResult changeImage(Long newImageRefId, ReferenceType type, Lon
4547
if(target.referenceId() != null &&
4648
!(target.type() == type && target.referenceId() == referenceId)
4749
) {
50+
log.debug("다른 대상 연결");
4851
log.error("conflict_image_ref");
4952
throw new IllegalArgumentException("conflict_image_ref");
5053
}
5154

5255
// 다른 경우 기존 연결 제거 후 새 연결
5356
if(current.isPresent() && !current.get().equals(newImageRefId)) {
57+
58+
log.debug("기존 연결 삭제 후 새연결");
59+
5460
current.ifPresent(imageRefPort::delete);
5561
imageRefPort.activate(newImageRefId, type, referenceId);
5662
}

src/main/java/flipnote/image/domain/model/BaseEntity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import org.springframework.data.annotation.CreatedDate;
66
import org.springframework.data.annotation.LastModifiedDate;
7+
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
78

89
import jakarta.persistence.Column;
910
import jakarta.persistence.EntityListeners;
@@ -12,7 +13,7 @@
1213

1314
@Getter
1415
@MappedSuperclass
15-
@EntityListeners(AutoCloseable.class)
16+
@EntityListeners(AuditingEntityListener.class)
1617
public abstract class BaseEntity {
1718

1819
@CreatedDate

src/main/java/flipnote/image/domain/model/reference/ImageRef.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@
2323

2424
@Getter
2525
@Entity
26-
@Table(name = "image_reference",
27-
uniqueConstraints = @UniqueConstraint(
28-
name = "uk_image_ref",
29-
columnNames = {"reference_type", "reference_id"}
30-
)
31-
)
26+
@Table(name = "image_reference")
3227
@NoArgsConstructor(access = AccessLevel.PROTECTED)
3328
public class ImageRef extends BaseEntity {
3429
@Id

0 commit comments

Comments
 (0)