| 1 | |
package com.ctrip.framework.apollo.adminservice.controller; |
| 2 | |
|
| 3 | |
import org.springframework.beans.factory.annotation.Autowired; |
| 4 | |
import org.springframework.web.bind.annotation.PathVariable; |
| 5 | |
import org.springframework.web.bind.annotation.RequestBody; |
| 6 | |
import org.springframework.web.bind.annotation.RequestMapping; |
| 7 | |
import org.springframework.web.bind.annotation.RequestMethod; |
| 8 | |
import org.springframework.web.bind.annotation.RestController; |
| 9 | |
|
| 10 | |
import com.ctrip.framework.apollo.common.entity.AppNamespace; |
| 11 | |
import com.ctrip.framework.apollo.biz.service.AppNamespaceService; |
| 12 | |
import com.ctrip.framework.apollo.common.utils.BeanUtils; |
| 13 | |
import com.ctrip.framework.apollo.core.dto.AppNamespaceDTO; |
| 14 | |
|
| 15 | |
import java.util.List; |
| 16 | |
|
| 17 | |
@RestController |
| 18 | 1 | public class AppNamespaceController { |
| 19 | |
|
| 20 | |
@Autowired |
| 21 | |
private AppNamespaceService appNamespaceService; |
| 22 | |
|
| 23 | |
@RequestMapping("/apps/{appId}/appnamespace/{appnamespace}/unique") |
| 24 | |
public boolean isAppNamespaceUnique(@PathVariable("appId") String appId, |
| 25 | |
@PathVariable("appnamespace") String appnamespace) { |
| 26 | 0 | return appNamespaceService.isAppNamespaceNameUnique(appId, appnamespace); |
| 27 | |
} |
| 28 | |
|
| 29 | |
@RequestMapping("/appnamespaces/public") |
| 30 | |
public List<AppNamespaceDTO> findPublicAppNamespaces(){ |
| 31 | 0 | List<AppNamespace> appNamespaces = appNamespaceService.findPublicAppNamespaces(); |
| 32 | 0 | return BeanUtils.batchTransform(AppNamespaceDTO.class, appNamespaces); |
| 33 | |
} |
| 34 | |
|
| 35 | |
@RequestMapping(value = "/apps/{appId}/appnamespaces", method = RequestMethod.POST) |
| 36 | |
public AppNamespaceDTO createOrUpdate( @RequestBody AppNamespaceDTO appNamespace){ |
| 37 | |
|
| 38 | 0 | AppNamespace entity = BeanUtils.transfrom(AppNamespace.class, appNamespace); |
| 39 | 0 | AppNamespace managedEntity = appNamespaceService.findOne(entity.getAppId(), entity.getName()); |
| 40 | |
|
| 41 | 0 | if (managedEntity != null){ |
| 42 | 0 | BeanUtils.copyEntityProperties(entity, managedEntity); |
| 43 | 0 | entity = appNamespaceService.update(managedEntity); |
| 44 | |
}else { |
| 45 | 0 | entity = appNamespaceService.createAppNamespace(entity, entity.getDataChangeCreatedBy()); |
| 46 | |
} |
| 47 | |
|
| 48 | 0 | return BeanUtils.transfrom(AppNamespaceDTO.class, entity); |
| 49 | |
|
| 50 | |
} |
| 51 | |
|
| 52 | |
} |