Advertisement
Guest User

Untitled

a guest
Aug 9th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.73 KB | None | 0 0
  1. package pl.bpo.archiwumallegro.controller;
  2.  
  3.  
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.data.domain.Pageable;
  6. import org.springframework.http.MediaType;
  7. import org.springframework.web.bind.annotation.PathVariable;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestParam;
  10. import org.springframework.web.bind.annotation.RestController;
  11.  
  12. import pl.bpo.archiwumallegro.model.Auction;
  13. import pl.bpo.archiwumallegro.model.index.auctions.AuctionIndexSearchParams;
  14. import pl.bpo.archiwumallegro.services.AuctionContentReaderService;
  15. import pl.bpo.archiwumallegro.services.AuctionService;
  16.  
  17. import java.util.List;
  18. import java.util.Map;
  19.  
  20. @RestController
  21. public class AuctionQueryController {
  22.  
  23.     private AuctionService auctionService;
  24.     private AuctionContentReaderService auctionContentReaderService;
  25.  
  26.     @Autowired
  27.     public AuctionQueryController(AuctionService auctionService, AuctionContentReaderService auctionContentReaderService) {
  28.         this.auctionService = auctionService;
  29.         this.auctionContentReaderService = auctionContentReaderService;
  30.     }
  31.  
  32.     @RequestMapping(value = "/auctions/getById/{auctionId}", produces = MediaType.APPLICATION_JSON_VALUE)
  33.     private Auction getById(@PathVariable("auctionId") Long auctionId) {
  34.         return auctionService.findAuctionById(auctionId);
  35.     }
  36.  
  37.     @RequestMapping(value = "/auctions/getByUserId/{userId}", produces = MediaType.APPLICATION_JSON_VALUE)
  38.     private List<Auction> getByUserId(@PathVariable("userId") Long userId) {
  39.         return auctionService.findByUserId(userId);
  40.     }
  41.  
  42.     @RequestMapping(value = "/auctions/content/{auctionId}", produces = MediaType.APPLICATION_JSON_VALUE)
  43.     private String getContent(@PathVariable("auctionId") Long auctionId) {
  44.         return auctionContentReaderService.findContent(auctionId);
  45.     }
  46.  
  47.     @RequestMapping(value = "/auctions/search", produces = MediaType.APPLICATION_JSON_VALUE)
  48.     private Map search(
  49.             @RequestParam(value = "categoryId", required = false) Long categoryId,
  50.             @RequestParam(value = "treeCategoryId", required = false) Long treeCategoryId,
  51.             @RequestParam(value = "currency", required = false) String currency,
  52.             @RequestParam(value = "priceFrom", required = false) Long priceFrom,
  53.             @RequestParam(value = "priceTo", required = false) Long priceTo,
  54.             @RequestParam(value = "startDateFrom", required = false) Long startDateFrom,
  55.             @RequestParam(value = "startDateTo", required = false) Long startDateTo,
  56.             @RequestParam(value = "endDateFrom", required = false) Long endDateFrom,
  57.             @RequestParam(value = "endDateTo", required = false) Long endDateTo,
  58.             @RequestParam(value = "title", required = false) String title,
  59.             @RequestParam(value = "uid", required = false) Long uid,
  60.             @RequestParam(value = "uids", required = false) String uids,
  61.             @RequestParam(value = "categories", required = false) String categories,
  62.             @RequestParam(value = "item", required = false) String itemId,
  63.             @RequestParam(value = "orderBy", required = false) String orderBy,
  64.             @RequestParam(value = "orderDir", required = false) String orderDir,
  65.             @RequestParam(value = "loc", required = false) String loc,
  66.             @RequestParam(value = "pow", required = false) String pow,
  67.             @RequestParam(value = "woj", required = false) String woj,
  68.             @RequestParam(value = "catdec", required = false) Long catdec,
  69.             Pageable pageable) {
  70.  
  71.         final AuctionIndexSearchParams searchParams = AuctionIndexSearchParams.builder()
  72.                 .itemId(itemId)
  73.                 .categoryId(categoryId)
  74.                 .treeCategoryId(treeCategoryId)
  75.                 .currency(currency)
  76.                 .priceFrom(priceFrom)
  77.                 .priceTo(priceTo)
  78.                 .startDateFrom(startDateFrom)
  79.                 .startDateTo(startDateTo)
  80.                 .endDateFrom(endDateFrom)
  81.                 .endDateTo(endDateTo)
  82.                 .title(title)
  83.                 .loc(loc)
  84.                 .pow(pow)
  85.                 .woj(woj)
  86.                 .uid(uid)
  87.                 .catdec(catdec)
  88.                 .uids(uids)
  89.                 .categories(categories)
  90.                 .orderBy(orderBy)
  91.                 .orderDir(orderDir)
  92.                 .build();
  93.        
  94.        
  95.         return auctionService.searchByIndexParams(searchParams, pageable);
  96.     }
  97.     @RequestMapping(value = "/auctions/findAll", produces = MediaType.APPLICATION_JSON_VALUE)
  98.     private Map findAll(
  99.             @RequestParam(value = "categoryId", required = false) Long categoryId,
  100.             @RequestParam(value = "treeCategoryId", required = false) Long treeCategoryId,
  101.             @RequestParam(value = "currency", required = false) String currency,
  102.             @RequestParam(value = "priceFrom", required = false) Long priceFrom,
  103.             @RequestParam(value = "priceTo", required = false) Long priceTo,
  104.             @RequestParam(value = "startDateFrom", required = false) Long startDateFrom,
  105.             @RequestParam(value = "startDateTo", required = false) Long startDateTo,
  106.             @RequestParam(value = "endDateFrom", required = false) Long endDateFrom,
  107.             @RequestParam(value = "endDateTo", required = false) Long endDateTo,
  108.             @RequestParam(value = "title", required = false) String title,
  109.             @RequestParam(value = "uid", required = false) Long uid,
  110.             @RequestParam(value = "uids", required = false) String uids,
  111.             @RequestParam(value = "categories", required = false) String categories,
  112.             @RequestParam(value = "item", required = false) String itemId,
  113.             @RequestParam(value = "orderBy", required = false) String orderBy,
  114.             @RequestParam(value = "orderDir", required = false) String orderDir) {
  115.  
  116.         final AuctionIndexSearchParams searchParams = AuctionIndexSearchParams.builder()
  117.                 .categoryId(categoryId)
  118.                 .itemId(itemId)
  119.                 .treeCategoryId(treeCategoryId)
  120.                 .currency(currency)
  121.                 .priceFrom(priceFrom)
  122.                 .priceTo(priceTo)
  123.                 .startDateFrom(startDateFrom)
  124.                 .startDateTo(startDateTo)
  125.                 .endDateFrom(endDateFrom)
  126.                 .endDateTo(endDateTo)
  127.                 .title(title)
  128.                 .uid(uid)
  129.                 .uids(uids)
  130.                 .orderBy(orderBy)
  131.                 .orderDir(orderDir)
  132.                 .categories(categories)
  133.                 .build();
  134.  
  135.         return auctionService.findAllByIndexParams(searchParams, null);
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement