Skip to content

Commit

Permalink
Revert "Merge remote-tracking branch 'origin/feature/#17-blueprint' i…
Browse files Browse the repository at this point in the history
…nto feature/#17-blueprint"

This reverts commit 9f42d0b.
  • Loading branch information
nookcoder committed Jul 17, 2023
1 parent 9f42d0b commit 3014a89
Show file tree
Hide file tree
Showing 16 changed files with 309 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,37 @@

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;

@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);
}
private final Logger logger = LoggerFactory.getLogger(BlueprintController.class);
private final AwsBlueprintService awsBlueprintService;

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

@GetMapping("/test")
@AuthorizationFromToken
public String testMiddleware(String userId) {
System.out.printf("userId: %s\n", userId);
return userId;
}
@PostMapping("/aws")
public String createAwsBlueprint(@RequestBody AwsBluePrintDto awsBluePrintDto) {
awsBlueprintService.store(awsBluePrintDto);
return "hello-world";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

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

@Entity
Expand All @@ -17,24 +20,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, S3, ElastiCache, CloudFront, AutoScaling
VPC, SUBNET, ELB, EC2, EFS, WAF, ROUTE53, NAT_GATEWAY, RDS,
}
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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
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,15 +3,14 @@

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(Long bluePrintId);
AwsBluePrintDto getAwsBlueprint();

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

void store(AwsBluePrintDto awsBluePrintDto, String userId);
void store(AwsBluePrintDto awsBluePrintDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
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 @@ -30,75 +28,63 @@
@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(Long bluePrintId) {
AwsBluePrint awsBluePrintById = awsBluePrintRepository.findAwsBluePrintById(bluePrintId);
if (awsBluePrintById == null) {
throw new RuntimeException("awsBluePrintById is null");
}
@Override
public AwsBluePrintDto getAwsBlueprint() {
AwsBluePrint awsBluePrintById = awsBluePrintRepository.findAwsBluePrintById(1L);
logger.info("awsBluePrintById: {}", awsBluePrintById);
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<AwsBluePrintListDto> getMyAwsBlueprints(String oauthId) {
Member member = memberRepository.findMemberByOauthId(oauthId);
if (member == null) {
throw new RuntimeException("member is null");
}
@Override
public List<AwsBluePrintDto> getMyAwsBlueprints() {
return null;
}

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;
}
@Override
public void store(AwsBluePrintDto awsBluePrintDto) {
// Member member = memberRepository.findMemberById(1L);

@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);
// 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.kumofactory.cloud.global.middleware;

public class AuthorizationFromToken {
}
Loading

0 comments on commit 3014a89

Please sign in to comment.