Skip to content

Commit 7b429cb

Browse files
authored
Merge pull request #74 from CommitField/feat/#20
Feat/#20
2 parents 064f85c + 4d478df commit 7b429cb

File tree

10 files changed

+183
-73
lines changed

10 files changed

+183
-73
lines changed

โ€Žsrc/main/java/cmf/commitField/domain/chat/chatRoom/controller/ChatRoomController.javaโ€Ž

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import cmf.commitField.domain.chat.chatRoom.dto.ChatRoomDto;
55
import cmf.commitField.domain.chat.chatRoom.service.ChatRoomService;
66
import cmf.commitField.domain.user.entity.CustomOAuth2User;
7+
import cmf.commitField.global.error.ErrorCode;
78
import cmf.commitField.global.globalDto.GlobalResponse;
89
import cmf.commitField.global.security.LoginCheck;
910
import jakarta.validation.Valid;
@@ -32,9 +33,9 @@ public GlobalResponse<Object> createRoom(
3233
CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
3334
Long userId = principal.getId(); // getId()๋ฅผ ํ†ตํ•ด userId๋ฅผ ์ถ”์ถœ
3435
chatRoomService.createRoom(chatRoomRequest, userId); // userId๋ฅผ ์ „๋‹ฌ
35-
return GlobalResponse.success();
36+
return GlobalResponse.success("์ฑ„ํŒ…๋ฐฉ์„ ์ƒ์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.");
3637
} else {
37-
throw new IllegalArgumentException("User not logged in.");
38+
throw new IllegalArgumentException("๋กœ๊ทธ์ธ ํ›„์— ์ด์šฉํ•ด ์ฃผ์„ธ์š”.");
3839
}
3940
}
4041

@@ -47,9 +48,9 @@ public GlobalResponse<Object> joinRoom(@PathVariable Long roomId) {
4748
CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
4849
Long userId = principal.getId(); // getId()๋ฅผ ํ†ตํ•ด userId๋ฅผ ์ถ”์ถœ
4950
chatRoomService.joinRoom(roomId, userId); // userId๋ฅผ ์ „๋‹ฌ
50-
return GlobalResponse.success();
51+
return GlobalResponse.success("ํ•ด๋‹น ์ฑ„ํŒ…๋ฐฉ์— ์ž…์žฅํ•˜์…จ์Šต๋‹ˆ๋‹ค");
5152
} else {
52-
throw new IllegalArgumentException("User not logged in.");
53+
throw new IllegalArgumentException("๋กœ๊ทธ์ธ ํ›„์— ์ด์šฉํ•ด ์ฃผ์„ธ์š”.");
5354
}
5455
}
5556

@@ -58,7 +59,13 @@ public GlobalResponse<Object> joinRoom(@PathVariable Long roomId) {
5859
@LoginCheck
5960
public GlobalResponse<Object> roomList(Pageable pageable) {
6061
List<ChatRoomDto> roomList = chatRoomService.getRoomList(pageable);
61-
return GlobalResponse.success(roomList);
62+
63+
// ๋ฐฉ ๋ฆฌ์ŠคํŠธ๊ฐ€ ๋น„์–ด ์žˆ์œผ๋ฉด notFound ์‘๋‹ต ๋ฐ˜ํ™˜
64+
if (roomList.isEmpty()) {
65+
return GlobalResponse.error(ErrorCode.NO_ROOM_FOUND);
66+
}
67+
68+
return GlobalResponse.success("์ „์ฒด ๋ชฉ๋ก ์กฐํšŒ์— ์„ฑ๊ณตํ•˜์˜€์Šต๋‹ˆ๋‹ค.",roomList);
6269
}
6370

6471
// ์‚ฌ์šฉ์ž(์ž์‹ )๊ฐ€ ์ƒ์„ฑํ•œ ๋ฐฉ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ
@@ -72,9 +79,15 @@ public GlobalResponse<Object> getByUserRoomList(Pageable pageable) {
7279
Long userId = principal.getId(); // getId()๋ฅผ ํ†ตํ•ด userId๋ฅผ ์ถ”์ถœ
7380

7481
List<ChatRoomDto> userByRoomList = chatRoomService.getUserByRoomList(userId, pageable);
75-
return GlobalResponse.success(userByRoomList);
82+
83+
// ๋ฐฉ ๋ฆฌ์ŠคํŠธ๊ฐ€ ๋น„์–ด ์žˆ์œผ๋ฉด notFound ์‘๋‹ต ๋ฐ˜ํ™˜
84+
if (userByRoomList.isEmpty()) {
85+
return GlobalResponse.error(ErrorCode.USER_CREATED_ROOM_NOT_FOUND);
86+
}
87+
88+
return GlobalResponse.success("์‚ฌ์šฉ์ž๊ฐ€ ์ƒ์„ฑํ•œ ๋ฐฉ ์กฐํšŒ ์„ฑ๊ณต.",userByRoomList);
7689
} else {
77-
throw new IllegalArgumentException("User not logged in.");
90+
throw new IllegalArgumentException("๋กœ๊ทธ์ธ ํ›„์— ์ด์šฉํ•ด ์ฃผ์„ธ์š”.");
7891
}
7992
}
8093

@@ -88,9 +101,15 @@ public GlobalResponse<Object> getByUserRoomPartList(Pageable pageable) {
88101
CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
89102
Long userId = principal.getId(); // getId()๋ฅผ ํ†ตํ•ด userId๋ฅผ ์ถ”์ถœ
90103
List<ChatRoomDto> userByRoomPartList = chatRoomService.getUserByRoomPartList(userId, pageable);
91-
return GlobalResponse.success(userByRoomPartList);
104+
105+
// ๋งŒ์•ฝ ๋ฐฉ ๋ฆฌ์ŠคํŠธ๊ฐ€ ์—†๋‹ค๋ฉด notFound ์‘๋‹ต ๋ฐ˜ํ™˜
106+
if (userByRoomPartList.isEmpty()) {
107+
return GlobalResponse.error(ErrorCode.NONE_ROOM);
108+
}
109+
110+
return GlobalResponse.success("์‚ฌ์šฉ์ž๊ฐ€ ๋“ค์–ด๊ฐ€ ์žˆ๋Š” ๋ฐฉ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ ์„ฑ๊ณต.",userByRoomPartList);
92111
} else {
93-
throw new IllegalArgumentException("User not logged in.");
112+
throw new IllegalArgumentException("๋กœ๊ทธ์ธ ํ›„์— ์ด์šฉํ•ด ์ฃผ์„ธ์š”.");
94113
}
95114
}
96115

@@ -105,27 +124,27 @@ public GlobalResponse<Object> outRoom(
105124
CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
106125
Long userId = principal.getId(); // getId()๋ฅผ ํ†ตํ•ด userId๋ฅผ ์ถ”์ถœ
107126
chatRoomService.outRoom(userId, roomId);
108-
return GlobalResponse.success();
127+
return GlobalResponse.success("์ฑ„ํŒ…๋ฐฉ์„ ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค.");
128+
} else {
129+
throw new IllegalArgumentException("๋กœ๊ทธ์ธ ํ›„์— ์ด์šฉํ•ด ์ฃผ์„ธ์š”.");
130+
}
131+
}
132+
133+
// ์ฑ„ํŒ…๋ฐฉ ์‚ญ์ œ
134+
@DeleteMapping("/room/delete/{roomId}")
135+
@LoginCheck
136+
public GlobalResponse<Object> deleteRoom(
137+
@PathVariable Long roomId) {
138+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
139+
140+
if (authentication instanceof OAuth2AuthenticationToken) {
141+
CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
142+
Long userId = principal.getId(); // getId()๋ฅผ ํ†ตํ•ด userId๋ฅผ ์ถ”์ถœ
143+
chatRoomService.deleteRoom(userId, roomId);
144+
return GlobalResponse.success("์ฑ„ํŒ…๋ฐฉ์„ ์‚ญ์ œํ–ˆ์Šต๋‹ˆ๋‹ค.");
109145
} else {
110-
throw new IllegalArgumentException("User not logged in.");
146+
throw new IllegalArgumentException("๋กœ๊ทธ์ธ ํ›„์— ์ด์šฉํ•ด ์ฃผ์„ธ์š”.");
111147
}
112148
}
113-
//
114-
// // ์ฑ„ํŒ…๋ฐฉ ์‚ญ์ œ
115-
// @DeleteMapping("/room/delete/{roomId}")
116-
// @LoginCheck
117-
// public ResponseEntity<Object> deleteRoom(
118-
// @PathVariable Long roomId) {
119-
// Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
120-
//
121-
// if (authentication instanceof OAuth2AuthenticationToken) {
122-
// CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
123-
// Long userId = principal.getId(); // getId()๋ฅผ ํ†ตํ•ด userId๋ฅผ ์ถ”์ถœ
124-
// chatRoomService.deleteRoom(userId, roomId);
125-
// return ResponseEntity.ok().body("success");
126-
// } else {
127-
// throw new IllegalArgumentException("User not logged in.");
128-
// }
129-
// }
130149

131150
}

โ€Žsrc/main/java/cmf/commitField/domain/chat/chatRoom/service/ChatRoomService.javaโ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public interface ChatRoomService {
2121
List<ChatRoomDto> getUserByRoomPartList(Long userId, Pageable pageable);
2222

2323
void outRoom(Long userId, Long roomId);
24-
//
25-
// void deleteRoom(Long userId, Long roomId);
24+
25+
void deleteRoom(Long userId, Long roomId);
2626
}

โ€Žsrc/main/java/cmf/commitField/domain/chat/chatRoom/service/ChatRoomServiceImpl.javaโ€Ž

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,17 @@ public void joinRoom(Long roomId, Long userId) {
7474

7575
// ํ˜„์žฌ ์ธ์› ์ˆ˜ ์กฐํšŒ
7676
Long currentUserCount = userChatRoomRepository.countByChatRoomId(roomId);
77-
7877
// ์ฑ„ํŒ…๋ฐฉ์ด ๊ฝ‰ ์ฐผ์„ ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ
7978
if (currentUserCount >= chatRoom.getUserCountMax()) {
8079
throw new CustomException(ErrorCode.ROOM_USER_FULL);
8180
}
8281

82+
// ์ด๋ฏธ ์ฐธ์—ฌํ•œ ๋ฐฉ์ธ์ง€ ํ™•์ธ
83+
if (userChatRoomRepository.existsByChatRoomIdAndUserId(roomId, userId)) {
84+
throw new CustomException(ErrorCode.ALREADY_JOIN_ROOM);
85+
}
86+
87+
8388
// user_chatroom ๊ด€๊ณ„ ์ƒ์„ฑ
8489
UserChatRoom userChatRoom = UserChatRoom.builder()
8590
.user(findUser)
@@ -131,33 +136,36 @@ public List<ChatRoomDto> getUserByRoomPartList(Long userId, Pageable pageable) {
131136
}
132137

133138
@Override
134-
@Transactional(readOnly = true)
139+
@Transactional
135140
public void outRoom(Long userId, Long roomId) {
136141
Long roomCreatorId = chatRoomRepository
137142
.findChatRoomByRoomCreator(roomId);
138143
// ๋ฐฉ์žฅ์ด ์•„๋‹ˆ๋ผ๋ฉด
139144
if (!Objects.equals(roomCreatorId, userId)) {
140-
userChatRoomRepository.deleteUserChatRoomByUserId(userId);
145+
userChatRoomRepository.deleteUserChatRoomByChatRoom_IdAndUserId(roomId, userId);
141146
return;
142147
}
143148
// ๋ฐฉ์žฅ์ด๋ผ๋ฉด ๋ฐฉ ์‚ญ์ œ
144149
userChatRoomRepository.deleteUserChatRoomByChatRoom_Id(roomId);
145150
chatRoomRepository.deleteById(roomId);
151+
// chatMsgRepository.deleteById(roomId); ๋ฐฉ ์‚ญ์ œ ์‹œ ์ฑ„ํŒ…๋„ ๋‹ค ์‚ญ์ œ(ํ•„์š” ์‹œ)
146152
}
147153

148-
//// chatMsgRepository.deleteById(roomId); ๋ฐฉ ์‚ญ์ œ ์‹œ ์ฑ„ํŒ…๋„ ๋‹ค ์‚ญ์ œ ๋˜์–ด์•ผ ํ•จ.
149-
// @Override
150-
// @Transactional
151-
// public void deleteRoom(Long userId, Long roomId) {
152-
// Long roomCreatorId = chatRoomRepository
153-
// .findChatRoomByRoomCreator(roomId);
154-
// if (!Objects.equals(roomCreatorId, userId)) {
155-
// throw new CustomException(ErrorCode.NOT_ROOM_CREATOR);
156-
// }
157-
// userChatRoomRepository.deleteUserChatRoomByChatRoom_Id(roomId);
158-
// chatRoomRepository.deleteById(roomId);
159-
// ์ฑ„ํŒ… ๋ฉ”์‹œ์ง€ ๊ตฌํ˜„ ์‹œ, ๋ฐฉ ์‚ญ์ œํ•  ๋•Œ ๋ฉ”์‹œ์ง€๋„ ๊ฐ™์ด ์‚ญ์ œ๋˜๋Š” ๋ฉ”์„œ๋“œ ๊ตฌํ˜„
160-
//}
154+
155+
@Override
156+
@Transactional
157+
public void deleteRoom(Long userId, Long roomId) {
158+
Long roomCreatorId = chatRoomRepository
159+
.findChatRoomByRoomCreator(roomId);
160+
//๋ฐฉ์žฅ์ด ์•„๋‹ ๊ฒฝ์šฐ, ์‚ญ์ œ ๋ถˆ๊ฐ€
161+
if (!Objects.equals(roomCreatorId, userId)) {
162+
throw new CustomException(ErrorCode.NOT_ROOM_CREATOR);
163+
}
164+
//๋ชจ๋“  ์‚ฌ์šฉ์ž ์ œ๊ฑฐ ํ›„ ๋ฐฉ ์‚ญ์ œ
165+
userChatRoomRepository.deleteUserChatRoomByChatRoom_Id(roomId);
166+
chatRoomRepository.deleteById(roomId);
167+
// chatMessageRepository.deleteId(roomId);
168+
}
161169

162170

163171

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cmf.commitField.domain.chat.userChatRoom.dto;
2+
3+
import lombok.*;
4+
5+
@Getter
6+
@Setter
7+
@NoArgsConstructor
8+
@AllArgsConstructor
9+
@Builder
10+
public class UserChatRoomDto {
11+
private Long userId;
12+
}

โ€Žsrc/main/java/cmf/commitField/domain/chat/userChatRoom/repository/UserChatRoomRepository.javaโ€Ž

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.springframework.data.repository.query.Param;
1111
import org.springframework.stereotype.Repository;
1212

13+
import java.util.List;
14+
1315
@Repository
1416
public interface UserChatRoomRepository extends JpaRepository<UserChatRoom, Long> {
1517

@@ -18,11 +20,19 @@ public interface UserChatRoomRepository extends JpaRepository<UserChatRoom, Long
1820
Long countByChatRoomId(Long roomId); // ๋น„๊ด€์  ๋ฝ
1921

2022
// @Query("select count(*) from UserChatRoom u where u.chatRoom.id = ?1 ")
21-
// Long countNonLockByChatRoomId(Long roomId); // test ์šฉ๋„
2223
@Query("select count(*) from UserChatRoom u where u.chatRoom.id = :roomId")
2324
Long countNonLockByChatRoomId(@Param("roomId")Long roomId); // test ์šฉ๋„
24-
25+
// ํŠน์ • ๋ฐฉ์˜ ๋ชจ๋“  ์œ ์ € ๊ด€๊ณ„ ์‚ญ์ œ
2526
void deleteUserChatRoomByChatRoom_Id(Long chatRoomId);
26-
27+
// ํŠน์ • ๋ฐฉ์—์„œ ํŠน์ • ์‚ฌ์šฉ์ž๋งŒ ์‚ญ์ œ
28+
void deleteUserChatRoomByChatRoom_IdAndUserId(Long chatRoomId, Long userId);
29+
// ํŠน์ • ๋ฐฉ๊ณผ ์‚ฌ์šฉ์ž ๊ด€๊ณ„ ์‚ญ์ œ
2730
void deleteUserChatRoomByUserId(Long userId);
31+
// ์‚ฌ์šฉ์ž๊ฐ€ ํ•ด๋‹น ๋ฐฉ์— ์ฐธ์—ฌํ•œ ์—ฌ๋ถ€ ํ™•์ธ
32+
boolean existsByChatRoomIdAndUserId(Long roomId, Long userId);
33+
// ํŠน์ • ๋ฐฉ์— ์ฐธ์—ฌํ•œ ๋ชจ๋“  UserChatRoom ๊ด€๊ณ„ ์กฐํšŒ
34+
List<UserChatRoom> findByChatRoom_Id(Long chatRoomId);
35+
36+
37+
2838
}

โ€Žsrc/main/java/cmf/commitField/domain/user/entity/User.javaโ€Ž

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import lombok.Setter;
1212
import lombok.experimental.SuperBuilder;
1313

14+
import java.util.ArrayList;
1415
import java.util.List;
1516

1617
@Entity
@@ -32,13 +33,13 @@ public enum Role {
3233
USER, ADMIN
3334
}
3435
//์ถ”๊ฐ€
35-
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
36-
private List<ChatRoom> chatRooms;
36+
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
37+
private List<ChatRoom> chatRooms = new ArrayList<>();
3738

38-
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
39-
private List<UserChatRoom> userChatRooms;
39+
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
40+
private List<UserChatRoom> userChatRooms = new ArrayList<>();
4041

41-
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
42-
private List<ChatMessage> chatMessages;
42+
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
43+
private List<ChatMessage> chatMessages = new ArrayList<>();
4344

4445
}

โ€Žsrc/main/java/cmf/commitField/domain/user/service/CustomOAuth2UserService.javaโ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.security.oauth2.core.user.OAuth2User;
99
import org.springframework.stereotype.Service;
1010

11+
import java.util.ArrayList;
1112
import java.util.Map;
1213
import java.util.Optional;
1314

@@ -41,7 +42,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) {
4142
user.setAvatarUrl(avatarUrl);
4243
user.setEmail(email); // GitHub์—์„œ ์ด๋ฉ”์ผ์ด ๋ณ€๊ฒฝ๋  ์ˆ˜๋„ ์žˆ์œผ๋‹ˆ ์—…๋ฐ์ดํŠธ\
4344
} else {
44-
user = new User(username, email, name, avatarUrl, User.Role.USER, null, null, null);
45+
user = new User(username, email, name, avatarUrl, User.Role.USER, new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
4546
userRepository.save(user);
4647
}
4748

โ€Žsrc/main/java/cmf/commitField/global/error/ErrorCode.javaโ€Ž

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public enum ErrorCode {
2323
PASSWORD_MISMATCH(HttpStatus.BAD_REQUEST, "๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
2424

2525
// Auth
26+
LOGIN_REQUIRED(HttpStatus.UNAUTHORIZED, "๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค."),
2627
ACCESS_DENIED(HttpStatus.UNAUTHORIZED, "์ธ์ฆ๋˜์ง€ ์•Š์€ ์œ ์ €์ž…๋‹ˆ๋‹ค."),
2728
SC_FORBIDDEN(HttpStatus.UNAUTHORIZED, "๊ถŒํ•œ์ด ์—†๋Š” ์œ ์ €์ž…๋‹ˆ๋‹ค."),
2829
INVALID_JWT_SIGNATURE(HttpStatus.UNAUTHORIZED, "์„œ๋ช… ๊ฒ€์ฆ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค." ),
@@ -36,9 +37,15 @@ public enum ErrorCode {
3637
//chatroom
3738
NOT_FOUND_ROOM(HttpStatus.NOT_FOUND, "์ด๋ฏธ ์‚ญ์ œ๋œ ๋ฐฉ์ด๊ฑฐ๋‚˜ ๋ฐฉ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
3839
ROOM_USER_FULL(HttpStatus.BAD_REQUEST, "๋ฐฉ์— ์‚ฌ์šฉ์ž๊ฐ€ ๋‹ค ์ฐจ ์žˆ์Šต๋‹ˆ๋‹ค."),
39-
NONE_ROOM(HttpStatus.NOT_FOUND, "ํ˜„์žฌ ๋ฐฉ์ด ์—†์Šต๋‹ˆ๋‹ค."),
4040
CHAT_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "์ฑ„ํŒ… ์ „์†ก์— ์˜ค๋ฅ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค."),
41-
NOT_ROOM_CREATOR(HttpStatus.FORBIDDEN, "๋ฐฉ ์ƒ์„ฑ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.");
41+
NO_ROOM_FOUND(HttpStatus.NOT_FOUND, "์ฑ„ํŒ…๋ฐฉ์ด ์—†์Šต๋‹ˆ๋‹ค."),
42+
43+
//user_chatroom
44+
NONE_ROOM(HttpStatus.NOT_FOUND, "์‚ฌ์šฉ์ž๊ฐ€ ๋“ค์–ด๊ฐ€ ์žˆ๋Š” ๋ฐฉ์ด ์—†์Šต๋‹ˆ๋‹ค."),
45+
NOT_ROOM_CREATOR(HttpStatus.FORBIDDEN, "๋ฐฉ ์ƒ์„ฑ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค."),
46+
USER_CREATED_ROOM_NOT_FOUND(HttpStatus.NOT_FOUND, "์‚ฌ์šฉ์ž๊ฐ€ ์ƒ์„ฑํ•œ ๋ฐฉ์ด ์—†์Šต๋‹ˆ๋‹ค."),
47+
ALREADY_JOIN_ROOM(HttpStatus.BAD_REQUEST, "์‚ฌ์šฉ์ž๋Š” ์ด๋ฏธ ํ•ด๋‹น ๋ฐฉ์— ์ฐธ์—ฌํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค."),
48+
NOT_EXIST_CLIENT(HttpStatus.NOT_FOUND, "์ฑ„ํŒ…๋ฐฉ์— ์‚ฌ์šฉ์ž๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");
4249

4350
private final HttpStatus httpStatus;
4451
private final String message;

โ€Žsrc/main/java/cmf/commitField/global/globalDto/GlobalResponse.javaโ€Ž

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,39 @@ private GlobalResponse(ErrorCode errorCode, T data) {
2929
this.data = data;
3030
}
3131

32+
// ๋ฉ”์‹œ์ง€์™€ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›๋Š” ์ƒ์„ฑ์ž
33+
private GlobalResponse(int statusCode, String message, T data) {
34+
this.timestamp = LocalDateTime.now();
35+
this.statusCode = statusCode;
36+
this.message = message;
37+
this.data = data;
38+
}
39+
40+
// ์„ฑ๊ณต ์‘๋‹ต (๋ฐ์ดํ„ฐ ํฌํ•จ)
41+
public static <T> GlobalResponse<T> success(String message, T data) {
42+
return new GlobalResponse<>(GlobalResponseCode.OK.getCode(), message, data);
43+
}
44+
3245
// ์„ฑ๊ณต ์‘๋‹ต (๋ฐ์ดํ„ฐ ํฌํ•จ)
3346
public static <T> GlobalResponse<T> success(T data) {
3447
return new GlobalResponse<>(GlobalResponseCode.OK, data);
3548
}
3649

3750
// ์„ฑ๊ณต ์‘๋‹ต (๋ฐ์ดํ„ฐ ์—†์Œ)
38-
public static <T> GlobalResponse<T> success() {
39-
return success(null);
51+
public static <T> GlobalResponse<T> success(String message) {
52+
return success(message, null);
4053
}
4154

4255
// ์—๋Ÿฌ ์‘๋‹ต (๋ฐ์ดํ„ฐ ํฌํ•จ)
4356
public static <T> GlobalResponse<T> error(ErrorCode errorCode, T data) {
4457
return new GlobalResponse<>(errorCode, data);
4558
}
4659

60+
// ์„ฑ๊ณต ์‘๋‹ต (๊ธฐ๋ณธ ๋ฉ”์„ธ์ง€)
61+
public static <T> GlobalResponse<T> success() {
62+
return success(null);
63+
}
64+
4765
// ์—๋Ÿฌ ์‘๋‹ต (๋ฐ์ดํ„ฐ ์—†์Œ)
4866
public static <T> GlobalResponse<T> error(ErrorCode errorCode) {
4967
return error(errorCode, null);

0 commit comments

Comments
ย (0)