Skip to content

Commit

Permalink
fix: fix address module
Browse files Browse the repository at this point in the history
  • Loading branch information
Nhat-Original committed May 16, 2024
1 parent fb1cdc6 commit 3cfa385
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.github.nhatoriginal.spring.repository;

import com.github.nhatoriginal.spring.model.User;
import com.google.googlejavaformat.Op;

import jakarta.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

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

public interface UserRepository extends JpaRepository<User, UUID> {

User findByEmail(String email);

@Modifying
@Transactional
@Query(value = "DELETE FROM user_addresses WHERE address_id = :addressId", nativeQuery = true)
void deleteUserAddressesByAddressId(UUID addressId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ public Address save(SaveAddressDto saveAddressDto) {
return savedAddress;
}

public Address delete(UUID id) {
return addressRepository.findById(id)
public void delete(UUID id) {
addressRepository.findById(id)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Address not found"));

userRepository.deleteUserAddressesByAddressId(id);
addressRepository.deleteById(id);
}
}

0 comments on commit 3cfa385

Please sign in to comment.