Skip to content

Commit

Permalink
✨ 내가 조회한 크리에이터 기능 추가 (#115)
Browse files Browse the repository at this point in the history
* 🐛 오류 해결

* 🗃️ ViewRecord 테이블 추가

* 🗃️ UsersViewRecord 테이블 추가

* 🗃️ 연관관계 설정

* 🐛 컬럼명 변경

* 🗃️ BaseEntity 추가

* ✨ ViewRecordRepository와 Exception 작성

* ✨ UsersViewRecordRepository와 Exception 작성

* 🎨 ViewService 인터페이스 작성

---------

Co-authored-by: MinseoKangQ <[email protected]>
  • Loading branch information
Jindongleee and MinseoKangQ committed Nov 16, 2024
1 parent 943efdb commit 8c91420
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/example/gather_back_end/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public class User extends BaseEntity {
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Work> workList = new ArrayList<>();

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<UsersViewRecord> usersViewRecordList = new ArrayList<>();

// 유저 생성
public static User createUserInfo(String profileImgUrl, String username, String name, String email, String role, String nickname) {
return User.builder()
Expand Down
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 src/main/java/org/example/gather_back_end/domain/ViewRecord.java
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<>();
}
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);
}
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);
}
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);
}
}
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;
}
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);
}
}
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);
}

0 comments on commit 8c91420

Please sign in to comment.