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;
//import dto.ProductDto;
//import model.Product;
import com.nisum.ascend.inventory.dto.ProductDto;
import com.nisum.ascend.inventory.model.Product;
import io.swagger.models.Response;
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.RestController;
import com.nisum.ascend.inventory.service.ProductService;
import reactor.core.publisher.Flux;
@RestController
......@@ -14,9 +18,8 @@ public class ProductController {
@Autowired
ProductService productService;
// @GetMapping()
// public Flux<Product> findAll() {
// Flux<Product> prods = productService.findAll();
// return prods;
// }
@GetMapping()
public ResponseEntity<Flux<ProductDto>> findAll() {
return ResponseEntity.ok(productService.findAll());
}
}
......@@ -8,7 +8,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Getter
@Setter
@Document
@Document(collection = "products")
public class Product {
@Id
private String id;
......
package com.nisum.ascend.inventory.service;
import com.nisum.ascend.inventory.dto.ProductDto;
import com.nisum.ascend.inventory.model.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
......@@ -11,4 +12,12 @@ public class ProductService {
@Autowired
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