Skip to content

Commit

Permalink
✨ feat: add user unblock api
Browse files Browse the repository at this point in the history
  • Loading branch information
yunyoung1819 committed Jul 23, 2023
1 parent 1962dae commit c085f64
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
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 @@ -21,9 +22,19 @@ public class UserBlockController {
@PostMapping("/users/block")
public ResponseEntity<BlockUserResponseDto> blockUser(
@ReqUser User user,
@RequestParam(value = "blockUserID") Long blockUserID
@RequestParam(value = "blockUserId") Long blockUserId
) {
var response = userBlockService.blockUser(user, blockUserID);
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 @@ -34,4 +34,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);
}
}

0 comments on commit c085f64

Please sign in to comment.