Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ dependencies {
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'

// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'

//WebSocket
implementation 'org.springframework.boot:spring-boot-starter-websocket'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,62 @@
package com.metlab_project.backend.controller.chatroom;

import com.metlab_project.backend.domain.dto.chatroom.req.ChatroomCreateRequest;
import com.metlab_project.backend.domain.dto.chatroom.res.ChatRoomResponse;
import com.metlab_project.backend.domain.dto.chatroom.res.MemberResponse;
import com.metlab_project.backend.domain.entity.Message;
import com.metlab_project.backend.domain.entity.user.User;
import com.metlab_project.backend.domain.dto.chatroom.res.ChatRoomDetailResponse;
import com.metlab_project.backend.service.chatroom.ChatRoomService;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/chatroom")
public class ChatroomController {
@GetMapping("/list")
@Operation(summary = "STATUS가 WAITING인 채팅룸 불러오기", description = "STATUS가 WAITING인 채팅룸을 불러옵니다.")
public ResponseEntity<?> getAllChatroom(){
//Status Waiting인 채팅룸 불러오는건데, /list-my에서 넘겨줄 본인이 속한 채팅방 제외하고 불러오면됨.
return ResponseEntity.ok(true);
}
public class ChatRoomController {

private final ChatRoomService chatRoomService;

@GetMapping("/list-my")
@Operation(summary = "유저가 참가중인 채팅룸 불러오기", description = "유저가 참가중인 채팅룸을 불러옵니다.")
public ResponseEntity<?> getMyChatroom(){
//본인이 속한 채팅룸(Status 상관없이 불러오면 됨)
return ResponseEntity.ok(true);
@GetMapping("/list")
@Operation(summary = "모든 채팅룸 불러오기", description = "모든 채팅룸을 불러옵니다.")
public ResponseEntity<?> getAllChatroom() {
List<ChatRoomResponse> allChatRooms = chatRoomService.getAllChatrooms();
return ResponseEntity.ok(allChatRooms);
}

@GetMapping("/participants/{chatroomid}")
@Operation(summary = "채팅룸 참여 유저 불러오기", description = "특정 채팅룸의 참여자 목록을 불러옵니다.")
public ResponseEntity<?> getParticipants(@PathVariable("chatroomid") String chatroomId){
return ResponseEntity.ok(true);
public ResponseEntity<?> getParticipants(@PathVariable("chatroomid") Integer chatroomId) {
List<MemberResponse> members = chatRoomService.getChatRoomDetail(chatroomId).getMembers();
return ResponseEntity.ok(members);
}

@PostMapping
@Operation(summary = "채팅룸 생성하기", description = "채팅룸을 생성합니다.")
public ResponseEntity createChatroom(@Valid @RequestBody ChatroomCreateRequest request) {
// @Valid 사용 시 유효성 검증 실패 시 MethodArgumentNotValidException 발생 가능
ChatRoomResponse newChatRoom = chatRoomService.createChatroom(request);
return ResponseEntity.ok(newChatRoom);
}

@GetMapping("/summary/{chatroomid}")
@Operation(summary = "채팅룸 요약 불러오기", description = "특정 채팅룸의 요약 정보를 불러옵니다.")
public ResponseEntity<?> getChatroomSummary(@PathVariable("chatroomid") String chatroomId){
return ResponseEntity.ok(true);
@DeleteMapping("/{chatroomId}")
@Operation(summary = "채팅룸 삭제하기", description = "특정 채팅룸을 삭제합니다.")
public ResponseEntity<Void> deleteChatroom(@PathVariable("chatroomId") Integer chatroomId) {
chatRoomService.deleteChatroom(chatroomId);
return ResponseEntity.noContent().build(); // 204 No Content
}

@PostMapping
@Operation(summary = "채팅룸 생성하기", description = "채팅룸을 생성합니다.")
public ResponseEntity createChatroom(@Valid @RequestBody ChatroomCreateRequest request){
return ResponseEntity.ok(true);
@GetMapping("/{chatroomId}/messages")
@Operation(summary = "채팅룸 내역 가져오기", description = "특정 채팅룸의 채팅 내역을 가져옵니다.")
public ResponseEntity<List<Message>> getChatMessages(@PathVariable("chatroomId") Integer chatroomId) {
List<Message> messages = chatRoomService.getChatMessages(chatroomId);
return ResponseEntity.ok(messages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Getter;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class ChatroomCreateRequest {
// 채팅룸 생성 ResponseDTO
private String chatroomName;
private LocalDateTime deadline;
private String hashtags;
private Integer maxUser;
private String host;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.metlab_project.backend.domain.dto.chatroom.res;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

@Getter
@AllArgsConstructor
public class ChatRoomDetailResponse {
private Integer id;
private String name;
private String title;
private String subTitle;
private List<MemberResponse> members;
private Integer maxMembers;
private Boolean enterCheck;
private String host;
private Integer maleCount;
private Integer femaleCount;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
package com.metlab_project.backend.domain.dto.chatroom.res;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

@Getter
@AllArgsConstructor
public class ChatRoomResponse {
private Integer id;
private String title;
private String subTitle;
private Integer maxMembers;
private Boolean enterCheck;
private String host;
private Integer maleCount;
private Integer femaleCount;
private String profileImage;
private Boolean hasStarted;

public ChatRoomResponse(Integer id, String title, String subTitle, Integer maxMembers, Boolean enterCheck, String host, Integer maleCount, Integer femaleCount, String profileImage, Boolean hasStarted) {
this.id = id;
this.title = title;
this.subTitle = subTitle;
this.maxMembers = maxMembers;
this.enterCheck = enterCheck;
this.host = host;
this.maleCount = maleCount;
this.femaleCount = femaleCount;
this.profileImage = profileImage;
this.hasStarted = hasStarted;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.metlab_project.backend.domain.dto.chatroom.res;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class MemberResponse {
private String gender;
private String major;
private String studentId;
private String nickname;
private String profileImage;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ public class ChatRoom {
@Column(name = "chatroom_name", nullable = false, length = 30)
private String chatroomName;

@Column(name = "title", length = 100)
private String title;

@Column(name = "sub_title", length = 100)
private String subTitle;

@Column(name = "profile_image", length = 255)
private String profileImage;

@Column(name = "host", nullable = false, length = 30)
private String host; // host's schoolEmail

Expand All @@ -39,20 +48,28 @@ public class ChatRoom {
@Column(name = "total_participant")
private Integer totalParticipant;

@Column(name = "max_members")
private Integer maxMembers;

@Column(name = "enter_check")
private Boolean enterCheck;

private LocalDateTime deadline;

@Enumerated(EnumType.STRING)
@Builder.Default
@Column(name = "status")
@Column(name = "status", length = 20)
private Status status = Status.WAITING;

@Column(length = 100)
private String hashtags;

@Builder.Default
@ManyToMany(mappedBy = "chatRooms")
private List<User> users = new ArrayList<>();

@OneToMany(mappedBy = "chatRoom")
private List<Message> messages;
@OneToMany(mappedBy = "chatRoom", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Message> messages = new ArrayList<>();

public enum Status {
WAITING,
Expand All @@ -68,4 +85,4 @@ public void removeUser(User user) {
this.users.remove(user);
user.getChatRooms().remove(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Message {
@JoinColumn(name = "chatroom_id", insertable = false, updatable = false)
private ChatRoom chatRoom;

private enum MessageType {
public enum MessageType {
CHAT,
JOIN,
LEAVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public class User {
)
private List<ChatRoom> chatRooms = new ArrayList<>();

@Column(length = 30)
private String major;

@Column(length = 255)
private String profileImage;

public void addChatRoom(ChatRoom chatRoom) {
this.chatRooms.add(chatRoom);
chatRoom.getUsers().add(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public enum CustomErrorCode {
TOKEN_CLAIMS_EMPTY(HttpStatus.UNAUTHORIZED, "401", "Token claims are empty"),
REFRESH_TOKEN_NOT_FOUND(HttpStatus.NOT_FOUND, "404", "Refresh token not found"),
REFRESH_TOKEN_EXPIRED(HttpStatus.UNAUTHORIZED, "401", "Refresh token has expired"),
TOKEN_BLACKLISTED(HttpStatus.UNAUTHORIZED, "401", "Token has been blacklisted");
TOKEN_BLACKLISTED(HttpStatus.UNAUTHORIZED, "401", "Token has been blacklisted"),
//그 외
UNKNOWN(HttpStatus.INTERNAL_SERVER_ERROR, "500", "Internal Server Error occurred");

@NonNull
private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public CustomException(Exception exception) {
this.detail = exception.getMessage();
}
}
}
}

Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.metlab_project.backend.repository.chatroom;

import com.metlab_project.backend.domain.entity.ChatRoom;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ChatRoomRepository extends JpaRepository<ChatRoom, Integer> {
List<ChatRoom> findByStatus(ChatRoom.Status status);
List<ChatRoom> findByIdIn(List<Integer> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MessageRepository extends JpaRepository<Message, Integer> {
List<Message> findByChatroomIdAndTypeOrderByCreatedAtAsc(Integer chatroomId, Message.MessageType type);
}
Loading