Skip to content

Commit

Permalink
add localekeys
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Oct 20, 2024
1 parent 37c405a commit a351cf4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public enum ApiExceptionEnum {
MODEL_NOT_SUPPORTED(19004, LocaleKeys.MODEL_NOT_SUPPORTED),
CHAT_THREAD_NOT_FOUND(19005, LocaleKeys.CHAT_THREAD_NOT_FOUND),
NO_PLATFORM_IN_USE(19006, LocaleKeys.NO_PLATFORM_IN_USE),
PLATFORM_NOT_IN_USE(19007, LocaleKeys.PLATFORM_NOT_IN_USE),
PLATFORM_IS_ACTIVE(19008, LocaleKeys.PLATFORM_IS_ACTIVE),
;

private final Integer code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public enum LocaleKeys {

CHAT_LANGUAGE_PROMPT("chat.language.prompt"),
NO_PLATFORM_IN_USE("no.platform.in.use"),
PLATFORM_NOT_IN_USE("platform.not.in.use"),
PLATFORM_IS_ACTIVE("platform.is.active"),
;

private final String key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private AIAssistant buildAIAssistant(
public ChatThreadVO createChatThreads() {
AuthPlatformPO authPlatformPO = getActiveAuthPlatform();
if (authPlatformPO == null || authPlatformPO.getIsDeleted()) {
throw new ApiException(ApiExceptionEnum.PLATFORM_NOT_AUTHORIZED);
throw new ApiException(ApiExceptionEnum.NO_PLATFORM_IN_USE);
}
AuthPlatformDTO authPlatformDTO = AuthPlatformConverter.INSTANCE.fromPO2DTO(authPlatformPO);
Long userId = SessionUserHolder.getUserId();
Expand Down Expand Up @@ -151,10 +151,8 @@ public boolean deleteChatThreads(Long threadId) {
chatThreadPO.setIsDeleted(true);
chatThreadDao.partialUpdateById(chatThreadPO);
List<ChatMessagePO> chatMessagePOS = chatMessageDao.findAllByThreadId(threadId);
for (ChatMessagePO chatMessagePO : chatMessagePOS) {
chatMessagePO.setIsDeleted(true);
chatMessageDao.partialUpdateById(chatMessagePO);
}
chatMessagePOS.forEach(chatMessagePO -> chatMessagePO.setIsDeleted(true));
chatMessageDao.partialUpdateByIds(chatMessagePOS);

return true;
}
Expand Down Expand Up @@ -187,8 +185,10 @@ public SseEmitter talk(Long threadId, String message) {
throw new ApiException(ApiExceptionEnum.CHAT_THREAD_NOT_FOUND);
}
AuthPlatformPO authPlatformPO = getActiveAuthPlatform();
if (authPlatformPO == null) {
throw new ApiException(ApiExceptionEnum.NO_PLATFORM_IN_USE);
if (authPlatformPO == null
|| authPlatformPO.getIsDeleted()
|| !authPlatformPO.getId().equals(chatThreadPO.getAuthId())) {
throw new ApiException(ApiExceptionEnum.PLATFORM_NOT_IN_USE);
}
AuthPlatformDTO authPlatformDTO = AuthPlatformConverter.INSTANCE.fromPO2DTO(authPlatformPO);
ChatThreadDTO chatThreadDTO = ChatThreadConverter.INSTANCE.fromPO2DTO(chatThreadPO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ public boolean deleteAuthorizedPlatform(Long authId) {
throw new ApiException(ApiExceptionEnum.PLATFORM_NOT_AUTHORIZED);
}

if (AuthPlatformStatus.isActive(authPlatformPO.getStatus())) {
throw new ApiException(ApiExceptionEnum.PLATFORM_IS_ACTIVE);
}

authPlatformPO.setIsDeleted(true);
authPlatformDao.partialUpdateById(authPlatformPO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ config.not.found=Config not exist
command.not.found=Command not found for level [{0}]
command.not.supported=Command [{0}] not supported for level [{1}]

platform.not.found=platform not found
platform.not.authorized=platform not authorized
permission.denied=permission denied
credit.incorrect=credit incorrect
model.not.supported=model not supported
chat.thread.not.found=chat thread not found
no.platform.in.use=no platform currently in use
platform.not.found=Platform not found
platform.not.authorized=Platform not authorized
permission.denied=Permission denied
credit.incorrect=Credit incorrect
model.not.supported=Model not supported
chat.thread.not.found=Chat thread not found
no.platform.in.use=No platform currently in use
platform.not.in.use=Corresponding platform not use
platform.is.active=The platform is active
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ credit.incorrect=凭证不正确
model.not.supported=模型不支持
chat.thread.not.found=线程不存在
no.platform.in.use=没有正在使用的平台
platform.not.in.use=对应的平台未使用
platform.is.active=平台正在使用

0 comments on commit a351cf4

Please sign in to comment.