-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from Team-Smeme/sohyeon_#181
[FIX] Soft Delete 구조 변경
- Loading branch information
Showing
12 changed files
with
123 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.smeme.server.model; | ||
|
||
import com.smeme.server.model.topic.Topic; | ||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import static jakarta.persistence.FetchType.LAZY; | ||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
public class DeletedDiary { | ||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
@Column(name = "diary_id") | ||
private Long id; | ||
|
||
@Column(columnDefinition = "TEXT") | ||
private String content; | ||
|
||
@Column(nullable = false) | ||
@Enumerated(value = EnumType.STRING) | ||
private LangType targetLang; | ||
|
||
private boolean isPublic; | ||
|
||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "topic_id") | ||
private Topic topic; | ||
|
||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "member_id") | ||
private Member member; | ||
|
||
private LocalDateTime createdAt; | ||
|
||
private LocalDateTime updatedAt; | ||
|
||
public DeletedDiary(Diary diary) { | ||
this.content = diary.getContent(); | ||
this.targetLang = diary.getTargetLang(); | ||
this.isPublic = diary.isPublic(); | ||
this.topic = diary.getTopic(); | ||
this.member = diary.getMember(); | ||
this.createdAt = diary.getCreatedAt(); | ||
this.updatedAt = LocalDateTime.now(); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/smeme/server/repository/diary/DeletedDiaryRepository.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.smeme.server.repository.diary; | ||
|
||
import com.smeme.server.model.DeletedDiary; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public interface DeletedDiaryRepository extends JpaRepository<DeletedDiary, Long> { | ||
void deleteByUpdatedAtBefore(LocalDateTime expiredAt); | ||
} |
3 changes: 0 additions & 3 deletions
3
src/main/java/com/smeme/server/repository/diary/DiaryCustomRepository.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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
package com.smeme.server.repository.diary; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import com.smeme.server.model.Diary; | ||
|
||
public interface DiaryCustomRepository { | ||
List<Diary> findByExpiredDate(); | ||
|
||
Optional<Diary> findByIdFetchJoinCorrections(Long id); | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/smeme/server/scheduler/DiaryScheduler.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,19 @@ | ||
package com.smeme.server.scheduler; | ||
|
||
import com.smeme.server.service.DiaryService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@EnableScheduling | ||
@RequiredArgsConstructor | ||
public class DiaryScheduler { | ||
private final DiaryService diaryService; | ||
|
||
@Scheduled(cron = "0 0 0 * * *") | ||
public void deleteExpiredDiaries() { | ||
diaryService.deleteExpiredDiary(); | ||
} | ||
} |
26 changes: 8 additions & 18 deletions
26
...server/controller/ScheduleController.java → ...me/server/scheduler/MessageScheduler.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 |
---|---|---|
@@ -1,34 +1,24 @@ | ||
package com.smeme.server.controller; | ||
|
||
import java.time.LocalDateTime; | ||
package com.smeme.server.scheduler; | ||
|
||
import com.smeme.server.config.ValueConfig; | ||
import com.smeme.server.service.MessageService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.smeme.server.service.DiaryService; | ||
import com.smeme.server.service.MessageService; | ||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import java.time.LocalDateTime; | ||
|
||
@RestController | ||
@Component | ||
@EnableScheduling | ||
@RequiredArgsConstructor | ||
public class ScheduleController { | ||
|
||
public class MessageScheduler { | ||
private final MessageService messageService; | ||
private final DiaryService diaryService; | ||
private final ValueConfig valueConfig; | ||
|
||
// @Scheduled(cron = "0 0/30 * * * *") | ||
@Scheduled(cron = "${fcm.cron_expression}") | ||
public void pushMessage() throws InterruptedException { | ||
Thread.sleep(1000); | ||
messageService.pushMessageForTrainingTime(LocalDateTime.now(), valueConfig.getMESSAGE_TITLE(), valueConfig.getMESSAGE_BODY()); | ||
} | ||
|
||
@Scheduled(cron = "0 0 0 * * *") | ||
public void deleteExpiredDiaries() { | ||
diaryService.deleteByExpiredDate(); | ||
} | ||
} |
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