Skip to content

Commit

Permalink
Merge pull request #6 from beyond-sw-camp/fix/pop
Browse files Browse the repository at this point in the history
์ถ”์ฒœํŽ˜์ด์ง€ fix(importBlock)
  • Loading branch information
tteia authored Sep 5, 2024
2 parents 14f9d20 + 08f1539 commit 494aeb7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
7 changes: 0 additions & 7 deletions src/main/java/com/example/want/api/block/domain/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -123,7 +119,4 @@ public void changeIsDelete() {
this.isDeleted = "Y";
}

public void updateLocation(Location location) {
this.location = location;
}
}
17 changes: 12 additions & 5 deletions src/main/java/com/example/want/api/block/dto/ImportBlockRqDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,11 @@ public List<BlockActiveListRsDto> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,7 +25,7 @@ public class Location {

private Long popularCount;
private String placeName;
private String category;
private Category category;

@ManyToOne(fetch = FetchType.LAZY)
@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,5 +15,5 @@ public class LocationResDto {
private Double longitude;
private Long popularCount;
private String placeName;
private String category;
private Category category;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 ์—์„œ ์ฐพ๊ธฐ
Expand Down

0 comments on commit 494aeb7

Please sign in to comment.