-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 🐛 오류 해결 * 🗃️ ViewRecord 테이블 추가 * 🗃️ UsersViewRecord 테이블 추가 * 🗃️ 연관관계 설정 * 🐛 컬럼명 변경 * 🗃️ BaseEntity 추가 * ✨ ViewRecordRepository와 Exception 작성 * ✨ UsersViewRecordRepository와 Exception 작성 * 🎨 ViewService 인터페이스 작성 --------- Co-authored-by: MinseoKangQ <[email protected]>
- Loading branch information
1 parent
943efdb
commit 8c91420
Showing
9 changed files
with
165 additions
and
0 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
40 changes: 40 additions & 0 deletions
40
src/main/java/org/example/gather_back_end/domain/UsersViewRecord.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,40 @@ | ||
package org.example.gather_back_end.domain; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.example.gather_back_end.util.entity.BaseEntity; | ||
|
||
@Entity | ||
@Table(name = "ViewRecord") | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class UsersViewRecord extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
// 회원 연관관계 | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
// 기록 테이블 연관관계 | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "view_record_id") | ||
private ViewRecord viewRecord; | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/example/gather_back_end/domain/ViewRecord.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,40 @@ | ||
package org.example.gather_back_end.domain; | ||
|
||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.example.gather_back_end.util.entity.BaseEntity; | ||
|
||
@Entity | ||
@Table(name = "ViewRecord") | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class ViewRecord extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
// 몇 번 봤는지 | ||
@Builder.Default | ||
private Integer viewCount = 0; | ||
|
||
// 크리에이터명 | ||
private String nickname; | ||
|
||
@OneToMany(mappedBy = "viewRecord", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<UsersViewRecord> usersViewRecordList = new ArrayList<>(); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/example/gather_back_end/repository/UsersViewRecordRepository.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,17 @@ | ||
package org.example.gather_back_end.repository; | ||
|
||
import java.util.Optional; | ||
import org.example.gather_back_end.domain.UsersViewRecord; | ||
import org.example.gather_back_end.view.exception.UsersViewRecordNotFoundException; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface UsersViewRecordRepository extends JpaRepository<UsersViewRecord, Long> { | ||
|
||
default UsersViewRecord getById(Long id) { | ||
return findById(id).orElseThrow(UsersViewRecordNotFoundException::new); | ||
} | ||
|
||
Optional<UsersViewRecord> findById(Long id); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/example/gather_back_end/repository/ViewRecordRepository.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,17 @@ | ||
package org.example.gather_back_end.repository; | ||
|
||
import java.util.Optional; | ||
import org.example.gather_back_end.domain.ViewRecord; | ||
import org.example.gather_back_end.view.exception.ViewRecordNotFoundException; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ViewRecordRepository extends JpaRepository<ViewRecord, Long> { | ||
|
||
default ViewRecord getById(Long id) { | ||
return findById(id).orElseThrow(ViewRecordNotFoundException::new); | ||
} | ||
|
||
Optional<ViewRecord> findById(Long id); | ||
} |
10 changes: 10 additions & 0 deletions
10
...ain/java/org/example/gather_back_end/view/exception/UsersViewRecordNotFoundException.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 org.example.gather_back_end.view.exception; | ||
|
||
import org.example.gather_back_end.util.exception.BaseException; | ||
|
||
public class UsersViewRecordNotFoundException extends BaseException { | ||
|
||
public UsersViewRecordNotFoundException() { | ||
super(ViewRecordErrorCode.USERS_VIEW_RECORD_NOT_FOUND); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/example/gather_back_end/view/exception/ViewRecordErrorCode.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 org.example.gather_back_end.view.exception; | ||
|
||
import static org.example.gather_back_end.util.constant.StaticValue.NOT_FOUND; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.example.gather_back_end.util.exception.BaseErrorCode; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ViewRecordErrorCode implements BaseErrorCode { | ||
|
||
VIEW_RECORD_NOT_FOUND(NOT_FOUND, "VIEW_RECORD_404_1", "ViewRecord 엔티티를 찾을 수 없습니다."), | ||
USERS_VIEW_RECORD_NOT_FOUND(NOT_FOUND, "USERS_VIEW_RECORD_404_1", "UsersViewRecord 엔티티를 찾을 수 없습니다."); | ||
|
||
private final int httpStatus; | ||
private final String code; | ||
private final String message; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/example/gather_back_end/view/exception/ViewRecordNotFoundException.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 org.example.gather_back_end.view.exception; | ||
|
||
import org.example.gather_back_end.util.exception.BaseException; | ||
|
||
public class ViewRecordNotFoundException extends BaseException { | ||
|
||
public ViewRecordNotFoundException() { | ||
super(ViewRecordErrorCode.VIEW_RECORD_NOT_FOUND); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/example/gather_back_end/view/service/ViewService.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,9 @@ | ||
package org.example.gather_back_end.view.service; | ||
|
||
import java.util.List; | ||
import org.example.gather_back_end.creator.dto.filtering.CreatorInfo; | ||
|
||
public interface ViewService { | ||
void execute(String providerId, String nickname); | ||
List<CreatorInfo> getViewCreatorList(String providerId); | ||
} |