Skip to content

Commit

Permalink
Merge pull request #11 from CodingWasabi/#10_admin
Browse files Browse the repository at this point in the history
#10 admin
  • Loading branch information
daehwan2yo authored Jun 2, 2021
2 parents 74d5b6a + 86681e1 commit 7e65332
Show file tree
Hide file tree
Showing 55 changed files with 154 additions and 58,770 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,54 @@
package com.codingwasabi.bigtong.admin.controller;

import com.codingwasabi.bigtong.admin.entity.RoomType;
import com.codingwasabi.bigtong.admin.service.ChatRoomService;
import com.codingwasabi.bigtong.main.Account;
import com.codingwasabi.bigtong.admin.service.AdminService;
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;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@RestController
@Controller
@RequiredArgsConstructor
@RequestMapping("/admin")
public class AdminController {

private final AdminService adminService;
private final ChatRoomService chatRoomService;


// 바꿔야함
@GetMapping("/connecting")
public List<Account> showConnectiongUser(){
return adminService.userConnecting();
public String showConnectiongUser(Model model){

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

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

return "connecting";
}


@PostMapping("/create")
public String create_chatRoom(){

if(!chatRoomService.checkRoomExist()){
chatRoomService.createChatRoom("GRAIN");
chatRoomService.createChatRoom("VEGETABLE");
chatRoomService.createChatRoom("FRUIT");
chatRoomService.createChatRoom("MEAT");
chatRoomService.createChatRoom("FISH");
}
return "redirect:/";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,5 @@
public class ChatRoomController {
private final ChatRoomService chatRoomService;

@PostMapping("/create")
public Long create_chatRoom(@RequestParam String type){

// test log
log.info("admin : ChatRoomController : create_chatRoom");
return chatRoomService.createChatRoom(type);
}
}
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 @@ -6,6 +6,7 @@
import com.codingwasabi.bigtong.admin.entity.ChatRoom;
import com.codingwasabi.bigtong.main.Account;
import com.codingwasabi.bigtong.main.repository.AccountRepository;
import com.codingwasabi.bigtong.websocket.exception.ChatRoomNotExistException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -37,4 +38,15 @@ public Long createChatRoom(String type){
}


public boolean checkRoomExist(){
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public void message_in(WebSocketSession webSocketSession, ChatMessage chatMessag

// inetSocketAddress 형태의 주소를 String형태로 캐스팅
// inetSocketAddress -> inetAddress : get String ip
account.insertSession(webSocketSession.getId(),
webSocketSession.getRemoteAddress().getAddress().getHostAddress());
account.insertSession(webSocketSession.getId(),webSocketSession.getRemoteAddress().getAddress().getHostAddress());
account.enterRoom(chatRoom);

chatRoomRepository.flush();
Expand Down
10 changes: 4 additions & 6 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ spring:
hibernate:
ddl-auto: create

database: mysql
database-platform: org.hibernate.dialect.MySQL8Dialect

datasource:
url: jdbc:mysql://gogogo.ccszmnhxhmwx.ap-northeast-2.rds.amazonaws.com/bigtong
username: admin
password: 1q2w3e4r!
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:h2:tcp://localhost/~/bigtong
username: sa
password:
driver-class-name: org.h2.Driver

#logging:
#level:
Expand Down
Loading

0 comments on commit 7e65332

Please sign in to comment.