Skip to content

Commit

Permalink
Address comments from Adrian
Browse files Browse the repository at this point in the history
  • Loading branch information
TaoChenOSU committed Apr 28, 2023
1 parent deda587 commit 25c5a6a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace SemanticKernel.Service.Controllers;

/// <summary>
/// Controller for chat history.
/// This controller is responsible for creating new chat sessions, retrieving chat sessions,
/// retrieving chat messages, and editing chat sessions.
/// </summary>
[ApiController]
[Authorize]
Expand Down Expand Up @@ -45,11 +47,11 @@ public class ChatHistoryController : ControllerBase
/// <param name="chatParameters">Object that contains the parameters to create a new chat.</param>
/// <returns>The HTTP action result.</returns>
[HttpPost]
[Route("chat/create")]
[Route("chatSession/create")]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> CreateChatAsync(
public async Task<IActionResult> CreateChatSessionAsync(
[FromBody] ChatSession chatParameters)
{
var userId = chatParameters.UserId;
Expand All @@ -62,20 +64,20 @@ public class ChatHistoryController : ControllerBase
await this.SaveResponseAsync(initialBotMessage, newChat.Id);

this._logger.LogDebug("Created chat session with id {0} for user {1}.", newChat.Id, userId);
return this.CreatedAtAction(nameof(this.GetChatByIdAsync), new { chatId = newChat.Id }, newChat);
return this.CreatedAtAction(nameof(this.GetChatSessionByIdAsync), new { chatId = newChat.Id }, newChat);
}

/// <summary>
/// Get a chat session by id.
/// </summary>
/// <param name="chatId">The chat id.</param>
[HttpGet]
[ActionName("GetChatByIdAsync")]
[Route("chat/getChat/{chatId:guid}")]
[ActionName("GetChatSessionByIdAsync")]
[Route("chatSession/getChat/{chatId:guid}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetChatByIdAsync(Guid chatId)
public async Task<IActionResult> GetChatSessionByIdAsync(Guid chatId)
{
var chat = await this._chatSessionRepository.FindByIdAsync(chatId.ToString());
if (chat == null)
Expand All @@ -88,14 +90,17 @@ public async Task<IActionResult> GetChatByIdAsync(Guid chatId)

/// <summary>
/// Get all chat sessions associated with a user. Return an empty list if no chats are found.
/// The regex pattern that is used to match the user id will match the following format:
/// - 2 period separated groups of one or more hyphen-delimitated alphanumeric strings.
/// The pattern matches two GUIDs in canonical textual representation separated by a period.
/// </summary>
/// <param name="userId">The user id.</param>
[HttpGet]
[Route("chat/getAllChats/{userId:regex(([[a-z0-9]]+-)+[[a-z0-9]]+\\.([[a-z0-9]]+-)+[[a-z0-9]]+)}")]
[Route("chatSession/getAllChats/{userId:regex(([[a-z0-9]]+-)+[[a-z0-9]]+\\.([[a-z0-9]]+-)+[[a-z0-9]]+)}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetAllChatsAsync(string userId)
public async Task<IActionResult> GetAllChatSessionsAsync(string userId)
{
var chats = await this._chatSessionRepository.FindByUserIdAsync(userId);
if (chats == null)
Expand All @@ -116,7 +121,7 @@ public async Task<IActionResult> GetAllChatsAsync(string userId)
/// <param name="count">The number of messages to return. -1 will return all messages starting from startIdx.</param>
/// [Authorize]
[HttpGet]
[Route("chat/getChatMessages/{chatId:guid}")]
[Route("chatSession/getChatMessages/{chatId:guid}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
Expand Down Expand Up @@ -149,11 +154,11 @@ public async Task<IActionResult> GetAllChatsAsync(string userId)
/// </summary>
/// <param name="chatParameters">Object that contains the parameters to edit the chat.</param>
[HttpPost]
[Route("chat/edit")]
[Route("chatSession/edit")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> EditChatAsync([FromBody] ChatSession chatParameters)
public async Task<IActionResult> EditChatSessionAsync([FromBody] ChatSession chatParameters)
{
var chatId = chatParameters.Id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ChatService extends BaseService {

const result = await this.getResponseAsync<IChatSession>(
{
commandPath: 'chat/create',
commandPath: 'chatSession/create',
method: 'POST',
body: body,
},
Expand All @@ -38,7 +38,7 @@ export class ChatService extends BaseService {
): Promise<IChatSession> => {
const result = await this.getResponseAsync<IChatSession>(
{
commandPath: `chat/getChat/${chatId}`,
commandPath: `chatSession/getChat/${chatId}`,
method: 'GET',
},
accessToken,
Expand All @@ -55,7 +55,7 @@ export class ChatService extends BaseService {
): Promise<IChatSession[]> => {
const result = await this.getResponseAsync<IChatSession[]>(
{
commandPath: `chat/getAllChats/${userId}`,
commandPath: `chatSession/getAllChats/${userId}`,
method: 'GET',
},
accessToken,
Expand All @@ -73,7 +73,7 @@ export class ChatService extends BaseService {
): Promise<IChatMessage[]> => {
const result = await this.getResponseAsync<IChatMessage[]>(
{
commandPath: `chat/getChatMessages/${chatId}?startIdx=${startIdx}&count=${count}`,
commandPath: `chatSession/getChatMessages/${chatId}?startIdx=${startIdx}&count=${count}`,
method: 'GET',
},
accessToken,
Expand All @@ -97,7 +97,7 @@ export class ChatService extends BaseService {

const result = await this.getResponseAsync<any>(
{
commandPath: `chat/edit`,
commandPath: `chatSession/edit`,
method: 'POST',
body: body,
},
Expand Down

0 comments on commit 25c5a6a

Please sign in to comment.