-
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.
- Loading branch information
Showing
15 changed files
with
401 additions
and
66 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.