-
Notifications
You must be signed in to change notification settings - Fork 46
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
[댓글 기능] 제이 미션 제출합니다. #107
[댓글 기능] 제이 미션 제출합니다. #107
Changes from 1 commit
dd87430
a2287b4
940525c
5430d29
1f9ef73
8dced8c
9a3475c
8731d42
66751cd
8901bf4
07ebbc1
f2e700e
1961b76
f44d9ff
8ef6ba5
dc2a199
087e5e0
15e570a
47ae91d
6e9726b
c2ea962
e6f5579
3e2bd3e
63235c6
924cee2
7c83e30
bb280ba
e00061f
614121c
8d0188b
7a76891
2553842
c2f89df
dbe40f5
8985502
e537451
c48f2f6
e2fec3b
6f21dfa
0ed6e1b
615e6fd
0e6e088
5447551
cefea32
b4d7ea5
e42ed91
b90115e
9f8190b
59eaeb7
95ae854
09b41c6
840253b
49fbaa5
52a6d6c
f4537c5
ed42da0
cabf579
ccb502d
8eb91d1
cc93b1a
5304a84
0c28a01
b4ef0a2
85ff44c
c915849
fc5aa5c
ed0e739
e743f49
411388d
6be9e90
c1b252e
8454227
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
package techcourse.myblog.domain; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.*; | ||
import java.util.Objects; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
@@ -17,8 +14,13 @@ public class User { | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false, length = 50) | ||
private String name; | ||
|
||
@Column(nullable = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. java bean validator를 사용하여 email 등 포맷의 유효성 검증을 할 수 있어요 |
||
private String email; | ||
|
||
@Column(nullable = false) | ||
private String password; | ||
|
||
private User() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package techcourse.myblog.support.auth; | ||
|
||
public class UserAuthentication { | ||
private String sessionId; | ||
|
||
public String getSessionId() { | ||
return sessionId; | ||
} | ||
|
||
public void setSessionId(String sessionId) { | ||
this.sessionId = sessionId; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package techcourse.myblog.support.auth; | ||
|
||
import techcourse.myblog.domain.User; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class UserSessionContextHolder { | ||
private static Map<UserAuthentication, User> context = new ConcurrentHashMap<>(); | ||
|
||
public static void bindContext(UserAuthentication authentication, User user) { | ||
context.put(authentication, user); | ||
} | ||
|
||
public static User getUserAuthentication(UserAuthentication authentication) { | ||
return context.get(authentication); | ||
} | ||
|
||
public static void removeAuthentication(UserAuthentication authentication) { | ||
context.remove(authentication); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,18 @@ | |
import org.modelmapper.ModelMapper; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import techcourse.myblog.support.auth.UserAuthentication; | ||
import techcourse.myblog.support.config.mapper.CommentResponseMapper; | ||
import techcourse.myblog.support.encryptor.EncryptHelper; | ||
import techcourse.myblog.support.encryptor.SaltEncrypt; | ||
import techcourse.myblog.web.interceptor.AuthInterceptor; | ||
import techcourse.myblog.web.interceptor.SessionContextInterceptor; | ||
import techcourse.myblog.web.resolver.SessionResolver; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
public class WebConfig { | ||
|
@@ -17,13 +23,22 @@ public WebMvcConfigurer interceptorConfigure() { | |
return new WebMvcConfigurer() { | ||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(new AuthInterceptor()) | ||
registry.addInterceptor(new AuthInterceptor(userAuthentication())) | ||
.addPathPatterns("/users") | ||
.addPathPatterns("/mypage-edit") | ||
.addPathPatterns("/mypage") | ||
.addPathPatterns("/mypage/*") | ||
.addPathPatterns("/writing") | ||
.addPathPatterns("/articles"); | ||
|
||
registry.addInterceptor(new SessionContextInterceptor(userAuthentication())) | ||
.addPathPatterns("/logout") | ||
.addPathPatterns("/users/*"); | ||
} | ||
|
||
@Override | ||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) { | ||
resolvers.add(new SessionResolver()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
}; | ||
} | ||
|
@@ -39,4 +54,9 @@ public ModelMapper modelMapper() { | |
modelMapper.addMappings(new CommentResponseMapper()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
return modelMapper; | ||
} | ||
|
||
@Bean | ||
public UserAuthentication userAuthentication() { | ||
return new UserAuthentication(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
import techcourse.myblog.service.CommentService; | ||
import techcourse.myblog.service.dto.ArticleRequest; | ||
|
||
import javax.servlet.http.HttpSession; | ||
import javax.validation.Valid; | ||
|
||
@Controller | ||
|
@@ -23,21 +22,14 @@ public ArticleController(ArticleService articleService, CommentService commentSe | |
this.commentService = commentService; | ||
} | ||
|
||
// @GetMapping("/") | ||
// public String index(@RequestParam(defaultValue = "1") int page, Model model) { | ||
// model.addAttribute("articles", articleService.findAll(page)); | ||
// return "index"; | ||
// } | ||
|
||
@GetMapping() | ||
public String formArticle(Model model) { | ||
model.addAttribute("article", null); | ||
return "article-edit"; | ||
} | ||
|
||
@PostMapping() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ()는 제거해주셔도 됩니다. |
||
public String saveArticle(@Valid ArticleRequest articleRequest, Model model, HttpSession httpSession) { | ||
User user = (User) httpSession.getAttribute("user"); | ||
public String saveArticle(@Valid ArticleRequest articleRequest, Model model, User user) { | ||
Article article = articleService.save(articleRequest, user); | ||
model.addAttribute("article", article); | ||
return "redirect:/articles/" + article.getId(); | ||
|
@@ -52,22 +44,22 @@ public String selectArticle(@PathVariable("articleId") long articleId, Model mod | |
} | ||
|
||
@GetMapping("/{articleId}/edit") | ||
public String edit(@PathVariable("articleId") long articleId, Model model, HttpSession httpSession) { | ||
Article article = articleService.findByIdWithUser(articleId, (User) httpSession.getAttribute("user")); | ||
public String edit(@PathVariable("articleId") long articleId, Model model, User user) { | ||
Article article = articleService.findByIdWithUser(articleId, user); | ||
model.addAttribute("article", article); | ||
return "article-edit"; | ||
} | ||
|
||
@PutMapping("/{articleId}") | ||
public String editArticle(@PathVariable("articleId") long articleId, @ModelAttribute ArticleRequest articleRequest, HttpSession httpSession, Model model) { | ||
Article article = articleService.editArticle(articleRequest, articleId, (User) httpSession.getAttribute("user")); | ||
public String editArticle(@PathVariable("articleId") long articleId, @ModelAttribute ArticleRequest articleRequest, User user, Model model) { | ||
Article article = articleService.editArticle(articleRequest, articleId, user); | ||
model.addAttribute("article", article); | ||
return "redirect:/articles/" + articleId; | ||
} | ||
|
||
@DeleteMapping("/{articleId}") | ||
public String deleteArticle(@PathVariable("articleId") long articleId, HttpSession httpSession) { | ||
articleService.deleteById(articleId, (User) httpSession.getAttribute("user")); | ||
public String deleteArticle(@PathVariable("articleId") long articleId, User user) { | ||
articleService.deleteById(articleId, user); | ||
return "redirect:/"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 구조에서는 contents는 varchar(255)로 세팅될텐데요. 더 긴 문자열을 받을 수 있도록 데이터타입을 바꿔주는 것은 어떨까요
지금과 같이 데이터 크기를 결정하기 힘든 큰 크기의 데이터는 @lob을 쓰는 것도 한번 고려해보세요.