Skip to content

Commit 9b973f1

Browse files
authored
fix: 널 처리 (#29)
1 parent 93c6918 commit 9b973f1

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/main/java/kr/kro/photoliner/domain/photo/dto/response/PhotosResponse.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import java.time.LocalDateTime;
44
import java.util.List;
5+
import java.util.Optional;
56
import kr.kro.photoliner.domain.photo.model.Photo;
67
import kr.kro.photoliner.domain.photo.model.Photos;
8+
import org.locationtech.jts.geom.Point;
79

810
public record PhotosResponse(
911
Integer count,
@@ -23,18 +25,19 @@ public record InnerPhotoResponse(
2325
Long id,
2426
String filePath,
2527
LocalDateTime capturedDt,
26-
double lat,
27-
double lng,
28+
Double lat,
29+
Double lng,
2830
Long userId
2931
) {
3032

3133
public static InnerPhotoResponse from(Photo photo) {
34+
Optional<Point> location = Optional.ofNullable(photo.getLocation());
3235
return new InnerPhotoResponse(
3336
photo.getId(),
3437
photo.getFilePath(),
3538
photo.getCapturedDt(),
36-
photo.getLocation().getY(),
37-
photo.getLocation().getX(),
39+
location.map(Point::getY).orElse(null),
40+
location.map(Point::getX).orElse(null),
3841
photo.getUser().getId());
3942
}
4043
}

src/main/java/kr/kro/photoliner/domain/photo/model/Photo.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import jakarta.validation.constraints.NotNull;
1313
import java.time.LocalDate;
1414
import java.time.LocalDateTime;
15+
import java.util.Optional;
1516
import kr.kro.photoliner.common.model.BaseEntity;
1617
import kr.kro.photoliner.domain.user.model.User;
1718
import lombok.AccessLevel;
@@ -52,8 +53,10 @@ public class Photo extends BaseEntity {
5253
private User user;
5354

5455
public boolean isBetween(LocalDate start, LocalDate end) {
55-
LocalDate capturedDate = capturedDt.toLocalDate();
56-
return capturedDate.isAfter(start) && capturedDate.isBefore(end);
56+
return Optional.ofNullable(capturedDt)
57+
.map(LocalDateTime::toLocalDate)
58+
.filter(localDate -> localDate.isAfter(start) && localDate.isBefore(end))
59+
.isPresent();
5760
}
5861

5962
public void updateCapturedDate(LocalDateTime capturedDt) {

0 commit comments

Comments
 (0)