/
EnrollController.java
89 lines (80 loc) · 3.32 KB
/
EnrollController.java
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
package com.spring.ott.controller;
import java.security.Principal;
import java.util.HashMap;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import com.spring.ott.service.ErollPartyService;
import com.spring.ott.service.MatchingCheckService;
import com.spring.ott.service.PartyService;
import com.spring.ott.service.WatingRoomService;
import com.spring.ott.vo.PartyVo;
@Controller
public class EnrollController {
@Autowired MatchingCheckService matchingCheckService;
@Autowired PartyService partyService;
@Autowired WatingRoomService watingService;
@Autowired ErollPartyService enrollPartyService;
@Autowired private ServletContext servletContext;
@GetMapping("/autoMatch/matching/enroll")
public String enroll(Principal principal, int ott_id, Model model) {
//이미 해당 유저의 매칭이 진행중인 경우
HashMap<Integer,Object> matchinCheck = matchingCheckService.matchingCheck(principal.getName());
if( !matchinCheck.containsKey(0)) {
if(matchinCheck.containsKey(1)) {
model.addAttribute("msg", "이미 매칭된 파티가 존재합니다! My파티 페이지로 이동합니다");
model.addAttribute("url", servletContext.getContextPath() + "/autoMatch/myParty");
return "home/alert";
}
else if(matchinCheck.containsKey(2)) {
model.addAttribute("msg", "이미 매칭된 파티가 존재합니다! My파티 페이지로 이동합니다");
model.addAttribute("url", servletContext.getContextPath() + "/autoMatch/myParty");
return "home/alert";
}
else {
model.addAttribute("msg", "이미 고객님의 파티매칭이 진행중입니다! My파티 페이지로 이동합니다");
model.addAttribute("url", servletContext.getContextPath() + "/autoMatch/myParty");
return "home/alert";
}
}
else {
//매칭이 진행중이지 않은 유저만 매칭진행
PartyVo myParty = partyService.getMyParty(ott_id);
//Wating 테이블에 등록
if(myParty == null) {
HashMap<String, Object> map = new HashMap<>();
map.put("user_id", principal.getName());
map.put("ott_id", ott_id);
watingService.enroll(map);
//해당 Party에 바로추가
}else {
HashMap<String, Object> map = new HashMap<>();
map.put("party_id", myParty.getParty_id());
map.put("user_id", principal.getName());
map.put("input_num", 1);
//enroll 멤버
enrollPartyService.enrollParty(map);
//핸드폰 알림기능(예정)
}
model.addAttribute("msg", "정상적으로 등록하였습니다!");
model.addAttribute("url", servletContext.getContextPath() + "/autoMatch/myParty");
return "home/alert";
}
}
@GetMapping("/autoMatch/matching/enroll/{invite_code}")
public String invited_enroll(@PathVariable String invite_code, Model model, Principal principal) {
PartyVo vo = partyService.checkInvite(invite_code);
if(vo == null) {
model.addAttribute("msg", "유효하지 않은 초대 코드입니다!");
return "home/home.tiles";
}
if(vo.getMember_num() >= 3) {
model.addAttribute("msg", "정원이 초과된 파티입니다!");
return "home/home.tiles";
}
return "redirect:/autoMatch/party";
}
}