Skip to content

Commit

Permalink
hotfix: announcement bookmark device id null
Browse files Browse the repository at this point in the history
  • Loading branch information
jcw1031 committed May 10, 2024
1 parent e7773ab commit a54c6cf
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/main/java/ac/knu/likeknu/service/AnnouncementService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import ac.knu.likeknu.domain.Device;
import ac.knu.likeknu.domain.constants.Campus;
import ac.knu.likeknu.domain.constants.Category;
import ac.knu.likeknu.exception.BusinessException;
import ac.knu.likeknu.repository.AnnouncementRepository;
import ac.knu.likeknu.repository.DeviceRepository;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -48,15 +47,12 @@ public List<AnnouncementListResponse> getAnnouncements(Campus campus, Category c

if (deviceId != null) {
Optional<Device> findDevice = deviceRepository.findById(deviceId);
if (findDevice.isEmpty()) {
if (findDevice.isPresent()) {
Device device = findDevice.get();
return announcementsPage.stream()
.map(AnnouncementListResponse::of)
.map(announcement -> AnnouncementListResponse.of(announcement, device.getBookmarks()))
.toList();
}
Device device = findDevice.get();
return announcementsPage.stream()
.map(announcement -> AnnouncementListResponse.of(announcement, device.getBookmarks()))
.toList();
}
return announcementsPage.stream()
.map(AnnouncementListResponse::of)
Expand All @@ -71,10 +67,17 @@ public List<AnnouncementListResponse> searchAnnouncements(Campus campus, PageDto
Slice<Announcement> announcementsPage = announcementRepository
.findByCampusInAndAnnouncementTitleContains(Set.of(campus, Campus.ALL), keyword, pageRequest);

Device device = deviceRepository.findById(deviceId)
.orElseThrow(() -> new BusinessException(String.format("Device not found! [%s]", deviceId)));
if (deviceId != null) {
Optional<Device> findDevice = deviceRepository.findById(deviceId);
if (findDevice.isPresent()) {
Device device = findDevice.get();
return announcementsPage.stream()
.map(announcement -> AnnouncementListResponse.of(announcement, device.getBookmarks()))
.toList();
}
}
return announcementsPage.stream()
.map(announcement -> AnnouncementListResponse.of(announcement, device.getBookmarks()))
.map(AnnouncementListResponse::of)
.toList();
}
}

0 comments on commit a54c6cf

Please sign in to comment.