Skip to content

Commit

Permalink
refactor : 효근이 요구사항 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
nookcoder committed Jul 13, 2023
1 parent 384dede commit a91f169
Show file tree
Hide file tree
Showing 19 changed files with 307 additions and 362 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,35 @@
import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintDto;
import com.kumofactory.cloud.blueprint.service.AwsBlueprintService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/blueprint")
@Slf4j
public class BlueprintController {
private final Logger logger = LoggerFactory.getLogger(BlueprintController.class);
private final AwsBlueprintService awsBlueprintService;

private final AwsBlueprintService awsBlueprintService;
// TODO : 토큰에서 유저 정보 가져오는 로직 추가
// TODO : blueprint list 주는 api 추가
// TODO : blueprint id 값으로 blueprint 가져오는 api 추가
@GetMapping("/aws")
public AwsBluePrintDto getAwsBlueprint() {
try {
AwsBluePrintDto awsBlueprint = awsBlueprintService.getAwsBlueprint();
return awsBlueprint;
} catch (RuntimeException e) {
return null;
}
}

// TODO : 토큰에서 유저 정보 가져오는 로직 추가
@GetMapping("/aws")
public AwsBluePrintDto getAwsBlueprint() {
try {
AwsBluePrintDto awsBlueprint = awsBlueprintService.getAwsBlueprint();
return awsBlueprint;
} catch (RuntimeException e) {
return null;
}
}

@PostMapping("/aws")
public String createAwsBlueprint(@RequestBody AwsBluePrintDto awsBluePrintDto) {
awsBlueprintService.store(awsBluePrintDto);
return "hello-world";
}
@PostMapping("/aws")
public String createAwsBlueprint(@RequestBody AwsBluePrintDto awsBluePrintDto) {
awsBlueprintService.store(awsBluePrintDto);
return "hello-world";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.kumofactory.cloud.blueprint.domain;

import com.kumofactory.cloud.blueprint.dto.ComponentDotDto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ComponentDot {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@CreationTimestamp
private Date created_at;
@UpdateTimestamp
private Date updated_at;

private Integer x; // 점의 x 좌표
private Integer y; // 점의 y 좌표
private String componentId; // 점이 속한 컴포넌트의 id

public static ComponentDot createComponentDot(ComponentDotDto componentDotDto) {
ComponentDot componentDot = new ComponentDot();
componentDot.setComponentId(componentDotDto.getComponentId());
componentDot.setX(componentDotDto.getX());
componentDot.setY(componentDotDto.getY());
return componentDot;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.kumofactory.cloud.blueprint.domain;

import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint;
import com.kumofactory.cloud.blueprint.dto.ComponentLineDto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.util.Date;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ComponentLine {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@CreationTimestamp
private Date created_at;
@UpdateTimestamp
private Date updated_at;

private String ui_id; // Client 에서 생성하는 uuid
@OneToOne(cascade = CascadeType.ALL)
private ComponentDot source;
@OneToOne(cascade = CascadeType.ALL)
private ComponentDot destination;
@ManyToOne
private AwsBluePrint bluePrint;

public static ComponentLine createComponentLink(ComponentLineDto lineDto, AwsBluePrint bluePrint) {
ComponentLine componentLink = new ComponentLine();
componentLink.setUi_id(lineDto.getId());
componentLink.setSource(ComponentDot.createComponentDot(lineDto.getSrc()));
componentLink.setDestination(ComponentDot.createComponentDot(lineDto.getDst()));
componentLink.setBluePrint(bluePrint);
return componentLink;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.kumofactory.cloud.blueprint.domain.aws;

import com.kumofactory.cloud.blueprint.domain.ComponentLine;
import com.kumofactory.cloud.member.domain.Member;

import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
Expand All @@ -11,6 +13,7 @@
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand Down Expand Up @@ -40,5 +43,7 @@ public class AwsBluePrint {
@OneToMany(mappedBy = "bluePrint", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
private List<AwsComponent> cspComponents;

@OneToMany(mappedBy = "bluePrint", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
private List<ComponentLine> lines;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kumofactory.cloud.blueprint.domain.aws;

import com.kumofactory.cloud.blueprint.domain.ComponentPoint;
import com.kumofactory.cloud.blueprint.dto.aws.AwsComponentDto;

import java.util.Date;
Expand All @@ -11,7 +10,6 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.UpdateTimestamp;

@Entity
Expand All @@ -20,40 +18,37 @@
@NoArgsConstructor
public class AwsComponent {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@CreationTimestamp
private Date created_at;
@UpdateTimestamp
private Date updated_at;

@Column(unique = true)
private String ui_id; // Client 에서 생성하는 uuid

@Enumerated(EnumType.STRING)
private AwsComponentType type; // Component 타입 (vm, vpc, subnet, ...)

// Component 의 좌측 상단 좌표
private Integer position_x;
private Integer position_y;

@ManyToOne
private AwsBluePrint bluePrint;

@OneToMany(mappedBy = "cspComponent", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<ComponentPoint> componentPoint;

// ============== 생성함수 ================= //
public static AwsComponent createAwsComponent(AwsComponentDto awsComponentDto,
AwsBluePrint awsBluePrint) {
AwsComponent awsComponent = new AwsComponent();
awsComponent.setUi_id(awsComponentDto.getId());
awsComponent.setPosition_x(awsComponentDto.getX());
awsComponent.setPosition_y(awsComponentDto.getY());
awsComponent.setType(awsComponentDto.getType());
awsComponent.setBluePrint(awsBluePrint);
return awsComponent;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@CreationTimestamp
private Date created_at;
@UpdateTimestamp
private Date updated_at;

@Column(unique = true)
private String ui_id; // Client 에서 생성하는 uuid

@Enumerated(EnumType.STRING)
private AwsComponentType type; // Component 타입 (vm, vpc, subnet, ...)

// Component 의 좌측 상단 좌표
private Integer position_x;
private Integer position_y;

@ManyToOne
private AwsBluePrint bluePrint;

// ============== 생성함수 ================= //
public static AwsComponent createAwsComponent(AwsComponentDto awsComponentDto,
AwsBluePrint awsBluePrint) {
AwsComponent awsComponent = new AwsComponent();
awsComponent.setUi_id(awsComponentDto.getId());
awsComponent.setPosition_x(awsComponentDto.getX());
awsComponent.setPosition_y(awsComponentDto.getY());
awsComponent.setType(awsComponentDto.getType());
awsComponent.setBluePrint(awsBluePrint);
return awsComponent;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.kumofactory.cloud.blueprint.domain.aws;

public enum AwsComponentType {
VPC, SUBNET, ELB, EC2, EFS, WAF, ROUTE53, NAT_GATEWAY, RDS
VPC, SUBNET, ELB, EC2, EFS, WAF, ROUTE53, NAT_GATEWAY, RDS,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kumofactory.cloud.blueprint.dto;

import com.kumofactory.cloud.blueprint.domain.ComponentDot;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ComponentDotDto {
private Integer x;
private Integer y;
private String componentId;

public static ComponentDotDto mapper(ComponentDot componentDot) {
ComponentDotDto componentDotDto = new ComponentDotDto();
componentDotDto.setX(componentDot.getX());
componentDotDto.setY(componentDot.getY());
componentDotDto.setComponentId(componentDot.getComponentId());
return componentDotDto;
}
}
Loading

0 comments on commit a91f169

Please sign in to comment.