-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into frontend
- Loading branch information
Showing
15 changed files
with
1,257 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
{ | ||
"name": "ddara-backend", | ||
"private": true, | ||
"workspaces": [ | ||
"frontend", | ||
"backend" | ||
], | ||
"version": "0.0.0", | ||
"type": "module", | ||
"description": "๋ฐ๋ผ๋ฐ๋ผ์ ์ ๋ฐ๋ผ๊ธธ๋ฐ๋ผ BackEnd ์ฝ๋", | ||
"main": "index.js", | ||
"scripts": { | ||
"dev": "node src/index.js", | ||
"test": "vitest", | ||
"test:watch": "vitest --watch", | ||
"test:coverage": "vitest run --coverage", | ||
"lint": "pnpm lint-staged" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"bcrypt": "^5.1.1", | ||
"dotenv": "^16.4.5", | ||
"express": "^4.21.1", | ||
"express-validator": "^7.2.0", | ||
"jsonwebtoken": "^9.0.2", | ||
"pg": "^8.13.1", | ||
"swagger-jsdoc": "^6.2.8", | ||
"swagger-ui-express": "^5.0.1", | ||
"uuid": "^11.0.3", | ||
"ws": "^8.11.0" | ||
} | ||
} | ||
"name": "ddara-backend", | ||
"private": true, | ||
"workspaces": [ | ||
"frontend", | ||
"backend" | ||
], | ||
"version": "0.0.0", | ||
"type": "module", | ||
"description": "๋ฐ๋ผ๋ฐ๋ผ์ ์ ๋ฐ๋ผ๊ธธ๋ฐ๋ผ BackEnd ์ฝ๋", | ||
"main": "index.js", | ||
"scripts": { | ||
"dev": "node src/index.js", | ||
"test": "vitest", | ||
"test:watch": "vitest --watch", | ||
"test:coverage": "vitest run --coverage", | ||
"lint": "pnpm lint-staged" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"bcrypt": "^5.1.1", | ||
"dotenv": "^16.4.5", | ||
"express": "^4.21.1", | ||
"express-validator": "^7.2.0", | ||
"jsonwebtoken": "^9.0.2", | ||
"pg": "^8.13.1", | ||
"swagger-jsdoc": "^6.2.8", | ||
"swagger-ui-express": "^5.0.1", | ||
"uuid": "^11.0.3", | ||
"ws": "^8.11.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,44 @@ | ||
import { loginUser } from '../services/authService.js'; | ||
import { loginUser, registerUser } from '../services/authService.js'; | ||
|
||
export const login = async (req, res) => { | ||
/** | ||
* @description ๋ก๊ทธ์ธ ์ปจํธ๋กค๋ฌ | ||
*/ | ||
export const loginController = async (req, res) => { | ||
const { id, password } = req.body; | ||
|
||
try { | ||
const token = await loginUser(id, password); | ||
if (!token) { | ||
return res.status(401).json({ message: 'Invalid ID or password' }); | ||
return res.status(401).json({ success: false, message: 'Invalid ID or password' }); | ||
} | ||
return res.status(200).json({ token }); | ||
return res.status(201).json({ | ||
success: true, | ||
message: 'Login successfully', | ||
data: token, | ||
}); | ||
} catch (error) { | ||
console.error('Login error:', error); | ||
return res.status(500).json({ message: 'Server error occurred' }); | ||
return res.status(500).json({ success: false, message: 'Server error occurred' }); | ||
} | ||
}; | ||
|
||
/** | ||
* @description ํ์๊ฐ์ ์ปจํธ๋กค๋ฌ | ||
*/ | ||
export const registerUserController = async (req, res) => { | ||
try { | ||
const { id, name, password, email } = req.body; | ||
const newUser = await registerUser(id, name, password, email); | ||
return res.status(201).json({ | ||
success: true, | ||
message: 'Login successfully', | ||
data: newUser, | ||
}); | ||
} catch (error) { | ||
if (error.message === 'User ID already exists') { | ||
return res.status(409).json({ error: 'User ID already exists' }); | ||
} | ||
console.error('User registration error:', error); | ||
res.status(500).json({ error: 'Server error' }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { | ||
addGuestService, | ||
createChannelService, | ||
getChannelByIdService, | ||
getChannelGuestInfoService, | ||
getUserChannels, | ||
} from '../services/channelService.js'; | ||
|
||
/** | ||
* @description ์ฑ๋ ์์ฑ ์ปจํธ๋กค๋ฌ | ||
*/ | ||
export const createChannelController = async (req, res) => { | ||
try { | ||
const { name, host_id, guests } = req.body; | ||
|
||
const channel = await createChannelService(name, host_id, guests); | ||
|
||
return res.status(201).json({ | ||
success: true, | ||
message: 'Channel created successfully', | ||
data: channel, | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
return res.status(500).json({ | ||
success: false, | ||
message: 'Server error', | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* @description ์ฑ๋์ ๊ฒ์คํธ ์ถ๊ฐ ์ปจํธ๋กค๋ฌ | ||
*/ | ||
export const addGuestController = async (req, res) => { | ||
try { | ||
const { channelId } = req.params; | ||
const { guests } = req.body; | ||
|
||
const updatedChannel = await addGuestService(channelId, guests); | ||
|
||
if (!updatedChannel) { | ||
return res.status(404).json({ | ||
success: false, | ||
message: 'Channel not found', | ||
}); | ||
} | ||
|
||
return res.status(200).json({ | ||
success: true, | ||
message: 'Guests added successfully', | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
return res.status(500).json({ | ||
success: false, | ||
message: 'Server error', | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* @description ์ฑ๋ ์ ๋ณด ์กฐํ ์ปจํธ๋กค๋ฌ | ||
*/ | ||
export const getChannelInfoController = async (req, res) => { | ||
const { id } = req.params; | ||
|
||
try { | ||
const channel = await getChannelByIdService(id); | ||
if (!channel) { | ||
return res.status(404).json({ success: false, message: 'Channel not found' }); | ||
} | ||
return res.status(200).json({ | ||
success: true, | ||
message: 'Get channel successfully', | ||
data: channel, | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
return res.status(500).json({ success: false, message: 'Server error' }); | ||
} | ||
}; | ||
|
||
/** | ||
* @description ์ฑ๋์ ํน์ ๊ฒ์คํธ ์ ๋ณด ์กฐํ ์ปจํธ๋กค๋ฌ | ||
*/ | ||
export const getChannelGuestInfoController = async (req, res) => { | ||
const { channelId, guestId } = req.params; | ||
try { | ||
const result = await getChannelGuestInfoService(channelId, guestId); | ||
if (result) { | ||
res.status(200).json({ | ||
success: true, | ||
message: 'Get guest data successfully', | ||
data: result, | ||
}); | ||
} else { | ||
res.status(404).json({ success: false, message: 'Channel or guest not found' }); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({ success: false, message: 'Server error' }); | ||
} | ||
}; | ||
|
||
/** | ||
* @description ์ฌ์ฉ์์ ์ฑ๋ ๋ฆฌ์คํธ ์กฐํ ์ปจํธ๋กค๋ฌ | ||
*/ | ||
export const getUserChannelsController = async (req, res) => { | ||
const { userId } = req.params; | ||
|
||
try { | ||
const channels = await getUserChannels(userId); | ||
if (!channels.length) { | ||
return res.status(404).json({ success: false, message: 'No channels found for this user.' }); | ||
} | ||
res.status(200).json({ | ||
success: true, | ||
message: 'Get channels successfully', | ||
data: channels, | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
return res.status(500).json({ success: false, message: 'Server error' }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.