Skip to content

Commit

Permalink
feat: Disconnect couple
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyeoon00 committed Sep 9, 2023
1 parent f399095 commit 923298f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.http.HttpStatus;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
Expand Down Expand Up @@ -57,4 +59,11 @@ public CoupleConnectionResponseDto checkConnection(
) {
return coupleService.checkConnection(userId);
}

@DeleteMapping("")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void disconnectCouple(@AuthenticationPrincipal Long userId) {
coupleService.disconnectCouple(userId);
}

}
9 changes: 9 additions & 0 deletions src/main/java/com/universe/uni/service/CoupleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,13 @@ public CoupleConnectionResponseDto checkConnection(Long userId) {
public void deleteCouple(Long coupleId) {
coupleRepository.deleteById(coupleId);
}

@Override
@Transactional
public void disconnectCouple(Long userId) {
final User user = userRepository.findById(userId)
.orElseThrow(() -> new BadRequestException(ErrorType.USER_NOT_EXISTENT));
final Couple couple = user.getCouple();
deleteCouple(couple.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ CoupleDto createCoupleByStartDate(

@Transactional
void deleteCouple(Long coupleId);

@Transactional
void disconnectCouple(Long userId);
}

0 comments on commit 923298f

Please sign in to comment.