Skip to content

πŸ“š μ½”λ“œ μ»¨λ²€μ…˜

μ΅œμ€€ν˜Έ edited this page Mar 26, 2024 · 11 revisions

KOIN API V2μ—μ„œ μ‚¬μš©ν•˜λŠ” μ½”λ“œ μ»¨λ²€μ…˜ 섀정에 λŒ€ν•œ λ¬Έμ„œμž…λ‹ˆλ‹€.

ν•΄λ‹Ή μ»¨λ²€μ…˜μ€

Java

v1.0

μ•„λž˜ μ»¨λ²€μ…˜μ„ IntelliJ에 μ μš©ν•œλ‹€.

μžμ„Έν•œ 적용 방식은 πŸ’‘ μ½”λ“œμ»¨λ²€μ…˜ μ μš©ν•˜κΈ° λ¬Έμ„œλ₯Ό μ°Έκ³ ν•˜μ—¬ μ μš©ν•œλ‹€.

파일 λ‚΄μš© 보기
<code_scheme name="BCSDLab-Backend-coding-convention-v1.0">
<!-- Referenced by Naver coding convention for Java (version 1.2) -->
<!-- https://naver.github.io/hackday-conventions-java/ -->
  <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
  <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="3" />
  <option name="IMPORT_LAYOUT_TABLE">
    <value>
      <emptyLine />
      <package name="" withSubpackages="true" static="true" />
      <emptyLine />
      <package name="java" withSubpackages="true" static="false" />
      <emptyLine />
      <package name="javax" withSubpackages="true" static="false" />
      <emptyLine />
      <package name="org" withSubpackages="true" static="false" />
      <emptyLine />
      <package name="net" withSubpackages="true" static="false" />
      <emptyLine />
      <package name="com" withSubpackages="true" static="false" />
      <emptyLine />
      <package name="" withSubpackages="true" static="false" />
      <emptyLine />
    </value>
  </option>
  <option name="RIGHT_MARGIN" value="120" />
  <option name="ENABLE_JAVADOC_FORMATTING" value="false" />
  <option name="JD_KEEP_EMPTY_LINES" value="false" />
  <option name="FORMATTER_TAGS_ENABLED" value="true" />
  <XML>
    <option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
  </XML>
  <codeStyleSettings language="JAVA">
    <option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
    <option name="LINE_COMMENT_ADD_SPACE" value="true" />
    <option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
    <option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
    <option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
    <option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
    <option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
    <option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
    <option name="SPACE_AFTER_TYPE_CAST" value="false" />
    <option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
    <option name="CALL_PARAMETERS_WRAP" value="1" />
    <option name="METHOD_PARAMETERS_WRAP" value="1" />
    <option name="EXTENDS_LIST_WRAP" value="1" />
    <option name="METHOD_CALL_CHAIN_WRAP" value="5" />
    <option name="THROWS_LIST_WRAP" value="5" />
    <option name="EXTENDS_KEYWORD_WRAP" value="1" />
    <option name="BINARY_OPERATION_WRAP" value="1" />
    <option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" />
    <option name="TERNARY_OPERATION_WRAP" value="1" />
    <option name="ARRAY_INITIALIZER_WRAP" value="1" />
    <indentOptions>
      <option name="CONTINUATION_INDENT_SIZE" value="4" />
      <option name="USE_TAB_CHARACTER" value="false" />
    </indentOptions>
  </codeStyleSettings>
</code_scheme>

static import

static importλŠ” μ™€μΌλ“œμΉ΄λ“œ(*) μ‚¬μš©μ„ ν—ˆμš©ν•œλ‹€. 단, 3κ°œλΆ€ν„° ν—ˆμš©ν•œλ‹€.

쀄 μ΅œλŒ€ λ„ˆλΉ„

λ„€μ΄λ²„λŠ” 120, ꡬ글은 100자 κΈ°μ€€μœΌλ‘œ 쀄 μ΅œλŒ€ λ„ˆλΉ„λ₯Ό μž‘λŠ”λ‹€.

빈 쀄

  • λ©”μ„œλ“œ 사이에 빈 쀄을 μΆ”κ°€ν•œλ‹€.
  • 클래슀의 λ§ˆμ§€λ§‰ λ©”μ„œλ“œμ—λŠ” 빈 쀄을 μΆ”κ°€ν•˜μ§€ μ•ŠλŠ”λ‹€. (λ©”μ„œλ“œλ₯Ό ν¬ν•¨ν•˜μ—¬ 클래슀 λ‚΄λΆ€μ˜ λ§ˆμ§€λ§‰ κ΄„ν˜Έμ— 빈 쀄을 μΆ”κ°€ν•˜μ§€ μ•ŠλŠ”λ‹€.)

Application

Package Architecture

ꡬ쑰 보기
└── koin
    β”œβ”€β”€ KoinApplication.java
    β”œβ”€β”€ domain
    β”‚   β”œβ”€β”€ shop
    β”‚   β”‚   β”œβ”€β”€ controller
    β”‚   β”‚   β”‚   └── ShopController.java
    β”‚   β”‚   β”œβ”€β”€ domain
    β”‚   β”‚   β”‚   β”œβ”€β”€ Menu.java
    β”‚   β”‚   β”‚   β”œβ”€β”€ MenuCategory.java
    β”‚   β”‚   β”‚   β”œβ”€β”€ MenuCategoryMap.java
    β”‚   β”‚   β”‚   β”œβ”€β”€ MenuImage.java
    β”‚   β”‚   β”‚   └── MenuOption.java
    β”‚   β”‚   β”œβ”€β”€ dto
    β”‚   β”‚   β”‚   └── ShopMenuResponse.java
    β”‚   β”‚   β”œβ”€β”€ repository
    β”‚   β”‚   β”‚   └── MenuRepository.java
    β”‚   β”‚   └── service
    β”‚   β”‚       └── ShopService.java
    └── global
        β”œβ”€β”€ common
        β”‚   └── BaseEntity.java
        β”œβ”€β”€ config
        β”‚   └── JpaConfiguration.java
        └── exception
            └── GlobalExceptionHandler.java
μœ„μ™€ 같은 νŒ¨ν‚€μ§€ ꡬ쑰λ₯Ό μ‚¬μš©ν•œλ‹€.

λ©”μ„œλ“œ 이름

  • Service Layerμ—μ„œλŠ” λΉ„μ¦ˆλ‹ˆμŠ€ λ‘œμ§μ„ λ‚˜νƒ€λ‚΄λŠ” μš©μ–΄λ₯Ό μ‚¬μš©ν•œλ‹€.
    • 쑰회: getXXX
  • Repository Layerμ—μ„œλŠ” λ°μ΄ν„°λ² μ΄μŠ€ 접근을 λ‚˜νƒ€λ‚΄λŠ” μš©μ–΄λ₯Ό μ‚¬μš©ν•œλ‹€.
    • Repositoryμ—μ„œ λ‹¨μˆœ μ‘°νšŒλ‘œμ§μ„ ν˜ΈμΆœν•  경우 Entity getByXXX() λ©”μ†Œλ“œλ₯Ό ν˜ΈμΆœν•œλ‹€.
    • λ³„λ„μ˜ μ˜ˆμ™Έ 핸듀링이 ν•„μš”ν•œ 경우 Optinal<Entity> findByXXX() λ©”μ†Œλ“œλ₯Ό ν˜ΈμΆœν•œλ‹€.
    • JPAλ₯Ό μ‚¬μš©ν•˜μ—¬ Repository interfaceλ₯Ό μ •μ˜ν•  λ•Œ Repositoryλ₯Ό 상속받아 κ΅¬ν˜„ν•œλ‹€.

DTO

  • recordλ₯Ό μ‚¬μš©ν•œλ‹€.
  • Java Codeμ—μ„œλŠ” camelCaseλ₯Ό 톡해 μž‘μ„±ν•˜κ³  결과물둜 snake_caseλ₯Ό μš”κ΅¬ν•  경우 @JsonNaming(value = SnakeCaseStrategy.class)등을 톡해 snake_case둜 μ‘λ‹΅λ˜λ„λ‘ν•œλ‹€.
  • κΈ°μ‘΄ 코인에 μ—†λ˜ μƒˆλ‘œμš΄ κΈ°λŠ₯을 λ§Œλ“œλŠ” 경우 κ²°κ³Όλ¬Όλ‘œλŠ” snake_case둜 μ‘λ‹΅λ˜λ„λ‘ ν•œλ‹€.
    • ν΄λΌμ΄μ–ΈνŠΈμ˜ ν˜Όλž€μ„ 덜기 μœ„ν•΄ κΈ°μ‘΄ μ½”μΈμ˜ DTO μ»¨λ²€μ…˜μ„ 따라간닀
    • image

Test

μΈμˆ˜ν…ŒμŠ€νŠΈ

ν•΄λ‹Ή μ»¨λ²€μ…˜μ€ λ§ˆμ΄κ·Έλ ˆμ΄μ…˜ κ³Όμ •μ—μ„œ ν•„μˆ˜λ‘œ μ μš©λ˜λŠ” μ»¨λ²€μ…˜μž…λ‹ˆλ‹€.

κΈ°λŠ₯을 μž‘μ„±ν•  λ•Œ μΈμˆ˜ν…ŒμŠ€νŠΈλ₯Ό λ°˜λ“œμ‹œ μž‘μ„±ν•΄μ•Όν•œλ‹€. μΈμˆ˜ν…ŒμŠ€νŠΈλŠ” RestAssuredλ₯Ό μ‚¬μš©ν•˜μ—¬ μž‘μ„±ν•œλ‹€.

μžμ„Έν•œ λ‚΄μš©μ€ μ½”λ“œλ₯Ό μ°Έκ³ ν•œλ‹€.