Skip to content

Commit 30d8744

Browse files
authoredJun 27, 2024ยทยท
Merge pull request #4 from Skhuthon/yong
Yong
2 parents 9127e34 + beec81c commit 30d8744

File tree

8 files changed

+143
-3
lines changed

8 files changed

+143
-3
lines changed
 
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

+15-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.skhuton.skhudebug.bughunt.repository.BughuntRepository;
99
import org.skhuton.skhudebug.exception.ErrorCode;
1010
import org.skhuton.skhudebug.exception.model.NotFoundException;
11+
import org.skhuton.skhudebug.match.domain.HuntReqManagement;
12+
import org.skhuton.skhudebug.match.repository.HuntMatchRepository;
1113
import org.skhuton.skhudebug.member.domain.User;
1214
import org.skhuton.skhudebug.member.repository.UserRepository;
1315
import org.springframework.stereotype.Service;
@@ -24,9 +26,10 @@
2426
public class BughuntService {
2527
private final BughuntRepository bughuntRepository;
2628
private final UserRepository userRepository;
29+
private final HuntMatchRepository huntMatchRepository;
2730

2831
@Transactional
29-
public Bughunt save(BughuntSaveReqDto bughuntSaveReqDto) {
32+
public void save(BughuntSaveReqDto bughuntSaveReqDto) {
3033
User user = userRepository.findByLoginId(bughuntSaveReqDto.loginId()).orElseThrow(
3134
()-> new NotFoundException(
3235
ErrorCode.USER_NOT_FOUND,
@@ -42,7 +45,17 @@ public Bughunt save(BughuntSaveReqDto bughuntSaveReqDto) {
4245
.radius(bughuntSaveReqDto.radius())
4346
.build();
4447
bughunt.setCreatedAt(LocalDateTime.now());
45-
return bughuntRepository.save(bughunt);
48+
bughuntRepository.save(bughunt);
49+
50+
//์š”์ฒญ ์•„์ด๋”” ๊ฐ’ ๊ฐ€์ ธ์™€์„œ ์ €์žฅํ•˜๊ธฐ.
51+
Bughunt getvalue = bughuntRepository.findByUser(user);
52+
HuntReqManagement huntReqManagement = HuntReqManagement.builder()
53+
.requestId(getvalue.getId())
54+
.senderId(user.getLoginId())
55+
.senderId(null)
56+
.complete(false)
57+
.build();
58+
huntMatchRepository.save(huntReqManagement);
4659
}
4760
public BughuntListResDto findAll(){
4861
List<Bughunt> bughunts = bughuntRepository.findAll();

โ€Žsrc/main/java/org/skhuton/skhudebug/exception/SuccessCode.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ 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, "ํ—Œํ„ฐ ๊ตฌ์ธ ์š”์ฒญ ์ˆ˜๋ฝ ์™„๋ฃŒ"),
2021
;
2122

2223
private final HttpStatus httpStatus;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.MatchReqDto;
11+
import org.skhuton.skhudebug.match.service.MatchService;
12+
import org.springframework.web.bind.annotation.PostMapping;
13+
import org.springframework.web.bind.annotation.RequestBody;
14+
import org.springframework.web.bind.annotation.RestController;
15+
16+
@RestController
17+
@RequiredArgsConstructor
18+
@Tag(name = "Bughunt Match API", description = "ํ—ŒํŠธ ์š”์ฒญ์˜ ์ˆ˜๋ฝ๊ณผ ์—…๋ฌด์˜ ์™„๋ฃŒ๋ฅผ ๋‹ด๋‹นํ•˜๋Š” API")
19+
public class BughuntMatchController {
20+
private final MatchService matchService;
21+
22+
@Operation(summary = "ํ—ŒํŠธ ์š”์ฒญ ์ˆ˜๋ฝ", description = "ํ—ŒํŠธ ์š”์ฒญ์„ ์ˆ˜๋ฝํ•˜๋Š” API")
23+
@Parameters({
24+
@Parameter(name = "senderId", description = "ํ˜ธ์ถœํ•˜๋Š” ์‚ฌ์šฉ์ž ์•„์ด๋””", required = true),
25+
@Parameter(name = "requestId", description = "ํ—ŒํŠธ ์š”์ฒญ ๊ฑด ๊ณ ์œ ์˜ ์•„์ด๋””", required = true),
26+
@Parameter(name = "receiveId", description = "ํ˜ธ์ถœ๋ฐ›๋Š” ์‚ฌ์šฉ์ž์˜ ์•„์ด๋””", required = true)
27+
})
28+
@PostMapping("/bughunt-matching")
29+
public BaseResponse<String> bughuntMatching(@RequestBody MatchReqDto matchReqDto) {
30+
matchService.acceptByHunter(matchReqDto);
31+
return BaseResponse.success(SuccessCode.BUGHUNT_REQUEST_ACCEPT);
32+
}
33+
}
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 = false)
29+
private String receiveId;
30+
31+
@Column(name = "complete", nullable = false)
32+
private boolean complete;
33+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.MatchReqDto;
6+
import org.skhuton.skhudebug.match.repository.HuntMatchRepository;
7+
import org.springframework.stereotype.Service;
8+
import org.springframework.transaction.annotation.Transactional;
9+
10+
@Service
11+
@RequiredArgsConstructor
12+
public class MatchService {
13+
private final HuntMatchRepository huntMatchRepository;
14+
/**
15+
* ํ˜ธ์ถœ ์ˆ˜๋ฝ
16+
*
17+
* 1. ์ˆ˜๋ฝ ๋ฒ„ํŠผ ํด๋ฆญ
18+
* 2. ๋ฒŒ๋ ˆ์— ๋Œ€ํ•œ ์ •๋ณด์™€ ํ˜ธ์ถœํ•œ ์œ ์ €, ์ˆ˜๋ฝํ•œ ์œ ์ €์˜ ์•„์ด๋””๋ฅผ ๋‹ด์€ ์š”์ฒญ ๋ฐ์ดํ„ฐ ์ „์†ก
19+
* 3. ์š”์ฒญ ๊ด€๋ฆฌ ํ…Œ์ด๋ธ”์—์„œ ์ˆ˜๋ฝ ์ปฌ๋Ÿผ์„ true๋กœ ๋ณ€๊ฒฝ
20+
*
21+
* ์š”์ฒญ๊ด€๋ฆฌํ…Œ์ด๋ธ”์˜ ํŠน์ • ์ปฌ๋Ÿผ๋“ค์ด true๊ฐ€ ๋  ๋•Œ๊นŒ์ง€ ๋ฒŒ๋ ˆ ์žก์€ ์ƒํƒœ๋กœ ์ทจ๊ธ‰ํ•˜์ง€ ์•Š์Œ.
22+
*/
23+
@Transactional
24+
public void acceptByHunter(MatchReqDto matchReqDto) {
25+
HuntReqManagement huntReqManagement = huntMatchRepository.findBySenderId(matchReqDto.senderId());
26+
huntReqManagement.setReceiveId(matchReqDto.receiveId());
27+
huntMatchRepository.save(huntReqManagement);
28+
}
29+
}

0 commit comments

Comments
 (0)
Please sign in to comment.