Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Member Entity 추가 이후 DIR 도메인의 연관관계 추가 및 로직 수정 #19

Merged
merged 2 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/java/com/mergedoc/backend/dir/entity/DIR.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mergedoc.backend.dir.entity;

import com.mergedoc.backend.Base.BaseEntity;
import com.mergedoc.backend.member.entity.Member;
import lombok.*;

import javax.persistence.*;
Expand All @@ -13,14 +14,19 @@ public class DIR extends InDIR{
@Id @GeneratedValue
private Long id;

// member 구현 후 연관관계 셋팅 필요
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
private DIR parent;

@Builder
public DIR(DIR parent) {
public DIR(Member member, DIR parent, String name, String path) {
this.member = member;
this.parent = parent;
this.setName(name);
this.setPath(path);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/mergedoc/backend/dir/entity/InDIR.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public abstract class InDIR extends BaseEntity {
private String path;
private String name;

public void setPath(String path) {
protected void setPath(String path) {
this.path = path;
}
public void setName(String name) {
protected void setName(String name) {
this.name = name;
}
}
16 changes: 14 additions & 2 deletions src/main/java/com/mergedoc/backend/dir/entity/PageInDIR.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mergedoc.backend.dir.entity;

import com.mergedoc.backend.Base.BaseEntity;
import com.mergedoc.backend.member.entity.Member;
import com.mergedoc.backend.page.entity.Page;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -20,10 +22,20 @@ public class PageInDIR extends InDIR{
@JoinColumn(name = "dir_id")
private DIR dir;

// Page Entity 추가 후 연관관계 추가
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "page_id")
private Page page;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@Builder
public PageInDIR(DIR dir) {
public PageInDIR(DIR dir, Page page, Member member, String path, String name) {
this.dir = dir;
this.page = page;
this.member = member;
this.setName(name);
this.setPath(path);
}
}
10 changes: 9 additions & 1 deletion src/main/java/com/mergedoc/backend/dir/entity/UnitInDIR.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mergedoc.backend.dir.entity;

import com.mergedoc.backend.Base.BaseEntity;
import com.mergedoc.backend.member.entity.Member;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -23,9 +24,16 @@ public class UnitInDIR extends InDIR{

// Unit Entity 추가 후 연관관계 추가

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;


@Builder
public UnitInDIR(DIR dir) {
public UnitInDIR(DIR dir, Member member, String path, String name) {
this.dir = dir;
this.member = member;
this.setName(name);
this.setPath(path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,68 +19,97 @@ public class DIRRepository {

private final EntityManager em;

public void saveDIR(DIR dir) {
em.persist(dir);
}
public void saveDIR(DIR dir) {em.persist(dir);}
public void saveUnitInDIR(UnitInDIR unitInDIR) {em.persist(unitInDIR);}
public void savePageInDIR(PageInDIR pageInDir) {
em.persist(pageInDir);
}

public List<InDIR> findAllByPath(String path) {
List<InDIR> findFiles = new ArrayList<>();
public DIR findDIRById(Long id) { return em.find(DIR.class, id); }
public PageInDIR findPageById(Long id) { return em.find(PageInDIR.class, id); }
public UnitInDIR findUnitById(Long id) { return em.find(UnitInDIR.class, id); }

public List<DIR> findDIRsInDIR(Long id) {
return em.createQuery("select d from DIR d " +
"where d.parent = :id" ,DIR.class)
.setParameter("id", id)
.getResultList();
}
public List<PageInDIR> findPagesInDIR(Long id) {
return em.createQuery("select p from PageInDIR p " +
"where p.dir.id = :id" ,PageInDIR.class)
.setParameter("id", id)
.getResultList();
}

public List<UnitInDIR> findUnitsInDIR(Long id) {
return em.createQuery("select u from UnitInDIR u " +
"where u.dir.id = :id" ,UnitInDIR.class)
.setParameter("id", id)
.getResultList();
}

public List<InDIR> findAllMemberFileByPath(Long memberId, String path) {
List<InDIR> result = new ArrayList<>();

findFiles.addAll(findDIRsByPath(path));
findFiles.addAll(findPagesByPath(path));
findFiles.addAll(findUnitsByPath(path));
result.addAll(findAllMemberDIRsByPath(memberId, path));
result.addAll(findAllMemberPagesByPath(memberId, path));
result.addAll(findAllMemberUnitsByPath(memberId, path));

return findFiles;
return result;
}

public List<DIR> findDIRsByPath(String path) {
return em.createQuery("select d from DIR d where d.path = :path", DIR.class)
public List<DIR> findAllMemberDIRsByPath(Long memberId, String path) {
return em.createQuery("select d from DIR d " +
"where d.member.id = :memberId and d.path = :path", DIR.class)
.setParameter("memberId", memberId)
.setParameter("path", path)
.getResultList();
}

public Optional<DIR> findDIRByPathAndName(String path, String name) {
return em.createQuery("select d from DIR d where " +
"d.path = :path and d.name = :name", DIR.class)
public List<PageInDIR> findAllMemberPagesByPath(Long memberId, String path) {
return em.createQuery("select p from PageInDIR p " +
"where p.member.id = :memberId and p.path = :path", PageInDIR.class)
.setParameter("memberId", memberId)
.setParameter("path", path)
.setParameter("name", name)
.getResultList()
.stream().findFirst();
.getResultList();
}


public List<UnitInDIR> findUnitsByPath(String path) {
return em.createQuery("select u from UnitInDIR u where u.path = :path", UnitInDIR.class)
public List<UnitInDIR> findAllMemberUnitsByPath(Long memberId, String path) {
return em.createQuery("select u from UnitInDIR u " +
"where u.member.id = :memberId and u.path = :path", UnitInDIR.class)
.setParameter("memberId", memberId)
.setParameter("path", path)
.getResultList();
}

public Optional<UnitInDIR> findUnitByPathAndName(String path, String name) {
return em.createQuery("select u from UnitInDIR u where " +
"u.path = :path and u.name = :name", UnitInDIR.class)
public Optional<DIR> findMemberDIRByPathName(Long memberId, String path, String name) {
return em.createQuery("select d from DIR d " +
"where d.member.id = :memberId and d.path = :path and d.name = :name", DIR.class)
.setParameter("memberId", memberId)
.setParameter("path", path)
.setParameter("name", name)
.getResultList()
.stream().findFirst();
.getResultList().stream()
.findFirst();
}

public List<PageInDIR> findPagesByPath(String path) {
return em.createQuery("select p from PageInDIR p where p.path = :path", PageInDIR.class)
public Optional<PageInDIR> findMemberPageByPathName(Long memberId, String path, String name) {
return em.createQuery("select p from PageInDIR p " +
"where p.member.id = :memberId and p.path = :path and p.name = :name", PageInDIR.class)
.setParameter("memberId", memberId)
.setParameter("path", path)
.getResultList();
.setParameter("name", name)
.getResultList().stream()
.findFirst();
}

public Optional<PageInDIR> findPageByPathAndName(String path, String name) {
return em.createQuery("select p from PageInDIR p where " +
"p.path = :path and p.name = :name", PageInDIR.class)
public Optional<UnitInDIR> findMemberUnitByPathName(Long memberId, String path, String name) {
return em.createQuery("select u from UnitInDIR u " +
"where u.member.id = :memberId and u.path = :path and u.name = :name", UnitInDIR.class)
.setParameter("memberId", memberId)
.setParameter("path", path)
.setParameter("name", name)
.getResultList()
.stream().findFirst();
.getResultList().stream()
.findFirst();
}

}
Loading