Skip to content

Commit 085bcff

Browse files
author
rezaalemy
committed
embedded and byref documents in mongo
1 parent cdc17eb commit 085bcff

File tree

13 files changed

+490
-80
lines changed

13 files changed

+490
-80
lines changed

Diff for: objects.mv.db

-12 KB
Binary file not shown.

Diff for: pom.xml

+22-30
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<groupId>org.springframework.boot</groupId>
3939
<artifactId>spring-boot-starter-jpa</artifactId>
4040
</dependency>
41-
4241
<dependency>
4342
<groupId>org.springframework.boot</groupId>
4443
<artifactId>spring-boot-starter-security</artifactId>
@@ -51,24 +50,7 @@
5150
<groupId>org.springframework.boot</groupId>
5251
<artifactId>spring-boot-starter-webflux</artifactId>
5352
</dependency>
54-
<dependency>
55-
<groupId>org.springframework.boot</groupId>
56-
<artifactId>spring-boot-starter-data-mongodb</artifactId>
57-
</dependency>
58-
<dependency>
59-
<groupId>io.projectreactor</groupId>
60-
<artifactId>reactor-core</artifactId>
61-
</dependency>
62-
<dependency>
63-
<groupId>org.mongodb</groupId>
64-
<artifactId>mongodb-driver-reactivestreams</artifactId>
65-
<version>1.9.0</version>
66-
</dependency>
67-
<dependency>
68-
<groupId>de.flapdoodle.embed</groupId>
69-
<artifactId>de.flapdoodle.embed.mongo</artifactId>
70-
<scope>runtime</scope>
71-
</dependency>
53+
7254
<dependency>
7355
<groupId>org.springframework.boot</groupId>
7456
<artifactId>spring-boot-devtools</artifactId>
@@ -86,6 +68,27 @@
8668
</dependency>
8769

8870

71+
<dependency>
72+
<groupId>org.springframework.data</groupId>
73+
<artifactId>spring-data-mongodb</artifactId>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>org.mongodb</groupId>
78+
<artifactId>mongodb-driver-reactivestreams</artifactId>
79+
<version>1.5.0</version>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>io.projectreactor</groupId>
84+
<artifactId>reactor-core</artifactId>
85+
</dependency>
86+
87+
<dependency>
88+
<groupId>de.flapdoodle.embed</groupId>
89+
<artifactId>de.flapdoodle.embed.mongo</artifactId>
90+
</dependency>
91+
8992
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all -->
9093
<dependency>
9194
<groupId>org.hamcrest</groupId>
@@ -121,23 +124,12 @@
121124
<scope>test</scope>
122125
</dependency>
123126

124-
<dependency>
125-
<groupId>org.springframework.restdocs</groupId>
126-
<artifactId>spring-restdocs-webtestclient</artifactId>
127-
<scope>test</scope>
128-
</dependency>
129-
130127
<dependency>
131128
<groupId>org.springframework.boot</groupId>
132129
<artifactId>spring-boot-starter-test</artifactId>
133130
<scope>test</scope>
134131
</dependency>
135132

136-
<dependency>
137-
<groupId>de.flapdoodle.embed</groupId>
138-
<artifactId>de.flapdoodle.embed.mongo</artifactId>
139-
<scope>test</scope>
140-
</dependency>
141133

142134
<dependency>
143135
<groupId>io.projectreactor</groupId>
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
package com.curisprofound.tddwebstack;
22

3+
import com.curisprofound.tddwebstack.db.Book;
4+
import com.curisprofound.tddwebstack.db.BookRepository;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.ApplicationArguments;
7+
import org.springframework.boot.ApplicationRunner;
38
import org.springframework.boot.SpringApplication;
49
import org.springframework.boot.autoconfigure.SpringBootApplication;
10+
import org.springframework.context.annotation.Bean;
511

612
@SpringBootApplication
713
public class TddWebStackApplication {
814

9-
public static void main(String[] args) {
10-
SpringApplication.run(TddWebStackApplication.class, args);
11-
}
15+
private final BookRepository bookRepository;
16+
17+
@Autowired
18+
public TddWebStackApplication(BookRepository bookRepository) {
19+
this.bookRepository = bookRepository;
20+
}
21+
22+
public static void main(String[] args) {
23+
SpringApplication.run(TddWebStackApplication.class, args);
24+
}
25+
1226
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.curisprofound.tddwebstack.db;
2+
3+
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
import org.springframework.data.mongodb.core.mapping.Document;
8+
9+
import javax.persistence.Id;
10+
11+
@AllArgsConstructor
12+
@NoArgsConstructor
13+
@Data
14+
public class Author {
15+
private String name;
16+
private String phone;
17+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.curisprofound.tddwebstack.db;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
import org.springframework.data.mongodb.core.mapping.DBRef;
7+
import org.springframework.data.mongodb.core.mapping.Document;
8+
9+
import javax.persistence.Id;
10+
import java.util.Map;
11+
12+
@Document
13+
@AllArgsConstructor
14+
@NoArgsConstructor
15+
@Data
16+
public class Book {
17+
@Id
18+
private String id;
19+
private String title;
20+
private Author author;
21+
22+
@DBRef
23+
private Publisher publisher;
24+
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.curisprofound.tddwebstack.db;
2+
3+
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
4+
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
5+
6+
public interface BookRepository extends ReactiveMongoRepository<Book,String> {
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.curisprofound.tddwebstack.db;
2+
3+
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
import org.springframework.data.mongodb.core.mapping.Document;
8+
9+
import javax.persistence.Id;
10+
11+
@Document
12+
@AllArgsConstructor
13+
@NoArgsConstructor
14+
@Data
15+
public class Publisher {
16+
@Id
17+
private String id;
18+
19+
private String name;
20+
private String postalCode;
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.curisprofound.tddwebstack.db;
2+
3+
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
4+
5+
public interface PublisherRepository extends ReactiveMongoRepository<Publisher, String> {
6+
}

0 commit comments

Comments
 (0)