Skip to content

Commit ed57efb

Browse files
authored
Merge pull request #134 from TimeBank-Sparta/feat/add-location-search
feat: 위치기반 게시글 조회추가
2 parents b6dd8ac + 26e8de2 commit ed57efb

30 files changed

Lines changed: 422 additions & 57 deletions

help-service/src/main/generated/com/timebank/helpservice/help_request/domain/model/QHelpRequest.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.querydsl.core.types.PathMetadata;
88
import javax.annotation.processing.Generated;
99
import com.querydsl.core.types.Path;
10+
import com.querydsl.core.types.dsl.PathInits;
1011

1112

1213
/**
@@ -17,12 +18,12 @@ public class QHelpRequest extends EntityPathBase<HelpRequest> {
1718

1819
private static final long serialVersionUID = -1064961014L;
1920

21+
private static final PathInits INITS = PathInits.DIRECT2;
22+
2023
public static final QHelpRequest helpRequest = new QHelpRequest("helpRequest");
2124

2225
public final com.timebank.common.domain.QTimestamped _super = new com.timebank.common.domain.QTimestamped(this);
2326

24-
public final StringPath address = createString("address");
25-
2627
public final StringPath content = createString("content");
2728

2829
//inherited
@@ -39,6 +40,10 @@ public class QHelpRequest extends EntityPathBase<HelpRequest> {
3940

4041
public final NumberPath<Long> id = createNumber("id", Long.class);
4142

43+
public final com.timebank.helpservice.help_request.domain.vo.QHelpRequestLocation location;
44+
45+
public final com.timebank.helpservice.help_request.domain.vo.QHelpRequestMetrics postMetric;
46+
4247
public final EnumPath<com.timebank.helpservice.help_request.domain.PostStatus> postStatus = createEnum("postStatus", com.timebank.helpservice.help_request.domain.PostStatus.class);
4348

4449
public final NumberPath<Integer> recruitmentCount = createNumber("recruitmentCount", Integer.class);
@@ -60,15 +65,25 @@ public class QHelpRequest extends EntityPathBase<HelpRequest> {
6065
public final StringPath updatedBy = _super.updatedBy;
6166

6267
public QHelpRequest(String variable) {
63-
super(HelpRequest.class, forVariable(variable));
68+
this(HelpRequest.class, forVariable(variable), INITS);
6469
}
6570

6671
public QHelpRequest(Path<? extends HelpRequest> path) {
67-
super(path.getType(), path.getMetadata());
72+
this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS));
6873
}
6974

7075
public QHelpRequest(PathMetadata metadata) {
71-
super(HelpRequest.class, metadata);
76+
this(metadata, PathInits.getFor(metadata, INITS));
77+
}
78+
79+
public QHelpRequest(PathMetadata metadata, PathInits inits) {
80+
this(HelpRequest.class, metadata, inits);
81+
}
82+
83+
public QHelpRequest(Class<? extends HelpRequest> type, PathMetadata metadata, PathInits inits) {
84+
super(type, metadata, inits);
85+
this.location = inits.isInitialized("location") ? new com.timebank.helpservice.help_request.domain.vo.QHelpRequestLocation(forProperty("location")) : null;
86+
this.postMetric = inits.isInitialized("postMetric") ? new com.timebank.helpservice.help_request.domain.vo.QHelpRequestMetrics(forProperty("postMetric")) : null;
7287
}
7388

7489
}

help-service/src/main/java/com/timebank/helpservice/help_request/application/dto/request/CreateHelpRequestCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.timebank.helpservice.help_request.domain.PostStatus;
66
import com.timebank.helpservice.help_request.domain.vo.HelpRequestInfo;
7+
import com.timebank.helpservice.help_request.domain.vo.HelpRequestLocation;
78

89
import lombok.Builder;
910

@@ -18,7 +19,7 @@ public record CreateHelpRequestCommand(
1819
int recruitmentCount,
1920
PostStatus postStatus
2021
) {
21-
public HelpRequestInfo toHelpRequestInfoWithUserID(Long userId) {
22+
public HelpRequestInfo toHelpRequestInfoWithUserIdAndLocation(Long userId, HelpRequestLocation location) {
2223
return HelpRequestInfo.builder()
2324
.requesterId(userId)
2425
.title(title)
@@ -28,6 +29,7 @@ public HelpRequestInfo toHelpRequestInfoWithUserID(Long userId) {
2829
.requiredTime(requiredTime)
2930
.requestedPoint(requestedPoint)
3031
.recruitmentCount(recruitmentCount)
32+
.location(location)
3133
.build();
3234
}
3335
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.timebank.helpservice.help_request.application.dto.request;
2+
3+
import com.timebank.helpservice.help_request.domain.repository.search.SearchNearByQuery;
4+
5+
import lombok.Builder;
6+
7+
@Builder
8+
public record NearByUserLocationQuery(
9+
double userLatitude,
10+
double userLongitude
11+
) {
12+
13+
public SearchNearByQuery toQuery() {
14+
return SearchNearByQuery.builder()
15+
.userLatitude(userLatitude)
16+
.userLongitude(userLongitude)
17+
.build();
18+
}
19+
}

help-service/src/main/java/com/timebank/helpservice/help_request/application/dto/request/UpdateHelpRequestCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.timebank.helpservice.help_request.domain.PostStatus;
66
import com.timebank.helpservice.help_request.domain.vo.HelpRequestInfo;
7+
import com.timebank.helpservice.help_request.domain.vo.HelpRequestLocation;
78

89
import lombok.Builder;
910

@@ -18,7 +19,7 @@ public record UpdateHelpRequestCommand(
1819
int recruitmentCount,
1920
PostStatus postStatus
2021
) {
21-
public HelpRequestInfo toHelpRequestInfo() {
22+
public HelpRequestInfo toHelpRequestInfoWithLocation(HelpRequestLocation location) {
2223
return HelpRequestInfo.builder()
2324
.title(title)
2425
.content(content)
@@ -28,6 +29,7 @@ public HelpRequestInfo toHelpRequestInfo() {
2829
.requestedPoint(requestedPoint)
2930
.recruitmentCount(recruitmentCount)
3031
.postStatus(postStatus)
32+
.location(location)
3133
.build();
3234
}
3335
}

help-service/src/main/java/com/timebank/helpservice/help_request/application/dto/response/CreateHelpRequestResponse.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.timebank.helpservice.help_request.domain.PostStatus;
66
import com.timebank.helpservice.help_request.domain.model.HelpRequest;
7+
import com.timebank.helpservice.help_request.domain.vo.HelpRequestLocation;
78

89
import lombok.Builder;
910

@@ -12,24 +13,24 @@ public record CreateHelpRequestResponse(
1213
Long helpRequestId,
1314
String title,
1415
String content,
15-
String address,
1616
LocalDateTime scheduledAt,
1717
int requiredTime,
1818
int requestedPoint,
1919
int recruitmentCount,
20-
PostStatus postStatus
20+
PostStatus postStatus,
21+
HelpRequestLocation location
2122
) {
2223
public static CreateHelpRequestResponse from(HelpRequest helpRequest) {
2324
return CreateHelpRequestResponse.builder()
2425
.helpRequestId(helpRequest.getId())
2526
.title(helpRequest.getTitle())
2627
.content(helpRequest.getContent())
27-
.address(helpRequest.getAddress())
2828
.scheduledAt(helpRequest.getScheduledAt())
2929
.requiredTime(helpRequest.getRequiredTime())
3030
.requestedPoint(helpRequest.getRequestedPoint())
3131
.recruitmentCount(helpRequest.getRecruitmentCount())
3232
.postStatus(helpRequest.getPostStatus())
33+
.location(helpRequest.getLocation())
3334
.build();
3435
}
3536
}

help-service/src/main/java/com/timebank/helpservice/help_request/application/dto/response/HelpRequestResponse.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.timebank.helpservice.help_request.domain.PostStatus;
66
import com.timebank.helpservice.help_request.domain.model.HelpRequest;
7+
import com.timebank.helpservice.help_request.domain.vo.HelpRequestLocation;
78

89
import lombok.Builder;
910

@@ -13,25 +14,25 @@ public record HelpRequestResponse(
1314
Long requesterId,
1415
String title,
1516
String content,
16-
String address,
1717
LocalDateTime scheduledAt,
1818
int requiredTime,
1919
int requestedPoint,
2020
int recruitmentCount,
21-
PostStatus postStatus
21+
PostStatus postStatus,
22+
HelpRequestLocation location
2223
) {
2324
public static HelpRequestResponse from(HelpRequest helpRequest) {
2425
return HelpRequestResponse.builder()
2526
.helpRequestId(helpRequest.getId())
2627
.requesterId(helpRequest.getRequesterId())
2728
.title(helpRequest.getTitle())
2829
.content(helpRequest.getContent())
29-
.address(helpRequest.getAddress())
3030
.scheduledAt(helpRequest.getScheduledAt())
3131
.requiredTime(helpRequest.getRequiredTime())
3232
.requestedPoint(helpRequest.getRequestedPoint())
3333
.recruitmentCount(helpRequest.getRecruitmentCount())
3434
.postStatus(helpRequest.getPostStatus())
35+
.location(helpRequest.getLocation())
3536
.build();
3637
}
3738
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.timebank.helpservice.help_request.application.dto.response;
2+
3+
import java.util.List;
4+
5+
public record KakaoGeoResponse(List<Document> documents) {
6+
7+
public record Document(String addressName, String x, String y) {
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.timebank.helpservice.help_request.application.dto.response;
2+
3+
import java.time.LocalDateTime;
4+
5+
import com.timebank.helpservice.help_request.domain.PostStatus;
6+
import com.timebank.helpservice.help_request.domain.model.HelpRequest;
7+
import com.timebank.helpservice.help_request.domain.vo.HelpRequestLocation;
8+
9+
import lombok.Builder;
10+
11+
@Builder
12+
public record NearByUserLocationResponse(
13+
Long helpRequestId,
14+
String title,
15+
String content,
16+
LocalDateTime scheduledAt,
17+
int requiredTime,
18+
int requestedPoint,
19+
int recruitmentCount,
20+
PostStatus postStatus,
21+
HelpRequestLocation location
22+
) {
23+
public static NearByUserLocationResponse from(HelpRequest helpRequest) {
24+
return NearByUserLocationResponse.builder()
25+
.helpRequestId(helpRequest.getId())
26+
.title(helpRequest.getTitle())
27+
.content(helpRequest.getContent())
28+
.scheduledAt(helpRequest.getScheduledAt())
29+
.requiredTime(helpRequest.getRequiredTime())
30+
.requestedPoint(helpRequest.getRequestedPoint())
31+
.recruitmentCount(helpRequest.getRecruitmentCount())
32+
.postStatus(helpRequest.getPostStatus())
33+
.location(helpRequest.getLocation())
34+
.build();
35+
}
36+
}

help-service/src/main/java/com/timebank/helpservice/help_request/application/dto/response/UpdateHelpRequestResponse.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.timebank.helpservice.help_request.domain.PostStatus;
66
import com.timebank.helpservice.help_request.domain.model.HelpRequest;
7+
import com.timebank.helpservice.help_request.domain.vo.HelpRequestLocation;
78

89
import lombok.Builder;
910

@@ -12,24 +13,24 @@ public record UpdateHelpRequestResponse(
1213
Long helpRequestId,
1314
String title,
1415
String content,
15-
String address,
1616
LocalDateTime scheduledAt,
1717
int requiredTime,
1818
int requestedPoint,
1919
int recruitmentCount,
20-
PostStatus postStatus
20+
PostStatus postStatus,
21+
HelpRequestLocation location
2122
) {
2223
public static UpdateHelpRequestResponse from(HelpRequest helpRequest) {
2324
return UpdateHelpRequestResponse.builder()
2425
.helpRequestId(helpRequest.getId())
2526
.title(helpRequest.getTitle())
2627
.content(helpRequest.getContent())
27-
.address(helpRequest.getAddress())
2828
.scheduledAt(helpRequest.getScheduledAt())
2929
.requiredTime(helpRequest.getRequiredTime())
3030
.requestedPoint(helpRequest.getRequestedPoint())
3131
.recruitmentCount(helpRequest.getRecruitmentCount())
3232
.postStatus(helpRequest.getPostStatus())
33+
.location(helpRequest.getLocation())
3334
.build();
3435
}
3536
}

help-service/src/main/java/com/timebank/helpservice/help_request/application/service/HelpRequestService.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
import com.timebank.helpservice.help_request.application.dto.request.CreateHelpRequestCommand;
1616
import com.timebank.helpservice.help_request.application.dto.request.HelpRequestToHelperKafkaDto;
1717
import com.timebank.helpservice.help_request.application.dto.request.HoldPointRequestDto;
18+
import com.timebank.helpservice.help_request.application.dto.request.NearByUserLocationQuery;
1819
import com.timebank.helpservice.help_request.application.dto.request.SearchHelpRequestQuery;
1920
import com.timebank.helpservice.help_request.application.dto.request.UpdateHelpRequestCommand;
2021
import com.timebank.helpservice.help_request.application.dto.response.CreateHelpRequestResponse;
2122
import com.timebank.helpservice.help_request.application.dto.response.HelpRequestResponse;
23+
import com.timebank.helpservice.help_request.application.dto.response.KakaoGeoResponse;
24+
import com.timebank.helpservice.help_request.application.dto.response.NearByUserLocationResponse;
2225
import com.timebank.helpservice.help_request.application.dto.response.UpdateHelpRequestResponse;
2326
import com.timebank.helpservice.help_request.domain.model.HelpRequest;
2427
import com.timebank.helpservice.help_request.domain.repository.HelpRequestRepository;
28+
import com.timebank.helpservice.help_request.domain.vo.HelpRequestLocation;
2529

2630
import jakarta.persistence.EntityNotFoundException;
2731
import lombok.RequiredArgsConstructor;
@@ -34,15 +38,18 @@ public class HelpRequestService {
3438
private final HelpRequestRepository helpRequestRepository;
3539
private final HelpRequestEventProducer eventProducer;
3640
private final PointClient pointClient;
41+
private final KakaoClient kakaoClient;
3742
private final KafkaTemplate<String, Object> kafkaTemplate;
3843

3944
/**
4045
* 도움 요청 글 생성 (작성 시 알림 이벤트 발행 – 필요에 따라 추가)
4146
*/
4247
@Transactional
4348
public CreateHelpRequestResponse createHelpRequest(CreateHelpRequestCommand command, Long userId) {
49+
4450
HelpRequest helpRequest = helpRequestRepository.save(
45-
HelpRequest.createFrom(command.toHelpRequestInfoWithUserID(userId)));
51+
HelpRequest.createFrom(
52+
command.toHelpRequestInfoWithUserIdAndLocation(userId, getLocation(command.address()))));
4653

4754
// (선택 사항) 도움 요청 글 생성 시 알림 이벤트 (예: POST_CREATED)
4855
NotificationEvent event = NotificationEvent.builder()
@@ -84,7 +91,7 @@ public Page<HelpRequestResponse> searchHelpRequest(SearchHelpRequestQuery reques
8491
@Transactional
8592
public UpdateHelpRequestResponse updateHelpRequest(UpdateHelpRequestCommand command, Long helpRequestId) {
8693
HelpRequest helpRequest = getHelpRequestOrThrow(helpRequestId);
87-
helpRequest.update(command.toHelpRequestInfo());
94+
helpRequest.update(command.toHelpRequestInfoWithLocation(getLocation(command.address())));
8895

8996
// (선택 사항) 업데이트 알림 발행 – 필요 시
9097
NotificationEvent event = NotificationEvent.builder()
@@ -133,6 +140,7 @@ public UpdateHelpRequestResponse completeHelpRequest(Long helpRequestId, Long us
133140
/**
134141
* 도움 요청 글 삭제 (알림 이벤트 발행 – 선택 사항)
135142
*/
143+
@Transactional
136144
public void deleteHelpRequest(Long helpRequestId, String username) {
137145
HelpRequest helpRequest = getHelpRequestOrThrow(helpRequestId);
138146
helpRequest.delete(username);
@@ -148,6 +156,13 @@ public void deleteHelpRequest(Long helpRequestId, String username) {
148156
kafkaTemplate.send(NotificationEventType.DELETED.getTopic(), event);
149157
}
150158

159+
@Transactional
160+
public Page<NearByUserLocationResponse> nearByUserLocation(NearByUserLocationQuery query, Pageable pageable) {
161+
double searchRangeByKm = 20;
162+
return helpRequestRepository.findHelpRequestNearby(query.toQuery(), searchRangeByKm, pageable)
163+
.map(NearByUserLocationResponse::from);
164+
}
165+
151166
@Transactional(readOnly = true)
152167
public boolean existHelpRequest(Long helpRequestId) {
153168
return helpRequestRepository.existsById(helpRequestId);
@@ -158,4 +173,13 @@ private HelpRequest getHelpRequestOrThrow(Long helpRequestId) {
158173
.orElseThrow(() -> new EntityNotFoundException("게시글이 없습니다."));
159174
}
160175

176+
public HelpRequestLocation getLocation(String address) {
177+
KakaoGeoResponse response = kakaoClient.searchAddress(address);
178+
if (response.documents().isEmpty()) {
179+
throw new IllegalArgumentException("해당 주소에 대한 좌표를 찾을 수 없습니다.");
180+
}
181+
KakaoGeoResponse.Document doc = response.documents().get(0);
182+
return HelpRequestLocation.createOf(address, Double.parseDouble(doc.x()), Double.parseDouble(doc.y()));
183+
}
184+
161185
}

0 commit comments

Comments
 (0)