Subversion Repositories SmartDukaan

Rev

Rev 36321 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.v2.controller;

import com.spice.profitmandi.service.catalog.BrandsService;
import com.spice.profitmandi.web.controller.BrandController;
import com.spice.profitmandi.web.v2.response.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/v2")
public class V2BrandController extends V2BaseController {

    @Autowired
    private BrandController brandController;

    @Autowired
    private BrandsService brandsService;

    @GetMapping("/brand/all")
    public ResponseEntity<ApiResponse<?>> getAll(HttpServletRequest request,
                                                 @RequestParam(name = "pageNumber") int pageNumber,
                                                 @RequestParam(name = "pageSize") int pageSize) throws Throwable {
        return wrapResponse(brandController.getAll(request, pageNumber, pageSize));
    }

    @GetMapping("/brand/id")
    public ResponseEntity<ApiResponse<?>> getById(HttpServletRequest request,
                                                  @RequestParam(name = "id") int id) throws Throwable {
        return wrapResponse(brandController.getById(request, id));
    }

    @Transactional(readOnly = true)
    @GetMapping("/brand/active")
    public ResponseEntity<ApiResponse<?>> getActiveBrands() throws Throwable {
        return ResponseEntity.ok(ApiResponse.success(brandsService.getAllActiveBrands()));
    }
}