์ฌ์ฉ์ ์ธ์ฆ(๋ก๊ทธ์ธ/๋ก๊ทธ์์) ๋ฐ ์ฌ์ฉ์ ๊ณ์ ๊ด๋ฆฌ๋ฅผ ๋ด๋นํ๋ API์
๋๋ค. ์ฌ์ฉ์๋ ์์นด๋ฐ๋ฏธ ๋ด์์ owner, admin, manager, member ๋ฑ๊ธ์ผ๋ก ๊ตฌ๋ถ๋ฉ๋๋ค.
๋ผ์ฐํธ ํ์ผ:
backend/src/routes/users.js์ปจํธ๋กค๋ฌ ํ์ผ:backend/src/controllers/users.js๋ชจ๋ธ ํ์ผ:backend/src/models/User.js
| ๋ฉ์๋ | ๊ฒฝ๋ก | ์ค๋ช | ๊ถํ |
|---|---|---|---|
POST |
/api/users/login/local |
๋ก์ปฌ ๋ก๊ทธ์ธ | ๋น์ธ์ฆ |
POST |
/api/users/login/google |
Google ๋ก๊ทธ์ธ | ๋น์ธ์ฆ |
GET |
/api/users/logout |
๋ก๊ทธ์์ | isLoggedIn |
POST |
/api/users |
์ฌ์ฉ์ ์์ฑ | owner|admin |
GET |
/api/users |
์ฌ์ฉ์ ๋ชฉ๋ก ์กฐํ | isLoggedIn |
GET |
/api/users/current |
ํ์ฌ ์ฌ์ฉ์ ์ ๋ณด | isLoggedIn |
GET |
/api/users/:_id |
์ฌ์ฉ์ ์์ธ ์กฐํ | isLoggedIn |
GET |
/api/users/:_id/profile |
ํ๋กํ ์กฐํ | isLoggedIn |
PUT |
/api/users/profile |
ํ๋กํ ์์ | isLoggedIn |
PUT |
/api/users/:_id/password |
๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ | isLoggedIn |
PUT |
/api/users/:_id/email |
์ด๋ฉ์ผ ๋ณ๊ฒฝ | isLoggedIn |
PUT |
/api/users/:_id/tel |
์ ํ๋ฒํธ ๋ณ๊ฒฝ | isLoggedIn |
PUT |
/api/users/:_id/userName |
์ฌ์ฉ์ ์ด๋ฆ ๋ณ๊ฒฝ | isLoggedIn |
PUT |
/api/users/:_id/auth |
๊ถํ ๋ฑ๊ธ ๋ณ๊ฒฝ | owner|admin |
PUT |
/api/users/:_id/google |
Google ๊ณ์ ์ฐ๊ฒฐ | admin |
DELETE |
/api/users/:_id/google |
Google ๊ณ์ ํด์ | admin |
POST |
/api/users/:_id/schools |
ํ๊ต ๋ฑ๋ก | admin |
DELETE |
/api/users/:_id/schools |
ํ๊ต ๋ฑ๋ก ํด์ | admin |
DELETE |
/api/users/:_id |
์ฌ์ฉ์ ์ญ์ | admin |
์์นด๋ฐ๋ฏธ ID, ์ฌ์ฉ์ ID, ๋น๋ฐ๋ฒํธ๋ฅผ ์ฌ์ฉํ์ฌ ๋ก๊ทธ์ธํฉ๋๋ค.
POST /api/users/login/local
๊ถํ: ๋น์ธ์ฆ (๋ก๊ทธ์ธ ์ํ์ด๋ฉด ๊ฐ์ ๋ก๊ทธ์์ ํ ์งํ)
| ํ๋ | ํ์ | ํ์ | ์ค๋ช |
|---|---|---|---|
academyId |
string |
O | ์์นด๋ฐ๋ฏธ ID |
userId |
string |
O | ์ฌ์ฉ์ ID |
password |
string |
O | ๋น๋ฐ๋ฒํธ |
{
"academyId": "my-academy",
"userId": "user01",
"password": "mypassword123"
}{
"user": {
"_id": "507f1f77bcf86cd799439011",
"userId": "user01",
"userName": "ํ๊ธธ๋",
"auth": "member",
"email": "user01@example.com",
"tel": "010-1234-5678",
"academyId": "my-academy",
"academyName": "๋์ ์์นด๋ฐ๋ฏธ",
"schools": [
{
"school": "507f1f77bcf86cd799439012",
"schoolId": "school01",
"schoolName": "ํ
์คํธ ํ๊ต"
}
],
"snsId": {},
"profile": "/uploads/profiles/user01.jpg"
}
}| ์ํ ์ฝ๋ | ๋ฉ์์ง | ์ค๋ช |
|---|---|---|
400 |
FIELD_REQUIRED(...) |
ํ์ ํ๋ ๋๋ฝ |
401 |
LOGIN_FAILED |
๋ก๊ทธ์ธ ์คํจ (ID ๋๋ ๋น๋ฐ๋ฒํธ ๋ถ์ผ์น) |
403 |
ACADEMY_INACTIVATED |
๋นํ์ฑํ๋ ์์นด๋ฐ๋ฏธ |
Google OAuth๋ฅผ ํตํด ๋ก๊ทธ์ธํฉ๋๋ค. ์ฌ์ ์ ์ฌ์ฉ์ ๊ณ์ ์ Google ๊ณ์ ์ด ์ฐ๊ฒฐ๋์ด ์์ด์ผ ํฉ๋๋ค.
POST /api/users/login/google
๊ถํ: ๋น์ธ์ฆ
| ํ๋ | ํ์ | ํ์ | ์ค๋ช |
|---|---|---|---|
academyId |
string |
O | ์์นด๋ฐ๋ฏธ ID |
credential |
string |
O | Google OAuth ์ธ์ฆ ํ ํฐ |
ํ์ฌ ์ธ์ ์ ์ข ๋ฃํฉ๋๋ค.
GET /api/users/logout
๊ถํ: isLoggedIn
{}๋ก๊ทธ์ธ๋ ํ์ฌ ์ฌ์ฉ์์ ์ ๋ณด๋ฅผ ์กฐํํฉ๋๋ค. ์ธ์ ์์ ์ฌ์ฉ์๋ฅผ ์๋ณํฉ๋๋ค.
GET /api/users/current
๊ถํ: isLoggedIn
{
"user": {
"_id": "507f1f77bcf86cd799439011",
"userId": "user01",
"userName": "ํ๊ธธ๋",
"auth": "member",
"email": "user01@example.com",
"tel": "010-1234-5678",
"academyId": "my-academy",
"academyName": "๋์ ์์นด๋ฐ๋ฏธ",
"schools": [
{
"school": "507f1f77bcf86cd799439012",
"schoolId": "school01",
"schoolName": "ํ
์คํธ ํ๊ต"
}
],
"snsId": {
"google": "user01@gmail.com"
},
"profile": "/uploads/profiles/user01.jpg"
}
}์๋ก์ด ์ฌ์ฉ์ ๊ณ์ ์ ์์ฑํฉ๋๋ค. ๋น๋ฐ๋ฒํธ๋ ์๋ ์์ฑ๋์ด ์๋ต์ ํฌํจ๋ฉ๋๋ค.
POST /api/users
๊ถํ: owner ๋๋ admin
| ํ๋ | ํ์ | ํ์ | ์ค๋ช |
|---|---|---|---|
userId |
string |
O | ์ฌ์ฉ์ ๊ณ ์ ID |
userName |
string |
O | ์ฌ์ฉ์ ์ด๋ฆ |
auth |
string |
X | ๊ถํ ๋ฑ๊ธ (admin, manager, member). ๊ธฐ๋ณธ๊ฐ: member |
email |
string |
X | ์ด๋ฉ์ผ |
tel |
string |
X | ์ ํ๋ฒํธ |
schools |
object[] |
X | ๋ฑ๋กํ ํ๊ต ๋ชฉ๋ก |
{
"userId": "newuser01",
"userName": "๊น์ ์
",
"auth": "member",
"email": "newuser@example.com"
}{
"user": {
"_id": "507f1f77bcf86cd799439013",
"userId": "newuser01",
"userName": "๊น์ ์
",
"auth": "member",
"password": "์๋์์ฑ๋๋น๋ฐ๋ฒํธ",
"academyId": "my-academy",
"academyName": "๋์ ์์นด๋ฐ๋ฏธ"
}
}| ์ํ ์ฝ๋ | ๋ฉ์์ง | ์ค๋ช |
|---|---|---|
400 |
FIELD_REQUIRED(...) |
ํ์ ํ๋ ๋๋ฝ |
400 |
FIELD_INVALID(...) |
์ ํจ์ฑ ๊ฒ์ฌ ์คํจ |
409 |
FIELD_IN_USE(userId) |
์ด๋ฏธ ์ฌ์ฉ ์ค์ธ ์ฌ์ฉ์ ID |
์์นด๋ฐ๋ฏธ ๋ด์ ์ฌ์ฉ์ ๋ชฉ๋ก์ ์กฐํํฉ๋๋ค.
GET /api/users
๊ถํ: isLoggedIn
| ํ๋ผ๋ฏธํฐ | ํ์ | ํ์ | ์ค๋ช |
|---|---|---|---|
userId |
string |
X | ์ฌ์ฉ์ ID๋ก ํํฐ๋ง |
userName |
string |
X | ์ฌ์ฉ์ ์ด๋ฆ์ผ๋ก ํํฐ๋ง |
auth |
string |
X | ๊ถํ ๋ฑ๊ธ์ผ๋ก ํํฐ๋ง |
{
"users": [
{
"_id": "507f1f77bcf86cd799439011",
"userId": "user01",
"userName": "ํ๊ธธ๋",
"auth": "member",
"email": "user01@example.com",
"schools": [
{
"school": "507f1f77bcf86cd799439012",
"schoolId": "school01",
"schoolName": "ํ
์คํธ ํ๊ต"
}
]
}
]
}์ฐธ๊ณ :
passwordํ๋๋ ์คํค๋ง ๋ ๋ฒจ์์select: false๋ก ์ค์ ๋์ด ์์ด ์กฐํ ์๋ต์ ํฌํจ๋์ง ์์ต๋๋ค.
ํน์ ์ฌ์ฉ์์ ์์ธ ์ ๋ณด๋ฅผ ์กฐํํฉ๋๋ค.
GET /api/users/:_id
๊ถํ: isLoggedIn
| ํ๋ผ๋ฏธํฐ | ํ์ | ์ค๋ช |
|---|---|---|
_id |
string |
์ฌ์ฉ์ ObjectId |
{
"user": {
"_id": "507f1f77bcf86cd799439011",
"userId": "user01",
"userName": "ํ๊ธธ๋",
"auth": "member",
"email": "user01@example.com",
"tel": "010-1234-5678",
"schools": [...],
"snsId": { "google": "user01@gmail.com" },
"profile": "/uploads/profiles/user01.jpg"
}
}GET /api/users/:_id/profile
๊ถํ: isLoggedIn
ํ์ฌ ๋ก๊ทธ์ธ๋ ์ฌ์ฉ์์ ํ๋กํ(์ฌ์ง)์ ์์ ํฉ๋๋ค.
PUT /api/users/profile
๊ถํ: isLoggedIn
์ฌ์ฉ์์ ๋น๋ฐ๋ฒํธ๋ฅผ ๋ณ๊ฒฝํฉ๋๋ค. ๋ณธ์ธ ๋๋ ๊ด๋ฆฌ์๊ฐ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
PUT /api/users/:_id/password
๊ถํ: isLoggedIn
| ํ๋ผ๋ฏธํฐ | ํ์ | ์ค๋ช |
|---|---|---|
_id |
string |
์ฌ์ฉ์ ObjectId |
| ํ๋ | ํ์ | ํ์ | ์ค๋ช |
|---|---|---|---|
password |
string |
O | ํ์ฌ ๋น๋ฐ๋ฒํธ (๋ณธ์ธ ๋ณ๊ฒฝ ์) |
newPassword |
string |
O | ์ ๋น๋ฐ๋ฒํธ |
{
"password": "ํ์ฌ๋น๋ฐ๋ฒํธ",
"newPassword": "์๋น๋ฐ๋ฒํธ123"
}{}| ์ํ ์ฝ๋ | ๋ฉ์์ง | ์ค๋ช |
|---|---|---|
400 |
FIELD_REQUIRED(...) |
ํ์ ํ๋ ๋๋ฝ |
401 |
PASSWORD_INCORRECT |
ํ์ฌ ๋น๋ฐ๋ฒํธ ๋ถ์ผ์น |
์ฐธ๊ณ : ๋น๋ฐ๋ฒํธ๋
bcrypt๋ก ํด์ํ๋์ด ์ ์ฅ๋ฉ๋๋ค. API ์๋ต์ ํ๋ฌธ ๋น๋ฐ๋ฒํธ๊ฐ ํฌํจ๋์ง ์์ต๋๋ค.
PUT /api/users/:_id/email
๊ถํ: isLoggedIn
| ํ๋ | ํ์ | ํ์ | ์ค๋ช |
|---|---|---|---|
email |
string |
X | ์ ์ด๋ฉ์ผ ์ฃผ์ |
PUT /api/users/:_id/tel
๊ถํ: isLoggedIn
| ํ๋ | ํ์ | ํ์ | ์ค๋ช |
|---|---|---|---|
tel |
string |
X | ์ ์ ํ๋ฒํธ |
PUT /api/users/:_id/userName
๊ถํ: isLoggedIn
| ํ๋ | ํ์ | ํ์ | ์ค๋ช |
|---|---|---|---|
userName |
string |
O | ์ ์ฌ์ฉ์ ์ด๋ฆ |
์ฌ์ฉ์์ ๊ถํ ๋ฑ๊ธ์ ๋ณ๊ฒฝํฉ๋๋ค.
PUT /api/users/:_id/auth
๊ถํ: owner ๋๋ admin
| ํ๋ | ํ์ | ํ์ | ์ค๋ช |
|---|---|---|---|
auth |
string |
O | ์ ๊ถํ ๋ฑ๊ธ (admin, manager, member) |
{
"auth": "manager"
}์ฌ์ฉ์ ๊ณ์ ์ Google ์ด๋ฉ์ผ์ ์ฐ๊ฒฐํ์ฌ Google ๋ก๊ทธ์ธ์ ํ์ฑํํฉ๋๋ค.
PUT /api/users/:_id/google
๊ถํ: admin
| ํ๋ | ํ์ | ํ์ | ์ค๋ช |
|---|---|---|---|
email |
string |
O | ์ฐ๊ฒฐํ Google ์ด๋ฉ์ผ |
DELETE /api/users/:_id/google
๊ถํ: admin
์ฌ์ฉ์๋ฅผ ํน์ ํ๊ต์ ๋ฑ๋กํฉ๋๋ค.
POST /api/users/:_id/schools
๊ถํ: admin
| ํ๋ | ํ์ | ํ์ | ์ค๋ช |
|---|---|---|---|
school |
string |
O | ํ๊ต ObjectId |
schoolId |
string |
O | ํ๊ต ID |
schoolName |
string |
O | ํ๊ต ์ด๋ฆ |
DELETE /api/users/:_id/schools
๊ถํ: admin
| ํ๋ผ๋ฏธํฐ | ํ์ | ํ์ | ์ค๋ช |
|---|---|---|---|
school |
string |
O | ํด์ ํ ํ๊ต ObjectId |
์ฌ์ฉ์ ๊ณ์ ์ ์ญ์ ํฉ๋๋ค.
DELETE /api/users/:_id
๊ถํ: admin
| ํ๋ผ๋ฏธํฐ | ํ์ | ์ค๋ช |
|---|---|---|
_id |
string |
์ญ์ ํ ์ฌ์ฉ์ ObjectId |
{}| ํจ์๋ช | ๋ฉ์๋ | ๊ฒฝ๋ก | ์ค๋ช |
|---|---|---|---|
LoginLocal |
POST | /api/users/login/local |
๋ก์ปฌ ๋ก๊ทธ์ธ |
LoginGoogle |
POST | /api/users/login/google |
Google ๋ก๊ทธ์ธ |
Logout |
GET | /api/users/logout |
๋ก๊ทธ์์ |
RMySelf |
GET | /api/users/current |
ํ์ฌ ์ฌ์ฉ์ ์ ๋ณด |
CUser |
POST | /api/users |
์ฌ์ฉ์ ์์ฑ |
RUsers |
GET | /api/users |
์ฌ์ฉ์ ๋ชฉ๋ก |
RUser |
GET | /api/users/:_id |
์ฌ์ฉ์ ์์ธ |
RUserProfile |
GET | /api/users/:_id/profile |
ํ๋กํ ์กฐํ |
UUserProfile |
PUT | /api/users/profile |
ํ๋กํ ์์ |
UPassword |
PUT | /api/users/:_id/password |
๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ |
UEmail |
PUT | /api/users/:_id/email |
์ด๋ฉ์ผ ๋ณ๊ฒฝ |
UTel |
PUT | /api/users/:_id/tel |
์ ํ๋ฒํธ ๋ณ๊ฒฝ |
UUserName |
PUT | /api/users/:_id/userName |
์ด๋ฆ ๋ณ๊ฒฝ |
UAuth |
PUT | /api/users/:_id/auth |
๊ถํ ๋ณ๊ฒฝ |
UConnectGoogle |
PUT | /api/users/:_id/google |
Google ์ฐ๊ฒฐ |
DDisconnectGoogle |
DELETE | /api/users/:_id/google |
Google ํด์ |
CUserSchool |
POST | /api/users/:_id/schools |
ํ๊ต ๋ฑ๋ก |
DUserSchool |
DELETE | /api/users/:_id/schools |
ํ๊ต ํด์ |
DUser |
DELETE | /api/users/:_id |
์ฌ์ฉ์ ์ญ์ |