网站首页 网站源码
website
站点相关全部源代码,隐藏了一些关于服务器的信息
namespace Dpz.Core.Service.RepositoryServiceImpl;

public class CodeNoteService : ICodeNoteService
{
    private readonly IRepository<CodeNote> _repository;
    private readonly IMapper _mapper;

    public CodeNoteService(IRepository<CodeNote> repository, IMapper mapper)
    {
        _repository = repository;
        _mapper = mapper;
    }

    public async Task<string> SaveNoteAsync(string[]? path, string name, string note)
    {
        var pathStr = path is not null && path.Length > 0 ? string.Join("/", path) : "";
        var codeNote = await _repository.SearchFor(x => x.Name == name && x.Path == pathStr).FirstOrDefaultAsync();
        if (codeNote == null)
        {
            var entity = new CodeNote
            {
                CreateTime = DateTime.Now,
                LastUpdateTime = DateTime.Now,
                Name = name,
                Note = note,
                Path = pathStr
            };
            await _repository.InsertAsync(entity);
            return entity.Id.ToString();
        }

        codeNote.Note = note;
        codeNote.LastUpdateTime = DateTime.Now;
        await _repository.UpdateAsync(codeNote);
        return codeNote.Id.ToString();
    }

    public async Task<List<VmCodeNote>> GetNoteAsync(string[]? path)
    {
        var pathStr = path is not null && path.Length > 0 ? string.Join("/", path) : "";
        var list = await _repository.SearchFor(x => x.Path == pathStr).ToListAsync();
        return _mapper.Map<List<VmCodeNote>>(list);
    }

    public async Task<List<VmCodeNote>> GetAllNoteAsync()
    {
        var list = await _repository.SearchFor(x => true).ToListAsync();
        return _mapper.Map<List<VmCodeNote>>(list);
    }

    public async Task DeleteAsync(string[]? path, string name)
    {
        var pathStr = path is not null && path.Length > 0 ? string.Join("/", path) : "";
        await _repository.DeleteAsync(x => x.Name == name && x.Path == pathStr);
    }
}
loading