Commit f7d9c104 authored by Khai Yuan ​Liew's avatar Khai Yuan ​Liew

[AFP-55] Work on ProductController

parent 4ca01743
package com.nisum.ascend.inventory.controller; package com.nisum.ascend.inventory.controller;
//import dto.ProductDto; import com.nisum.ascend.inventory.dto.ProductDto;
//import model.Product; import com.nisum.ascend.inventory.model.Product;
import io.swagger.models.Response;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.nisum.ascend.inventory.service.ProductService; import com.nisum.ascend.inventory.service.ProductService;
import reactor.core.publisher.Flux;
@RestController @RestController
...@@ -14,9 +18,8 @@ public class ProductController { ...@@ -14,9 +18,8 @@ public class ProductController {
@Autowired @Autowired
ProductService productService; ProductService productService;
// @GetMapping() @GetMapping()
// public Flux<Product> findAll() { public ResponseEntity<Flux<ProductDto>> findAll() {
// Flux<Product> prods = productService.findAll(); return ResponseEntity.ok(productService.findAll());
// return prods; }
// }
} }
...@@ -8,7 +8,7 @@ import org.springframework.data.mongodb.core.mapping.Document; ...@@ -8,7 +8,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Getter @Getter
@Setter @Setter
@Document @Document(collection = "products")
public class Product { public class Product {
@Id @Id
private String id; private String id;
......
package com.nisum.ascend.inventory.service; package com.nisum.ascend.inventory.service;
import com.nisum.ascend.inventory.dto.ProductDto; import com.nisum.ascend.inventory.dto.ProductDto;
import com.nisum.ascend.inventory.model.Product;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
...@@ -11,4 +12,12 @@ public class ProductService { ...@@ -11,4 +12,12 @@ public class ProductService {
@Autowired @Autowired
ProductRepository productRepository; ProductRepository productRepository;
public Flux<ProductDto> findAll() {
return productRepository.findAll()
.map(ProductDto::generateDtoFromProduct)
.flatMap(Flux::just);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment