Skip to content

Instantly share code, notes, and snippets.

@srdelarosa
Created March 23, 2021 02:48
Show Gist options
  • Save srdelarosa/458c624a0b0b734424b5572c28cd2eca to your computer and use it in GitHub Desktop.
Save srdelarosa/458c624a0b0b734424b5572c28cd2eca to your computer and use it in GitHub Desktop.
package com.newhorizons.takeitnow.products.presentation.web.controller;
import com.newhorizons.takeitnow.products.application.mainmodule.dto.ProductDto;
import com.newhorizons.takeitnow.products.application.mainmodule.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/products")
public class ProductController {
@Autowired
private Environment environment;
@Autowired
private IProductService productService;
@GetMapping("/getAll")
public List<ProductDto> getAll(){
return productService.getAll().stream().map(
p -> {
p.setPortInUse(environment.getProperty("local.server.port"));
return p;
}).collect(Collectors.toList());
}
@GetMapping("/getProduct/{productId}")
public ProductDto getProduct(@PathVariable("productId") long productId){
ProductDto productDto = productService.getProduct(productId).get();
productDto.setPortInUse(environment.getProperty("local.server.port"));
return productDto;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment