Skip to content
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

✨ feat(api): add user unblock api #263

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -26,4 +27,14 @@ public ResponseEntity<BlockUserResponseDto> blockUser(
var response = userBlockService.blockUser(user, blockUserID);
return ResponseDto.ok(response);
}

@Operation(summary = "사용자 차단 해제하기")
@DeleteMapping("/users/unblock")
public ResponseEntity<Void> unBlockUser(
@ReqUser User user,
@RequestParam(value = "unblockUserId") Long unblockUserId
) {
userBlockService.unBlockUser(user, unblockUserId);
return ResponseDto.noContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface BlockUserRepository extends JpaRepository<BlockUser, Long> {

@Query("SELECT b.blockedId FROM BlockUser b WHERE b.blockerId = :blockerId")
List<Long> findBlockedIdsByBlockerId(@Param("blockerId") Long blockerId);

Optional<BlockUser> findBlockUserByBlockerIdAndBlockedId(@Param("blockerId") Long blockerId, @Param("blockedId") Long blockedId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class UserBlockService {
public BlockUserResponseDto blockUser(User user, Long blockUserID) {
var blockUser = userRepository.findUserById(blockUserID)
.orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND, user.getId()));

/*
* blockerId : 차단한 사용자 아이디
* blockedId : 차단된 사용자 아이디
Expand All @@ -34,4 +33,12 @@ public BlockUserResponseDto blockUser(User user, Long blockUserID) {
blockUserRepository.save(block);
return new BlockUserResponseDto(blockUser);
}

@Transactional
public void unBlockUser(User user, Long unblockUserId) {
var userId = user.getId();
var blockedUser = blockUserRepository.findBlockUserByBlockerIdAndBlockedId(userId, unblockUserId)
.orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND, unblockUserId));
blockUserRepository.delete(blockedUser);
}
}
Loading