Skip to content

Commit

Permalink
add detail
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Dec 3, 2024
1 parent d66fe9b commit 7cf44f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
*/
package org.apache.bigtop.manager.server.model.converter;

import org.apache.bigtop.manager.dao.po.AuthPlatformPO;
import org.apache.bigtop.manager.dao.po.ChatThreadPO;
import org.apache.bigtop.manager.dao.po.PlatformPO;
import org.apache.bigtop.manager.server.config.MapStructSharedConfig;
import org.apache.bigtop.manager.server.model.dto.ChatThreadDTO;
import org.apache.bigtop.manager.server.model.req.ChatbotThreadReq;
import org.apache.bigtop.manager.server.model.vo.ChatThreadVO;

import org.mapstruct.Context;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
Expand All @@ -35,7 +38,10 @@ public interface ChatThreadConverter {
ChatThreadConverter INSTANCE = Mappers.getMapper(ChatThreadConverter.class);

@Mapping(source = "id", target = "threadId")
ChatThreadVO fromPO2VO(ChatThreadPO platformAuthorizedPO);
@Mapping(target = "model", expression = "java(authPlatformPO.getModel())")
@Mapping(target = "platformName", expression = "java(platformPO.getName())")
ChatThreadVO fromPO2VO(
ChatThreadPO platformAuthorizedPO, @Context AuthPlatformPO authPlatformPO, @Context PlatformPO platformPO);

ChatThreadPO fromDTO2PO(ChatThreadDTO chatThreadDTO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class ChatThreadVO {

private String name;

private String platformName;

private String model;

private String createTime;

private String updateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public ChatThreadVO createChatThread(ChatThreadDTO chatThreadDTO) {
ChatThreadPO chatThreadPO = ChatThreadConverter.INSTANCE.fromDTO2PO(chatThreadDTO);
chatThreadPO.setUserId(userId);
chatThreadDao.save(chatThreadPO);
return ChatThreadConverter.INSTANCE.fromPO2VO(chatThreadPO);
return ChatThreadConverter.INSTANCE.fromPO2VO(chatThreadPO, authPlatformPO, platformPO);
}

@Override
Expand All @@ -165,6 +165,8 @@ public List<ChatThreadVO> getAllChatThreads() {
if (authPlatformPO == null) {
throw new ApiException(ApiExceptionEnum.NO_PLATFORM_IN_USE);
}
PlatformPO platformPO = platformDao.findById(authPlatformPO.getPlatformId());

Long authId = authPlatformPO.getId();
Long userId = SessionUserHolder.getUserId();
List<ChatThreadPO> chatThreadPOS = chatThreadDao.findAllByAuthIdAndUserId(authId, userId);
Expand All @@ -173,7 +175,8 @@ public List<ChatThreadVO> getAllChatThreads() {
if (chatThreadPO.getIsDeleted()) {
continue;
}
ChatThreadVO chatThreadVO = ChatThreadConverter.INSTANCE.fromPO2VO(chatThreadPO);
ChatThreadVO chatThreadVO =
ChatThreadConverter.INSTANCE.fromPO2VO(chatThreadPO, authPlatformPO, platformPO);
chatThreads.add(chatThreadVO);
}
return chatThreads;
Expand Down Expand Up @@ -282,7 +285,9 @@ public ChatThreadVO updateChatThread(ChatThreadDTO chatThreadDTO) {
chatThreadPO.setName(chatThreadDTO.getName());
chatThreadDao.partialUpdateById(chatThreadPO);

return ChatThreadConverter.INSTANCE.fromPO2VO(chatThreadPO);
AuthPlatformPO authPlatformPO = authPlatformDao.findById(chatThreadPO.getAuthId());
return ChatThreadConverter.INSTANCE.fromPO2VO(
chatThreadPO, authPlatformPO, platformDao.findById(authPlatformPO.getPlatformId()));
}

@Override
Expand All @@ -295,6 +300,8 @@ public ChatThreadVO getChatThread(Long threadId) {
if (!chatThreadPO.getUserId().equals(userId)) {
throw new ApiException(ApiExceptionEnum.PERMISSION_DENIED);
}
return ChatThreadConverter.INSTANCE.fromPO2VO(chatThreadPO);
AuthPlatformPO authPlatformPO = authPlatformDao.findById(chatThreadPO.getAuthId());
return ChatThreadConverter.INSTANCE.fromPO2VO(
chatThreadPO, authPlatformPO, platformDao.findById(authPlatformPO.getPlatformId()));
}
}

0 comments on commit 7cf44f2

Please sign in to comment.