Skip to content

Commit 6a3b34f

Browse files
authored
Mongo Schema Refactor (#39)
* remove old 404 * Change db Schema * change id fieldname * remove realID references
1 parent 860c650 commit 6a3b34f

File tree

11 files changed

+54
-103
lines changed

11 files changed

+54
-103
lines changed

src/main/java/com/mangasite/domain/Manga.java

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.mangasite.domain;
22

3-
import java.math.BigInteger;
43
import java.time.LocalDate;
54
import java.time.ZoneId;
65
import java.util.List;
@@ -14,7 +13,6 @@
1413
/**
1514
* A class that represents a single manga <br>
1615
* <br>
17-
* a = alias <br>
1816
* c = categories(genre) <br>
1917
* h = hits <br>
2018
* i = infoSourceUrl <br>
@@ -29,30 +27,17 @@
2927
@Document(collection = "Manga")
3028
public class Manga {
3129

32-
@Id private BigInteger id;
33-
private int realID;
34-
private String a;
30+
@Id private Integer id;
31+
private String t;
3532
private List<String> c;
3633
private Integer h;
3734
private String im;
3835
private long ld;
3936
private Integer s;
40-
private String t;
4137
private MangaInfo info;
4238

4339
@PersistenceConstructor
44-
public Manga(
45-
int realID,
46-
String a,
47-
List<String> c,
48-
Integer h,
49-
String im,
50-
long ld,
51-
Integer s,
52-
String t,
53-
MangaInfo info) {
54-
this.realID = realID;
55-
this.a = a;
40+
public Manga(List<String> c, Integer h, String im, long ld, Integer s, String t, MangaInfo info) {
5641
this.c = c;
5742
this.h = h;
5843
this.im = im;
@@ -63,7 +48,6 @@ public Manga(
6348
}
6449

6550
public Manga(MangaChangeRequest request) {
66-
a = request.alias();
6751
c = request.genre();
6852
h = request.hits();
6953
im = request.coverImageURL();
@@ -93,20 +77,12 @@ public Manga(MangaChangeRequest request) {
9377
info.setReleased(request.releaseDate());
9478
}
9579

96-
public int getRealID() {
97-
return realID;
98-
}
99-
100-
public void setRealID(int realID) {
101-
this.realID = realID;
102-
}
103-
104-
public String getA() {
105-
return a;
80+
public int getId() {
81+
return id;
10682
}
10783

108-
public void setA(String a) {
109-
this.a = a;
84+
public void setId(int id) {
85+
this.id = id;
11086
}
11187

11288
public List<String> getC() {
@@ -165,16 +141,8 @@ public void setInfo(MangaInfo info) {
165141
this.info = info;
166142
}
167143

168-
public BigInteger getId() {
169-
return id;
170-
}
171-
172-
public void setId(BigInteger id) {
173-
this.id = id;
174-
}
175-
176144
@Override
177145
public String toString() {
178-
return "Manga [realID=" + realID + ", h=" + h + ", t=" + t + "]";
146+
return "Manga [id=" + id + ", h=" + h + ", t=" + t + "]";
179147
}
180148
}
Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.mangasite.domain;
22

3-
import java.math.BigInteger;
43
import java.util.List;
54

65
import org.springframework.data.annotation.Id;
@@ -10,48 +9,36 @@
109
@Document(collection = "Chapters")
1110
public class MangaChapters {
1211

13-
@Id private BigInteger id;
14-
private Integer realID;
12+
@Id private Integer id;
1513
private String mangaName;
1614
private List<Chapter> chapters;
1715

1816
@PersistenceConstructor
19-
public MangaChapters(int realID, String mangaName, List<Chapter> chapters) {
17+
public MangaChapters(String mangaName, List<Chapter> chapters) {
2018

21-
this.realID = realID;
2219
this.mangaName = mangaName;
2320
this.chapters = chapters;
2421
}
2522

26-
public MangaChapters() {}
27-
28-
public MangaChapters(String mangaName, int realID, String index, String firstPageURL) {
23+
public MangaChapters(int id, String mangaName, String index, String firstPageURL) {
2924

25+
this.id = id;
3026
final var chapter = new Chapter();
3127
chapter.setChapterIndex("Chapter " + index);
3228
final List<List<Object>> imageList = List.of(List.of(0, firstPageURL));
3329
chapter.setImages(imageList);
3430
this.mangaName = mangaName;
3531
chapters = List.of(chapter);
36-
this.realID = realID;
3732
}
3833

39-
public BigInteger getId() {
34+
public Integer getId() {
4035
return id;
4136
}
4237

43-
public void setId(BigInteger id) {
38+
public void setId(Integer id) {
4439
this.id = id;
4540
}
4641

47-
public Integer getRealID() {
48-
return realID;
49-
}
50-
51-
public void setRealID(Integer realID) {
52-
this.realID = realID;
53-
}
54-
5542
public String getMangaName() {
5643
return mangaName;
5744
}
@@ -67,4 +54,9 @@ public List<Chapter> getChapters() {
6754
public void setChapters(List<Chapter> chapters) {
6855
this.chapters = chapters;
6956
}
57+
58+
@Override
59+
public String toString() {
60+
return "MangaChapters [id=" + id + ", mangaName=" + mangaName + "]";
61+
}
7062
}

src/main/java/com/mangasite/record/MangaChangeRequest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/**
66
* A class that represents a single manga <br>
77
* <br>
8-
* a = alias <br>
98
* c = categories(genre) <br>
109
* h = hits <br>
1110
* i = infoSourceUrl <br>
@@ -18,7 +17,6 @@
1817
* @author Josiah
1918
*/
2019
public record MangaChangeRequest(
21-
String alias,
2220
List<String> genre,
2321
Integer hits,
2422
String coverImageURL,
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.mangasite.repo;
22

3-
import java.math.BigInteger;
4-
53
import org.springframework.data.mongodb.repository.Query;
64
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
75
import org.springframework.stereotype.Repository;
@@ -12,12 +10,10 @@
1210
import reactor.core.publisher.Mono;
1311

1412
@Repository
15-
public interface ChapterRepo extends ReactiveMongoRepository<MangaChapters, BigInteger> {
13+
public interface ChapterRepo extends ReactiveMongoRepository<MangaChapters, Integer> {
1614

1715
Mono<MangaChapters> getByMangaName(String Name);
1816

19-
Mono<MangaChapters> getByRealID(int realID);
20-
21-
@Query("{'realID' : ?0}")
22-
Flux<MangaChapters> getDupsByRealID(int realID);
17+
@Query("{'id' : ?0}")
18+
Flux<MangaChapters> getDupsById(int id);
2319
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.mangasite.repo;
22

3-
import java.math.BigInteger;
4-
53
import org.springframework.data.mongodb.repository.Aggregation;
64
import org.springframework.data.mongodb.repository.Query;
75
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
@@ -13,16 +11,13 @@
1311
import reactor.core.publisher.Mono;
1412

1513
@Repository
16-
public interface MangaRepo extends ReactiveMongoRepository<Manga, BigInteger> {
14+
public interface MangaRepo extends ReactiveMongoRepository<Manga, Integer> {
1715

1816
@Aggregation("{$sample: {size: ?0}}")
1917
Flux<Manga> sample(int size);
2018

21-
Mono<Manga> getBya(String a);
22-
23-
@Query("{'realID' : ?0}")
24-
Mono<Manga> getByRealID(int RealID);
25-
2619
@Query("{'ld' : { $gte: ?0, $lte: ?1 } }")
2720
Flux<Manga> findByLd(long l, long m);
21+
22+
Mono<Manga> getByt(String t);
2823
}

src/main/java/com/mangasite/services/ChapterService.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public ChapterService(ChapterRepo repo, MangaRepo mangaRepo) {
5252
*
5353
* @param ChapterID the numerical ID of the chapter
5454
*/
55-
public Mono<MangaChapters> getByID(int ChapterID) {
55+
public Mono<MangaChapters> getByID(int chapterID) {
5656

57-
return repo.getByRealID(ChapterID);
57+
return repo.findById(chapterID);
5858
}
5959

6060
/** Returns a single Mono<Chapter> that contains the Chapter with the given name */
@@ -71,11 +71,11 @@ public Mono<MangaChapters> getOne(String name) {
7171
public Mono<Tuple2<Manga, MangaChapters>> addChapter(List<ChapterChangeRequest> requestList) {
7272

7373
return mangaRepo
74-
.getByRealID(requestList.get(0).mangaId())
74+
.findById(requestList.get(0).mangaId())
7575
.zipWith(
76-
repo.getByRealID(requestList.get(0).mangaId()),
76+
repo.findById(requestList.get(0).mangaId()),
7777
(m, c) -> {
78-
System.out.println("Updating " + m.getT() + "\nRealID: " + m.getRealID());
78+
System.out.println("Updating " + m.getT() + "\nID: " + m.getId());
7979
System.out.println(
8080
"Before change : " + m.getInfo().getChapters().size() + " chapters");
8181
requestList.forEach(processChapterRequests(m, c));
@@ -94,7 +94,7 @@ public Mono<Tuple2<Manga, MangaChapters>> addChapter(List<ChapterChangeRequest>
9494
public Flux<Tuple2<PageChangeRequest, String>> updatePageLink(
9595
int id, List<PageChangeRequest> requestList) {
9696

97-
return repo.getByRealID(id)
97+
return repo.findById(id)
9898
// if Chapter Doesn't exist, create in table
9999
.flatMap(chapterExistsFunc(requestList))
100100
.doOnNext(c -> requestList.forEach(processPageRequests(c)))
@@ -202,7 +202,7 @@ private Function<MangaChapters, Mono<MangaChapters>> chapterExistsFunc(
202202
r.mangaId(), r.chapterIndex(), r.chapterName(), 0, ""))
203203
.toList();
204204

205-
return addChapter(chapterRequests).then(repo.getByRealID(c.getRealID()));
205+
return addChapter(chapterRequests).then(repo.findById(c.getId()));
206206
}
207207
return just(c);
208208
};
@@ -222,9 +222,9 @@ public void deleteDuplicateChapters(Optional<Integer> idParam) {
222222

223223
idParam.ifPresentOrElse(
224224
id -> {
225-
repo.getByRealID(id)
225+
repo.findById(id)
226226
.flatMap(this::removeChapterDups)
227-
.mergeWith(mangaRepo.getByRealID(id).flatMap(this::removeMangaDups))
227+
.mergeWith(mangaRepo.findById(id).flatMap(this::removeMangaDups))
228228
.distinct()
229229
.subscribe(System.out::println);
230230
},
@@ -264,12 +264,12 @@ public Mono<Tuple2<Manga, MangaChapters>> clearChapters(int id) {
264264

265265
final var mangaClearMono =
266266
mangaRepo
267-
.getByRealID(id)
267+
.findById(id)
268268
.doOnNext(m -> m.getInfo().getChapters().removeIf(c -> !c.get(0).equals("1")))
269269
.flatMap(mangaRepo::save);
270270

271271
final var chapterClearMono =
272-
repo.getByRealID(id)
272+
repo.findById(id)
273273
.doOnNext(
274274
mc -> mc.getChapters().removeIf(c -> !c.getChapterIndex().equals("Chapter 1")))
275275
.doOnNext(mc -> mc.getChapters().get(0).setImages(List.of(List.of(0, ""))))

0 commit comments

Comments
 (0)