1단계: 카탈로그
도메인 설정
blueprint/petstore/env.yml
elasticore:
enable: true
config:
domainName: petstore
framework: springboot
mode: jpa
j2ee: jakarta
apiPath: "/api" # REST 주소는 /api/petstore/...
table:
prefix: ps_
referenceColumn: short # 다른 애그리거트 참조 컬럼: category_id (기본은 2.x 식 category_category_id)
annotations:
genid: "genid(io.elasticore.springboot3.util.IdUtils.newId)"
namespace:
base: io.elasticore.sample.petstore
namespace: base 가 헥사고날 패키지를 io.elasticore.sample.petstore 아래에 깔고, referenceColumn: short 는 ID 참조의
컬럼 이름을 필드 이름으로(category_id) 만듭니다 - 새 프로젝트의 선택입니다. ps_ 는 테이블 접두사입니다.
분류, 상품, 품목
blueprint/petstore/model/entity.yml
entity:
# ---- catalog: reference data, edited by the shop ----------------------
Category:
meta: entity @root @editable @expose(20) @access(read=public) -- 분류 (Fish, Dogs ...)
fields:
categoryId: long @id @sequence
name: string(30)! @search(like)
description: string(3000)!
Product:
meta: entity @root @editable @expose(20) @access(read=public) @sort(name+) -- 상품 (Angelfish, Bulldog ...)
fields:
productId: long @id @sequence
name: string(30)! @search(like)
description: string(3000)!
category: Category @ManyToOne # -> categoryId
Item:
meta: entity @root @editable @expose(50) @access(read=public) @terms(pet, 반려동물, 상품) -- 판매 단위 (Large, Male Puppy ...)
fields:
itemId: long @id @sequence
name: string(30)! @search(like)
description: string(3000)!
imagePath: string(100)
unitCost: money(10.2)! @min(0.01, 'price must be positive') @terms(price, 가격)
product: Product @ManyToOne # -> productId
Country:
meta: entity @root @editable @expose(300) @access(read=public) -- 국가
fields:
isoCode: string(2) @id
name: string(80)! @search(like)
printableName: string(80)!
| 줄 | 하는 일 |
|---|---|
@root @editable | 필드 단위로 고치는 기준정보: 공개 setter 와 PUT |
@expose(20) | 페이지 크기 20 의 REST API (품목 50, 국가 300) |
@access(read=public) | 조회·검색은 누구나. 나머지(생성·수정·삭제)는 관리자 |
@sort(name+) | 요청이 정하지 않으면 상품은 이 름순 |
@search(like) | 이름 일부로 검색, v3 번들(헥사고날·DDD·Kotlin·-Pv3)에서는 대소문자 무시 |
category: Category @ManyToOne | 헥사고날 번들에서는 다른 루트 참조: 상품은 categoryId 를 가짐 |
money(10.2)! @min(0.01, '...') | 변환기가 붙은 Money, DTO 의 @DecimalMin, TypeScript 클라이언트의 같은 검사 |
@terms(...) | 업무에서 부르는 이름 - Ossie 로 나가는 동의어 |
응답
curl -s https://petstore.elasticore.io/api/petstore/item/1000
curl -s -X POST https://petstore.elasticore.io/api/petstore/product/search \
-H 'Content-Type: application/json' -d '{"name":"gold"}'
GET /api/petstore/item/{id}와POST /api/petstore/product/search는 누구나 부릅니다.{"name":"gold"}는 Golden Retriever 와 Goldfish 를,{"name":" BULL "}은 Bulldog 를 찾습니다 - 값의 앞뒤 공백을 지우고 대소문자 없이 비교합니다.sortCode없는 검색은 이름순입니다(@sort(name+)).- 로그인하지 않고 상품을 만들거나 바꾸면 401, 고객이면 403 입니다.
GET /api/petstore/item/99999는 404{"detail":"Item not found","code":"not-found"},GET /api/petstore/item/abc는 400itemId: must be a number입니다.- 가격 0 은 400
price must be positive- TypeScript 의validateItem()과 같은 문구입니다.
카탈로그는 시작할 때 data.sql 로 채워집니다(텍스트와 이미지는 원본의 것, CC BY-SA 3.0).
다음: 로그인하는 고객.