Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/#17-blueprint' into feat…
Browse files Browse the repository at this point in the history
…ure/#17-blueprint
  • Loading branch information
nookcoder committed Jul 17, 2023
2 parents 3b32950 + 49ee187 commit 9f42d0b
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,56 @@

import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint;
import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintDto;
import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintListDto;
import com.kumofactory.cloud.blueprint.service.AwsBlueprintService;
import com.kumofactory.cloud.global.middleware.auth.AuthorizationFromToken;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

@GetMapping("/aws/{id}")
@AuthorizationFromToken
public AwsBluePrintDto getAwsBlueprint(@PathVariable("id") Long id, String userId) {
try {
logger.info("aws blue print id: {}", id);
AwsBluePrintDto awsBlueprint = awsBlueprintService.getAwsBlueprint(id);
return awsBlueprint;
} catch (RuntimeException e) {
return null;
}
}

@GetMapping("/aws/list")
@AuthorizationFromToken
public List<AwsBluePrintListDto> getAwsBlueprintList(String userId) {
logger.info("userId: {}", userId);
return awsBlueprintService.getMyAwsBlueprints(userId);
}

// 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;
}
}
@PostMapping("/aws")
@AuthorizationFromToken
public String createAwsBlueprint(@RequestBody AwsBluePrintDto awsBluePrintDto, String userId) {
logger.info(userId);
awsBlueprintService.store(awsBluePrintDto, userId);
return "hello-world";
}

@PostMapping("/aws")
public String createAwsBlueprint(@RequestBody AwsBluePrintDto awsBluePrintDto) {
awsBlueprintService.store(awsBluePrintDto);
return "hello-world";
}
@GetMapping("/test")
@AuthorizationFromToken
public String testMiddleware(String userId) {
System.out.printf("userId: %s\n", userId);
return userId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
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 javax.persistence.*;
import java.util.Date;

@Entity
Expand All @@ -20,24 +17,24 @@
@NoArgsConstructor
@AllArgsConstructor
public class ComponentDot {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@CreationTimestamp
private Date created_at;
@UpdateTimestamp
private Date updated_at;
@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
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;
}
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
@@ -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, S3, ElastiCache, CloudFront, AutoScaling
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
@Data
public class AwsBluePrintDto {

private String name;
private List<AwsComponentDto> components;
private List<ComponentLineDto> links;

public static List<AwsComponentDto> awsComponentDtosMapper(List<AwsComponent> awsComponentDtos) {
List<AwsComponentDto> awsComponentDtoList = new ArrayList<>();
for (AwsComponent awsComponent : awsComponentDtos) {
awsComponentDtoList.add(AwsComponentDto.mapper(awsComponent));
}
return awsComponentDtoList;
}

public static List<ComponentLineDto> componentLinkDtoListMapper(List<ComponentLine> componentLinks) {
List<ComponentLineDto> componentLinkDtoList = new ArrayList<>();
for (ComponentLine pointLink : componentLinks) {
componentLinkDtoList.add(ComponentLineDto.mapper(pointLink));
}
return componentLinkDtoList;
}
private String name;
private List<AwsComponentDto> components;
private List<ComponentLineDto> links;

public static List<AwsComponentDto> awsComponentDtosMapper(List<AwsComponent> awsComponentDtos) {
List<AwsComponentDto> awsComponentDtoList = new ArrayList<>();
for (AwsComponent awsComponent : awsComponentDtos) {
awsComponentDtoList.add(AwsComponentDto.mapper(awsComponent));
}
return awsComponentDtoList;
}

public static List<ComponentLineDto> componentLinkDtoListMapper(List<ComponentLine> componentLinks) {
List<ComponentLineDto> componentLinkDtoList = new ArrayList<>();
for (ComponentLine pointLink : componentLinks) {
componentLinkDtoList.add(ComponentLineDto.mapper(pointLink));
}
return componentLinkDtoList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.kumofactory.cloud.blueprint.dto.aws;

import lombok.Getter;
import lombok.Setter;

import java.util.Date;

@Getter
@Setter
public class AwsBluePrintListDto {
private Long id;
private String name;
private Date createdAt;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.kumofactory.cloud.blueprint.repository.aws;

import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint;
import com.kumofactory.cloud.member.domain.Member;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AwsBluePrintRepository extends JpaRepository<AwsBluePrint, Long> {
AwsBluePrint findAwsBluePrintById(long id);

AwsBluePrint findAwsBluePrintByMemberId(long memberId);

List<AwsBluePrint> findAwsBluePrintsByMember(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint;
import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintDto;
import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintListDto;

import java.util.List;

public interface AwsBlueprintService {

AwsBluePrintDto getAwsBlueprint();
AwsBluePrintDto getAwsBlueprint(Long bluePrintId);

List<AwsBluePrintDto> getMyAwsBlueprints();
List<AwsBluePrintListDto> getMyAwsBlueprints(String userId);

void store(AwsBluePrintDto awsBluePrintDto);
void store(AwsBluePrintDto awsBluePrintDto, String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import com.kumofactory.cloud.blueprint.dto.ComponentLineDto;
import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintDto;

import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintListDto;
import com.kumofactory.cloud.blueprint.dto.aws.AwsComponentDto;
import com.kumofactory.cloud.blueprint.repository.ComponentDotRepository;
import com.kumofactory.cloud.blueprint.repository.ComponentLineRepository;
import com.kumofactory.cloud.blueprint.repository.aws.AwsBluePrintRepository;
import com.kumofactory.cloud.blueprint.repository.aws.AwsComponentRepository;
import com.kumofactory.cloud.member.MemberRepository;
import com.kumofactory.cloud.member.domain.Member;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
Expand All @@ -28,63 +30,75 @@
@Repository
public class AwsBlueprintServiceImpl implements AwsBlueprintService {

private final MemberRepository memberRepository;
private final AwsBluePrintRepository awsBluePrintRepository;
private final AwsComponentRepository awsComponentRepository;
private final ComponentLineRepository componentLineRepository;
private final ComponentDotRepository componentDotRepository;
private final Logger logger = LoggerFactory.getLogger(AwsBlueprintServiceImpl.class);
private final MemberRepository memberRepository;
private final AwsBluePrintRepository awsBluePrintRepository;
private final AwsComponentRepository awsComponentRepository;
private final ComponentLineRepository componentLineRepository;
private final ComponentDotRepository componentDotRepository;
private final Logger logger = LoggerFactory.getLogger(AwsBlueprintServiceImpl.class);


@Override
public AwsBluePrintDto getAwsBlueprint() {
AwsBluePrint awsBluePrintById = awsBluePrintRepository.findAwsBluePrintById(1L);
logger.info("awsBluePrintById: {}", awsBluePrintById);
if (awsBluePrintById == null) {
throw new RuntimeException("awsBluePrintById is null");
}
@Override
public AwsBluePrintDto getAwsBlueprint(Long bluePrintId) {
AwsBluePrint awsBluePrintById = awsBluePrintRepository.findAwsBluePrintById(bluePrintId);
if (awsBluePrintById == null) {
throw new RuntimeException("awsBluePrintById is null");
}

List<AwsComponent> awsComponents = awsComponentRepository.findAllByBluePrint(awsBluePrintById);
List<ComponentLine> componentLines = componentLineRepository.findAllByBluePrint(awsBluePrintById);
AwsBluePrintDto awsBluePrintDto = new AwsBluePrintDto();
awsBluePrintDto.setName(awsBluePrintById.getName());
awsBluePrintDto.setComponents(AwsBluePrintDto.awsComponentDtosMapper(awsComponents));
awsBluePrintDto.setLinks(AwsBluePrintDto.componentLinkDtoListMapper(componentLines));
return awsBluePrintDto;
}
List<AwsComponent> awsComponents = awsComponentRepository.findAllByBluePrint(awsBluePrintById);
List<ComponentLine> componentLines = componentLineRepository.findAllByBluePrint(awsBluePrintById);
AwsBluePrintDto awsBluePrintDto = new AwsBluePrintDto();
awsBluePrintDto.setName(awsBluePrintById.getName());
awsBluePrintDto.setComponents(AwsBluePrintDto.awsComponentDtosMapper(awsComponents));
awsBluePrintDto.setLinks(AwsBluePrintDto.componentLinkDtoListMapper(componentLines));
return awsBluePrintDto;
}

@Override
public List<AwsBluePrintDto> getMyAwsBlueprints() {
return null;
}
@Override
public List<AwsBluePrintListDto> getMyAwsBlueprints(String oauthId) {
Member member = memberRepository.findMemberByOauthId(oauthId);
if (member == null) {
throw new RuntimeException("member is null");
}

@Override
public void store(AwsBluePrintDto awsBluePrintDto) {
// Member member = memberRepository.findMemberById(1L);
List<AwsBluePrint> awsBluePrints = awsBluePrintRepository.findAwsBluePrintsByMember(member);
List<AwsBluePrintListDto> awsBluePrintDtos = new ArrayList<>();
for (AwsBluePrint awsBluePrint : awsBluePrints) {
AwsBluePrintListDto dto = new AwsBluePrintListDto();
dto.setName(awsBluePrint.getName());
dto.setId(awsBluePrint.getId());
dto.setCreatedAt(awsBluePrint.getCreated_at());
awsBluePrintDtos.add(dto);
}
return awsBluePrintDtos;
}

// BluePrint 저장
AwsBluePrint awsBluePrint = new AwsBluePrint();
awsBluePrint.setName(awsBluePrintDto.getName());
// awsBluePrint.setMember(member);
AwsBluePrint savedBlueprint = awsBluePrintRepository.save(awsBluePrint);
logger.info("savedBlueprint: {}", savedBlueprint);
@Override
public void store(AwsBluePrintDto awsBluePrintDto, String userId) {
Member member = memberRepository.findMemberByOauthId(userId);
// BluePrint 저장
AwsBluePrint awsBluePrint = new AwsBluePrint();
awsBluePrint.setName(awsBluePrintDto.getName());
awsBluePrint.setMember(member);
AwsBluePrint savedBlueprint = awsBluePrintRepository.save(awsBluePrint);
logger.info("savedBlueprint: {}", savedBlueprint);

List<AwsComponent> components = new ArrayList<>();
List<ComponentLineDto> links = awsBluePrintDto.getLinks();
List<AwsComponent> components = new ArrayList<>();
List<ComponentLineDto> links = awsBluePrintDto.getLinks();

// Components 저장
for (AwsComponentDto component : awsBluePrintDto.getComponents()) {
AwsComponent awsComponent = AwsComponent.createAwsComponent(component, savedBlueprint);
components.add(awsComponent);
}
awsComponentRepository.saveAll(components);
// Components 저장
for (AwsComponentDto component : awsBluePrintDto.getComponents()) {
AwsComponent awsComponent = AwsComponent.createAwsComponent(component, savedBlueprint);
components.add(awsComponent);
}
awsComponentRepository.saveAll(components);

// Lines 저장
List<ComponentLine> componentLines = new ArrayList<>();
for (ComponentLineDto link : links) {
ComponentLine componentLink = ComponentLine.createComponentLink(link, savedBlueprint);
componentLines.add(componentLink);
}
componentLineRepository.saveAll(componentLines);
}
// Lines 저장
List<ComponentLine> componentLines = new ArrayList<>();
for (ComponentLineDto link : links) {
ComponentLine componentLink = ComponentLine.createComponentLink(link, savedBlueprint);
componentLines.add(componentLink);
}
componentLineRepository.saveAll(componentLines);
}
}

This file was deleted.

Loading

0 comments on commit 9f42d0b

Please sign in to comment.