Skip to content

Commit

Permalink
Merge pull request #51 from oven-2023/feature/chat
Browse files Browse the repository at this point in the history
feat: add get my chatrooms api
  • Loading branch information
haen-su authored Nov 2, 2023
2 parents 78498b2 + 6f5bd09 commit 4959199
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public Response<List<ChatroomListDto>> getChatroomList(@RequestParam(value = "pr

}

@Operation(summary = "내 구독방 조회 API")
@GetMapping(value = "/chatrooms/my")
public Response<List<ChatroomListDto>> getMyChatroomList(@AuthenticationPrincipal User user) {

return Response.success(ResponseCode.SUCCESS_OK, getChatroomService.getMyChatroomList(user));

}

@Operation(summary = "채팅방 생성 API")
@PostMapping(value = "/chatrooms")
public Response<CreateChatroomResponse> createChatroom(@AuthenticationPrincipal User user,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/oven/server/api/chat/domain/Entrance.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.oven.server.common.BaseEntity;
import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor
public class Entrance extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface EntranceRepository extends JpaRepository<Entrance, Long> {

Optional<Entrance> findByUserAndChatroom(User user, Chatroom chatroom);

List<Entrance> findByUser(User user);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.oven.server.api.chat.domain.Chatroom;
import com.oven.server.api.chat.dto.response.ChatroomListDto;
import com.oven.server.api.chat.repository.ChatroomRepository;
import com.oven.server.api.chat.repository.EntranceRepository;
import com.oven.server.api.user.domain.User;
import com.oven.server.api.work.domain.Provider;
import com.oven.server.api.work.repository.ProviderRepository;
import com.oven.server.common.exception.BaseException;
Expand All @@ -22,6 +24,7 @@ public class GetChatroomService {

private final ChatroomRepository chatroomRepository;
private final ProviderRepository providerRepository;
private final EntranceRepository entranceRepository;

public List<ChatroomListDto> getChatroomList(Long providerId) {

Expand Down Expand Up @@ -50,4 +53,20 @@ public List<ChatroomListDto> getChatroomList(Long providerId) {

}

public List<ChatroomListDto> getMyChatroomList(User user) {

return entranceRepository.findByUser(user)
.stream()
.map(
entrance -> ChatroomListDto.builder()
.chatroomId(entrance.getChatroom().getId())
.providerId(entrance.getChatroom().getProvider().getId())
.title(entrance.getChatroom().getTitle())
.count(entrance.getChatroom().getCount())
.wholeNum(entrance.getChatroom().getWholeNum())
.build()
).collect(Collectors.toList());

}

}

0 comments on commit 4959199

Please sign in to comment.