-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
350 additions
and
61 deletions.
There are no files selected for viewing
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/jisungin/api/talkroomlike/TalkRoomLikeController.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.jisungin.api.talkroomlike; | ||
|
||
import com.jisungin.api.ApiResponse; | ||
import com.jisungin.api.oauth.Auth; | ||
import com.jisungin.api.oauth.AuthContext; | ||
import com.jisungin.application.talkroomlike.TalkRoomLikeService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RequestMapping("/v1") | ||
@RestController | ||
public class TalkRoomLikeController { | ||
|
||
private final TalkRoomLikeService talkRoomLikeService; | ||
|
||
@PostMapping("/talk-rooms/{talkRoomId}/likes") | ||
public ApiResponse<Void> likeTalkRoom(@PathVariable Long talkRoomId, | ||
@Auth AuthContext authContext) { | ||
talkRoomLikeService.likeTalkRoom(talkRoomId, authContext.getUserId()); | ||
|
||
return ApiResponse.<Void>builder() | ||
.message("좋아요 성공") | ||
.status(HttpStatus.OK) | ||
.build(); | ||
} | ||
|
||
@DeleteMapping("/talk-rooms/{talkRoomId}/likes") | ||
public ApiResponse<Void> nuLikeTalkRoom(@PathVariable Long talkRoomId, | ||
@Auth AuthContext authContext) { | ||
talkRoomLikeService.unLikeTalkRoom(talkRoomId, authContext.getUserId()); | ||
|
||
return ApiResponse.<Void>builder() | ||
.message("좋아요 취소") | ||
.status(HttpStatus.OK) | ||
.build(); | ||
} | ||
|
||
} |
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
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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/jisungin/application/talkroom/response/TalkRoomLikeQueryResponse.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.jisungin.application.talkroom.response; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class TalkRoomLikeQueryResponse { | ||
|
||
private Long talkRoomId; | ||
private Long likeCount; | ||
|
||
@Builder | ||
@QueryProjection | ||
public TalkRoomLikeQueryResponse(Long talkRoomId, Long likeCount) { | ||
this.talkRoomId = talkRoomId; | ||
this.likeCount = likeCount; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/jisungin/application/talkroom/response/TalkRoomLikeUserIdResponse.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.jisungin.application.talkroom.response; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class TalkRoomLikeUserIdResponse { | ||
|
||
private Long talkRoomId; | ||
private Long userId; | ||
|
||
@Builder | ||
@QueryProjection | ||
public TalkRoomLikeUserIdResponse(Long talkRoomId, Long userId) { | ||
this.talkRoomId = talkRoomId; | ||
this.userId = userId; | ||
} | ||
|
||
} |
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
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
55 changes: 55 additions & 0 deletions
55
src/main/java/com/jisungin/application/talkroomlike/TalkRoomLikeService.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.jisungin.application.talkroomlike; | ||
|
||
import com.jisungin.domain.talkroom.TalkRoom; | ||
import com.jisungin.domain.talkroom.repository.TalkRoomRepository; | ||
import com.jisungin.domain.talkroomlike.TalkRoomLike; | ||
import com.jisungin.domain.talkroomlike.repository.TalkRoomLikeRepository; | ||
import com.jisungin.domain.user.User; | ||
import com.jisungin.domain.user.repository.UserRepository; | ||
import com.jisungin.exception.BusinessException; | ||
import com.jisungin.exception.ErrorCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
@Service | ||
public class TalkRoomLikeService { | ||
|
||
private final TalkRoomLikeRepository talkRoomLikeRepository; | ||
private final TalkRoomRepository talkRoomRepository; | ||
private final UserRepository userRepository; | ||
|
||
@Transactional | ||
public void likeTalkRoom(Long talkRoomId, Long userId) { | ||
TalkRoom talkRoom = talkRoomRepository.findById(talkRoomId) | ||
.orElseThrow(() -> new BusinessException(ErrorCode.TALK_ROOM_NOT_FOUND)); | ||
|
||
User user = userRepository.findById(userId).orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND)); | ||
|
||
if (talkRoomLikeRepository.findByTalkRoomIdAndUserId(talkRoomId, userId).isPresent()) { | ||
throw new BusinessException(ErrorCode.LIKE_EXIST); | ||
} | ||
|
||
TalkRoomLike talkRoomLike = TalkRoomLike.likeTalkRoom(user, talkRoom); | ||
|
||
talkRoomLikeRepository.save(talkRoomLike); | ||
} | ||
|
||
|
||
@Transactional | ||
public void unLikeTalkRoom(Long talkRoomId, Long userId) { | ||
TalkRoom talkRoom = talkRoomRepository.findById(talkRoomId) | ||
.orElseThrow(() -> new BusinessException(ErrorCode.TALK_ROOM_NOT_FOUND)); | ||
|
||
User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new BusinessException(ErrorCode.TALK_ROOM_NOT_FOUND)); | ||
|
||
TalkRoomLike talkRoomLike = talkRoomLikeRepository.findByTalkRoomIdAndUserId(talkRoom.getId(), user.getId()) | ||
.orElseThrow(() -> new BusinessException(ErrorCode.TALK_ROOM_LIKE_NOT_FOUND)); | ||
|
||
talkRoomLikeRepository.delete(talkRoomLike); | ||
} | ||
|
||
} |
Oops, something went wrong.