package com.lemans.ds.product import com.lemans.ds.ReportAndLocaleCommonsController class ProductController extends ReportAndLocaleCommonsController { def productService def productManagerService def index() { Map criteria = common() + pagination() + catalog() + filters(['brandCode', 'isDigiActive', 'vendorId', 'productName', 'productNameLocale', 'productId', 'flagId', 'mode', 'goliveDateRange']) if (params.categoryId) { criteria.categoryId = params.list('categoryId') } if (params.derivedPartStatusId) { criteria.derivedPartStatusId = params.list('derivedPartStatusId') } if (params.flagId) { criteria.flagId = params.list('flagId') } if (params.brandId) { criteria.brandId = params.list('brandId') } renderPaginated productService.findProducts(criteria) } def show(Integer productId) { Map criteria = common() + catalog() + [productId: productId, entityClass: 'Product'] renderOne productService.findProductById(criteria) } def add() { Map values = request.JSON + catalog() + common() if (!(values.isDigiActive)) { values.put('isDigiActive', '0') } renderObject productManagerService.createProduct(values, auditUserName) } def update(Integer catalogInstanceId, Integer productId) { Map values = request.JSON + common() + [productId: productId] if (isDefaultLocale()) { renderObject productManagerService.updateProduct(values, catalogInstanceId, auditUserName) } else { ProductLocale productLocale = productManagerService.updateProductWithLocale(values, catalogInstanceId, auditUserName) renderObject(productLocale, productLocale?.productId) } } def remove(Integer catalogInstanceId, Integer productId) { renderDelete productManagerService.deleteProduct(catalogInstanceId, productId, auditUserName) } def splitValidation(Integer productId) { Map data = productService.splitValidationForProduct(productId, filters(['skipFitmentValidation'])) render toJson([results: data.results, rejectionMessage: data.rejectionMessage, jiraId: data.jiraId]) } private Map catalog() { [catalogInstanceId: params.int('catalogInstanceId')] } }