Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 12 additions & 12 deletions config/cookie.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
const accessTokenOption = {
httpOnly: true,
secure: true,
sameSite: "None",
sameSite: 'None',
maxAge: 1000 * 60 * 60 * 3,
path: "/",
domain: ".sjcpop.com",
path: '/',
domain: '.sjcpop.com',
};

const refreshTokenOption = {
httpOnly: true,
secure: true,
sameSite: "None",
sameSite: 'None',
maxAge: 1000 * 60 * 60 * 24 * 7,
path: "/",
domain: ".sjcpop.com",
path: '/',
domain: '.sjcpop.com',
};

const clearAccessTokenOption = {
httpOnly: true,
secure: true,
sameSite: "None",
sameSite: 'None',
maxAge: 0,
path: "/",
domain: ".sjcpop.com",
path: '/',
domain: '.sjcpop.com',
};

const clearRefreshTokenOption = {
httpOnly: true,
secure: true,
sameSite: "None",
sameSite: 'None',
maxAge: 0,
path: "/",
domain: ".sjcpop.com",
path: '/',
domain: '.sjcpop.com',
};

export {
Expand Down
26 changes: 26 additions & 0 deletions controllers/followController.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ const getFollowers = async (req, res) => {
}
};

const getSpringFollowers = async (req, res) => {
const { userId } = req.params;
try {
const followers = await followService.getSpringFollowers(parseInt(userId));
res.status(200).json({ status: { success: true }, items: followers });
} catch (error) {
res.status(500).json({
status: { success: false, code: 500, message: error.message },
});
}
};

const getFollowing = async (req, res) => {
const { id: userId } = req.user;
const { userId: targetUserId } = req.params;
Expand All @@ -40,6 +52,18 @@ const getFollowing = async (req, res) => {
}
};

const getSpringFollowing = async (req, res) => {
const { userId } = req.params;
try {
const following = await followService.getSpringFollowing(parseInt(userId));
res.status(200).json({ status: { success: true }, items: following });
} catch (error) {
res.status(500).json({
status: { success: false, code: 500, message: error.message },
});
}
};

const createFollow = async (req, res) => {
const { id: userId } = req.user;
const { userId: targetUserId } = req.params;
Expand Down Expand Up @@ -122,10 +146,12 @@ const getFollowingCount = async (req, res) => {

export default {
getFollowers,
getSpringFollowers,
getFollowing,
createFollow,
deleteFollow,
deleteFollower,
getFollowersCount,
getFollowingCount,
getSpringFollowing,
};
4 changes: 1 addition & 3 deletions controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ const deleteUser = async (req, res) => {
const { id: userId } = req.user;
try {
await userService.deleteUser(parseInt(userId));
res
.status(204)
.json({ status: { success: true }, message: '회원탈퇴 성공' });
res.status(200).json({ status: { success: true } });
} catch (error) {
res.status(500).json({
status: { success: false, code: 500, message: error.message },
Expand Down
56 changes: 56 additions & 0 deletions repositorys/followRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,60 @@ const getFollowingCount = async (userId) => {
return followingCount;
};

const getSpringFollowers = async (userId) => {
const followers = await prisma.follow.findMany({
where: { following_id: userId },
include: {
follower: {
select: {
id: true,
nickname: true,
profile_image: true,
email: true,
},
},
},
});

// follower 객체만 추출하여 반환
const followerInfo = followers.map((follow) => {
const { profile_image, ...rest } = follow.follower;
return {
...rest,
profileImage: profile_image,
};
});

return followerInfo;
};

const getSpringFollowing = async (userId) => {
const following = await prisma.follow.findMany({
where: { follower_id: userId },
include: {
following: {
select: {
id: true,
nickname: true,
profile_image: true,
email: true,
},
},
},
});

// following 객체만 추출하여 반환
const followingInfo = following.map((follow) => {
const { profile_image, ...rest } = follow.following;
return {
...rest,
profileImage: profile_image,
};
});

return followingInfo;
};

export default {
getFollowers,
getFollowing,
Expand All @@ -252,4 +306,6 @@ export default {
deleteFollower,
getFollowersCount,
getFollowingCount,
getSpringFollowers,
getSpringFollowing,
};
3 changes: 3 additions & 0 deletions router/followRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,4 +818,7 @@ router.get('/:userId/followers/count', followController.getFollowersCount);
*/
router.get('/:userId/following/count', followController.getFollowingCount);

router.get('/:userId/spring-followers', followController.getSpringFollowers);

router.get('/:userId/spring-following', followController.getSpringFollowing);
export default router;
12 changes: 12 additions & 0 deletions services/followService.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ const getFollowingCount = async (userId) => {
return followingCount;
};

const getSpringFollowers = async (userId) => {
const followers = await followRepository.getSpringFollowers(userId);
return followers;
};

const getSpringFollowing = async (userId) => {
const following = await followRepository.getSpringFollowing(userId);
return following;
};

export default {
getFollowers,
getFollowing,
Expand All @@ -58,4 +68,6 @@ export default {
deleteFollower,
getFollowersCount,
getFollowingCount,
getSpringFollowers,
getSpringFollowing,
};
Loading