ํฐ์คํ ๋ฆฌ ๋ทฐ
Project/Instagram
[spring] ํด๋ก ์ฝ๋ฉ17 Follow - ํ๋ก์ฐ, ์ธํ๋ก์ฐ
yeahajeong 2020. 4. 20. 20:46๋ฐ์ํ
Controller
FollowController
//ํ๋ก์ฐ ์์ฒญ
@PostMapping("/follow/{id}")
public String follow(@PathVariable String id, HttpSession session, Model model) throws Exception {
logger.info("/follow/" + id + " : ํ๋ก์ฐ ์์ฒญ ");
Object object = session.getAttribute("login");
UsersVO activeUser = (UsersVO)object;
UsersVO passiveUser = usersService.inquiryOfUserById(id);
FollowVO follow = new FollowVO();
follow.setActiveUser(activeUser.getUserNo());
follow.setPassiveUser(passiveUser.getUserNo());
followService.follow(follow);
return "FollowOK";
}
ํ๋ก์ฐ ์์ฒญ์ ํ๋ก์ฐํ ์ ์ ์ id๋ฅผ ๊ฐ์ง๊ณ ๋์ด๊ฐ๋ค. ๋ก๊ทธ์ธ์ธ์ ์ ๊ฐ์ ธ์์ activeUser์ ๋ด๊ณ ํ๋ก์ฐํ ์ ์ id๋ก ํด๋น ์ ์ ์ ์ ์ฒด์ ๋ณด๋ฅผ ์กฐํํด์ passiveUser์ ๋ด๋๋ค. FollowVO ๊ฐ์ฒด๋ฅผ ๋ง๋ค์ด ๊ฐ์ ์ง์ ํด ์ค๋ค DB์ ์ ์ฅํ๋ค.
//์ธํ๋ก์ฐ ์์ฒญ
@PostMapping("/unfollow/{id}")
public String unfollow(@PathVariable String id, HttpSession session, Model model) throws Exception {
logger.info("/unfollow/" + id + " : ์ธํ๋ก์ฐ ์์ฒญ ");
Object object = session.getAttribute("login");
UsersVO activeUser = (UsersVO)object;
UsersVO passiveUser = usersService.inquiryOfUserById(id);
FollowVO follow = new FollowVO();
follow.setActiveUser(activeUser.getUserNo());
follow.setPassiveUser(passiveUser.getUserNo());
followService.unfollow(follow);
return "UnFollowOK";
}
ํ๋ก์ฐ๊ธฐ๋ฅ๊ณผ ๋๊ฐ์ด ๋์ํ๋ค. DB์ชฝ์ผ๋ก ๋ฐ์ดํฐ๊ฐ ๋ค์ด๊ฐ๋ฉด์ DB์ ์ ์ฅ๋ ํ๋ก์ฐ๊ฐ ์ญ์ ๊ฐ ๋๋ค.
Service
FollowService
@Override
public void follow(FollowVO follow) {
followDAO.follow(follow);
}
@Override
public void unfollow(FollowVO follow) {
followDAO.unfollow(follow);
}
View
personal-list.jsp
$('#follow-btn').on('click', function() {
follow(true);
});
$('#unfollow-btn').on('click', function() {
follow(false);
});
function follow(check) {
if(check) {
$.ajax({
type: "POST",
url: "/myapp/follow/${user.id}",
headers: {
"Content-Type": "application/json",
"X-HTTP-Method-Override": "POST"
},
success: function(result) {
console.log("result : " + result);
if(result === "FollowOK"){
$(".follow").html('<button class="followBtn" id="unfollow-btn">์ธํ๋ก์ฐ</button>');
location.href="/myapp/post/${user.id}";
}
}
});
} else {
$.ajax({
type: "POST",
url: "/myapp/unfollow/${user.id}",
headers: {
"Content-Type": "application/json",
"X-HTTP-Method-Override": "POST"
},
success: function(result) {
console.log("result : " + result);
if(result === "UnFollowOK"){
$(".follow").html('<button class="followBtn" id="follow-btn">ํ๋ก์ฐ</button>');
location.href="/myapp/post/${user.id}";
}
}
});
}
}
๋ฐ์ํ
'Project > Instagram' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[spring] ํด๋ก ์ฝ๋ฉ19 Interceptor (1) | 2020.04.21 |
---|---|
[spring] ํด๋ก ์ฝ๋ฉ 18 Follow - ํ๋ก์, ํ๋ก์ ๋ฆฌ์คํธ ์กฐํ (0) | 2020.04.21 |
[spring] ํด๋ก ์ฝ๋ฉ16 Follow - Model, Repository, Mapper, Test, Service, Controller (0) | 2020.04.20 |
[spring] ํด๋ก ์ฝ๋ฉ15 Post - ๊ฒ์๊ธ ์ญ์ (0) | 2020.04.20 |
[spring] ํด๋ก ์ฝ๋ฉ14 Post - ๊ฒ์๊ธ ๋ฑ๋ก (0) | 2020.04.20 |
๋๊ธ
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- ์๋ฃ๊ตฌ์กฐ
- Java
- ์๊ณ ๋ฆฌ์ฆ
- ๊ฒ์๋ฌผ ์ญ์
- ์ดํด๋ฆฝ์ค ํ๊ธ ์ธ์ฝ๋ฉ
- tomcat์ค์น
- ๊ฐ๋ฐํ๊ฒฝ๊ตฌ์ถ
- Algorithm
- ๋ถํธ ์๋์์ฑ
- ๋ณ๋ช ์ฒ๋ฆฌ
- typeAliases
- ์คํ๋ง๋ถํธ ์๋์์ฑ
- ๊ฐ๋ฐ
- ์ดํด๋ฆฝ์ค ์ค์น
- ์๋ฐ
- ์จ๋ฆฌ์์ค
- java ํ๊ฒฝ๋ณ์
- ๊ฒ์ํ๋ง๋ค๊ธฐ
- java jdk ์ค์น
- ๊ฒ์ํ ์ญ์
- ๊ฒ์๋ฌผ์กฐํ
- ๊ฒ์ํ ์กฐํ
- mysql์ค์น
- ์ ์ฒด๊ฒ์๋ฌผ ์กฐํ
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
๊ธ ๋ณด๊ดํจ