Skip to content

Commit

Permalink
#10
Browse files Browse the repository at this point in the history
[feat]
현재 접속중인 인원 수 완성
  • Loading branch information
daehwan2yo committed Jun 2, 2021
1 parent 825b893 commit fa01787
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -25,9 +26,15 @@ public class AdminController {

// 바꿔야함
@GetMapping("/connecting")
public String showConnectiongUser(){
public String showConnectiongUser(Model model){

return null;
List<Account> accountList = adminService.userConnecting();

model.addAttribute("accountList",accountList);
model.addAttribute("count",accountList.size());
model.addAttribute("isNull","접속된 유저가 현재 없습니다.");

return "connecting";
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
public interface ChatRoomRepository extends JpaRepository<ChatRoom,Long> {

Optional<ChatRoom> findChatRoomByType(RoomType type);

boolean existsChatRoomByType(RoomType type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ public Long createChatRoom(String type){


public boolean checkRoomExist(){
chatRoomRepository.findChatRoomByType(RoomType.GRAIN).orElseThrow(ChatRoomNotExistException::new);
chatRoomRepository.findChatRoomByType(RoomType.FISH).orElseThrow(ChatRoomNotExistException::new);
chatRoomRepository.findChatRoomByType(RoomType.FRUIT).orElseThrow(ChatRoomNotExistException::new);
chatRoomRepository.findChatRoomByType(RoomType.VEGETABLE).orElseThrow(ChatRoomNotExistException::new);
chatRoomRepository.findChatRoomByType(RoomType.MEAT).orElseThrow(ChatRoomNotExistException::new);

return true;
if(chatRoomRepository.existsChatRoomByType(RoomType.GRAIN)
&&chatRoomRepository.existsChatRoomByType(RoomType.FRUIT)
&&chatRoomRepository.existsChatRoomByType(RoomType.FISH)
&&chatRoomRepository.existsChatRoomByType(RoomType.VEGETABLE)
&&chatRoomRepository.existsChatRoomByType(RoomType.MEAT)
)
return true;

return false;
}
}
53 changes: 53 additions & 0 deletions src/main/resources/templates/connecting.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymleaf.org">

<head th:replace="fragments/home_header::home_header"/>

<body>

<section class="content">
<div class="row">

<div class="box">
<div class="box-header">
<h3 class="box-title">접속중인 유저</h3>
</div>

<div class="box-body" th:if="${accountList} != null">
<p>현재 접속중인 유저 수 : </p>
<p th:text="${count}"></p>
<table id="table">
<thead>
<tr>
<th>닉네임</th>
<th>연결된 시각</th>
<th>ip 주소</th>
<th>접속중인 채팅방</th>
</tr>
</thead>
<tbody>
<tr th:each="account : ${accountList}">
<td th:text="${account.nickname}">닉네임</td>
<td th:text="${account.created}">연결된 시각</td>

<td th:if="${account.sessionIp}==null" th:text="${account.sessionIp}">ip</td>
<td th:unless="${account.sessionIp}==null" th:text="null">ip</td>


<td th:if="${account.chatRoom} != null" th:text="${account.chatRoom.type}">채팅방</td>
<td th:unless="${account.chatRoom} != null" th:text="null">채팅방</td>
</tr>
</tbody>
</table>
</div>

<div class="box-body" th:unless="${accountList} != null" th:text="${isNull}">

</div>
</div>

</div>

</section>
</body>
</html>
13 changes: 13 additions & 0 deletions src/main/resources/templates/fragments/connecting_header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment="connecting_header">
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">

<title>현재 연결된 유저 리스트</title>
</head>
10 changes: 6 additions & 4 deletions src/main/resources/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
<div class="mainmenu">
<h1>통큰 경매 관리자 페이지</h1>

<form role="form" action="/admin/create" method="post">
<form role="form" action="/admin/create" method="POST">
<p>
<button class="btn btn-lg btn-info btn-size" type="submit">방 생성하기</button>
</p>
</form>
<p>
<a class="btn btn-lg btn-info btn-size">접속중인 유저</a>
</p>

<form role="form" action="/admin/connecting" method="GET">
<p>
<button class="btn btn-lg btn-info btn-size">접속중인 유저</button>
</p>
</form>
<h2>품목 관리</h2>
<p class="lead">GRAIN</p>
<p>
Expand Down

0 comments on commit fa01787

Please sign in to comment.