Skip to content

Commit

Permalink
Refine biz and entity
Browse files Browse the repository at this point in the history
  • Loading branch information
yiming187 committed Apr 5, 2016
1 parent 05ed035 commit 06e5168
Show file tree
Hide file tree
Showing 46 changed files with 877 additions and 656 deletions.
@@ -0,0 +1,33 @@
package com.ctrip.apollo.adminservice.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ctrip.apollo.biz.entity.App;
import com.ctrip.apollo.biz.service.AppService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.AppDTO;

@RestController
public class AppController {

@Autowired
private AppService appService;

@RequestMapping("/apps/{appId}")
public AppDTO findByAppId(@PathVariable("appId") String appId) {
App app = appService.findByAppId(appId);
return BeanUtils.transfrom(AppDTO.class, app);
}

@RequestMapping("/apps")
public List<AppDTO> findByName(@RequestParam("name") String name) {
List<App> app = appService.findByName(name);
return BeanUtils.batchTransform(AppDTO.class, app);
}
}
@@ -1,24 +1,26 @@
package com.ctrip.apollo.adminservice.controller;

import com.ctrip.apollo.biz.service.AdminConfigService;
import com.ctrip.apollo.core.dto.ClusterDTO;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import com.ctrip.apollo.biz.entity.Cluster;
import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ClusterDTO;

@RestController
@RequestMapping("/cluster")
public class ClusterController {

@Autowired
private AdminConfigService adminConfigService;
private ViewService viewService;

@RequestMapping("/app/{appId}")
public List<ClusterDTO> findClustersByApp(@PathVariable String appId) {
return adminConfigService.findClustersByApp(appId);
@RequestMapping("/apps/{appId}/clusters")
public List<ClusterDTO> findClusters(@PathVariable("appId") String appId) {
List<Cluster> clusters = viewService.findClusters(appId);
return BeanUtils.batchTransform(ClusterDTO.class, clusters);
}
}

This file was deleted.

@@ -0,0 +1,36 @@
package com.ctrip.apollo.adminservice.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ctrip.apollo.biz.entity.Group;
import com.ctrip.apollo.biz.service.GroupService;
import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.GroupDTO;

@RestController
public class GroupController {

@Autowired
private ViewService viewService;

@Autowired
private GroupService groupService;

@RequestMapping("/apps/{appId}/clusters/{clusterId}/groups")
public List<GroupDTO> findGroups(@PathVariable("clusterId") Long clusterId) {
List<Group> groups = viewService.findGroups(clusterId);
return BeanUtils.batchTransform(GroupDTO.class, groups);
}

@RequestMapping("/groups/{groupId}")
public GroupDTO findOne(@PathVariable("groupId") Long groupId){
Group group = groupService.findOne(groupId);
return BeanUtils.transfrom(GroupDTO.class, group);
}
}
@@ -0,0 +1,27 @@
package com.ctrip.apollo.adminservice.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ctrip.apollo.biz.entity.Item;
import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ItemDTO;

@RestController
public class ItemController {

@Autowired
private ViewService viewService;

@RequestMapping("/apps/{appId}/clusters/{clusterId}/groups/{groupId}/items")
public List<ItemDTO> findItems(
@PathVariable("groupId") Long groupId) {
List<Item> items = viewService.findItems(groupId);
return BeanUtils.batchTransform(ItemDTO.class, items);
}
}
@@ -0,0 +1,36 @@
package com.ctrip.apollo.adminservice.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ctrip.apollo.biz.entity.Release;
import com.ctrip.apollo.biz.service.ReleaseService;
import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ReleaseDTO;

@RestController
public class ReleaseController {

@Autowired
private ViewService viewSerivce;

@Autowired
private ReleaseService releaseService;

@RequestMapping("/release/{releaseId}")
public ReleaseDTO findOne(@PathVariable("releaseId") long releaseId) {
Release release = releaseService.findOne(releaseId);
return BeanUtils.transfrom(ReleaseDTO.class, release);
}

@RequestMapping("/apps/{appId}/clusters/{clusterId}/groups/{groupId}/releases")
public List<ReleaseDTO> findReleases(@PathVariable("groupId") Long groupId){
List<Release> releases = viewSerivce.findReleases(groupId);
return BeanUtils.batchTransform(ReleaseDTO.class, releases);
}
}
@@ -1,29 +1,36 @@
package com.ctrip.apollo.adminservice.controller;

import com.ctrip.apollo.biz.service.AdminReleaseService;
import com.ctrip.apollo.core.dto.VersionDTO;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import com.ctrip.apollo.biz.entity.Version;
import com.ctrip.apollo.biz.service.VersionService;
import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.VersionDTO;

@RestController
@RequestMapping("/version")
public class VersionController {

@Autowired
private AdminReleaseService adminReleaseService;
private ViewService viewService;

@RequestMapping("/app/{appId}")
public List<VersionDTO> versions(@PathVariable String appId) {
return adminReleaseService.findVersionsByApp(appId);
@Autowired
private VersionService versionService;

@RequestMapping("/app/{appId}/clusters/{clusterId}/versions")
public List<VersionDTO> findVersions(@PathVariable("appId") String appId, @PathVariable("clusterId") Long clusterId) {
List<Version> versions = viewService.findVersions(clusterId);
return BeanUtils.batchTransform(VersionDTO.class, versions);
}

@RequestMapping("/{versionId}")
public VersionDTO version(@PathVariable long versionId) {
return adminReleaseService.loadVersionById(versionId);
@RequestMapping("/versions/{versionId}")
public VersionDTO findOne(@PathVariable("versionId") long versionId) {
Version version = versionService.findOne(versionId);
return BeanUtils.transfrom(VersionDTO.class, version);
}
}
37 changes: 17 additions & 20 deletions apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/App.java
Expand Up @@ -2,15 +2,9 @@

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class App extends BaseEntity{

@Id
@GeneratedValue
private long id;
public class App extends BaseEntity {

@Column(nullable = false)
private String name;
Expand All @@ -19,37 +13,40 @@ public class App extends BaseEntity{
private String appId;

@Column(nullable = false)
private String owner;
private String ownerName;

@Column(nullable = false)
private String ownerEmail;

public String getAppId() {
return appId;
}

public long getId() {
return id;
}

public String getName() {
return name;
}

public String getOwner() {
return owner;
public String getOwnerEmail() {
return ownerEmail;
}

public void setAppId(String appId) {
this.appId = appId;
public String getOwnerName() {
return ownerName;
}

public void setId(long id) {
this.id = id;
public void setAppId(String appId) {
this.appId = appId;
}

public void setName(String name) {
this.name = name;
}

public void setOwner(String owner) {
this.owner = owner;
public void setOwnerEmail(String ownerEmail) {
this.ownerEmail = ownerEmail;
}

public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
}
Expand Up @@ -3,6 +3,8 @@
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
Expand All @@ -11,8 +13,12 @@
@SQLDelete(sql = "Update Cluster set isDeleted = 1 where id = ?")
public abstract class BaseEntity {

@Id
@GeneratedValue
private long id;

private boolean isDeleted;

@Column(name = "DataChange_CreatedBy")
private String dataChangeCreatedBy;

Expand All @@ -24,7 +30,7 @@ public abstract class BaseEntity {

@Column(name = "DataChange_LastTime")
private Date dataChangeLastModifiedTime;

public String getDataChangeCreatedBy() {
return dataChangeCreatedBy;
}
Expand All @@ -41,6 +47,10 @@ public Date getDataChangeLastModifiedTime() {
return dataChangeLastModifiedTime;
}

public long getId() {
return id;
}

public boolean isDeleted() {
return isDeleted;
}
Expand All @@ -64,4 +74,8 @@ public void setDataChangeLastModifiedTime(Date dataChangeLastModifiedTime) {
public void setDeleted(boolean deleted) {
isDeleted = deleted;
}

public void setId(long id) {
this.id = id;
}
}

0 comments on commit 06e5168

Please sign in to comment.