Skip to content

Conversation

@shinminkyoung1
Copy link

@shinminkyoung1 shinminkyoung1 commented Jan 15, 2026

완료 작업 목록

버그데이 대비 추가 기능 구현

  1. index.html 상세구현 WIKI
  2. register.html 상세구현 WIKI
  3. login.html 상세구현 WIKI
  4. index / comment / write.html 상세구현 WIKI
  5. mypage.html [상세구현 WIKI](5. mypage.html 상세구현 WIKI)

주요 고민과 해결 과정

  1. [다음 글], [이전 글]로 이동

(?) 이동되지 않고 무한루프에 빠짐

articleDao.selectLatest()를 호출하고 있는데 사용자가 [이전 글]을 눌러서 ?id=10으로 들어와도, 코드에서 항상 selectLatest()(가장 최신글)만 가져오게 되어 있다면 계속 똑같은 글만 보여주거나 로직이 꼬이게 됨

→ URL에 id 파라미터로 id의 글을 가져오고, 없으면 최신글을 가져오도록 로직을 분기

  • ArticleIndexHandler

    @Override
        public void process(HttpRequest request, HttpResponse response) {
            String sessionId = request.getCookie("sid");
            User loginUser = SessionManager.getLoginUser(sessionId, AppConfig.getUserDao());
    
            try {
                String idParam = request.getParameter("id");
                Article targetArticle;
    
                if (idParam != null && !idParam.isEmpty()) {
                    targetArticle = articleDao.findById(Long.parseLong(idParam));
                } else {
                    targetArticle = articleDao.selectLatest();
                }
    
                Map<String, String> model = new HashMap<>();
                model.put("header_items", PageRender.renderHeader(loginUser));
    
                if (targetArticle != null) {
                    User writer = userDao.findUserById(targetArticle.writer());
                    List<Comment> comments = commentDao.findAllByArticleId(targetArticle.id());
    
                    model.put("posts_list", PageRender.renderLatestArticle(targetArticle, writer, comments.size()));
                    model.put("comment_list", PageRender.renderComments(comments));
    
                    Long prevId = articleDao.findPreviousId(targetArticle.id());
                    Long nextId = articleDao.findNextId(targetArticle.id());
                    model.put("post_nav", PageRender.renderPostNav(prevId, nextId, targetArticle.id()));
    
                } else {
                    model.put("posts_list", "<div class='post'><p class='post__article'>등록된 게시글이 없습니다.</p></div>");
                    model.put("comment_list", "");
                    model.put("post_nav", "");
                }
    
                File file = new File(Config.STATIC_RESOURCE_PATH + "/index.html");
                String content = new String(Files.readAllBytes(file.toPath()), Config.UTF_8);
                String renderedHtml = TemplateEngine.render(content, model);
    
                response.sendHtmlContent(renderedHtml);
    
            } catch (IOException e) {
                logger.error("Index rendering error: ", e);
                response.sendError(HttpStatus.INTERNAL_SERVER_ERROR);
            } catch (NumberFormatException e) {
                logger.error("Invalid ID format: ", e);
                response.sendRedirect(Config.DEFAULT_PAGE);
            }
        }
  1. 비밀번호 불일치 시 알람 이후 마이페이지 리다이렉트 될 때 사용자 정보가 리렌더링 되지 않는 문제 발생

기존에는 리다이렉트를 response.sendRedirect(Config.MYPAGE);로 치환자를 사용했음

→ 정확한 리다이렉트 페이지 경로로 수정해 myPageHandler을 호출할 수 있게 수정하여 해결

// 비밀번호 변경
if (newPwd != null && !newPwd.trim().isEmpty()) {

    if (!newPwd.equals(newPwdConfirm)) {
        logger.warn("Profile update failed: Password confirmation mismatch for user '{}'", loginUser.userId());

        response.addHeader("Set-Cookie", "update_error=pwd_mismatch; Path=/; Max-Age=5");
        response.sendRedirect("/mypage");
        return;
    }

    finalPassword = newPwd;
    logger.debug("Password change requested and validated for user '{}'", loginUser.userId());
}
  1. 핸들러 구조 설정 및 렌더링 방식 변경 등에 대한 고민..

AI에 도움받은 부분

  • 커밋 메시지 작성
  • html 관련 설정 및 구현

shinminkyoung1 and others added 30 commits January 4, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants