Skip to content

Commit

Permalink
Merge pull request #28 from GMD-music-recommend-app/bori
Browse files Browse the repository at this point in the history
modify : 서버 올리기 전 수정
  • Loading branch information
joeun-01 authored Dec 24, 2022
2 parents 66fbef2 + 657f170 commit 0544a72
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/sesac/gmd/src/song/SongController.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ public BaseResponse<List<GetPinsRes>> getPins(@RequestParam int radius, @Request
@ApiImplicitParam(name = "X-ACCESS-TOKEN", required = true, dataType = "string", paramType = "header"),
})
@ResponseBody
@PostMapping("/like/{userIdx}/{pinIdx}")
public BaseResponse<String> likeSong(@PathVariable int userIdx, @PathVariable int pinIdx){
@PostMapping("/like")
public BaseResponse<String> likeSong(@RequestBody PostLikeReq postLikeReq){
try{
int userIdxJwt = jwtService.getUserIdx();
//useridx로 접근한 유저가 같은 유저인지 확인하기
if(userIdx != userIdxJwt) {
if(postLikeReq.getUserIdx() != userIdxJwt) {
return new BaseResponse<>(BaseResponseStatus.INVALID_USER_JWT);
}
//유저 아이디랑 핀 아이디 넘겨주기
String result = songService.likeSong(userIdx, pinIdx);
String result = songService.likeSong(postLikeReq);
return new BaseResponse<>(result);
} catch(BaseException exception){
return new BaseResponse<>((exception.getStatus()));
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/sesac/gmd/src/song/SongDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ public List<GetPinsRes> getPins(GetPinsReq getPinsReq) {
}

/* 핀 공감 & 공감 취소 API */
public String likeSong(int userIdx, int pinIdx) {
public String likeSong(PostLikeReq postLikeReq) {
String getLikeQuery = "select * from pin_like_tbl where userIdx=? and pinIdx=?";
List<Map<String, Object>> rows = this.jdbcTemplate.queryForList(getLikeQuery, userIdx, pinIdx);
// 해당 사용자가 좋아요를 눌렀는지 확인.
List<Map<String, Object>> rows = this.jdbcTemplate.queryForList(getLikeQuery, postLikeReq.getUserIdx(), postLikeReq.getPinIdx());
// 해당 사용자가 좋아요를 눌렀는지 확인.
// userIdx와 pinIdx를 뽑아 rows에 저장해서 rows의 길이가 0인 경우, 즉 좋아요 누른 pin이 없는 경우 pin_like_tbl 테이블에 userIdx와 pinIdx를 저장하자.
if (rows.size() == 0) {
String createProductQuery = "insert into pin_like_tbl (userIdx, pinIdx) VALUES (?, ?)";

Object[] createProductParams = new Object[]{userIdx, pinIdx};
Object[] createProductParams = new Object[]{postLikeReq.getUserIdx(), postLikeReq.getPinIdx()};

this.jdbcTemplate.update(createProductQuery, createProductParams);

Expand All @@ -144,14 +144,13 @@ public String likeSong(int userIdx, int pinIdx) {
} else { // 그럼 그 반대의 경우는 rows의 길이가 0이 아닌, 이미 좋아요를 누른 게시글이다. DELETE 쿼리로 좋아요 취소를 구현한다.
String createProductQuery = "DELETE FROM pin_like_tbl WHERE userIdx=? and pinIdx=?";

Object[] createProductParams = new Object[]{userIdx, pinIdx};
Object[] createProductParams = new Object[]{postLikeReq.getUserIdx(), postLikeReq.getPinIdx()};

this.jdbcTemplate.update(createProductQuery, createProductParams);

return "핀 공감을 취소하였습니다.";

}

}

/* 댓글 작성 API */
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/sesac/gmd/src/song/SongService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public PostPinRes createPin(PostPinReq postPinReq) throws BaseException {
}

/* 핀 공감 & 공감 취소 API */
public String likeSong(int userIdx, int pinIdx) throws BaseException{
public String likeSong(PostLikeReq postLikeReq) throws BaseException{
try{
return songDao.likeSong(userIdx, pinIdx);
return songDao.likeSong(postLikeReq);
}catch(Exception exception){
throw new BaseException(DATABASE_ERROR);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/sesac/gmd/utils/JwtService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sesac.gmd.utils;

import com.sesac.gmd.config.BaseException;
import com.sesac.gmd.config.Secret.Secret;
import com.sesac.gmd.config.secret.Secret;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
Expand Down

0 comments on commit 0544a72

Please sign in to comment.