Skip to content

Commit

Permalink
add some function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin_Zhang committed Feb 11, 2025
1 parent e39ceec commit acd5eca
Show file tree
Hide file tree
Showing 171 changed files with 7,593 additions and 193 deletions.
6 changes: 6 additions & 0 deletions .idea/.idea.luminabrain/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions LuminaBrain.Application.Service/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace LuminaBrain.Application.Service;

public class Class1
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\LuminaBrain.Application\LuminaBrain.Application.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using FastWiki.Application.Contract.Notification;
using FastWiki.Application.Contract.Notification.Dto;

namespace LuminaBrain.Application.Service.Notification;

public class NotificationService(ICaptcha captcha) : INotificationService, IScopeDependency

Check failure on line 6 in LuminaBrain.Application.Service/Notification/NotificationService.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IScopeDependency' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in LuminaBrain.Application.Service/Notification/NotificationService.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ICaptcha' could not be found (are you missing a using directive or an assembly reference?)
{
public Task<VerificationDto> GetLoginVerificationCodeAsync()
{
var uuid = "login:" + Guid.NewGuid().ToString("N");

var code = captcha.Generate(uuid, 240);

return Task.FromResult(new VerificationDto
{
Key = uuid,
Code = "data:image/png;base64," + code.Base64
});
}

public Task<string> GetRegisterVerificationCodeAsync(string account)
{
var uuid = "register:" + account;

var code = captcha.Generate(uuid, 240);

return Task.FromResult(code.Base64);
}
}
23 changes: 23 additions & 0 deletions LuminaBrain.Application.Service/OpenAI/ChatCompleteService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using FastWiki.Application.Contract.OpenAI;
using FastWiki.Application.Contract.OpenAI.Dto;
using LuminaBrain.Core.Exceptions;

namespace LuminaBrain.Application.Service.OpenAI;

public class ChatCompleteService(
IHttpContextAccessor httpContextAccessor,
IAgentService agentService) : IChatCompleteService
{
public async Task ChatCompleteAsync(ChatCompleteInput input)
{
var httpContext = httpContextAccessor.HttpContext;
var agent = await agentService.GetAsync(input.AgentId);

if (agent == null)
{
throw new BusinessException("未找到对应的Agent");
}


}
}
67 changes: 67 additions & 0 deletions LuminaBrain.Application.Service/Powers/PowersService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using FastWiki.Application.Contract.Powers;
using FastWiki.Application.Contract.Powers.Dto;
using FastWiki.Application.Contract.Powers.Input;
using LuminaBrain.Core.Exceptions;

namespace LuminaBrain.Application.Service.Powers;

public class PowersService(IRoleRepository roleRepository, IMapper mapper) : IPowersService, IScopeDependency
{
public async Task CreateRoleAsync(RoleInput input)
{
var role = new Role(input.Name, input.Description, input.Code);

await roleRepository.CreateAsync(role);
}

public async Task UpdateRoleAsync(string id, RoleInput input)
{
var role = await roleRepository.SingleOrDefaultAsync(r => r.Id == id.ToString());
if (role == null)
{
throw new UserFriendlyException("角色不存在");
}

role.SetName(input.Name);
role.SetDescription(input.Description);
role.SetCode(input.Code);

await roleRepository.UpdateAsync(role);
}

public async Task DeleteRoleAsync(string id)
{
var role = await roleRepository.SingleOrDefaultAsync(r => r.Id == id.ToString());
if (role == null)
{
throw new UserFriendlyException("角色不存在");
}

await roleRepository.DeleteAsync(role);
}

public async Task<List<RoleDto>> GetRolesAsync()
{
var roles = await roleRepository.ListAsync();

var result = mapper.Map<List<RoleDto>>(roles);

return result;
}

public async Task BindUserRoleAsync(string userId, List<string> roleIds)
{
await roleRepository.DeleteUserRolesAsync(userId);

await roleRepository.BindUserRoleAsync(userId, roleIds);
}

public async Task<List<RoleDto>> GetUserRolesAsync(string userId)
{
var roles = roleRepository.GetRolesAsync(userId);

var result = mapper.Map<List<RoleDto>>(await roles);

return result;
}
}
63 changes: 63 additions & 0 deletions LuminaBrain.Application.Service/Users/UserService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using FastWiki.Core;

Check failure on line 1 in LuminaBrain.Application.Service/Users/UserService.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Core' does not exist in the namespace 'FastWiki' (are you missing an assembly reference?)
using FastWiki.Domain.Users.Aggregates;

Check failure on line 2 in LuminaBrain.Application.Service/Users/UserService.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Domain' does not exist in the namespace 'FastWiki' (are you missing an assembly reference?)
using MapsterMapper;

Check failure on line 3 in LuminaBrain.Application.Service/Users/UserService.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'MapsterMapper' could not be found (are you missing a using directive or an assembly reference?)

namespace FastWiki.Application.Users;

public class UserService(IUserRepository userRepository, IMapper mapper, IUserContext userContext)

Check failure on line 7 in LuminaBrain.Application.Service/Users/UserService.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IUserRepository' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 7 in LuminaBrain.Application.Service/Users/UserService.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IMapper' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 7 in LuminaBrain.Application.Service/Users/UserService.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IUserContext' could not be found (are you missing a using directive or an assembly reference?)
: IUserService, IScopeDependency

Check failure on line 8 in LuminaBrain.Application.Service/Users/UserService.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IUserService' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 8 in LuminaBrain.Application.Service/Users/UserService.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IScopeDependency' could not be found (are you missing a using directive or an assembly reference?)
{
public async Task<string> CreateAsync(CreateUserInput input)
{
var user = mapper.Map<User>(input);

user.SetPassword(input.Password);
user.SetEmail(input.Email);

user = await userRepository.CreateAsync(user);

return user.Id;
}

public async Task UpdateAsync(string id, UpdateUserInput input)
{
var user = await userRepository.GetAsync(id);
if (user == null)
{
throw new UserFriendlyException("用户不存在");
}

user.SetEmail(input.Email);
user.SetName(input.Name);
user.SetIntroduction(input.Introduction);

await userRepository.UpdateAsync(user);
}

public async Task DeleteAsync(string id)
{
var user = await userRepository.GetAsync(id);
if (user == null)
{
throw new UserFriendlyException("用户不存在");
}

await userRepository.DeleteAsync(user);
}

public async Task<PagedResultDto<UserDto>> GetListAsync(string? keyword, int page, int pageSize)
{
var users = await userRepository.GetListAsync(keyword, page, pageSize);

var count = await userRepository.GetCountAsync(keyword);

return new PagedResultDto<UserDto>(count, users.Select(mapper.Map<UserDto>).ToList());
}

public async Task<UserDto> GetCurrentAsync()
{
var user = await userRepository.GetAsync(userContext.UserId);

return mapper.Map<UserDto>(user);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("LuminaBrain.Application.Service")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e39ceec3274b766a6dd15f8d21c9e05584d3714e")]
[assembly: System.Reflection.AssemblyProductAttribute("LuminaBrain.Application.Service")]
[assembly: System.Reflection.AssemblyTitleAttribute("LuminaBrain.Application.Service")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
84a1ab6da88c2b4853e508baffef0e31d26998fb86c644bd8c936648eb3b0989
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
is_global = true
build_property.TargetFramework = net9.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = LuminaBrain.Application.Service
build_property.ProjectDir = F:\code\Austin\luminabrain\LuminaBrain.Application.Service\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.EffectiveAnalysisLevelStyle = 9.0
build_property.EnableCodeStyleSeverity =
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
Binary file not shown.
Loading

0 comments on commit acd5eca

Please sign in to comment.