-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from KAKAO-TOUR-API-CONTEST/devyj
Devyj
- Loading branch information
Showing
4 changed files
with
47 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,33 @@ | ||
package com.example.ai_jeju.domain; | ||
|
||
import com.example.ai_jeju.dto.ChatMessageDto; | ||
import com.example.ai_jeju.service.ChatService; | ||
import lombok.Builder; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import lombok.Data; | ||
import org.springframework.web.socket.WebSocketSession; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
@Data | ||
@Entity | ||
public class ChatRoom { | ||
|
||
private static final AtomicInteger idCounter = new AtomicInteger(0); | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String roomId; | ||
private String name; | ||
|
||
// 기본 생성자 | ||
public ChatRoom() { | ||
this.roomId = String.valueOf(idCounter.incrementAndGet()); | ||
} | ||
|
||
// 이름과 ID를 인자로 받는 생성자 | ||
// 이름과 roomId를 인자로 받는 생성자 | ||
public ChatRoom(String roomId, String name) { | ||
this.roomId = roomId; | ||
this.name = name; | ||
} | ||
|
||
public static ChatRoom create(String name) { | ||
ChatRoom chatRoom = new ChatRoom(); | ||
chatRoom.roomId = String.valueOf(idCounter.incrementAndGet()); | ||
chatRoom.name = name; | ||
return chatRoom; | ||
public static ChatRoom create(String roomId, String name) { | ||
return new ChatRoom(roomId, name); | ||
} | ||
} | ||
} |
30 changes: 4 additions & 26 deletions
30
src/main/java/com/example/ai_jeju/repository/ChatRoomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,12 @@ | ||
package com.example.ai_jeju.repository; | ||
|
||
|
||
import com.example.ai_jeju.domain.ChatRoom; | ||
import com.example.ai_jeju.domain.User; | ||
import jakarta.annotation.PostConstruct; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.*; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
public class ChatRoomRepository { | ||
|
||
private Map<String, ChatRoom> chatRoomMap; | ||
|
||
@PostConstruct | ||
private void init() { | ||
chatRoomMap = new LinkedHashMap<>(); | ||
|
||
// RoomId를 1, 2, 3으로 설정하여 방 생성 | ||
chatRoomMap.put("1", new ChatRoom("1", "Room 1")); | ||
chatRoomMap.put("2", new ChatRoom("2", "Room 2")); | ||
chatRoomMap.put("3", new ChatRoom("3", "Room 3")); | ||
} | ||
|
||
public List<ChatRoom> findAllRoom() { | ||
return new ArrayList<>(chatRoomMap.values()); | ||
} | ||
|
||
public ChatRoom findRoomById(String id) { | ||
return chatRoomMap.get(id); | ||
} | ||
} | ||
public interface ChatRoomRepository extends JpaRepository<ChatRoom, Long> { | ||
Optional<ChatRoom> findByRoomId(String roomId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters