Skip to content

Commit

Permalink
Solved id dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Troter2 committed Dec 15, 2024
1 parent 561c300 commit 1ed6ac3
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import java.math.BigDecimal;
import java.time.ZonedDateTime;

import java.util.List;


@Setter
Expand Down Expand Up @@ -72,9 +72,12 @@ public Advertisement() {
@PrePersist
private void initializeAdStatus() {
if (this.adStatus == null) {
this.adStatus = AdvertisementStatusRepositoryHolder.getRepository()
.findById(1L)
.orElseThrow(() -> new RuntimeException("Default AdvertisementStatus with ID 1 not found"));
List<AdvertisementStatus> entities = AdvertisementStatusRepositoryHolder.getRepository().findByStatus("Available");

if (entities.isEmpty()) {
throw new EntityNotFoundException("No entities found with status: Available" );
}
this.adStatus = entities.get(0);
}
}
}
Expand Down

0 comments on commit 1ed6ac3

Please sign in to comment.