Skip to content

Commit

Permalink
Merge pull request #124 from softeerbootcamp4th/feature/#116-admin-lo…
Browse files Browse the repository at this point in the history
…ttery-event-delete-expectation

Feature/#116 admin lottery event delete expectation
  • Loading branch information
k000927 authored Aug 13, 2024
2 parents bcea85f + 72d403b commit f9e7547
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,12 @@ public ResponseEntity<List<LotteryEventExpectationResponseDto>> getLotteryEventE

return ResponseEntity.ok(lotteryEventExpectationResponseDtoList);
}

// 추첨 이벤트 특정 기대평을 삭제
@PatchMapping("/event/lottery/expecations/{casperId}")
public ResponseEntity<Void> deleteLotteryEventExpectation(@PathVariable("casperId") Long casperId) {
adminService.deleteLotteryEventExpectation(casperId);

return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;

public record LotteryEventExpectationResponseDto(String expectation, LocalDate createdDate,
public record LotteryEventExpectationResponseDto(Long casperId, String expectation, LocalDate createdDate,
LocalTime createdTime) {

public static LotteryEventExpectationResponseDto of(CasperBot casperBot) {
Expand All @@ -16,6 +16,7 @@ public static LotteryEventExpectationResponseDto of(CasperBot casperBot) {
LocalTime createdTime = createdAt.toLocalTime();

return new LotteryEventExpectationResponseDto(
casperBot.getCasperId(),
casperBot.getExpectation(),
createdDate,
createdTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,16 @@ public CasperBot(CasperBotRequestDto requestDto, String phoneNumber) {
this.name = requestDto.getName();
this.expectation = requestDto.getExpectation();
}

public CasperBot deleteExpectation() {
if (!this.expectation.isEmpty()) {
this.expectation = "삭제된 기대평입니다.";
}

return this;
}

public boolean isDeleted() {
return this.expectation.equals("삭제된 기대평입니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.*;

@RequiredArgsConstructor
@Service
Expand Down Expand Up @@ -263,6 +260,7 @@ private LotteryEvent getCurrentLotteryEvent() {
return lotteryEventList.get(0);
}

@Transactional
public List<AdminRushEventResponseDto> updateRushEvents(List<RushEventRequestDto> rushEventRequestDtoList) {
LocalDateTime now = LocalDateTime.now();

Expand Down Expand Up @@ -319,7 +317,16 @@ public List<LotteryEventExpectationResponseDto> getLotteryEventExpectations(Long

List<CasperBot> casperBotList = casperBotRepository.findByPhoneNumber(lotteryParticipant.getBaseUser().getId());

return casperBotList.stream().map(LotteryEventExpectationResponseDto::of).toList();
// 기대평을 작성하지 않은 경우(기대평이 빈 문자열인 경우, 삭제된 경우)는 제외하여 반환합니다.
return casperBotList.stream().filter(casperBot -> !casperBot.getExpectation().isEmpty() && !casperBot.isDeleted()).map(LotteryEventExpectationResponseDto::of).toList();
}

@Transactional
public void deleteLotteryEventExpectation(Long casperId) {
CasperBot casperBot = casperBotRepository.findById(casperId).orElseThrow(
() -> new CustomException(CustomErrorCode.CASPERBOT_NOT_FOUND)
);

casperBot.deleteExpectation();
}
}

0 comments on commit f9e7547

Please sign in to comment.