Skip to content

Commit

Permalink
Merge pull request #153 from JNU-Parking-Ticket-Project/feature-#71
Browse files Browse the repository at this point in the history
[BE-71] feat: Event 초기화 #152
  • Loading branch information
BlackBean99 committed Dec 19, 2023
2 parents c8d86cc + 949cab1 commit f5885f1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jnu.ticketapi.api.event.controller;

import static com.jnu.ticketcommon.message.ResponseMessage.EVENT_SUCCESS_DELETE_MESSAGE;
import static com.jnu.ticketcommon.message.ResponseMessage.EVENT_SUCCESS_OPEN_MESSAGE;
import static com.jnu.ticketcommon.message.ResponseMessage.EVENT_SUCCESS_REGISTER_MESSAGE;
import static com.jnu.ticketcommon.message.ResponseMessage.EVENT_SUCCESS_UPDATE_STATUS_MESSAGE;
Expand All @@ -21,6 +22,7 @@
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -49,6 +51,13 @@ public SuccessResponse setEvent(@RequestBody DateTimePeriod dateTimePeriod) {
return new SuccessResponse(EVENT_SUCCESS_REGISTER_MESSAGE);
}

@Operation(summary = "주차권 리셋", description = "현재 활성화 및 대기중인 이벤트를")
@DeleteMapping("/events/reset")
public SuccessResponse resetEvent() {
EventWithDrawUseCase.resetEvent();
return new SuccessResponse(EVENT_SUCCESS_DELETE_MESSAGE);
}

@Operation(summary = "주차권 신청", description = "주차권 신청(주차권 신청시 잔고 감소)")
@Deprecated(since = "2023-12-08", forRemoval = true)
@PostMapping("/events/apply")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import com.jnu.ticketdomain.common.vo.DateTimePeriod;
import com.jnu.ticketdomain.domains.events.adaptor.EventAdaptor;
import com.jnu.ticketdomain.domains.events.domain.Event;
import com.jnu.ticketdomain.domains.events.domain.EventStatus;
import com.jnu.ticketdomain.domains.events.domain.Sector;
import com.jnu.ticketdomain.domains.events.exception.NotFoundEventException;
import com.jnu.ticketdomain.domains.events.exception.NotReadyEventStatusException;
import com.jnu.ticketinfrastructure.service.WaitingQueueService;
import java.util.List;
import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -54,4 +58,18 @@ public DateTimePeriod getEventPeriod() {
throw NotReadyEventStatusException.EXCEPTION;
});
}

public void resetEvent() {
Result<Event, Object> readyOrOpenEvent = eventAdaptor.findReadyOrOpenEvent();
readyOrOpenEvent.fold(
(event) -> {
eventAdaptor.updateEventStatus(event, EventStatus.CLOSED);
List<Sector> sector = event.getSector();
sector.forEach(Sector::resetAmount);
return null;
},
(error) -> {
throw NotFoundEventException.EXCEPTION;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class ResponseMessage {
public static final String SUCCESS_FINAL_SAVE = "최종 저장이 완료 되었습니다.";
public static final String PASSWORD_SUCCESS_CHANGE_MESSAGE = "성공적으로 비밀번호가 변경됐습니다";
public static final String EVENT_SUCCESS_REGISTER_MESSAGE = "성공적으로 이벤트가 등록됐습니다";
public static final String EVENT_SUCCESS_DELETE_MESSAGE = "성공적으로 이벤트가 삭제 됐습니다";
public static final String EVENT_SUCCESS_OPEN_MESSAGE = "성공적으로 이벤트가 오픈됐습니다";
public static final String EVENT_SUCCESS_UPDATE_STATUS_MESSAGE = "성공적으로 이벤트 상태가 수정됐습니다";
public static final String SECTOR_SUCCESS_REGISTER_MESSAGE = "성공적으로 구간이 등록됐습니다";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ public class Sector {
@Column(name = "sector_capacity", nullable = false)
private Integer sectorCapacity;

@Column(name = "init_sector_capacity", nullable = false)
private Integer initSectorCapacity;
// 예비 정원
@Column(name = "reserve", nullable = false)
private Integer reserve;

@Column(name = "init_reserve", nullable = false)
private Integer initReserve;

// 총 정원
@Column(name = "issue_amount", nullable = false)
private Integer issueAmount;
Expand All @@ -58,11 +63,19 @@ public Sector(String sectorNumber, String name, Integer sectorCapacity, Integer
this.sectorNumber = sectorNumber;
this.name = name;
this.sectorCapacity = sectorCapacity;
this.initSectorCapacity = sectorCapacity;
this.reserve = reserve;
this.initReserve = reserve;
this.issueAmount = sectorCapacity + reserve;
this.remainingAmount = this.issueAmount;
}

public void resetAmount() {
this.remainingAmount = this.issueAmount;
this.sectorCapacity = this.initSectorCapacity;
this.reserve = this.initReserve;
}

public void decreaseEventStock() {
checkEventLeft();
if (isSectorRemaining()) {
Expand Down
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ subprojects {
xml.required = false
csv.required = false
html.required = true
// xml 위치 조정
xml.destination file("${project.projectDir}/build/reports/jacoco.xml")
}

def Qdomains = []
Expand All @@ -82,6 +84,10 @@ subprojects {
)
}
}
test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

apply plugin: 'org.sonarqube'
sonarqube {
Expand All @@ -105,10 +111,7 @@ subprojects {
testAnnotationProcessor 'org.projectlombok:lombok'
}

test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

}

spotless {
Expand Down

0 comments on commit f5885f1

Please sign in to comment.