-
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 #103 from Hanaemong/hyeonu
Hyeonu
- Loading branch information
Showing
5 changed files
with
48 additions
and
6 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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/hana/hanalink/chat/controller/ChatRestController.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.hana.hanalink.chat.controller; | ||
|
||
import com.hana.hanalink.chat.domain.Chat; | ||
import com.hana.hanalink.chat.service.ChatService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Flux; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/chat") | ||
@RequiredArgsConstructor | ||
public class ChatRestController { | ||
private final ChatService chatService; | ||
|
||
@GetMapping("/{roomId}") | ||
public Flux<Chat> getChatsByRoomId(@PathVariable String roomId) { | ||
return chatService.getChatsByRoomId(roomId); | ||
} | ||
} |
9 changes: 7 additions & 2 deletions
9
src/main/java/com/hana/hanalink/chat/repository/ChatRepository.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,7 +1,12 @@ | ||
package com.hana.hanalink.chat.repository; | ||
|
||
import com.hana.hanalink.chat.domain.Chat; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.data.mongodb.repository.ReactiveMongoRepository; | ||
import org.springframework.stereotype.Repository; | ||
import reactor.core.publisher.Flux; | ||
|
||
public interface ChatRepository extends MongoRepository<Chat, String> { | ||
|
||
@Repository | ||
public interface ChatRepository extends ReactiveMongoRepository<Chat, String> { | ||
Flux<Chat> findByRoomId(String roomId); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/hana/hanalink/chat/service/ChatService.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,17 +1,27 @@ | ||
package com.hana.hanalink.chat.service; | ||
|
||
import com.hana.hanalink.chat.domain.Chat; | ||
import com.hana.hanalink.chat.repository.ChatRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate; | ||
import org.springframework.stereotype.Service; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ChatService { | ||
private final ReactiveMongoTemplate reactiveMongoTemplate; | ||
private final ChatRepository chatRepository; | ||
|
||
|
||
public Mono<Chat> saveChat(Chat chat) { | ||
return reactiveMongoTemplate.save(chat); | ||
} | ||
|
||
public Flux<Chat> getChatsByRoomId(String roomId) { | ||
return chatRepository.findByRoomId(roomId); | ||
} | ||
} |