Skip to content

Commit 6855c14

Browse files
committed
refactor: Archive 관련 매핑 테이블 추상 클래스 삭제 & SharingArchive 매핑 테이블 연동.
1 parent 69757b9 commit 6855c14

File tree

7 files changed

+63
-30
lines changed

7 files changed

+63
-30
lines changed
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package org.tuna.zoopzoop.backend.domain.archive.archive.entity;
22

3-
import jakarta.persistence.Column;
4-
import jakarta.persistence.Entity;
5-
import jakarta.persistence.Inheritance;
6-
import jakarta.persistence.InheritanceType;
3+
import jakarta.persistence.*;
74
import lombok.Getter;
85
import lombok.NoArgsConstructor;
96
import lombok.Setter;
7+
import org.tuna.zoopzoop.backend.domain.archive.archive.enums.ArchiveType;
108
import org.tuna.zoopzoop.backend.global.jpa.entity.BaseEntity;
119

1210
@Getter
@@ -16,9 +14,10 @@
1614
@Inheritance(strategy = InheritanceType.JOINED)
1715
public class Archive extends BaseEntity {
1816
@Column
19-
private String archiveType;
17+
@Enumerated(EnumType.STRING)
18+
private ArchiveType archiveType;
2019

21-
public Archive(String archiveType) {
20+
public Archive(ArchiveType archiveType) {
2221
this.archiveType = archiveType;
2322
}
2423
}

src/main/java/org/tuna/zoopzoop/backend/domain/archive/archive/entity/ArchiveMapping.java

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
package org.tuna.zoopzoop.backend.domain.archive.archive.entity;
22

3+
import jakarta.persistence.CascadeType;
34
import jakarta.persistence.Entity;
45
import jakarta.persistence.JoinColumn;
56
import jakarta.persistence.OneToOne;
67
import lombok.Getter;
78
import lombok.NoArgsConstructor;
89
import lombok.Setter;
10+
import org.tuna.zoopzoop.backend.domain.archive.archive.enums.ArchiveType;
911
import org.tuna.zoopzoop.backend.domain.member.entity.Member;
12+
import org.tuna.zoopzoop.backend.global.jpa.entity.BaseEntity;
1013

1114
@Getter
1215
@Setter
1316
@Entity
1417
@NoArgsConstructor
15-
public class PersonalArchive extends ArchiveMapping {
18+
public class PersonalArchive extends BaseEntity {
19+
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
20+
@JoinColumn(name = "archive_id", nullable = false)
21+
public Archive archive;
22+
1623
@OneToOne
1724
@JoinColumn(name = "member_id", nullable = false)
1825
private Member member;
1926

2027
public PersonalArchive(Member member) {
2128
this.member = member;
22-
this.archive = new Archive("개인");
29+
this.archive = new Archive(ArchiveType.PERSONAL);
2330
}
2431
}
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
package org.tuna.zoopzoop.backend.domain.archive.archive.entity;
22

3-
import jakarta.persistence.*;
3+
import jakarta.persistence.CascadeType;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.JoinColumn;
6+
import jakarta.persistence.OneToOne;
47
import lombok.Getter;
58
import lombok.NoArgsConstructor;
69
import lombok.Setter;
10+
import org.tuna.zoopzoop.backend.domain.archive.archive.enums.ArchiveType;
711
import org.tuna.zoopzoop.backend.domain.space.space.entity.Space;
12+
import org.tuna.zoopzoop.backend.global.jpa.entity.BaseEntity;
813

914
@Getter
1015
@Setter
1116
@Entity
1217
@NoArgsConstructor
13-
public class SharingArchive extends ArchiveMapping {
18+
public class SharingArchive extends BaseEntity {
19+
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
20+
@JoinColumn(name = "archive_id", nullable = false)
21+
public Archive archive;
22+
1423
@OneToOne
1524
@JoinColumn(name = "space_id", nullable = false)
1625
private Space space;
26+
27+
public SharingArchive(Space space) {
28+
this.space = space;
29+
this.archive = new Archive(ArchiveType.SHARED);
30+
}
1731
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.tuna.zoopzoop.backend.domain.space.repository;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.tuna.zoopzoop.backend.domain.space.space.entity.Space;
5+
6+
public interface SpaceRepository extends JpaRepository<Space, Integer> {
7+
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package org.tuna.zoopzoop.backend.domain.space.space.entity;
22

3-
import jakarta.persistence.CascadeType;
4-
import jakarta.persistence.Column;
5-
import jakarta.persistence.Entity;
6-
import jakarta.persistence.OneToMany;
3+
import jakarta.persistence.*;
74
import lombok.Builder;
85
import lombok.Getter;
9-
import lombok.NoArgsConstructor;
106
import lombok.Setter;
7+
import org.tuna.zoopzoop.backend.domain.archive.archive.entity.SharingArchive;
118
import org.tuna.zoopzoop.backend.domain.space.membership.entity.MemberShip;
129
import org.tuna.zoopzoop.backend.global.jpa.entity.BaseEntity;
1310

@@ -16,7 +13,6 @@
1613
@Getter
1714
@Setter
1815
@Entity
19-
@NoArgsConstructor
2016
public class Space extends BaseEntity {
2117
//Space 이름
2218
@Column(unique = true, nullable = false)
@@ -27,14 +23,22 @@ public class Space extends BaseEntity {
2723
@Column(nullable = false)
2824
private boolean active = true;
2925

26+
@OneToOne(mappedBy = "space", cascade = CascadeType.ALL, orphanRemoval = true)
27+
private SharingArchive sharingArchive;
28+
3029
//연결된 MemberShip
3130
//Space 삭제시 cascade.all
3231
@OneToMany(mappedBy = "space", cascade = CascadeType.ALL, orphanRemoval = true)
3332
private List<MemberShip> memberShips;
3433

34+
public Space() {
35+
this.sharingArchive = new SharingArchive(this);
36+
}
37+
3538
@Builder
3639
public Space(String name, Boolean active) {
3740
this.name = name;
3841
this.active = active;
42+
this.sharingArchive = new SharingArchive(this);
3943
}
4044
}

src/main/java/org/tuna/zoopzoop/backend/global/initData/BaseInitData.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
import org.springframework.transaction.annotation.Transactional;
1111
import org.tuna.zoopzoop.backend.domain.member.entity.Member;
1212
import org.tuna.zoopzoop.backend.domain.member.repository.MemberRepository;
13+
import org.tuna.zoopzoop.backend.domain.space.repository.SpaceRepository;
14+
import org.tuna.zoopzoop.backend.domain.space.space.entity.Space;
1315

1416
@Configuration
1517
@RequiredArgsConstructor
1618
public class BaseInitData {
1719
private final MemberRepository memberRepository;
20+
private final SpaceRepository spaceRepository;
1821

1922
@Autowired
2023
@Lazy
@@ -43,8 +46,21 @@ public void initalizeData() {
4346
.profileImageUrl("https://example.com/bob.png")
4447
.build();
4548

49+
Space space1 = Space.builder()
50+
.name("Space1")
51+
.active(true)
52+
.build();
53+
54+
Space space2 = Space.builder()
55+
.name("Space2")
56+
.active(true)
57+
.build();
58+
4659
memberRepository.save(member1);
4760
memberRepository.save(member2);
61+
62+
spaceRepository.save(space1);
63+
spaceRepository.save(space2);
4864
} catch (Exception e) {
4965
System.err.println("초기 데이터 생성 중 오류 발생: " + e.getMessage());
5066
}

0 commit comments

Comments
 (0)