Skip to content

Commit 0f41b0d

Browse files
committed
Kotlin + Spring 간단한 게시판 CRUD
1 parent 5d5454a commit 0f41b0d

32 files changed

+1242
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+

20230106/simple-board/.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/

20230106/simple-board/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# 게시판
2+
3+
간단한 Kotlin Spring 연습.
4+
5+
## 프로젝트 시작
6+
Spring Initializer 활용. (start.spring.io)
7+
### dependencies
8+
- spring boot starter web
9+
- spring boot devtools
10+
- h2 database
11+
12+
## 할 일
13+
전체적인 할 일은 게시글의 목록, 상세, 입력, 수정, 삭제
14+
영속성까지 쭉 실험해보기.
15+
16+
- [x] kotest 환경설정
17+
- [x] 계산기 덧셈 메서드를 통해서 kotest의 동작과 스펙 작성법 확인
18+
- [x] greeting -> "/" 경로에서 "hello"를 반환한다.
19+
- [ ] 글 목록 -> "/posts" 경로에서 글 목록을 반환한다.
20+
21+
### 게시글 설정
22+
- 구성: 작성자, 제목, 글 내용, 작성 시간
23+
- 예시
24+
25+
{
26+
"author": "Jin",
27+
"title": "피곤한 하루",
28+
"content": "아무것도 하기 싫다",
29+
"date": "2023-01-06T09:35:23.493Z"
30+
}
31+
32+
## Kotest 설정
33+
설정 - https://kotest.io/docs/quickstart
34+
Spring DI를 이용하기 위한 설정 - https://kotest.io/docs/extensions/spring.html
35+
36+
## Kotest
37+
DescribeSpec - https://kotest.io/docs/framework/testing-styles.html#describe-spec
38+
Setup mocks - https://kotest.io/docs/framework/integrations/mocking.html#option-1---setup-mocks-before-tests
39+
40+
## Exposed Spring Starter
41+
Hibernate를 대신해서 Exposed를 ORM 도구로 사용할 수 있게 해줌.
42+
https://github.com/JetBrains/Exposed/blob/c6cf3792997b28a2c6617c17adc5460ed77a1da7/exposed-spring-boot-starter/README.md
43+
44+
### DSL
45+
https://github.com/JetBrains/Exposed/wiki/DSL
46+
47+
## 알게 된것
48+
- live reload server - https://docs.spring.io/spring-boot/docs/1.5.16.RELEASE/reference/html/using-boot-devtools.html#using-boot-devtools-livereload
49+
- kotest library import 시 버전 명시를 해주지 않아서 못 불러옴.
50+
- 특정 port 번호에 있는 프로세스 삭제 https://stackoverflow.com/questions/3855127/find-and-kill-process-locking-port-3000-on-mac
51+
- Spring Boot 3.0.0 에서 데이터 베이스 연결이 안되는 이슈 https://github.com/JetBrains/Exposed/issues/1636
52+
- insert 쿼리문 틀림.
53+
54+
```sql
55+
INSERT INTO
56+
Posts (ID, AUTHOR, TITLE, CONTENT, CREATED)
57+
VALUES ('1', 'Jin', 'Hello', 'My name is Park', '2022-02-03T03:24:48')
58+
```
59+
60+
- 도메인 객체를 초기화할때 id에 파라메터를 받지 않고 초기화.
61+
```kotlin
62+
class Post(
63+
id: Long? = null,
64+
val author: String,
65+
val title: String,
66+
val content: String,
67+
val created: LocalDateTime,
68+
) {
69+
var id: Long = INITIAL_ID
70+
private set
71+
72+
init {
73+
if (id != null) {
74+
this.id = id
75+
}
76+
}
77+
}
78+
```
79+
80+
## 생각들
81+
- DTO 의 Date 형식의 타입은 DateTime, String 이어야 할까?
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
plugins {
4+
id("org.springframework.boot") version "3.0.1"
5+
id("io.spring.dependency-management") version "1.1.0"
6+
kotlin("jvm") version "1.7.22"
7+
kotlin("plugin.spring") version "1.7.22"
8+
}
9+
10+
group = "com.gringrape"
11+
version = "0.0.1-SNAPSHOT"
12+
java.sourceCompatibility = JavaVersion.VERSION_17
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
dependencies {
19+
implementation("org.springframework.boot:spring-boot-starter-web")
20+
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
21+
implementation("org.jetbrains.kotlin:kotlin-reflect")
22+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
23+
developmentOnly("org.springframework.boot:spring-boot-devtools")
24+
implementation("org.jetbrains.exposed:exposed-kotlin-datetime:0.41.1")
25+
implementation("org.springframework.boot:spring-boot-starter-validation:3.0.1")
26+
27+
implementation("org.jetbrains.exposed:exposed-spring-boot-starter:0.41.1")
28+
runtimeOnly("com.h2database:h2")
29+
30+
testImplementation("org.springframework.boot:spring-boot-starter-test") {
31+
exclude(module = "mockito-core")
32+
}
33+
testImplementation("io.kotest:kotest-runner-junit5:5.5.4")
34+
testImplementation("io.kotest:kotest-assertions-core:5.5.4")
35+
testImplementation("io.kotest.extensions:kotest-extensions-spring:1.1.2")
36+
testImplementation("io.mockk:mockk:1.13.3")
37+
testImplementation("com.ninja-squad:springmockk:4.0.0")
38+
}
39+
40+
tasks.withType<KotlinCompile> {
41+
kotlinOptions {
42+
freeCompilerArgs = listOf("-Xjsr305=strict")
43+
jvmTarget = "17"
44+
}
45+
}
46+
47+
tasks.withType<Test> {
48+
useJUnitPlatform()
49+
}
59.3 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)