Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/ApplicationCore/ApplicationCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</PropertyGroup>

<ItemGroup>
<Folder Include="Entities\" />
<Folder Include="Services\" />
</ItemGroup>

Expand Down
35 changes: 35 additions & 0 deletions src/ApplicationCore/Entities/Owner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using ApplicationCore.SharedKernel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ApplicationCore.Entities
{
public class Owner : Entity
{
public string Login { get; set; }
public string NodeId { get; set; }
public string AvatarUrl { get; set; }
public string Name { get; set; }
public string HtmlUrl { get; set; }
public string Bio { get; set; }
public string Company { get; set; }
public string Blog { get; set; }
public string Location { get; set; }
public string Email { get; set; }
public int PublicRepos { get; set; }
public bool? Hireable { get; set; }
public int Followers { get; set; }
public int Following { get; set; }
public int PublicGists { get; set; }
public int? Collaborators { get; set; }
public ICollection<Repositories> Repositories { get; set; }
}






}
32 changes: 32 additions & 0 deletions src/ApplicationCore/Entities/Repositories.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using ApplicationCore.SharedKernel;
using System;
using System.Collections.Generic;
using System.Text;

namespace ApplicationCore.Entities
{
/// <summary>
/// Root Object
/// </summary>
public class Repositories : Entity
{
public string NodeId { get; set; }
public string Name { get; set; }
public string FullName { get; set; }
public bool IsPrivate { get; set; }

public long OwnerId { get; set; }
public Owner Owner { get; set; }
public string HtmlUrl { get; set; }
public string Description { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
public string GitUrl { get; set; }
public int StargazersCount { get; set; }
public string Language { get; set; }
public int ForksCount { get; set; }
public int OpenIssuesCount { get; set; }
public string LicenseName { get; set; }
public string DefaultBranch { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/ApplicationCore/Interfaces/IAsyncRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ApplicationCore.Interfaces
{
public interface IAsyncRepository<T> where T : Entity
{
Task<T> GetByIdAsync(int id);
Task<T> GetByIdAsync(long id);
Task<List<T>> ListAllAsync();
Task<T> AddAsync(T entity);
Task UpdateAsync(T entity);
Expand Down
4 changes: 3 additions & 1 deletion src/ApplicationCore/SharedKernel/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace ApplicationCore.SharedKernel
{
public class Entity
{
public int Id { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public long Id { get; set; }
}
}
54 changes: 39 additions & 15 deletions src/Infrastructure/Data/EfRepository.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,86 @@
using ApplicationCore.Interfaces;
using ApplicationCore.SharedKernel;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.Data
{
public class EfRepository<T> : IRepository<T>, IAsyncRepository<T> where T : Entity
{
protected GithubTopperContext _dbContext;

public EfRepository(GithubTopperContext dbContext)
{
_dbContext = dbContext;
}

public T Add(T entity)
{
throw new NotImplementedException();
_dbContext.Set<T>().Add(entity);
_dbContext.SaveChanges();

return entity;
}

public Task<T> AddAsync(T entity)
public async Task<T> AddAsync(T entity)
{
throw new NotImplementedException();
_dbContext.Set<T>().Add(entity);
await _dbContext.SaveChangesAsync();

return entity;
}

public void Delete(T entity)
{
throw new NotImplementedException();
_dbContext.Set<T>().Remove(entity);
_dbContext.SaveChanges();
}

public Task DeleteAsync(T entity)
public async Task DeleteAsync(T entity)
{
throw new NotImplementedException();
_dbContext.Set<T>().Remove(entity);
await _dbContext.SaveChangesAsync();
}

public T GetById(int id)
{
throw new NotImplementedException();
return _dbContext.Set<T>().Find(id);
}

public Task<T> GetByIdAsync(int id)
public async Task<T> GetByIdAsync(long id)
{
throw new NotImplementedException();
return await _dbContext.Set<T>().FindAsync(id);
}

public IEnumerable<T> ListAll()
{
throw new NotImplementedException();
return _dbContext.Set<T>().AsEnumerable();
}

public async Task<List<T>> ListAllAsync()
{
return await _dbContext.Set<T>().ToListAsync();
}

public Task<List<T>> ListAllAsync()
public async Task<IEnumerable<T>> ListAllAsync(int id)
{
throw new NotImplementedException();
return await _dbContext.Set<T>().Include(p => p.Id == id).ToListAsync();
}

public void Update(T entity)
{
throw new NotImplementedException();
_dbContext.Entry(entity).State = EntityState.Modified;
_dbContext.SaveChanges();
}

public Task UpdateAsync(T entity)
public async Task UpdateAsync(T entity)
{
throw new NotImplementedException();
_dbContext.Entry(entity).State = EntityState.Modified;
await _dbContext.SaveChangesAsync();
}
}
}
23 changes: 22 additions & 1 deletion src/Infrastructure/Data/GithubTopperContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using ApplicationCore.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;
Expand All @@ -7,5 +8,25 @@ namespace Infrastructure.Data
{
public class GithubTopperContext : DbContext
{
public GithubTopperContext(DbContextOptions<GithubTopperContext> options) : base(options){ }

public DbSet<Owner> Owner { get; set; }
public DbSet<Repositories> Repositories { get; set; }

//protected override void OnModelCreating(ModelBuilder modelBuilder)
//{
// modelBuilder.Entity<Repositories>()
// .HasOne<Owner>(own => own.Owner)
// .WithMany(repos => repos.Repositories)
// .IsRequired();

//}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.EnableSensitiveDataLogging();

}


}
}
5 changes: 4 additions & 1 deletion src/Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Design" Version="1.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.4" />
</ItemGroup>

<ItemGroup>
Expand Down
118 changes: 118 additions & 0 deletions src/Infrastructure/Migrations/20181008230132_InitialCreate.Designer.cs

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

Loading