Commit 67b24376 authored by Khai Yuan ​Liew's avatar Khai Yuan ​Liew

[AFP-55] Start work on findAll controller [@kliew]

parent 1270fc1d
File added
File added
package controller; package controller;
import dto.ProductDto;
import model.Product;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import service.ProductService; import service.ProductService;
@RestController @RestController
@RequestMapping("/products")
public class ProductController { public class ProductController {
@Autowired @Autowired
ProductService productService; ProductService productService;
@GetMapping()
public Flux<Product> findAll() {
Flux<Product> prods = productService.findAll();
return prods;
}
} }
package service; package service;
import dto.ProductDto; import dto.ProductDto;
import 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;
...@@ -16,4 +17,8 @@ public class ProductService { ...@@ -16,4 +17,8 @@ public class ProductService {
.map(ProductDto::generateDtoFromProduct) .map(ProductDto::generateDtoFromProduct)
.flatMap(Flux::just); .flatMap(Flux::just);
} }
public Flux<Product> findAll(){
return productRepository.findAll();
}
} }
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