Public Education Example - TheOpenCloudEngine/uEngine-cloud GitHub Wiki
https://github.com/uengine-oss ์ผ๋ก ๋ค์ด๊ฐ์
https://github.com/uengine-oss/msa-tutorial-class-management-monolith ๋ฅผ git clone ํ๋ค
(๋ ๋ค๋ฅธ ์์ : ๋ณดํ์ฌ ์์ - https://github.com/jinyoung/sw-modeling-example-msa)
$ git clone https://github.com/uengine-oss/msa-tutorial-class-management-monolith.git
$ cd msa-tutorial-class-management-monolith
$ mvn spring-boot:run
ํด๋น ํ๋ก์ ํธ๋ฅผ ๋ค์ด๋ฐ๊ณ intellij๋ก ์ด์์๋, ์๋์ ๊ฐ์ด ํ๋ก์ ํธ ๊ตฌ์กฐ๊ฐ ๋์จ๋ค.
ํ์ฌ ํ๋ก์ ํธ๋ eureka ๊ฐ ์๋ค๋ ๊ฐ์ ํ์ ๋ง๋ค์ด์ง ์ฝ๋์ด๊ธฐ์, application.yml ํ์ผ์ ์ด์ด์ eureka.client.enabled : false ๋ก ์ค์ ํ์ฌ ์ค๋ค.
eureka:
client:
enabled: false
์ด์ ํด๋น ํ๋ก์ ํธ์ ๊ตฌ์กฐ๋ฅผ ์ดํด๋ณด์
HATEOAS ๊ฐ ์ ์ฉ๋ ์๋น์ค๋ ์ง์
์ ์์ ์กฐํ๋ฅผ ํ์์๋ ๋ชจ๋ ์ค๋ช
์ด ๋ค ๋์จ๋ค
$http localhost:8080
{
"_links": {
"clazzDays": {
"href": "http://localhost:8080/clazzDays{?page,size,sort}",
"templated": true
},
"clazzes": {
"href": "http://localhost:8080/clazzes{?page,size,sort}",
"templated": true
},
"courses": {
"href": "http://localhost:8080/courses{?page,size,sort}",
"templated": true
},
"customers": {
"href": "http://localhost:8080/customers{?page,size,sort}",
"templated": true
},
"enrollments": {
"href": "http://localhost:8080/enrollments{?page,size,sort}",
"templated": true
},
"instructors": {
"href": "http://localhost:8080/instructors{?page,size,sort}",
"templated": true
},
"profile": {
"href": "http://localhost:8080/profile"
}
}
}
ํ์ผ ๊ตฌ์กฐ๋ฅผ ์ค๋ช ํ์๋ฉด
- Clazz ๊ฐ์
- ClazzDay ๊ฐ์ ๋ ์
- Course ๊ต์ก ์ฝ์ค
- Customer ์๊ฐ์
- Enrollment ์๊ฐ์์ ์๊ฐ์ํ
- Instructor ๊ต์ก ๊ฐ์ฌ
์์๊ฐ์ ํด๋ ์ค ๋ค์ด ์๊ณ , ํด๋น ํด๋์ค๋ค์ Repository๋ก ๋ฌถ์ด์ ๊ตฌ์ฑ๋ ํ๋ก์ ํธ์ด๋ค.
## ๊ณผ์ ๋ฑ๋ก
$ http localhost:8080/courses title="software modeling lecture" duration=5 maxEnrollment=5 minEnrollment=1
## ๋ชจ๋ ์ ๋ณด์์คํ
์ ์ ์ฐจ ๋ฐ์ดํฐ๊ฐ ์ฑ์์ง๋ฉด์ ํ๋ก์ธ์ค๊ฐ ํ๋ฌ๊ฐ๋ค.
## ๋ฐ์ดํฐ๋ฅผ ์ด๋ฐ์ ๋ฃ์ง ์์๋๋ผ๋, PATCH๋ฅผ ํตํด ์ ์ฐจ ๋ฐ์ดํฐ๋ฅผ ๋ฃ์ด์ค๋ค.
$ http PATCH "http://localhost:8080/courses/1" description="MSA ๊ต์ฑ๊ณผ์ ์
๋๋ค"
{
"_links": {
"clazzes": {
"href": "http://localhost:8080/courses/1/clazzes"
},
"course": {
"href": "http://localhost:8080/courses/1"
},
"self": {
"href": "http://localhost:8080/courses/1"
}
},
"courseId": null,
"description": "MSA ๊ต์ฑ๊ณผ์ ์
๋๋ค",
"duration": 5,
"maxEnrollment": 5,
"minEnrollment": 1,
"title": "software modeling lecture",
"unitPrice": null
}
## ํด๋์ค 1 ๋ฑ๋ก - ์๋ฌ ๋ฐ์
$ http localhost:8080/clazzes course="http://localhost:8080/courses" id="1"
## ํด๋์ค 1 ๋ฑ๋ก - ์ ์ ์๋
## "http://localhost:8080/courses/1" ์ด๊ฒ์ด ๋ฌธ์์ด์ฒ๋ผ ๋์ด๊ฐ์ง๋ง HATEOAS์์๋ ๋ฌธ์์ด์ด ์๋๊ณ , ๋ฆฌ์์ค๋ฅผ ์ง์นญํ๋ ์๋ฏธ๋ฅผ ๊ฐ์ง๋ค
$ http localhost:8080/clazzes course="http://localhost:8080/courses/1"
{
"_links": {
"clazz": {
"href": "http://localhost:8080/clazzes/2"
},
"clazzDays": {
"href": "http://localhost:8080/clazzes/2/clazzDays"
},
"course": {
"href": "http://localhost:8080/clazzes/2/course"
},
"instructor": {
"href": "http://localhost:8080/clazzes/2/instructor"
},
"self": {
"href": "http://localhost:8080/clazzes/2"
}
},
"evaluationRate": 0,
"states": null
}
์ด ๊ฐ์์ ์ ์ผํ ํค๋ 2๋ฒ์ด๊ณ , 2๋ฒ ๊ฐ์์ ๊ณผ์ ์
http "http://localhost:8080/clazzes/2/course"
์ ํธ์ถํ์ฌ ํ์ธ ํ ์ ์๋ค.
http://localhost:8080/courses/1 ๊ณผ ๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ ๋ํ๋ด๋ ๊ฒ์ด ํ์ธ ๊ฐ๋ฅํ๋ค.
์ด ๋๊ฐ์ API๋ URL๋งํฌ๋ก relation์ด ๋ฌถ์ฌ ์๋ค.
API ์์ค์์๋ ๋ถ๋ฆฌ๊ฐ ๋์ด์๊ธฐ๋๋ฌธ์, ๋์ค์ ์๋น์ค๋ฅผ ๋ถ๋ฆฌํ๋๋ผ๋, API๋ ๋ณํ๊ฐ ์๊ธฐ๋๋ฌธ์ frontend์์ ์์ ์์ด ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค.