-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: 테스트 환경 콘솔 로그 출력 설정 추가 - additivity-false는 기본 콘솔 로그와의 중복 출력 방지를 위함 * test: 핀 수정 인수 테스트 추가 * feat: 핀 수정 시 수정 이력 저장 구현 및 테스트 * refactor: 사용하지 않는 변수 삭제 * feat: 새 핀 추가시에도 핀 이력 저장 * feat: 핀 수정 이력이 참조하는 엔티티 삭제 시 soft delete 하도록 이벤트 구현 - 회원 차단 시, 토픽 삭제 시, 핀 삭제 시 soft delete * feat: 핀 수정 이력은 삭제 개념이 없는 것으로 복구 (이전 커밋 revert) * test: 핀 수정 이력 이벤트 테스트 실패 수정 * test: 빠른 테스트 조건문 확인을 위해 assertAll softly로 변경 * refactor: hard delete 메서드 Query 작성해서 Modifying 적용 * rename: PinUpdateHistory 에서 PinHistory로 네이밍 변경 - 핀의 정보 변경 이력을 관리하는데 update라는 수식어가 불필요함 * test: 테스트 displayName 핀 정보 이력 관련 용어 통일 * fix: 핀 변경 이력 엔티티 컬럼 수정 - pin의 FK 외에도 변경 내용을 함께 저장해야 함 * refactor: 불필요한 공백 제거 * test: 일시 검증 메서드 수정, 핀 변경 일시 검증 추가 * feat: 핀 변경 이력 엔티티에 핀 변경 일시 컬럼 추가 - pinHistory의 createdAt과 저장 시 pin 의 updatedAt은 미세하게 다르므로 정확한 일시를 기록 * fix: PinHistoryCommandService 트랜잭션 어노테이션 추가 * fix: 핀 변경 이력 롤백 테스트 예외 수정, 실패 테스트 disabled 처리 * fix: 이벤트를 통한 롤백 테스트 통합 테스트로 이동 - DataJpaTest에서는 내부 트랜잭션의 롤백을 검증할 수 없음 * test: 새로운 테스트에 테스트 컨테이너 적용
- Loading branch information
Showing
15 changed files
with
393 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...d/src/main/java/com/mapbefine/mapbefine/history/application/PinHistoryCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.mapbefine.mapbefine.history.application; | ||
|
||
import com.mapbefine.mapbefine.history.domain.PinHistory; | ||
import com.mapbefine.mapbefine.history.domain.PinHistoryRepository; | ||
import com.mapbefine.mapbefine.pin.domain.Pin; | ||
import com.mapbefine.mapbefine.pin.event.PinUpdateEvent; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Transactional | ||
@Service | ||
public class PinHistoryCommandService { | ||
|
||
private final PinHistoryRepository pinHistoryRepository; | ||
|
||
public PinHistoryCommandService(PinHistoryRepository pinHistoryRepository) { | ||
this.pinHistoryRepository = pinHistoryRepository; | ||
} | ||
|
||
@EventListener | ||
public void saveHistory(PinUpdateEvent event) { | ||
Pin pin = event.pin(); | ||
pinHistoryRepository.save(new PinHistory(pin, event.member())); | ||
|
||
log.debug("pin history saved for update pin id =: {}", pin.getId()); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
backend/src/main/java/com/mapbefine/mapbefine/history/domain/PinHistory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.mapbefine.mapbefine.history.domain; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
import com.mapbefine.mapbefine.common.entity.BaseTimeEntity; | ||
import com.mapbefine.mapbefine.member.domain.Member; | ||
import com.mapbefine.mapbefine.pin.domain.Pin; | ||
import com.mapbefine.mapbefine.pin.domain.PinInfo; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@EntityListeners(AuditingEntityListener.class) | ||
@Entity | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Getter | ||
public class PinHistory extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "pin_id", nullable = false) | ||
private Pin pin; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "member_id", nullable = false) | ||
private Member member; | ||
|
||
@Embedded | ||
private PinInfo pinInfo; | ||
|
||
@Column(name = "pin_updated_at", nullable = false) | ||
private LocalDateTime pinUpdatedAt; | ||
|
||
public PinHistory(Pin pin, Member member) { | ||
this.pin = pin; | ||
PinInfo history = pin.getPinInfo(); | ||
this.pinInfo = PinInfo.of(history.getName(), history.getDescription()); | ||
this.pinUpdatedAt = pin.getUpdatedAt(); | ||
this.member = member; | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/mapbefine/mapbefine/history/domain/PinHistoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.mapbefine.mapbefine.history.domain; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface PinHistoryRepository extends JpaRepository<PinHistory, Long> { | ||
List<PinHistory> findAllByPinId(Long pinId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/com/mapbefine/mapbefine/pin/event/PinUpdateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mapbefine.mapbefine.pin.event; | ||
|
||
import com.mapbefine.mapbefine.member.domain.Member; | ||
import com.mapbefine.mapbefine.pin.domain.Pin; | ||
|
||
public record PinUpdateEvent(Pin pin, Member member) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.