convention
- application(java)
- pascal case : 클래스 또는 타입명
- camel case : 변수명
- application(python)
- 함수/ 변수/ attribute 소문자 + 언더바
- 클래스는 단어 첫문자마다 대문자 (CapWords)
- 모듈명은 짧은 소문자 + 언더바/ 패키지명은 짧게 소문자
- 상수는 모두 대문자 + 언더바 (ALL_CAPS)
- Public attribute는 밑줄로 시작x
- Protected instance attribute는 하나의 밑줄
- private instance attribute는 2개의 밑줄
def __init(self.name):
self.name = name #instance attribute
self._name = name #protectd attribute
self.__name = name #private attribute
- db(RDB) : Snake case : column명 (oracle 기준 upper 자동 설정)
- tableName : 시스템 구분 + product약식이름 + 언더바TB
- columnName : 컬러명+언더바+(..컬럼명)+언더바+접미사
_CD : code : 코드명
_NM : name : 코드이름과 같이 명칭
_NO : number : 게시물 번호/ 주민등록번호와 같이 논리명이 번호 겨우
_SQ : sequence
_DT : date
_ST : state
_FL : flag
_CNT : count
..
- db(mongodb:lowerCamelCase)
- dbName : 단수형+“db“접미사 (예: cleancodeDb, EmployeeManagementDb..)
- collectionName : 소문자의 복수형 (예: userProfiles, publicCloudAdvisors..)
- fieldName : 소문자 단수형이며, 배열 또는 컬렉션을 나타낼 경우 복수형
- url
- 단수/ 명사로 작성/ 명사 단어의 depth로 계층구분
- 케밥케이스(- : 하이픈) 사용
시스템끼리 convention 다를 경우
- oracle
- select문에서 as(alis) 사용하여 application convention에 전달
- mongodb
- Projection을 사용하여 apllication convention에 전달
- java
- @JsonProperty : 변수 annotation으로 mapping
- @JsonNaming : class에 annotation
- @JsonNaming(value = PropertyNamingStrategy.SnakeCaseStrategy.class)
- python
- pydantic.utils 를 사용하여 데이터 모델에 주입
error 관리
- 일관된 에러 메세지 포맷 관리
- java : @ControllerAdvice 와 @ExceptionHandler 활용한 포맷 관리
@ControllerAdvice
public class ApiExceptionHandler {
@ExceptionHandler(ApiException.class)
protected ResponseEntity<ErrorResponseEntity> handleCustomException(ApiException e) {
return ErrorResponseEntity.toResponseEntity(e);
}
@ExceptionHandler(Exception.class)
public void handleException(Exception e, HttpServletRequest request, HttpServletRespons response) throws IOException {
}
}
- python(fastAPI) : exception_handler 활용
app = FastAPI()
class CustomError(HTTPException):
def __init__(self, status_code: int, detail: str = None):
super().__init__(status_code=status_code, detail=detail)
@app.exception_handler(CustomError)
async def custom_error_handler(request: Request, exc: CustomError):
return JSONResponse(
status_code=exc.status_code,
content={"message": exc.detail},
)
@app.get("/raise-error")
async def raise_error():
raise CustomError(status_code=400, detail="error message")
ERD
- Entity : 사물(thing)
- Attribute : entity의 여러 속성(column)
- 식별자 : 기본키/ 유니크키/ 참조키..
- releationship
- 실선(식별) : B는 A의 기본키를 가지고, B의 기본키로 사용
- 점선(비식별) : A의 기본키를 가지고 있으나, B의 기본키로 사용하지 않음
- 0개 이상/ 1:1/ 1:N/ N:N..
- 서브타입 : 하나의 슈퍼 인스턴스는 서브 타입을 1개만 가지던가(배타적) 두 개 이상(포괄적)이 될 수 있다
- 배타적 서브타입 : 은행 고객 중에 사원이거나 일반 고객일 수 있다
- 포괄적(중복) 서브타입 : 은행 고객 중에 사원이면서 일반 고객일 수 있다