Migrate to new tribufu project structure (#2)

* Migrate to new tribufu project structure

* Update .gitignore

* Remove old api files

* Update Directory.Build.props

* Rename solution
This commit is contained in:
Guilherme Werner 2026-06-21 12:27:05 -03:00 committed by GitHub
parent be25ee8fe3
commit 7e8e192dc3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
115 changed files with 41 additions and 262 deletions

View file

@ -0,0 +1,43 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Tribufu.EntityFrameworkCore
{
public interface IRepository<T, K> where T : class
{
void Seed();
Task SeedAsync();
IList<T> List();
Task<IList<T>> ListAsync();
IList<T> List(uint page, uint limit);
Task<IList<T>> ListAsync(uint page, uint limit);
T? Find(K key);
Task<T?> FindAsync(K key);
T? Create(T entity);
Task<T?> CreateAsync(T entity);
T? Update(T entity);
Task<T?> UpdateAsync(T entity);
void Delete(K key);
Task DeleteAsync(K key);
void Delete(T entity);
Task DeleteAsync(T entity);
}
}

View file

@ -0,0 +1 @@
# Tribufu EntityFrameworkCore

View file

@ -0,0 +1,120 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Tribufu.EntityFrameworkCore
{
public class Repository<C, T, K> : IRepository<T, K> where C : DbContext where T : class
{
protected readonly C _dbContext;
protected readonly DbSet<T> _dbSet;
public Repository(C dbContext)
{
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
_dbSet = dbContext.Set<T>();
}
public virtual void Seed()
{
}
public virtual async Task SeedAsync()
{
}
public virtual IList<T> List()
{
return [.. _dbSet];
}
public virtual async Task<IList<T>> ListAsync()
{
return await _dbSet.ToListAsync();
}
public virtual IList<T> List(uint page, uint limit)
{
return _dbSet.Skip((int)((page < 1 ? 0 : page - 1) * limit)).Take((int)limit).ToList();
}
public virtual async Task<IList<T>> ListAsync(uint page, uint limit)
{
return await _dbSet.Skip((int)((page < 1 ? 0 : page - 1) * limit)).Take((int)limit).ToListAsync();
}
public virtual T? Find(K key)
{
return _dbSet.Find(key);
}
public virtual async Task<T?> FindAsync(K key)
{
return await _dbSet.FindAsync(key);
}
public virtual T? Create(T entity)
{
_dbSet.Add(entity);
var result = _dbContext.SaveChanges();
return result > 0 ? entity : null;
}
public virtual async Task<T?> CreateAsync(T entity)
{
await _dbSet.AddAsync(entity);
var result = await _dbContext.SaveChangesAsync();
return result > 0 ? entity : null;
}
public virtual T? Update(T entity)
{
_dbSet.Update(entity);
var result = _dbContext.SaveChanges();
return result > 0 ? entity : null;
}
public virtual async Task<T?> UpdateAsync(T entity)
{
_dbSet.Update(entity);
var result = await _dbContext.SaveChangesAsync();
return result > 0 ? entity : null;
}
public virtual void Delete(K key)
{
var entity = _dbSet.Find(key);
if (entity != null)
{
Delete(entity);
}
}
public virtual async Task DeleteAsync(K key)
{
var entity = await _dbSet.FindAsync(key);
if (entity != null)
{
await DeleteAsync(entity);
}
}
public virtual void Delete(T entity)
{
_dbSet.Remove(entity);
_dbContext.SaveChanges();
}
public virtual async Task DeleteAsync(T entity)
{
_dbSet.Remove(entity);
await _dbContext.SaveChangesAsync();
}
}
}

View file

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>Tribufu.EntityFrameworkCore</PackageId>
<Description>Tribufu EntityFrameworkCore</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<PropertyGroup>
<AppDesignerFolder>Properties</AppDesignerFolder>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsPublishable>false</IsPublishable>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tribufu.Configuration\Tribufu.Configuration.csproj" />
<ProjectReference Include="..\Tribufu.Logging\Tribufu.Logging.csproj" />
<ProjectReference Include="..\Tribufu.Platform\Tribufu.Platform.csproj" />
</ItemGroup>
</Project>