-
-
Save redjen8/16b5eed0faaa3c86aa80d02e7bd99dee to your computer and use it in GitHub Desktop.
yanolja member-company like request api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Transactional | |
@ResponseBody | |
@PostMapping("/like/company/{companyIdx}") | |
@ApiOperation(value="사용자 숙소 좋아요 요청", notes="사용자 별 숙소 좋아요 요청 처리, 동일한 요청 재전송 시 좋아요 취소") | |
public ResponseEntity<Map<String, Object>> makeLikeToCompany(@PathVariable int companyIdx, @RequestParam int memberIdx) { | |
Map<String, Object> resultMap = new HashMap<>(); | |
try { | |
int memberIdxByJwt = jwtService.getUserIdx(); | |
if (memberIdxByJwt != memberIdx) { | |
resultMap.put("resultCode", 4); | |
resultMap.put("resultMsg", "jwt 인증 오류"); | |
return new ResponseEntity<>(resultMap, HttpStatus.OK); | |
} | |
} | |
catch (BaseException exception) { | |
resultMap.put("resultCode", 3); | |
resultMap.put("resultMsg", "jwt 검증 오류"); | |
return new ResponseEntity<>(resultMap, HttpStatus.OK); | |
} | |
try { | |
int checkAlreadyLikedCompany = memberService.checkAlreadyLikedCompany(memberIdx, companyIdx); | |
if(checkAlreadyLikedCompany == 1) { // 이미 클릭했던 경우 | |
int cancelRes = memberService.cancelLikeToCompany(memberIdx, companyIdx); | |
if (cancelRes == 1) { | |
resultMap.put("resultCode", 0); | |
resultMap.put("resultMsg", "좋아요 취소 완료"); | |
} | |
else { | |
resultMap.put("resultCode", 5); | |
resultMap.put("resultMsg", "좋아요 취소 실패"); | |
} | |
} | |
else { | |
int makeRes = memberService.makeLikeToCompany(memberIdx, companyIdx); | |
if (makeRes == 1) { | |
resultMap.put("resultCode", 0); | |
resultMap.put("resultMsg", "좋아요 등록 완료"); | |
} | |
else { | |
resultMap.put("resultCode", 5); | |
resultMap.put("resultMsg", "좋아요 등록 실패"); | |
} | |
} | |
} | |
catch (Exception e) { | |
e.printStackTrace(); | |
resultMap.put("resultCode", 2); | |
resultMap.put("resultMsg", "데이터베이스 접근 오류"); | |
return new ResponseEntity<>(resultMap, HttpStatus.OK); | |
} | |
return new ResponseEntity<>(resultMap, HttpStatus.OK); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment