Skip to content

Commit 6ac1ae3

Browse files
committed
Java 소스 완성본 draft ver.
1 parent 5241a86 commit 6ac1ae3

35 files changed

Lines changed: 1554 additions & 1 deletion

.gitignore

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,4 +405,35 @@ FodyWeavers.xsd
405405
sns.db
406406
.DS_Store
407407

408-
.venv
408+
.venv
409+
410+
####################
411+
# Java
412+
####################
413+
414+
# Compiled class file
415+
*.class
416+
build/
417+
conf.sh
418+
419+
# Log file
420+
*.log
421+
422+
# BlueJ files
423+
*.ctxt
424+
425+
# Mobile Tools for Java (J2ME)
426+
mtj.tmp/
427+
428+
# Package Files #
429+
*.jar
430+
*.war
431+
*.nar
432+
*.ear
433+
*.zip
434+
*.tar.gz
435+
*.rar
436+
437+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
438+
hs_err_pid*
439+
replay_pid*

complete/java/demo/.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/gradlew text eol=lf
2+
*.bat text eol=crlf
3+
*.jar binary
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Spring Boot 기반 자바 개발을 위한 코드 생성 가이드 (VSCode + GitHub Copilot)
2+
3+
이 문서는 VSCode에서 GitHub Copilot을 활용해 Spring Boot 기반 자바 프로젝트를 개발할 때 따를 코드 생성 규칙과 가이드를 정의합니다.
4+
5+
---
6+
7+
## 1. 기본 설정
8+
9+
- **사용 언어**: Java 17 이상
10+
- **프레임워크**: Spring Boot 3.x
11+
- **빌드 도구**: Gradle (Kotlin DSL) 또는 Maven
12+
- **프로젝트 구조**: `src/main/java`, `src/main/resources` 표준 구조 사용
13+
- **이름 규칙**: 클래스 및 메서드는 `CamelCase`, 변수는 `lowerCamelCase`
14+
15+
---
16+
17+
## 2. 패키지 구조 예시
18+
19+
```
20+
com.example.project
21+
├── controller // REST 컨트롤러
22+
├── service // 비즈니스 로직
23+
├── repository // JPA 레포지토리
24+
├── domain // 엔티티 및 도메인 모델
25+
├── dto // DTO (데이터 전송 객체)
26+
├── config // 설정 클래스
27+
├── exception // 커스텀 예외 및 핸들러
28+
```
29+
30+
---
31+
32+
## 3. 코드 스타일
33+
34+
- **생성자 주입** 사용 (`@RequiredArgsConstructor`)
35+
- **Lombok**으로 보일러플레이트 제거:
36+
- `@Getter`, `@Setter`, `@ToString`, `@NoArgsConstructor`, `@AllArgsConstructor`
37+
- 모든 **public 클래스 및 메서드에 JavaDoc** 작성
38+
- 로그는 `@Slf4j`로 처리
39+
40+
---
41+
42+
## 4. REST API 작성 규칙
43+
44+
- `@RestController`, `@RequestMapping` 사용
45+
- 응답은 `ResponseEntity<>`로 감싸기
46+
- 요청 바디 검증은 `@Valid`와 함께 `@RequestBody` 사용
47+
- 예외는 `@ControllerAdvice`로 전역 처리
48+
49+
---
50+
51+
## 5. JPA 작성 규칙
52+
53+
- `@Entity`, `@Table`, `@Id` 필수 사용
54+
- `@ManyToOne(fetch = FetchType.LAZY)` 선호
55+
- 양방향 매핑은 꼭 필요할 때만 사용
56+
- 엔티티는 직접 반환하지 말고 DTO를 사용
57+
58+
---
59+
60+
## 6. 테스트 작성 규칙
61+
62+
- 통합 테스트: `@SpringBootTest`, 컨트롤러 테스트: `@WebMvcTest`
63+
- 의존성 목킹: `@MockBean` 또는 `Mockito`
64+
- 테스트 클래스 이름: `클래스명 + Test.java`
65+
- 테스트는 `src/test/java` 아래에 위치
66+
67+
---
68+
69+
## 7. Copilot 활용 팁
70+
71+
- `// 생성: 설명` 형태의 주석으로 Copilot에게 명령
72+
- 메서드 시그니처나 클래스 선언만 먼저 작성해도 자동 완성 유도 가능
73+
- 생성된 코드는 반드시 **리팩토링 및 검토**할 것
74+
- 필요한 로직 흐름에 대해 인라인 주석 사용 (예: `// 사용자 존재 여부 확인`)
75+
76+
---
77+
78+
## 예시 프롬프트
79+
80+
```java
81+
// 생성: 사용자(User) 엔티티를 관리하는 REST 컨트롤러
82+
```
83+
84+
```java
85+
// 생성: 이메일로 사용자 조회하는 서비스 메서드
86+
```
87+
88+
---
89+
90+
## 8. 의존성 설정 예시 (Gradle Kotlin DSL 기준)
91+
92+
```kotlin
93+
dependencies {
94+
implementation("org.springframework.boot:spring-boot-starter-web")
95+
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
96+
implementation("org.springframework.boot:spring-boot-starter-validation")
97+
implementation("org.projectlombok:lombok")
98+
runtimeOnly("com.h2database:h2") // 또는 사용 중인 DBMS
99+
testImplementation("org.springframework.boot:spring-boot-starter-test")
100+
}
101+
```
102+
103+
---
104+
105+
## 9. API 문서화
106+
107+
- Swagger(OpenAPI) 문서를 위해 `springdoc-openapi` 사용
108+
- 컨트롤러에 `@Operation`, DTO나 엔티티에 `@Schema` 활용
109+
110+
---
111+
112+
**끝.**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- @azure Rule - Use Azure Best Practices: When generating code for Azure, running terminal commands for Azure, or performing operations related to Azure, invoke your `azure_development-get_best_practices` tool if available.

complete/java/demo/.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
HELP.md
2+
.gradle
3+
build/
4+
!gradle/wrapper/gradle-wrapper.jar
5+
!**/src/main/**/build/
6+
!**/src/test/**/build/
7+
8+
### STS ###
9+
.apt_generated
10+
.classpath
11+
.factorypath
12+
.project
13+
.settings
14+
.springBeans
15+
.sts4-cache
16+
bin/
17+
!**/src/main/**/bin/
18+
!**/src/test/**/bin/
19+
20+
### IntelliJ IDEA ###
21+
.idea
22+
*.iws
23+
*.iml
24+
*.ipr
25+
out/
26+
!**/src/main/**/out/
27+
!**/src/test/**/out/
28+
29+
### NetBeans ###
30+
/nbproject/private/
31+
/nbbuild/
32+
/dist/
33+
/nbdist/
34+
/.nb-gradle/
35+
36+
### VS Code ###
37+
.vscode/

complete/java/demo/build.gradle

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
plugins {
2+
id 'java'
3+
id 'org.springframework.boot' version '3.4.4'
4+
id 'io.spring.dependency-management' version '1.1.7'
5+
}
6+
7+
group = 'com.example'
8+
version = '0.0.1-SNAPSHOT'
9+
10+
java {
11+
toolchain {
12+
languageVersion = JavaLanguageVersion.of(21)
13+
}
14+
}
15+
16+
configurations {
17+
compileOnly {
18+
extendsFrom annotationProcessor
19+
}
20+
}
21+
22+
repositories {
23+
mavenCentral()
24+
}
25+
26+
dependencies {
27+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
28+
implementation 'org.springframework.boot:spring-boot-starter-web'
29+
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
30+
31+
// Swagger UI
32+
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.4.0'
33+
34+
// SQLite Database
35+
implementation 'org.xerial:sqlite-jdbc:3.45.1.0'
36+
implementation 'org.hibernate.orm:hibernate-community-dialects:6.4.4.Final'
37+
38+
compileOnly 'org.projectlombok:lombok'
39+
annotationProcessor 'org.projectlombok:lombok'
40+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
41+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
42+
}
43+
44+
tasks.named('test') {
45+
useJUnitPlatform()
46+
}

complete/java/demo/diagram.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# SNS API 서비스 다이어그램
2+
3+
## 전체 시스템 구조
4+
5+
```
6+
+--------------------------------------------+
7+
| FastAPI 애플리케이션 |
8+
+--------------------------------------------+
9+
| - title: "Simple SNS API" |
10+
| - CORS 미들웨어 추가 |
11+
| - API 라우터 설정 (/api) |
12+
+--------------------------------------------+
13+
|
14+
| 사용
15+
v
16+
+--------------------------------------------+
17+
| 데이터베이스 |
18+
+--------------------------------------------+
19+
| - SQLite |
20+
| - 테이블: posts, comments, likes |
21+
+--------------------------------------------+
22+
|
23+
| 포함
24+
v
25+
+--------------------------------------------+
26+
| 데이터 모델 |
27+
+--------------------------------------------+
28+
| | | | |
29+
| v v v |
30+
+----------+ +------+ +------+ |
31+
| Post | |Comment| | Like | |
32+
+----------+ +------+ +------+ |
33+
+--------------------------------------------+
34+
|
35+
| 구현
36+
v
37+
+--------------------------------------------+
38+
| API 엔드포인트 |
39+
+--------------------------------------------+
40+
| 포스트 관련: |
41+
| - GET /api/posts |
42+
| - POST /api/posts |
43+
| - GET /api/posts/{postId} |
44+
| - PATCH /api/posts/{postId} |
45+
| - DELETE /api/posts/{postId} |
46+
| |
47+
| 댓글 관련: |
48+
| - GET /api/posts/{postId}/comments |
49+
| - POST /api/posts/{postId}/comments |
50+
| - GET /api/posts/{postId}/comments/{id} |
51+
| - PATCH /api/posts/{postId}/comments/{id} |
52+
| - DELETE /api/posts/{postId}/comments/{id}|
53+
| |
54+
| 좋아요 관련: |
55+
| - POST /api/posts/{postId}/likes |
56+
| - DELETE /api/posts/{postId}/likes |
57+
+--------------------------------------------+
58+
```
59+
60+
## 데이터 모델 상세 다이어그램
61+
62+
```
63+
+----------------+ +----------------+ +----------------+
64+
| Post | | Comment | | Like |
65+
+----------------+ +----------------+ +----------------+
66+
| id: int | | id: int | | postId: int |
67+
| userName: str | | postId: int | | userName: str |
68+
| content: str | | userName: str | | |
69+
| createdAt: str | | content: str | | |
70+
| updatedAt: str | | createdAt: str | | |
71+
| likeCount: int | | updatedAt: str | | |
72+
| commentCount:int| | | | |
73+
+----------------+ +----------------+ +----------------+
74+
| | |
75+
| 1 | * | *
76+
v v v
77+
+----------------+ +----------------+ +----------------+
78+
| PostCreate | | CommentCreate | | LikeBase |
79+
+----------------+ +----------------+ +----------------+
80+
| userName: str | | userName: str | | userName: str |
81+
| content: str | | content: str | | |
82+
+----------------+ +----------------+ +----------------+
83+
| |
84+
v v
85+
+----------------+ +----------------+
86+
| PostUpdate | | CommentUpdate |
87+
+----------------+ +----------------+
88+
| content: str | | content: str |
89+
+----------------+ +----------------+
90+
```
91+
92+
## 데이터베이스 스키마 다이어그램
93+
94+
```
95+
+----------------+ +----------------+ +----------------+
96+
| posts | | comments | | likes |
97+
+----------------+ +----------------+ +----------------+
98+
| id | | id | | postId |
99+
| userName | | postId | | userName |
100+
| content | | userName | +----------------+
101+
| createdAt | | content | ^
102+
| updatedAt | | createdAt | |
103+
| likeCount | | updatedAt | |
104+
| commentCount | +----------------+ |
105+
+----------------+ ^ |
106+
^ | |
107+
| +------------------------+
108+
| | |
109+
+-----------------------+------------------------+
110+
외래 키 관계
111+
```
112+
113+
## API 흐름 다이어그램
114+
115+
```
116+
클라이언트 → HTTP 요청 → FastAPI 애플리케이션 → API 라우터 → 비즈니스 로직 →
117+
SQLite 데이터베이스 → 결과 → Pydantic 모델 변환 → JSON 응답 → 클라이언트
118+
```
119+
120+
## API 엔드포인트 설명
121+
122+
1. **포스트 관련 API**
123+
- `GET /api/posts`: 모든 포스트 목록 조회
124+
- `POST /api/posts`: 새 포스트 작성
125+
- `GET /api/posts/{postId}`: 특정 포스트 조회
126+
- `PATCH /api/posts/{postId}`: 특정 포스트 수정
127+
- `DELETE /api/posts/{postId}`: 특정 포스트 삭제
128+
129+
2. **댓글 관련 API**
130+
- `GET /api/posts/{postId}/comments`: 특정 포스트의 댓글 목록 조회
131+
- `POST /api/posts/{postId}/comments`: 특정 포스트에 댓글 작성
132+
- `GET /api/posts/{postId}/comments/{commentId}`: 특정 댓글 조회
133+
- `PATCH /api/posts/{postId}/comments/{commentId}`: 특정 댓글 수정
134+
- `DELETE /api/posts/{postId}/comments/{commentId}`: 특정 댓글 삭제
135+
136+
3. **좋아요 관련 API**
137+
- `POST /api/posts/{postId}/likes`: 특정 포스트에 좋아요 추가
138+
- `DELETE /api/posts/{postId}/likes`: 특정 포스트의 좋아요 취소
42.7 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)