Commit 46727c12 by Yiming Liu

Add update API for ItemChangeSet

parent 7d905050
......@@ -15,7 +15,6 @@ import com.ctrip.apollo.biz.entity.Item;
import com.ctrip.apollo.biz.service.ItemService;
import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ItemChangeSets;
import com.ctrip.apollo.core.dto.ItemDTO;
import com.ctrip.apollo.core.exception.NotFoundException;
......
package com.ctrip.apollo.adminservice.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.ctrip.apollo.biz.service.ItemSetService;
import com.ctrip.apollo.core.dto.ItemChangeSets;
@RestController
public class ItemSetController {
@Autowired
private ItemSetService itemSetService;
@RequestMapping(path = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset", method = RequestMethod.POST)
public ResponseEntity<Void> create(@RequestBody ItemChangeSets changeSet) {
itemSetService.updateSet(changeSet);
return ResponseEntity.status(HttpStatus.OK).build();
}
}
package com.ctrip.apollo.biz.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ctrip.apollo.biz.entity.Item;
import com.ctrip.apollo.biz.repository.ItemRepository;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ItemChangeSets;
import com.ctrip.apollo.core.dto.ItemDTO;
@Service
public class ItemSetService {
@Autowired
private ItemRepository itemRepository;
public void updateSet(ItemChangeSets changeSet) {
for (ItemDTO item : changeSet.getCreateItems()) {
Item entity = BeanUtils.transfrom(Item.class, item);
itemRepository.save(entity);
}
for (ItemDTO item : changeSet.getUpdateItems()) {
Item entity = BeanUtils.transfrom(Item.class, item);
Item managedItem = itemRepository.findOne(entity.getId());
BeanUtils.copyEntityProperties(entity, managedItem);
itemRepository.save(managedItem);
}
for (ItemDTO item : changeSet.getDeletedItems()) {
Item entity = BeanUtils.transfrom(Item.class, item);
itemRepository.delete(entity.getId());
}
}
}
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