Skip to content

Commit

Permalink
fix: 목탁조회시 내 목탁 구분 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
thgr8ganzi committed Apr 6, 2024
1 parent ed662da commit dcee9be
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ResponseEntity<ResponseDto<List<ItemSaveResponseDto>>> itemList(
BigDecimal latitude,
BigDecimal longitude
) {
var response = itemService.itemList(latitude, longitude);
var response = itemService.itemList(user.getId(), latitude, longitude);
return ResponseDto.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ItemSaveResponseDto {
private BigDecimal longitude;
private String address;
private ItemType type;
private Boolean isMine = false;

public ItemSaveResponseDto(Item newItem) {
this.id = newItem.getId();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/core/api/item/service/ItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ public ItemSaveResponseDto itemSave(AuthUser user, ItemSaveDto itemSaveDto) {
return new ItemSaveResponseDto(newItem);
}

public List<ItemSaveResponseDto> itemList(BigDecimal latitude, BigDecimal longitude) {
public List<ItemSaveResponseDto> itemList(Long id, BigDecimal latitude, BigDecimal longitude) {
List<Item> allItems = itemRepository.findAll();
double lat = latitude.doubleValue();
double lon = longitude.doubleValue();

return allItems.stream()
.filter(item -> GeoUtils.calculateDistance(lat, lon, item.getLatitude().doubleValue(), item.getLongitude().doubleValue()) <= ADDRESS_RANGE)
.map(ItemSaveResponseDto::new)
.peek(itemSaveResponseDto -> itemSaveResponseDto.setIsMine(itemSaveResponseDto.getUid().equals(id)))
.toList();
}

Expand Down

0 comments on commit dcee9be

Please sign in to comment.