Error
This commit is contained in:
@@ -1,14 +0,0 @@
|
|||||||
package me.aski.catalogueservice;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
public class Application {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(Application.class, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package me.aski.catalogueservice;
|
||||||
|
|
||||||
|
import me.aski.catalogueservice.dao.CategoryRepository;
|
||||||
|
import me.aski.catalogueservice.dao.ProductRepository;
|
||||||
|
import me.aski.catalogueservice.entities.Category;
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class CatalogueServiceApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(CatalogueServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
CommandLineRunner start(CategoryRepository categoryRepository, ProductRepository productRepository) {
|
||||||
|
return args -> {
|
||||||
|
|
||||||
|
categoryRepository.deleteAll();
|
||||||
|
Stream.of("C1 Ordinateur", "C2 Imprimantes").forEach(c -> {
|
||||||
|
categoryRepository.save(new Category(c.split(" ")[0], c.split(" ")[1], new ArrayList<>()));
|
||||||
|
|
||||||
|
});
|
||||||
|
categoryRepository.findAll().forEach(System.out::println);
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package me.aski.catalogueservice.dao;
|
||||||
|
|
||||||
|
import me.aski.catalogueservice.entities.Category;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
|
|
||||||
|
@RepositoryRestResource
|
||||||
|
public interface CategoryRepository extends MongoRepository<Category, String> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package me.aski.catalogueservice.dao;
|
||||||
|
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
|
|
||||||
|
@RepositoryRestResource
|
||||||
|
public interface ProductRepository extends MongoRepository<Process, String> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package me.aski.catalogueservice.entities;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@Document
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@ToString
|
||||||
|
public class Category {
|
||||||
|
@Id
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
@DBRef
|
||||||
|
private Collection<Product> products = new ArrayList<>();
|
||||||
|
}
|
||||||
23
src/main/java/me/aski/catalogueservice/entities/Product.java
Normal file
23
src/main/java/me/aski/catalogueservice/entities/Product.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package me.aski.catalogueservice.entities;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
@Document
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@ToString
|
||||||
|
public class Product {
|
||||||
|
@Id
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private double price;
|
||||||
|
@DBRef
|
||||||
|
private Category category;
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class ApplicationTests {
|
public class CatalogueServiceApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextLoads() {
|
public void contextLoads() {
|
||||||
Reference in New Issue
Block a user