Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[develop → main] feat: social sign in, token authentication, trainer list, member management, community postlist, membership payment, consultant post #26

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
4f3f671
FIX : db
suyeongs Sep 8, 2023
c703b0b
FIX : db
suyeongs Sep 11, 2023
8edda89
modify: member_grade_id in the member_profiles table to have an initi…
Sep 12, 2023
85b4d81
feat: Social sign in and token authentication
Sep 12, 2023
0b9e614
chore: Update db migrations
suyeongs Sep 12, 2023
14eafd4
feat: Add API for getting trainer list without unit test code
suyeongs Sep 12, 2023
25315c1
feat: Add API for getting trainer list without unit test code
suyeongs Sep 14, 2023
3ffcd2b
management membershipstart, getManagement
Sep 14, 2023
f2c0593
add: modify threads table
dodoyoo Sep 15, 2023
732b845
chore: Update db migrations
suyeongs Sep 15, 2023
cdb8f96
Revert "chore: Update db migrations"
suyeongs Sep 15, 2023
adc74ee
chore: Update db migrations
suyeongs Sep 15, 2023
af5c997
add : modify threads table column name is title NOT NULL to NULL
dodoyoo Sep 15, 2023
df4475e
add : post consultant 2
dodoyoo Sep 13, 2023
56aaf45
Revert "add : post consultant 2"
suyeongs Sep 15, 2023
0526254
modify: users, member_profiles table
Sep 15, 2023
3ea5c1e
modify: social sign in feature
Sep 15, 2023
e343f92
[feature] community postlist comment API
Sep 12, 2023
90655eb
feat: Add API for membership payment without unit test code
suyeongs Sep 14, 2023
b0393a5
fix: 20230915114319_modify_threads_table.sql mysql syntax error corre…
suyeongs Sep 16, 2023
ede5f72
add : post consultant 2
dodoyoo Sep 13, 2023
53c18ef
remove: unnecessary comments
Sep 17, 2023
ff17f15
refactor: social sign in code
Sep 18, 2023
fdb00e9
modified management
Sep 16, 2023
b9a78c8
add: [feature] community postlistdetail API
Sep 18, 2023
c02d3c5
fix: Correct payment error status code, logic, and query; also, imple…
suyeongs Sep 18, 2023
f724429
refactor: Move offset and limit calculation logic from controller lay…
suyeongs Sep 18, 2023
a2e371f
modify: status code, message
Sep 18, 2023
e81dadc
add : mypage
Sep 19, 2023
8a4e51b
fix: data source error
Sep 19, 2023
5ef1251
fix: data source error
Sep 19, 2023
c3cfd9c
fix: data source error
Sep 19, 2023
aa0e771
fix: Reissue tokens after membership grade change following payment
suyeongs Sep 19, 2023
683b3a7
add : delete consultant casecade
dodoyoo Sep 19, 2023
a636296
feature: social-sign-in-test
Sep 18, 2023
31f3afe
add : custom/checkExercise, custom/checkDiet
Sep 19, 2023
ee3cc9c
add: create post
Sep 19, 2023
9c5eff7
add : consultant list 1
dodoyoo Sep 20, 2023
aa699ed
add : consultant list modify index & finish
dodoyoo Sep 20, 2023
f7f2c03
fix: user to users
Sep 21, 2023
137bbbd
add : checkTreadId
Sep 21, 2023
c1fc076
add: updateMypage
Sep 19, 2023
2978d4a
fix: table name USERS to users
Sep 21, 2023
7c194c0
feature: adding-image
Sep 20, 2023
f35fb98
add : Get Consultant List Detail
dodoyoo Sep 20, 2023
a1632ef
fix: adding multiple image
Sep 21, 2023
f1ce8b7
chore: Update db migrations
suyeongs Sep 21, 2023
93f0013
chore: Update db migrations
suyeongs Sep 21, 2023
d9eaa9c
feature: consultant-commnet
Sep 21, 2023
468a3d5
fix: all bug
Sep 21, 2023
c374821
final
suyeongs Sep 22, 2023
f0d047d
Update readme.md
yjieuny Sep 30, 2023
0349a67
Update readme.md
yjieuny Sep 30, 2023
f459ec0
fix: Modify the error in the consultation query statement
suyeongs Jan 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@ DB_USERNAME=username
DB_PASSWORD=password
DB_DATABASE=database

PORT=3000
PORT=3000

JWT_SECRET = JWT_SECRET
JWT_ALGORITHM = "JWT_ALGORITHM"

GRANT_TYPE = GRANT_TYPE
CLIENT_ID = CLIENT_ID
SIGN_IN_REDIRECT_URI = REDIRECT_URI
SIGN_UP_REDIRECT_URI = REDIRECT_URI
sladhe01 marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 14 additions & 0 deletions api/controllers/consultantController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const consultantService = require("../services/consultantService");
const { catchAsync } = require("../utils/error");

const createConsultant = catchAsync(async (req, res) => {
const { content, trainerId, threadTypesId = 3 } = await req.body;

const userId = req.user.userId;

const thread = await consultantService.createConsultThreads(userId, threadTypesId, content, trainerId);

res.status(201).json({message : "success"})
});

module.exports = { createConsultant };
22 changes: 22 additions & 0 deletions api/controllers/managementController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const managementService = require('../services/managementService');
const { catchAsync } = require('../utils/error');
const { addDays, format } = require('date-fns');

const getManagement = catchAsync(async (req, res) => {
const { userId, weekday } = req.query;
const membership = await managementService.getManagement(userId, weekday);
res.json(membership);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 해당 membership에 대한 리턴에는 상태코드가 적혀있지 않네요! 상태코드를 함께 꼭 리턴시 함께 줄 수 있도록 수정하여주세요!

});

const membershipStart = catchAsync(async (req, res) => {
const { userId, startDate } = req.body;

const startDateObject = new Date(startDate);
const after30Days = addDays(startDateObject, 30);
const endDate = format(after30Days, 'yyyy-MM-dd');

await managementService.membershipStart(userId, startDate, endDate);
res.status(200).json({ message: 'SUCCESS' });
});

module.exports = { getManagement, membershipStart };
43 changes: 43 additions & 0 deletions api/controllers/paymentController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const paymentService = require('../services/paymentService');
const { catchAsync } = require('../utils/error');

const getMembershipList = catchAsync(async (req, res) => {
const memberId = req.user.userId;
const membershipList = await paymentService.getMembershipList(memberId);

res.status(200).json({ membershipData: membershipList });
});

const getMatchingTrainer = catchAsync(async (req, res) => {
const memberId = req.user.userId;
const { trainerId } = req.body;

const matchingTrainer = await paymentService.getMatchingTrainer(
trainerId,
memberId
);

res.status(200).json({ trainerData: matchingTrainer });
});

const payForMembership = catchAsync(async (req, res) => {
const memberId = req.user.userId;
const { trainerId, membershipId, paymentsMethodId } = req.body;

const paymentInformation = await paymentService.payForMembership(
memberId,
membershipId,
trainerId,
paymentsMethodId
);

res
.status(200)
.json({ message: 'Payment completed', data: paymentInformation });
});

module.exports = {
getMembershipList,
getMatchingTrainer,
payForMembership,
};
10 changes: 10 additions & 0 deletions api/controllers/postController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { catchAsync } = require('../utils/error');
const postService = require('../services/postService');

const getPostListAll = catchAsync(async (req, res) => {
const allPosts = await postService.getPostListAll();

res.status(201).json({ data: allPosts });
});

module.exports = { getPostListAll };
14 changes: 14 additions & 0 deletions api/controllers/trainerController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const trainerService = require('../services/trainerService');
const { catchAsync } = require('../utils/error');

const getTrainerList = catchAsync(async (req, res) => {
const { page = 1, limit = 5 } = req.query;
const pageSize = parseInt(limit);
const offset = (page - 1) * pageSize;

const trainerList = await trainerService.getTrainerList(offset, pageSize);
suyeongs marked this conversation as resolved.
Show resolved Hide resolved

res.status(200).json({ data: trainerList });
});

module.exports = { getTrainerList };
88 changes: 88 additions & 0 deletions api/controllers/userController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const userService = require('../services/userService');
const { catchAsync } = require('../utils/error');

const kakaoSignIn = catchAsync(async (req, res) => {
const authCode = await req.query.code;
const endPoint = await req.path;
sladhe01 marked this conversation as resolved.
Show resolved Hide resolved
const redirectUri = await userService.getRedirectUri(endPoint);
const kakaoAccessToken = await userService.getKaKaoAccessToken(
authCode,
redirectUri
);
const { email, gender, birthyear, birthday } =
await userService.getUserInformation(kakaoAccessToken);
const age = await userService.calculateAge(birthyear, birthday);
const user = await userService.getUserByEmail(email);
if (!user) {
await userService.createUser(email, gender, age);
await res.status(401).json({
message: 'SIGN UP REQUIRED',
});
sladhe01 marked this conversation as resolved.
Show resolved Hide resolved
} else if (
user.email &&
user.age &&
user.gender &&
!user.nickname &&
!user.height &&
!user.weight
) {
await res.status(401).json({
message: 'SIGN UP REQUIRED',
});
} else if (
user.email &&
user.age &&
user.gender &&
user.nickname &&
user.height &&
user.weight
) {
const token = await userService.createToken(email);
await res
.status(200)
.json({ authorization: token, message: 'SIGN IN COMPLETED' });
}
});
sladhe01 marked this conversation as resolved.
Show resolved Hide resolved

const kakaoSignUp = catchAsync(async (req, res) => {
const authCode = await req.query.code;
const endPoint = await req.path;
const redirectUri = await userService.getRedirectUri(endPoint);
const kakaoAccessToken = await userService.getKaKaoAccessToken(
authCode,
redirectUri
);
const { email } = await userService.getUserInformation(kakaoAccessToken);
const { nickname, height, weight } = await req.body;

if (!nickname || !height || !weight) {
const error = new Error('KEY_ERROR');
error.statusCode = 400;

throw error;
}

await userService.addAdditionalInfo(email, nickname, height, weight);
const token = await userService.createToken(email);
await res.status(200).json({
message: 'SIGN UP COMPLETED',
authorization: token,
});
});

const checkDuplicateNickname = catchAsync(async (req, res) => {
const { nickname } = await req.body;
const result = await userService.checkDuplicateNickname(nickname);

result
? res.status(409).json({ message: 'DUPLICATED NICKNAME' })
: res.status(200).json({
message: 'AVAILABLE NICKNAME',
});
});

module.exports = {
kakaoSignIn,
kakaoSignUp,
checkDuplicateNickname,
};
27 changes: 27 additions & 0 deletions api/models/consultantDao.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const {dataSource} = require("./dataSource");

const createConsultant = async (userId, threadTypesId, content, trainerProfileId) => {
try{
await dataSource.query(
`
INSERT INTO threads (
user_id,
thread_types_id,
content,
trainer_profile_id
) VALUES (
?,
?,
?,
?
)
`,
[userId, threadTypesId, content, trainerProfileId]
)
}catch{
const error = new Error("error");
error.statusCode = 400;
throw error;
}};

module.exports = { createConsultant };
117 changes: 117 additions & 0 deletions api/models/managementDao.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
const { dataSource } = require('./dataSource');

const getMembershipByUser = async (userId) => {
try {
const membership = await dataSource.query(
`
SELECT
m.name as membershipName,
u.start_date as startDate,
u.end_date as endDate
FROM members_memberships u
JOIN memberships m
ON m.id = u.membership_id
WHERE member_id = ?;
`,
[userId]
);
return membership;
} catch {
const error = new Error('dataSource Error');
error.statusCode = 400;
throw error;
}
};

const getExerciseList = async (memberId, weekday) => {
try {
const exerciseList = await dataSource.query(
`
SELECT
id as exerciseId,
name as exerciseName,
description as exerciseDescription,
image_url as exerciseImageUrl,
checkbox as exerciseCheckbox
FROM exercises
WHERE member_id = ?
AND weekday = ?;
`,
[memberId, weekday]
);
return exerciseList;
} catch {
const error = new Error('dataSource Error');
error.statusCode = 400;
throw error;
}
};

const getDietList = async (memberId, weekday) => {
try {
const dietList = await dataSource.query(
`
SELECT
id as dietId,
name as dietName,
description as dietDescription
FROM diets
WHERE member_id = ?
AND weekday = ?;
`,
[memberId, weekday]
);
return dietList;
} catch {
const error = new Error('dataSource Error');
error.statusCode = 400;
throw error;
}
};

const membershipStart = async (startDate, endDate, membershipId, userId) => {
try {
const result = await dataSource.query(
`
UPDATE members_memberships
SET start_date = ?,
end_date = ?
WHERE membership_id = ?
AND member_id = ?;

`,
[startDate, endDate, membershipId, userId]
);
return result;
} catch {
const error = new Error('dataSource Error');
error.statusCode = 400;
throw error;
}
};

const getMembershipIdByUser = async (userId) => {
try {
const membershipId = await dataSource.query(
`
SELECT membership_id
FROM members_memberships
WHERE member_id = ?;
`,
[userId]
);
return membershipId;
} catch {
const error = new Error('dataSource Error');
error.statusCode = 400;
throw error;
}
};

module.exports = {
getExerciseList,
getDietList,
getMembershipByUser,
membershipStart,
getMembershipIdByUser,
};
Loading