diff --git a/backend/src/main/java/com/example/booktree/user/service/UserService.java b/backend/src/main/java/com/example/booktree/user/service/UserService.java index 093831ea..a614a7fe 100644 --- a/backend/src/main/java/com/example/booktree/user/service/UserService.java +++ b/backend/src/main/java/com/example/booktree/user/service/UserService.java @@ -4,6 +4,8 @@ import com.example.booktree.category.entity.Category; import com.example.booktree.category.repository.CategoryRepository; import com.example.booktree.comment.repository.CommentRepository; +import com.example.booktree.email.entity.EmailMessage; +import com.example.booktree.email.service.EmailService; import com.example.booktree.exception.BusinessLogicException; import com.example.booktree.exception.ExceptionCode; import com.example.booktree.follow.repository.FollowRepository; @@ -60,6 +62,7 @@ public class UserService { private final PasswordEncoder passwordEncoder; + private final EmailService emailService; private final TokenService tokenService; private final ImageService imageService; private static final String USER_IMAGE= DEFAULT_USER_IMAGE; @@ -139,16 +142,19 @@ public User findUserByEmail(String email){ } - //임시 비밀번호 발급 - 이메일로 비밀번호 - public String findPasswordByEmail(String email){ - + public void findPasswordByEmail(String email){ + EmailMessage emailMessage = EmailMessage.builder() + .to(email) + .subject("[BookTree] 임시 비밀번호 발급") + .build(); User user = findUserByEmail(email); String randomPassword = CreateRandomNumber.randomNumber(); user.setPassword(passwordEncoder.encode(randomPassword)); userRepository.save(user); - return randomPassword; - } + emailService.sendMail(emailMessage, "password",randomPassword); + + } //임시 비밀번호 발급 - 이메일, 핸드폰으로 비밀번호 public String findPasswordByEmailAndPhone(UserPasswordRequestDto.FindPwByEmailAndPhone findPwByEmailAndPhone){ diff --git a/frontend/src/app/components/CommentsSection.tsx b/frontend/src/app/components/CommentsSection.tsx index 4ee2b9e3..866ba1a1 100644 --- a/frontend/src/app/components/CommentsSection.tsx +++ b/frontend/src/app/components/CommentsSection.tsx @@ -334,10 +334,35 @@ export function CommentsSection({ postId }: { postId: number }) { }, [activeCommentId, activeReplyPopoverId]) // ─── 프로필 이미지 불러오기 ──────────────────────────────────── + // useEffect(() => { + // if (!comments.length) return + // const ids = Array.from( + // new Set([...comments.map((c) => c.userId), ...comments.flatMap((c) => c.replies.map((r) => r.userId))]), + // ) + // async function fetchUserImages() { + // const map: Record = {} + // await Promise.all( + // ids.map(async (id) => { + // try { + // const res = await fetch(`${API}/api/v1/users/get/profile/${id}`) + // if (!res.ok) return + // const { imageUrl } = await res.json() + // map[id] = imageUrl + // } catch {} + // }), + // ) + // setUserImages(map) + // } + // fetchUserImages() + // }, [comments]) + useEffect(() => { - if (!comments.length) return + if (!rawComments.length) return const ids = Array.from( - new Set([...comments.map((c) => c.userId), ...comments.flatMap((c) => c.replies.map((r) => r.userId))]), + new Set([ + ...rawComments.map((c) => c.userId), + ...rawComments.flatMap((c) => c.replies.map((r) => r.userId)), + ]), ) async function fetchUserImages() { const map: Record = {} @@ -354,7 +379,7 @@ export function CommentsSection({ postId }: { postId: number }) { setUserImages(map) } fetchUserImages() - }, [comments]) + }, [rawComments]) // ─── 렌더링 ──────────────────────────────────────────────────── return (