diff --git a/src/main/java/com/example/want/api/block/domain/Block.java b/src/main/java/com/example/want/api/block/domain/Block.java index 390ef3d..1e3bac2 100644 --- a/src/main/java/com/example/want/api/block/domain/Block.java +++ b/src/main/java/com/example/want/api/block/domain/Block.java @@ -30,10 +30,6 @@ public class Block extends BaseEntity { @Enumerated(EnumType.STRING) private Category category; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "location_id") - private Location location; - private Double latitude; private Double longitude; @@ -123,7 +119,4 @@ public void changeIsDelete() { this.isDeleted = "Y"; } - public void updateLocation(Location location) { - this.location = location; - } } diff --git a/src/main/java/com/example/want/api/block/dto/ImportBlockRqDto.java b/src/main/java/com/example/want/api/block/dto/ImportBlockRqDto.java index cc6dea3..d542a09 100644 --- a/src/main/java/com/example/want/api/block/dto/ImportBlockRqDto.java +++ b/src/main/java/com/example/want/api/block/dto/ImportBlockRqDto.java @@ -2,6 +2,7 @@ import com.example.want.api.block.domain.Block; import com.example.want.api.block.domain.Category; +import com.example.want.api.location.domain.Location; import com.example.want.api.project.domain.Project; import lombok.Builder; import lombok.Getter; @@ -10,16 +11,22 @@ @Builder public class ImportBlockRqDto { private Long projectId; - private Long blockId; + private Location location; - public Block toImport(Block findBlock, Project project) { + private Double latitude; + private Double longitude; + private String placeName; + private Category category; + + public Block toImport(Location location, Project project) { return Block.builder() - .title(findBlock.getTitle()) - .content(findBlock.getContent()) - .category(findBlock.getCategory()) + .category(location.getCategory()) .project(project) .heartCount(0L) .isActivated("N") + .latitude(location.getLatitude()) + .longitude(location.getLongitude()) + .placeName(location.getPlaceName()) .build(); } } \ No newline at end of file diff --git a/src/main/java/com/example/want/api/block/service/BlockService.java b/src/main/java/com/example/want/api/block/service/BlockService.java index 3a7ba02..f357d85 100644 --- a/src/main/java/com/example/want/api/block/service/BlockService.java +++ b/src/main/java/com/example/want/api/block/service/BlockService.java @@ -405,11 +405,11 @@ public List getBlocksByState(Long stateId) { @Transactional public Block importBlock(UserInfo userInfo, ImportBlockRqDto importDto) { Project project = validateProjectMember(importDto.getProjectId(), userInfo.getEmail()); - Block findBlock = blockRepository.findById(importDto.getBlockId()).orElseThrow(() -> new EntityNotFoundException("해당 블록을 찾을 수 없습니다.")); - Block block = importDto.toImport(findBlock, project); + Location location = importDto.getLocation(); + Block block = importDto.toImport(location, project); Long stateId = projectStateRepository.findByProject(block.getProject()).getState().getId(); - String redisKey = findBlock.getLatitude() + ":" + findBlock.getLongitude() + ":" + stateId + ":" + findBlock.getCategory() + ":" + block.getPlaceName(); + String redisKey = location.getLatitude() + ":" + location.getLongitude() + ":" + stateId + ":" + location.getCategory() + ":" + location.getPlaceName(); // Redis에서 값을 가져오거나 초기화 if (popularRedisTemplate.opsForValue().get(redisKey) == null) { diff --git a/src/main/java/com/example/want/api/location/domain/Location.java b/src/main/java/com/example/want/api/location/domain/Location.java index 1613057..9ba5769 100644 --- a/src/main/java/com/example/want/api/location/domain/Location.java +++ b/src/main/java/com/example/want/api/location/domain/Location.java @@ -1,5 +1,6 @@ package com.example.want.api.location.domain; +import com.example.want.api.block.domain.Category; import com.example.want.api.location.dto.LocationResDto; import com.example.want.api.state.domain.State; import lombok.AllArgsConstructor; @@ -24,7 +25,7 @@ public class Location { private Long popularCount; private String placeName; - private String category; + private Category category; @ManyToOne(fetch = FetchType.LAZY) @NotNull diff --git a/src/main/java/com/example/want/api/location/dto/LocationResDto.java b/src/main/java/com/example/want/api/location/dto/LocationResDto.java index 645f188..6448a41 100644 --- a/src/main/java/com/example/want/api/location/dto/LocationResDto.java +++ b/src/main/java/com/example/want/api/location/dto/LocationResDto.java @@ -1,5 +1,6 @@ package com.example.want.api.location.dto; +import com.example.want.api.block.domain.Category; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -14,5 +15,5 @@ public class LocationResDto { private Double longitude; private Long popularCount; private String placeName; - private String category; + private Category category; } diff --git a/src/main/java/com/example/want/api/location/service/LocationService.java b/src/main/java/com/example/want/api/location/service/LocationService.java index fdef1ea..cb66bb6 100644 --- a/src/main/java/com/example/want/api/location/service/LocationService.java +++ b/src/main/java/com/example/want/api/location/service/LocationService.java @@ -1,5 +1,6 @@ package com.example.want.api.location.service; +import com.example.want.api.block.domain.Category; import com.example.want.api.block.repository.BlockRepository; import com.example.want.api.location.domain.Location; import com.example.want.api.location.dto.LocationResDto; @@ -64,7 +65,7 @@ public void getPopularCountFromCache() { Double longitude = Double.parseDouble(findKey[1]); Long stateId = Long.parseLong(findKey[2]); State state = stateRepository.findById(stateId).orElseThrow(()->new EntityNotFoundException("해당 지역이 없습니다.")); - String category = findKey[3]; + Category category = Category.valueOf(findKey[3]); String placeName = findKey[4]; // 해당 위치를 LocationRepository 에서 찾기