-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchController.java
More file actions
149 lines (131 loc) · 7.81 KB
/
MatchController.java
File metadata and controls
149 lines (131 loc) · 7.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.example.moim.match.controller;
import com.example.moim.club.repository.ClubRepository;
import com.example.moim.global.exception.BaseResponse;
import com.example.moim.global.exception.ResponseCode;
import com.example.moim.match.dto.*;
import com.example.moim.match.exception.advice.MatchControllerAdvice;
import com.example.moim.match.repository.MatchRepository;
import com.example.moim.match.service.MatchService;
import com.example.moim.user.dto.UserDetailsImpl;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequiredArgsConstructor
public class MatchController implements MatchControllerDocs {
private final MatchService matchService;
private final ClubRepository clubRepository;
private final MatchRepository matchRepository;
//매치 등록(생성) 신청(참가)
//매치 생성
@PostMapping("/match")
public BaseResponse<MatchOutput> matchSave(@RequestBody @Valid MatchInput matchInput, @AuthenticationPrincipal UserDetailsImpl userDetailsImpl) {
return BaseResponse.onSuccess(matchService.saveMatch(userDetailsImpl.getUser(), matchInput), ResponseCode.OK);
}
//매치 등록
@PatchMapping(value = "/match", produces = MediaType.APPLICATION_JSON_VALUE)
public BaseResponse<MatchRegOutput> matchRegister(@RequestBody @Valid MatchRegInput matchRegInput,
@AuthenticationPrincipal UserDetailsImpl userDetailsImpl) {
return BaseResponse.onSuccess(matchService.registerMatch(userDetailsImpl.getUser(), matchRegInput), ResponseCode.OK);
}
// 매치 생성 취소
@DeleteMapping("/match")
public BaseResponse<String> matchCreationCancel(@RequestParam Long matchId,
@AuthenticationPrincipal UserDetailsImpl userDetailsImpl) {
String result = matchService.cancelMatch(userDetailsImpl.getUser(), matchId);
return BaseResponse.onSuccess(result, ResponseCode.OK);
}
//매치 신청 생성
@PostMapping("/match-application")
public BaseResponse<MatchApplyOutput> matchApplySave(@RequestParam Long matchId,
@RequestParam Long clubId,
@AuthenticationPrincipal UserDetailsImpl userDetailsImpl) {
return BaseResponse.onSuccess(matchService.saveMatchApp(userDetailsImpl.getUser(), matchId, clubId), ResponseCode.OK);
}
// 매치 신청 취소
@DeleteMapping("/match-application")
public BaseResponse<String> matchApplyCancel(@RequestParam Long matchId,
@RequestParam Long clubId,
@AuthenticationPrincipal UserDetailsImpl userDetailsImpl) {
String result = matchService.cancelMatchApplication(userDetailsImpl.getUser(), matchId, clubId);
return BaseResponse.onSuccess(result, ResponseCode.OK);
}
//매치 신청 완료
@PatchMapping("/match-application")
public BaseResponse<MatchApplyOutput> matchApply(@RequestBody @Valid MatchApplyInput matchApplyInput,
@AuthenticationPrincipal UserDetailsImpl userDetailsImpl) {
return BaseResponse.onSuccess(matchService.applyMatch(userDetailsImpl.getUser(), matchApplyInput), ResponseCode.OK);
}
//매치 초청
@PostMapping("/match-invite")
public BaseResponse<String> matchInvite(@RequestParam Long matchId,
@RequestParam Long clubId,
@AuthenticationPrincipal UserDetailsImpl userDetailsImpl) {
matchService.inviteMatch(userDetailsImpl.getUser(), matchId, clubId);
return BaseResponse.onSuccess("매치 초청 알림이 전송되었습니다.", ResponseCode.OK);
}
//매치 확정
@PostMapping("/match-confirm")
public BaseResponse<MatchConfirmOutput> matchConfirm(@RequestParam Long matchId,
@RequestParam Long clubId,
@AuthenticationPrincipal UserDetailsImpl userDetailsImpl) {
return BaseResponse.onSuccess(matchService.confirmMatch(matchId, clubId, userDetailsImpl.getUser()), ResponseCode.OK);
}
// 확정된 매치 취소
@DeleteMapping("/match-confirm")
public BaseResponse<String> cancelConfirmedMatch(@RequestParam Long matchId,
@AuthenticationPrincipal UserDetailsImpl userDetailsImpl) {
String result = matchService.cancelConfirmedMatch(userDetailsImpl.getUser(), matchId);
return BaseResponse.onSuccess(result, ResponseCode.OK);
}
//등록된 매치 검색
@GetMapping("/matches")
public BaseResponse<List<MatchSearchOutput>> findMatches(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl,
@ModelAttribute MatchSearchCond matchSearchCond) {
return BaseResponse.onSuccess(matchService.searchMatch(matchSearchCond), ResponseCode.OK);
}
//확정된 매치리스트
@GetMapping("/{clubId}/matches")
public BaseResponse<List<ConfirmedMatchOutput>> findConfirmedMatches(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl,
@PathVariable Long clubId) {
return BaseResponse.onSuccess(matchService.findConfirmedMatch(clubRepository.findById(clubId)
.orElseThrow(() -> new MatchControllerAdvice(ResponseCode.CLUB_NOT_FOUND))),
ResponseCode.OK);
}
//활동 지역 소재 모임 리스트
@GetMapping("/{clubId}/match-clubs")
public BaseResponse<List<MatchClubOutput>> findMatchClubs(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl,
@ModelAttribute MatchClubSearchCond matchClubSearchCond,
@PathVariable Long clubId) {
return BaseResponse.onSuccess(matchService.searchMatchClubs(matchClubSearchCond, clubRepository.findById(clubId)
.orElseThrow(() -> new MatchControllerAdvice(ResponseCode.CLUB_NOT_FOUND))),
ResponseCode.OK);
}
//매치 등록/신청 현황
@GetMapping("/{clubId}/match-status")
public BaseResponse<List<MatchStatusOutput>> getMatchStatus(@PathVariable Long clubId) {
return BaseResponse.onSuccess(matchService.findMatchStatus(clubRepository.findById(clubId)
.orElseThrow(() -> new MatchControllerAdvice(ResponseCode.CLUB_NOT_FOUND))),
ResponseCode.OK);
}
//매치 결과 기록
@PatchMapping(value = "/match/{matchId}", produces = MediaType.APPLICATION_JSON_VALUE)
public BaseResponse<MatchRecordOutput> matchRecordSave(@PathVariable Long matchId,
@RequestBody @Valid MatchRecordInput matchRecordInput,
@AuthenticationPrincipal UserDetailsImpl userDetailsImpl) {
return BaseResponse.onSuccess(matchService.saveMatchRecord(matchRepository.findById(matchId)
.orElseThrow(() -> new MatchControllerAdvice(ResponseCode.MATCH_NOT_FOUND)),
userDetailsImpl.getUser(),
matchRecordInput),
ResponseCode.OK);
}
//매치 메인 페이지(대시보드)
@GetMapping("/match/main/{clubId}")
public BaseResponse<MatchMainOutput> findMatchMain(@PathVariable Long clubId, @AuthenticationPrincipal UserDetailsImpl userDetailsImpl) {
return BaseResponse.onSuccess(matchService.matchMainFind(clubId), ResponseCode.OK);
}
}