-
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 #192 from RollingPaper42/dev
feat: 토큰을 담은 쿠키 추가
- Loading branch information
Showing
15 changed files
with
418 additions
and
109 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.strcat.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.strcat.dto.HistoryDto; | ||
import com.strcat.dto.HistoryItem; | ||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Column; | ||
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 jakarta.persistence.OneToMany; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.util.List; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import org.apache.commons.lang3.builder.HashCodeExclude; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@Entity | ||
@Data | ||
@ToString(exclude = {"user", "board"}) | ||
@NoArgsConstructor | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class History { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@JsonIgnore | ||
@ManyToOne | ||
@JoinColumn(name = "user_id", nullable = false) | ||
private User user; | ||
|
||
@JsonIgnore | ||
@ManyToOne | ||
@JoinColumn(name = "board_id", nullable = false) | ||
private Board board; | ||
|
||
@Column(name = "visited_at", nullable = false) | ||
private LocalDateTime visitedAt; | ||
|
||
|
||
public History(User user, Board board, LocalDateTime visitedAt) { | ||
this.user = user; | ||
this.board = board; | ||
this.visitedAt = visitedAt; | ||
} | ||
|
||
public HistoryItem toDto() { | ||
return new HistoryItem(board.getEncryptedId(), board.getTitle(), visitedAt); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.strcat.dto; | ||
|
||
import java.util.List; | ||
|
||
public record HistoryDto(List<HistoryItem> history) { | ||
} |
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,17 @@ | ||
package com.strcat.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.time.LocalDateTime; | ||
|
||
@Schema(example = """ | ||
{ | ||
"encryptedBoardId": "string", | ||
"title": "string", | ||
"visitTime": "2024-02-07 07:54:54" | ||
} | ||
""") | ||
public record HistoryItem(String encryptedBoardId, String title, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul") | ||
LocalDateTime visitTime) { | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/strcat/repository/HistoryRepository.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,21 @@ | ||
package com.strcat.repository; | ||
|
||
import com.strcat.domain.History; | ||
import com.strcat.domain.User; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface HistoryRepository extends JpaRepository<History, Long> { | ||
public List<History> findByUserIdOrderByVisitedAtAsc(Long userId); | ||
|
||
@Modifying | ||
@Query("DELETE FROM History h WHERE h.user = :user") | ||
public void deleteHistoriesByUser(User user); | ||
|
||
@Modifying | ||
@Query("DELETE FROM History h WHERE h.id = :id") | ||
public void deleteById(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
Oops, something went wrong.