[LG CNS AM CAMP 1기] 백엔드 II 14 | Spring

letthem·2025년 2월 14일
0

LG CNS AM CAMP 1기

목록 보기
30/31
post-thumbnail

[스프링 마이크로서비스 코딩 공작소] 1장 책에 필기

공동 책임 모델
https://aws.amazon.com/ko/compliance/shared-responsibility-model/

이벤트 스토밍
https://www.youtube.com/watch?v=F7EnW8dfetU

SpringBoot로 마이크로서비스 구축하기 - 1

프로젝트 생성

컨트롤러 생성

Controller/LicenseController

package com.optimagrowth.license.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "v1/organization/{organizationId}/license")
public class LicenseController {

}

License 모델

model/License

package com.optimagrowth.license.model;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
public class License {
    private int id;
    private String licenseId;
    private String description;
    private String organizationId;
    private String productName;
    private String licenseType;
}

Service

service/LicenseService

DB가 없어서 임의의 데이터를 만드는 것 !

package com.optimagrowth.license.service;

import com.optimagrowth.license.model.License;
import org.springframework.stereotype.Service;

import java.util.Random;

// 각 메서드는 CRUD 테스트를 위해서 임의의 데이터를 반환하는 코드를 추가

@Service
public class LicenseService {

    public License getLicense(String licenseId, String organizationId) {
        License license = new License();
        license.setId(new Random().nextInt(1000));
        license.setLicenseId(licenseId);
        license.setOrganizationId(organizationId);
        license.setDescription("Software product");
        license.setProductName("Ostock");
        license.setLicenseType("full");
        return license;
    }

    public String createLicense(License license, String organizationId) {
        String responseMessage = null;
        if (license != null) {
            license.setOrganizationId(organizationId);
            responseMessage = String.format("License created %s", license.toString());
        }
        return responseMessage;
    }

    public String updateLicense(License license, String organizationId) {
        String responseMessage = null;
        if (license != null) {
            license.setOrganizationId(organizationId);
            responseMessage = String.format("License updated %s", license.toString());
        }
        return responseMessage;
    }

    public String deleteLicense(String licenseId, String organizationId) {
        String responseMessage = null;
        responseMessage
                = String.format("Deleting license with id %s for the organization %s",
                    licenseId, organizationId);

        return responseMessage;
    }
}

컨트롤러 메서드를 추가

package com.optimagrowth.license.controller;

import com.optimagrowth.license.model.License;
import com.optimagrowth.license.service.LicenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "v1/organization/{organizationId}/license")
public class LicenseController {
    @Autowired
    private LicenseService licenseService;

    @GetMapping(value = "/{licenseId}")
    public ResponseEntity<License> getLicense(
            @PathVariable("organizationId") String organizationId,
            @PathVariable("licenseId") String licenseId) {
        License license = licenseService.getLicense(licenseId, organizationId);
        return ResponseEntity.ok(license);
    }

    @PutMapping
    public ResponseEntity<String> updateLicense(
            @PathVariable("organizationId") String organizationId,
            @RequestBody License request) {
        return ResponseEntity.ok(licenseService.updateLicense(request, organizationId));
    }

    @PostMapping
    public ResponseEntity<String> createLicense(
            @PathVariable("organizationId") String organizationId,
            @RequestBody License request) {
        return ResponseEntity.ok(licenseService.createLicense(request, organizationId));
    }

    @DeleteMapping(value= "/{licenseId}")
    public ResponseEntity<String> createLicense(
            @PathVariable("organizationId") String organizationId,
            @PathVariable("licenseId") String licenseId) {
        return ResponseEntity.ok(licenseService.deleteLicense(licenseId, organizationId));
    }
}

테스트

organizationId: optimaGrowth
licenseId: 1234567890

라이센스 조회 : 하드코딩된 라이센스 정보를 반환

라이센스 수정 : 라이센스 타입을 complete로 변경

라이센스 생성

미니 프로젝트

목적: 배웠던 내용 정리하기, 함께 일할 때 발생하는 문제 대처
기간: 2월 21일(금) ~ 27일(목)
* 27일은 프로젝트 결과 발표 및 리뷰를 진행하므로 개발 일정에서 제외합니다.
내용: 아래 요구사항을 만족하는 웹 애플리케이션 개발
1. 요구사항

  • 주제
    • OpenAI API 등을 이용한 맞춤형 뉴스 서비스
    • 뉴스 종류, 수집 방법, 제공 서비스 등은 조별로 세분화 (영화, 스포츠, ... 등)
  • 기능
    • 회원가입, 로그인/로그아웃, 파일 첨부 및 다운로드, 목록 조회, 상세 조회, 등록, 수정, 삭제, 관리자 기능 포함
    • 프론트엔드는 리액트, 백엔드는 스프링부트로 개발해서 상호 연동
    • 데이터베이스 종류는 무관
    • 기타 보유, 경험한 기술을 추가로 활용하는 것은 무관
    • 보안 요소를 도출하고, 강화 방법 추가 우대
    • 컨테이너 이미지를 만들어서 도커 허브에 배포하고, docker-compose를 이용해서 실행
  1. 산출물
  • 프로젝트 계획서 - 프로젝트 주제, 주제 선택 이유, 업무 분장, 일정 계획(WBS) 등
  • 프로젝트 일지 - 금일 할일, 수행 결과, 익일 계획, 주요 이슈 원인 및 해결 방법 등을 기록
  • 결과 보고서 = PPT 형식으로 발표 자료로 활용
    • UI 설계 - 핸드드로잉 또는 피그마와 같은 도구를 활용해서 프론트엔드 화면을 정의
    • API 설계 - 백엔드 API 개발 및 프론트엔드 연계에 필요한 정보를 포함
    • ERD 또는 데이터모델링 - 애플리케이션에서 사용할 데이터베이스의 데이터 구조 또는 엔티티를 정의
    • 기능 시연 동영상
    • docker-compose.yaml 내용 설명 (yaml 파일은 별도로 제출)
    • 소스 코드가 저장된 GitHub 주소
    • 장애 및 오류 사항과 대응 방법
    • 개인별 후기
  1. 제출형식 및 방법
  • 제출기한 : 2월 27일 9시까지

  • 제출방법 : 공유디렉터리에 조별로 제출

  • 파일형식 : 원본파일과 PDF파일을 함께 제출

  • 파 일 명 : 1조-결과보고서.pptx / 1조-결과보고서.pdf (원본 제출이 불가한 경우 제외)

  • 참조 자료 및 평가 방법은 추후 공지

0개의 댓글

관련 채용 정보