Skip to content

Commit 5e17619

Browse files
committed
♻️Refactor: 동호회 생성과 채팅방 생성 같은 요청 안에서 로직 처리
1 parent 9f42107 commit 5e17619

File tree

10 files changed

+33
-577
lines changed

10 files changed

+33
-577
lines changed

assets/stomp-test.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@
413413
}
414414

415415
const socket = new SockJS(
416-
"http://localhost:8080/ws",
416+
"http://localhost:8080/ws-stomp",
417417
null,
418418
{ transports: ["xhr-streaming", "xhr-polling"] } // ✅ opCode=7 우회
419419
);
@@ -442,7 +442,7 @@
442442
}
443443

444444
const rid = roomIdValue();
445-
const dest = `/topic/chat/rooms/${rid}`;
445+
const dest = `/sub/chat/rooms/${rid}`;
446446
$("roomTitle").textContent = `room: ${rid}`;
447447

448448
currentSub = stompClient.subscribe(dest, (frame) => {
@@ -459,10 +459,10 @@
459459
});
460460
}
461461
});
462-
stompClient.send("/app/chat.join", {}, JSON.stringify({
462+
stompClient.send("/pub/chat.join", {}, JSON.stringify({
463463
roomId: Number(roomIdValue()),
464-
userId: myUserId(),
465-
nickname: myNickname()
464+
senderUserId: myUserId(),
465+
senderNickname: myNickname()
466466
}));
467467
setSub("subscribed: " + dest);
468468
debug("[SUBSCRIBED] " + dest);
@@ -490,7 +490,7 @@
490490
content: text
491491
};
492492

493-
stompClient.send("/app/chat.send", {}, JSON.stringify(payload));
493+
stompClient.send("/pub/chat.send", {}, JSON.stringify(payload));
494494
debug("[SENT] " + JSON.stringify(payload));
495495

496496
contentEl.value = "";
@@ -501,10 +501,10 @@
501501

502502
// 🔽 여기 먼저
503503
if (stompClient && stompClient.connected) {
504-
stompClient.send("/app/chat.leave", {}, JSON.stringify({
504+
stompClient.send("/pub/chat.leave", {}, JSON.stringify({
505505
roomId: Number(roomIdValue()),
506-
userId: myUserId(),
507-
nickname: myNickname()
506+
senderUserId: myUserId(),
507+
senderNickname: myNickname()
508508
}));
509509
}
510510

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.be.sportizebe.domain.auth.dto.request;
22

3+
import io.swagger.v3.oas.annotations.media.Schema;
34
import jakarta.validation.constraints.Email;
45
import jakarta.validation.constraints.NotBlank;
56

67
public record LoginRequest(
78
@NotBlank(message = "아이디를 입력해주세요.")
89
@Email(message = "아이디는 이메일 형식만 지원합니다.")
10+
@Schema(description = "사용자 아이디(이메일 형식)", example = "user@example.com")
911
String username,
1012

1113
@NotBlank(message = "비밀번호를 입력해주세요.")
14+
@Schema(description = "비밀번호", example = "password123")
1215
String password
1316
) {
1417
}

src/main/java/com/be/sportizebe/domain/chat/service/ChatRoomService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.be.sportizebe.domain.chat.entity.ChatRoom;
44
import com.be.sportizebe.domain.chat.exception.ChatErrorCode;
55
import com.be.sportizebe.domain.chat.repository.ChatRoomRepository;
6+
import com.be.sportizebe.domain.club.entity.Club;
67
import com.be.sportizebe.domain.post.entity.Post;
78
import com.be.sportizebe.domain.user.entity.User;
89
import com.be.sportizebe.global.exception.CustomException;
@@ -19,10 +20,11 @@ public class ChatRoomService {
1920
private final ChatRoomRepository chatRoomRepository;
2021

2122
@Transactional
22-
public ChatRoom createGroup(String name) {
23+
public ChatRoom createGroup(Club club) {
2324
ChatRoom room = ChatRoom.builder()
24-
.chatRoomType(ChatRoom.ChatRoomType.GROUP)
25-
.build();
25+
.chatRoomType(ChatRoom.ChatRoomType.GROUP)
26+
.club(club)
27+
.build();
2628
return chatRoomRepository.save(room);
2729
}
2830

src/main/java/com/be/sportizebe/domain/club/controller/ClubController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ public class ClubController {
2727
@PostMapping("/{sportType}")
2828
@Operation(summary = "동호회 생성", description = "종목별 동호회를 생성합니다. 생성한 사용자가 동호회장이 됩니다.")
2929
public ResponseEntity<BaseResponse<ClubResponse>> createClub(
30-
@Parameter(description = "종목 (SOCCER, BASKETBALL)") @PathVariable SportType sportType,
3130
@RequestBody @Valid ClubCreateRequest request,
3231
@AuthenticationPrincipal User user) {
33-
ClubResponse response = clubService.createClub(sportType, request, user);
32+
ClubResponse response = clubService.createClub(request, user);
3433
return ResponseEntity.status(HttpStatus.CREATED)
3534
.body(BaseResponse.success("동호회 생성 성공", response));
3635
}

src/main/java/com/be/sportizebe/domain/club/dto/request/ClubCreateRequest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
import com.be.sportizebe.domain.club.entity.Club;
44
import com.be.sportizebe.domain.user.entity.SportType;
55
import com.be.sportizebe.domain.user.entity.User;
6+
import io.swagger.v3.oas.annotations.media.Schema;
67
import jakarta.validation.constraints.NotBlank;
78

89
public record ClubCreateRequest(
910
@NotBlank(message = "동호회 이름은 필수 입니다.")
10-
String name,
11-
String introduce,
12-
Integer maxMembers) {
11+
@Schema(description = "동호회 이름", example = "축구 동호회") String name,
12+
@Schema(description = "동호회 소개", example = "매주 토요일 축구합니다") String introduce,
13+
@Schema(description = "최대 정원", example = "20") Integer maxMembers) {
1314
// 관련 종목은 파라미터로 받음
1415
// TODO : S3 세팅 후 imgUrl은 multipartform으로 변경
1516

16-
public Club toEntity(SportType sportType, User user) {
17+
public Club toEntity(User user) {
1718
return Club.builder()
1819
.name(name)
1920
.introduce(introduce)
2021
.maxMembers(maxMembers)
21-
.sportType(sportType)
2222
.leader(user)
2323
.build();
2424
}

src/main/java/com/be/sportizebe/domain/club/dto/response/ClubResponse.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public record ClubResponse(
1111
@Schema(description = "동호회 ID", example = "1") Long clubId,
1212
@Schema(description = "동호회 이름", example = "축구 동호회") String name,
1313
@Schema(description = "동호회 소개", example = "매주 토요일 축구합니다") String introduce,
14-
@Schema(description = "종목", example = "SOCCER") SportType sportType,
1514
@Schema(description = "최대 정원", example = "20") Integer maxMembers,
1615
@Schema(description = "동호회장 닉네임", example = "닉네임") String leaderNickname) {
1716

@@ -20,7 +19,6 @@ public static ClubResponse from(Club club) {
2019
.clubId(club.getId())
2120
.name(club.getName())
2221
.introduce(club.getIntroduce())
23-
.sportType(club.getSportType())
2422
.maxMembers(club.getMaxMembers())
2523
.leaderNickname(club.getLeader().getNickname())
2624
.build();

src/main/java/com/be/sportizebe/domain/club/entity/Club.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@ public class Club extends BaseTimeEntity {
2525
private Long id;
2626

2727
@Column(nullable = false, unique = true)
28-
private String name; // 동호회 이름
28+
private String name; // 동호회 이름 == 단테 채팅방 이름
2929

3030
@Column(columnDefinition = "TEXT")
3131
private String introduce; // 동호회 소개글
3232

33-
@Enumerated(EnumType.STRING)
34-
@Column(nullable = false)
35-
private SportType sportType; // 동호회의 종목
36-
3733
@Column(nullable = false)
3834
private Integer maxMembers; // 최대 정원
3935

src/main/java/com/be/sportizebe/domain/club/service/ClubService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
import com.be.sportizebe.domain.user.entity.User;
77

88
public interface ClubService {
9-
ClubResponse createClub(SportType sportType, ClubCreateRequest request, User user); // 동호회 생성
9+
ClubResponse createClub(ClubCreateRequest request, User user); // 동호회 생성
1010
}

src/main/java/com/be/sportizebe/domain/club/service/ClubServiceImpl.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.be.sportizebe.domain.club.service;
22

3+
import com.be.sportizebe.domain.chat.service.ChatRoomService;
34
import com.be.sportizebe.domain.club.dto.request.ClubCreateRequest;
45
import com.be.sportizebe.domain.club.dto.response.ClubResponse;
56
import com.be.sportizebe.domain.club.entity.Club;
@@ -20,17 +21,18 @@
2021
public class ClubServiceImpl implements ClubService {
2122

2223
private final ClubRepository clubRepository;
24+
private final ChatRoomService chatRoomService;
2325
private final ClubMemberRepository clubMemberRepository;
2426

2527
@Override
2628
@Transactional
27-
public ClubResponse createClub(SportType sportType, ClubCreateRequest request, User user) {
29+
public ClubResponse createClub(ClubCreateRequest request, User user) {
2830
if (clubRepository.existsByName(request.name())) {
2931
throw new CustomException(ClubErrorCode.CLUB_NAME_DUPLICATED);
3032
}
3133

32-
33-
Club club = request.toEntity(sportType, user);
34+
// 동호회 엔티티 생성
35+
Club club = request.toEntity(user);
3436
clubRepository.save(club);
3537

3638
ClubMember leaderMember = ClubMember.builder()
@@ -40,6 +42,9 @@ public ClubResponse createClub(SportType sportType, ClubCreateRequest request, U
4042
.build();
4143
clubMemberRepository.save(leaderMember);
4244

45+
// 동호회 단체 채팅방 생성
46+
chatRoomService.createGroup(club);
47+
4348
return ClubResponse.from(club);
4449
}
4550
}

0 commit comments

Comments
 (0)