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

5주차 미션 / 서버 3조 이윤희 #52

Open
wants to merge 7 commits into
base: step3-jdbc-start
Choose a base branch
from

Conversation

lylylylh
Copy link

@lylylylh lylylylh commented Nov 6, 2024

제 webMVC repository를 삭제해버려서,, 다시 올립니당 ㅜ

Copy link

@JangIkhwan JangIkhwan left a comment

Choose a reason for hiding this comment

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

늦었지만 잘하셨습니다. 앞으로 더 힘내봅시다!! 👍

Comment on lines -12 to +25
return "/home.jsp";

List<Question> questions = questionDao.findAll();
req.setAttribute("questions", questions);

RequestDispatcher rd = req.getRequestDispatcher("/home.jsp");
rd.forward(req, resp);

return null;

Choose a reason for hiding this comment

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

여기서 forward를 안해도 됩니다...! /home.jsp를 리턴하면 DispatcherServlet이 forward를 해줘요

Comment on lines +9 to +27
public class ControllerUtils {

public static Question getQuestionAndCheckAuthorization(HttpServletRequest req, QuestionDao questionDao) throws Exception {

User user = (User) req.getSession().getAttribute("user");
if (user == null) {
throw new IllegalStateException("로그인이 필요합니다.");
}

int questionId = Integer.parseInt(req.getParameter("questionId"));
Question question = questionDao.findByQuestionId(questionId);

if (!user.getUserId().equals(question.getWriter())) {
throw new IllegalArgumentException("수정 권한이 없습니다.");
}

return question;
}
}
Copy link

@JangIkhwan JangIkhwan Nov 9, 2024

Choose a reason for hiding this comment

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

개인적인 견해로는 Controller 클래스가 이 작업을 수행하는 것이 좋을 것 같아요


public class CreateQnaController implements Controller {

private final QuestionDao questionDao = new QuestionDao();

Choose a reason for hiding this comment

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

지금은 필드주입으로 충분하지만 장기적인 관점에서 보면 생성자 주입을 사용하는 것이 더 좋을 것 같네요

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants