refine get agent

This commit is contained in:
Jicheng Lu 2023-08-28 00:36:11 -05:00
parent d7d0af2c15
commit 1bf8ecdc38
3 changed files with 10 additions and 2 deletions

View file

@ -27,9 +27,10 @@ public partial class AgentService
record.CreatedTime = DateTime.UtcNow;
record.UpdatedTime = DateTime.UtcNow;
var user = db.User.FirstOrDefault(x => x.ExternalId == _user.Id);
var userAgentRecord = new UserAgentRecord
{
UserId = _user.Id,
UserId = user?.Id ?? ObjectId.GenerateNewId().ToString(),
AgentId = record.Id,
CreatedTime = DateTime.UtcNow,
UpdatedTime = DateTime.UtcNow

View file

@ -11,7 +11,8 @@ public partial class AgentService
var db = _services.GetRequiredService<IBotSharpRepository>();
var query = from a in db.Agent
join ua in db.UserAgent on a.Id equals ua.AgentId
where ua.UserId == _user.Id
join u in db.User on ua.UserId equals u.Id
where u.ExternalId == _user.Id
select a.ToAgent();
return query.ToList();
}

View file

@ -7,6 +7,9 @@ public class AgentViewModel
public string Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Instruction { get; set; }
public string Functions { get; set; }
public List<string> Routes { get; set; }
public DateTime UpdatedDateTime { get; set; }
public static AgentViewModel FromAgent(Agent agent)
@ -16,6 +19,9 @@ public class AgentViewModel
Id = agent.Id,
Name = agent.Name,
Description = agent.Description,
Instruction = agent.Instruction,
Functions = agent.Functions,
Routes = agent.Routes,
UpdatedDateTime = agent.UpdatedDateTime
};
}