Skip to content

Commit f43130b

Browse files
committed
2 parents 5833972 + bfc9593 commit f43130b

19 files changed

+213
-78
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package org.skhuton.skhudebug.bughunt.repository;
22

33
import org.skhuton.skhudebug.bughunt.domain.Bughunt;
4+
import org.skhuton.skhudebug.member.domain.User;
45
import org.springframework.data.jpa.repository.JpaRepository;
56

67
import java.math.BigDecimal;
78
import java.util.List;
89

910
public interface BughuntRepository extends JpaRepository<Bughunt, Long> {
1011
List<Bughunt> findByLatitudeBetweenAndLongitudeBetween(BigDecimal minLat, BigDecimal maxLat, BigDecimal minLng, BigDecimal maxLng);
12+
13+
Bughunt findByUser(User user);
1114
}

src/main/java/org/skhuton/skhudebug/bughunt/service/BughuntService.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.skhuton.skhudebug.bughunt.repository.BughuntRepository;
1010
import org.skhuton.skhudebug.exception.ErrorCode;
1111
import org.skhuton.skhudebug.exception.model.NotFoundException;
12+
import org.skhuton.skhudebug.match.domain.HuntReqManagement;
13+
import org.skhuton.skhudebug.match.repository.HuntMatchRepository;
1214
import org.skhuton.skhudebug.member.domain.User;
1315
import org.skhuton.skhudebug.member.repository.UserRepository;
1416
import org.springframework.stereotype.Service;
@@ -25,9 +27,10 @@
2527
public class BughuntService {
2628
private final BughuntRepository bughuntRepository;
2729
private final UserRepository userRepository;
30+
private final HuntMatchRepository huntMatchRepository;
2831

2932
@Transactional
30-
public Bughunt save(BughuntSaveReqDto bughuntSaveReqDto) {
33+
public void save(BughuntSaveReqDto bughuntSaveReqDto) {
3134
User user = userRepository.findByLoginId(bughuntSaveReqDto.loginId()).orElseThrow(
3235
()-> new NotFoundException(
3336
ErrorCode.USER_NOT_FOUND,
@@ -43,7 +46,17 @@ public Bughunt save(BughuntSaveReqDto bughuntSaveReqDto) {
4346
.radius(bughuntSaveReqDto.radius())
4447
.build();
4548
bughunt.setCreatedAt(LocalDateTime.now());
46-
return bughuntRepository.save(bughunt);
49+
bughuntRepository.save(bughunt);
50+
51+
//요청 아이디 값 가져와서 저장하기.
52+
Bughunt getvalue = bughuntRepository.findByUser(user);
53+
HuntReqManagement huntReqManagement = HuntReqManagement.builder()
54+
.requestId(getvalue.getId())
55+
.senderId(user.getLoginId())
56+
.receiveId(null)
57+
.complete(false)
58+
.build();
59+
huntMatchRepository.save(huntReqManagement);
4760
}
4861

4962
public BughuntListResDto findAll(){

src/main/java/org/skhuton/skhudebug/exception/SuccessCode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public enum SuccessCode {
1616
/*200 OK*/
1717
RANKING_GET_SUCCESS(HttpStatus.OK, "랭킹 조회 성공"),
1818
GET_SUCCESS(HttpStatus.OK, "조회 완료"),
19-
BUGHUNT_RADIUS_GET_SUCCESS(HttpStatus.OK, "조회 완료")
19+
BUGHUNT_RADIUS_GET_SUCCESS(HttpStatus.OK, "조회 완료"),
20+
BUGHUNT_REQUEST_ACCEPT(HttpStatus.OK, "헌터 구인 요청 수락 완료"),
21+
BUGHUNT_REQUEST_COMPLETE(HttpStatus.OK, "벌레 제거 완료")
2022
;
2123

2224
private final HttpStatus httpStatus;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.skhuton.skhudebug.match.controller;
2+
3+
import io.swagger.v3.oas.annotations.Operation;
4+
import io.swagger.v3.oas.annotations.Parameter;
5+
import io.swagger.v3.oas.annotations.Parameters;
6+
import io.swagger.v3.oas.annotations.tags.Tag;
7+
import lombok.RequiredArgsConstructor;
8+
import org.skhuton.skhudebug.common.dto.BaseResponse;
9+
import org.skhuton.skhudebug.exception.SuccessCode;
10+
import org.skhuton.skhudebug.match.dto.CompleteHuntReqDto;
11+
import org.skhuton.skhudebug.match.dto.MatchReqDto;
12+
import org.skhuton.skhudebug.match.service.MatchService;
13+
import org.springframework.web.bind.annotation.PostMapping;
14+
import org.springframework.web.bind.annotation.RequestBody;
15+
import org.springframework.web.bind.annotation.RestController;
16+
17+
@RestController
18+
@RequiredArgsConstructor
19+
@Tag(name = "Bughunt Match API", description = "헌트 요청의 수락과 업무의 완료를 담당하는 API")
20+
public class BughuntMatchController {
21+
private final MatchService matchService;
22+
23+
@Operation(summary = "헌트 요청 수락", description = "헌트 요청을 수락하는 API")
24+
@Parameters({
25+
@Parameter(name = "senderId", description = "호출하는 사용자 아이디", required = true),
26+
@Parameter(name = "requestId", description = "헌트 요청 건 고유의 아이디", required = true),
27+
@Parameter(name = "receiveId", description = "호출받는 사용자의 아이디", required = true)
28+
})
29+
@PostMapping("/bughunt-matching")
30+
public BaseResponse<String> bughuntMatching(@RequestBody MatchReqDto matchReqDto) {
31+
matchService.acceptByHunter(matchReqDto);
32+
return BaseResponse.success(SuccessCode.BUGHUNT_REQUEST_ACCEPT);
33+
}
34+
35+
@Operation(summary = "헌트 요청 완료", description = "헌트 요청을 완료하는 API")
36+
@Parameters({
37+
@Parameter(name = "requestId", description = "헌트 요청 건 고유의 아이디", required = true)
38+
})
39+
@PostMapping("/bughunt/complete")
40+
public BaseResponse<String> bughuntComplete(@RequestBody CompleteHuntReqDto completeHuntReqDto) {
41+
matchService.completeMatch(completeHuntReqDto);
42+
return BaseResponse.success(SuccessCode.BUGHUNT_REQUEST_COMPLETE);
43+
}
44+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.skhuton.skhudebug.match.domain;
2+
3+
import jakarta.persistence.*;
4+
import lombok.*;
5+
6+
@Entity
7+
@Setter
8+
@Getter
9+
@Builder
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class HuntReqManagement {
13+
14+
/**
15+
* 요청 관리 엔티티
16+
*/
17+
@Id
18+
@GeneratedValue(strategy = GenerationType.IDENTITY)
19+
@Column(name = "hunt_match_id")
20+
private Long id;
21+
22+
@Column(name = "request_id", nullable = false)
23+
private Long requestId;
24+
25+
@Column(name = "sender_id", nullable = false)
26+
private String senderId;
27+
28+
@Column(name = "receive_id", nullable = true)
29+
private String receiveId;
30+
31+
@Column(name = "complete", nullable = true)
32+
private boolean complete;
33+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.skhuton.skhudebug.match.dto;
2+
3+
public record CompleteHuntReqDto(
4+
Long requestId
5+
) {
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.skhuton.skhudebug.match.dto;
2+
3+
import lombok.Builder;
4+
5+
public record MatchReqDto(
6+
String senderId,
7+
String receiveId,
8+
Long requestId
9+
) {
10+
@Builder
11+
public static MatchReqDto from(String senderId, String receiveId, Long requestId) {
12+
return MatchReqDto.builder()
13+
.senderId(senderId)
14+
.receiveId(receiveId)
15+
.requestId(requestId)
16+
.build();
17+
}
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.skhuton.skhudebug.match.repository;
2+
3+
import org.skhuton.skhudebug.match.domain.HuntReqManagement;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.stereotype.Repository;
6+
7+
@Repository
8+
public interface HuntMatchRepository extends JpaRepository<HuntReqManagement, Long> {
9+
HuntReqManagement findBySenderId(String senderId);
10+
HuntReqManagement findByRequestId(Long requestId);
11+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.skhuton.skhudebug.match.service;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import org.skhuton.skhudebug.match.domain.HuntReqManagement;
5+
import org.skhuton.skhudebug.match.dto.CompleteHuntReqDto;
6+
import org.skhuton.skhudebug.match.dto.MatchReqDto;
7+
import org.skhuton.skhudebug.match.repository.HuntMatchRepository;
8+
import org.springframework.stereotype.Service;
9+
import org.springframework.transaction.annotation.Transactional;
10+
11+
@Service
12+
@RequiredArgsConstructor
13+
public class MatchService {
14+
private final HuntMatchRepository huntMatchRepository;
15+
16+
/**
17+
* 호출 수락
18+
* <p>
19+
* 1. 수락 버튼 클릭
20+
* 2. 벌레에 대한 정보와 호출한 유저, 수락한 유저의 아이디를 담은 요청 데이터 전송
21+
* 3. 요청 관리 테이블에서 수락 컬럼을 true로 변경
22+
* <p>
23+
* 요청관리테이블의 특정 컬럼들이 true가 될 때까지 벌레 잡은 상태로 취급하지 않음.
24+
*/
25+
@Transactional
26+
public void acceptByHunter(MatchReqDto matchReqDto) {
27+
HuntReqManagement huntReqManagement = huntMatchRepository.findBySenderId(matchReqDto.senderId());
28+
huntReqManagement.setReceiveId(matchReqDto.receiveId());
29+
huntMatchRepository.save(huntReqManagement);
30+
}
31+
32+
@Transactional
33+
public void completeMatch(CompleteHuntReqDto completeHuntReqDto) {
34+
HuntReqManagement huntReqManagement = huntMatchRepository.findByRequestId(completeHuntReqDto.requestId());
35+
huntMatchRepository.save(HuntReqManagement.builder()
36+
.id(huntReqManagement.getId())
37+
.requestId(huntReqManagement.getRequestId())
38+
.senderId(huntReqManagement.getSenderId())
39+
.receiveId(huntReqManagement.getReceiveId())
40+
.complete(true)
41+
.build());
42+
}
43+
}

src/main/java/org/skhuton/skhudebug/member/controller/UserController.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.swagger.v3.oas.annotations.tags.Tag;
66
import jakarta.servlet.http.HttpServletRequest;
77
import lombok.RequiredArgsConstructor;
8+
import org.skhuton.skhudebug.member.dto.response.UserInfo;
89
import org.skhuton.skhudebug.member.service.UserService;
910
import org.springframework.http.HttpStatus;
1011
import org.springframework.http.ResponseEntity;
@@ -23,11 +24,8 @@ public class UserController {
2324
*/
2425
@Operation(summary = "로그인 확인", description = "해당 클라이언트의 로그인 확인")
2526
@GetMapping("/user/confirm")
26-
public ResponseEntity<String[]> confirm(HttpServletRequest request){
27-
String[] userInfo = { userService.loginConfirmUserName(request),
28-
String.valueOf(userService.loginConfirmUserID(request))
29-
};
30-
return new ResponseEntity<>(userInfo, HttpStatus.OK);
27+
public ResponseEntity<UserInfo> confirm(HttpServletRequest request){
28+
return new ResponseEntity<>(userService.loginConfirmUserID(request), HttpStatus.OK);
3129
}
3230

3331
@GetMapping("/test")

0 commit comments

Comments
 (0)