Skip to content

Commit

Permalink
[feat] 저장 취소 시 storecount 감소 메서드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
BackInGone committed Jan 26, 2024
1 parent 0f08345 commit 7958cc2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,11 @@ public void incrementStoreCount() {
this.storeCount++;
}
}

public void decrementStoreCount() {
if(this.storeCount > 0) {
this.storeCount--;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public void incrementStoreCount() {
}
}

public void decrementStoreCount() {
if(this.storedCount > 0) {
this.storedCount--;
}
}

public void incrementReviewCount() {
if(this.reviewCount == null) {
this.reviewCount = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public void unstoreCity(PrincipalDetails principalDetails, Long cityId) {
Long memberId = principalDetails.getMember().getId();
CityStore cityStore = cityStoreRepository.findByMemberIdAndCityId(memberId, cityId)
.orElseThrow(() -> new StoreNotFoundException(ErrorCode.STORE_NOT_FOUND));

City city = cityRepository.findById(cityId)
.orElseThrow();
city.decrementStoreCount();

cityStoreRepository.delete(cityStore);
}

Expand All @@ -117,6 +122,11 @@ public void unstorePlace(PrincipalDetails principalDetails, Long placeId) {
Long memberId = principalDetails.getMember().getId();
PlaceStore placeStore = placeStoreRepository.findByMemberIdAndPlaceId(memberId, placeId)
.orElseThrow(() -> new StoreNotFoundException(ErrorCode.STORE_NOT_FOUND));

Place place = placeRepository.findById(placeId)
.orElseThrow(()-> new PlaceNotFoundException());
place.decrementStoreCount();

placeStoreRepository.delete(placeStore);
}

Expand All @@ -125,6 +135,11 @@ public void unstoreTripRecord(PrincipalDetails principalDetails, Long tripRecord
Long memberId = principalDetails.getMember().getId();
TripRecordStore tripRecordStore = tripRecordStoreRepository.findByMemberIdAndTripRecordId(memberId, tripRecordId)
.orElseThrow(() -> new StoreNotFoundException(ErrorCode.STORE_NOT_FOUND));

TripRecord tripRecord = tripRecordRepository.findById(tripRecordId)
.orElseThrow(()-> new TripRecordNotFoundException());
tripRecord.decrementStoreCount();

tripRecordStoreRepository.delete(tripRecordStore);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ public void incrementStoreCount() {
}
}

public void decrementStoreCount() {
if(this.storeCount > 0) {
this.storeCount--;
}
}

public void incrementReviewCount() {
if(this.reviewCount == null) {
this.reviewCount = 1;
Expand Down

0 comments on commit 7958cc2

Please sign in to comment.