Skip to content

Commit

Permalink
backend | Change the transactional annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
ElviraMjeshtri committed Aug 14, 2023
1 parent f12e5f9 commit cef8d81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

import com.amigoscode.domain.provider.PageProvider;
import com.amigoscode.domain.provider.Provider;
import com.amigoscode.domain.provider.ProviderAlreadyExistsException;
import com.amigoscode.domain.provider.ProviderService;
import com.amigoscode.external.storage.provider.ProviderEntity;
import lombok.extern.java.Log;
import lombok.RequiredArgsConstructor;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Log
public class ProviderApplicationService {

private final ProviderService providerService;
Expand All @@ -26,8 +31,18 @@ public PageProvider findAll(Pageable pageable) {
}

@Transactional
public Provider save(Provider providerToSave) {
public Provider saveTransaction(Provider providerToSave) {
return providerService.save(providerToSave, authenticationFacade.getLoggedInUserId());

}

public Provider save(Provider providerToSave) {
try {
return saveTransaction(providerToSave);
} catch (DataIntegrityViolationException ex) {
log.warning("Provider " + providerToSave.getEmail() + " already exits in db");
throw new ProviderAlreadyExistsException();
}
}
@Transactional
public void update(Provider provider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void admin_should_get_response_code_conflict_when_provider_is_in_db() {
ErrorResponse.class);

//then
assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
assertEquals(HttpStatus.CONFLICT, response.getStatusCode());
}


Expand Down

0 comments on commit cef8d81

Please sign in to comment.