Skip to content
Merged
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
67 changes: 67 additions & 0 deletions HwProj.Common/HwProj.Repositories.Net8/CrudRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Z.EntityFramework.Plus;

namespace HwProj.Repositories.Net8;

public class CrudRepository<TEntity, TKey>(DbContext context) : ICrudRepository<TEntity, TKey>
where TEntity : class, IEntity<TKey>
where TKey : IEquatable<TKey>
{
protected DbContext Context => context;

public async Task<TKey> AddAsync(TEntity item)
{
await context.AddAsync(item);
await context.SaveChangesAsync();
return item.Id;
}

public async Task<List<TKey>> AddRangeAsync(IEnumerable<TEntity> items)
{
items = items.ToList();
await context.AddRangeAsync(items);
await context.SaveChangesAsync();
return items.Select(item => item.Id).ToList();
}

public async Task DeleteAsync(TKey id)
{
await context.Set<TEntity>()
.Where(entity => entity.Id.Equals(id))
.DeleteAsync()
;
}

public async Task UpdateAsync(TKey id, Expression<Func<TEntity, TEntity>> updateFactory)
{
await context.Set<TEntity>()
.Where(entity => entity.Id.Equals(id))
.UpdateAsync(updateFactory)
;
}

public IQueryable<TEntity> GetAll()
{
return context.Set<TEntity>().AsNoTracking();
}

public IQueryable<TEntity> FindAll(Expression<Func<TEntity, bool>> predicate)
{
return context.Set<TEntity>().AsNoTracking().Where(predicate);
}

public async Task<TEntity> GetAsync(TKey id)
{
return await context.FindAsync<TEntity>(id);
}

public async Task<TEntity> FindAsync(Expression<Func<TEntity, bool>> predicate)
{
return await context.Set<TEntity>().AsNoTracking().FirstOrDefaultAsync(predicate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.9" />
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="9.104.0" />
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions HwProj.Common/HwProj.Repositories.Net8/ICrudRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace HwProj.Repositories.Net8;

public interface ICrudRepository<TEntity, TKey>
where TEntity : IEntity<TKey>
where TKey : IEquatable<TKey>
{
Task<TKey> AddAsync(TEntity item);
Task<List<TKey>> AddRangeAsync(IEnumerable<TEntity> items);
Task DeleteAsync(TKey id);
Task UpdateAsync(TKey id, Expression<Func<TEntity, TEntity>> updateFactory);
IQueryable<TEntity> GetAll();
IQueryable<TEntity> FindAll(Expression<Func<TEntity, bool>> predicate);
Task<TEntity> GetAsync(TKey id);
Task<TEntity> FindAsync(Expression<Func<TEntity, bool>> predicate);
}
9 changes: 9 additions & 0 deletions HwProj.Common/HwProj.Repositories.Net8/IEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace HwProj.Repositories.Net8;

public interface IEntity<TKey>
where TKey : IEquatable<TKey>
{
TKey Id { get; set; }
}
1 change: 1 addition & 0 deletions HwProj.CoursesService/HwProj.CoursesService.API/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ COPY ["HwProj.Common/HwProj.Repositories/", "HwProj.Common/HwProj.Repositories/"
COPY ["HwProj.AuthService/HwProj.AuthService.Client/", "HwProj.AuthService/HwProj.AuthService.Client/"]
COPY ["HwProj.ContentService/HwProj.ContentService.Client/", "HwProj.ContentService/HwProj.ContentService.Client/"]
COPY ["HwProj.Common/HwProj.HttpUtils/", "HwProj.Common/HwProj.HttpUtils/"]
COPY ["HwProj.NotificationsService/HwProj.NotificationService.Events/", "HwProj.NotificationsService/HwProj.NotificationService.Events/"]

WORKDIR "/src/HwProj.CoursesService/HwProj.CoursesService.API"
RUN dotnet publish "HwProj.CoursesService.API.csproj" -c Release -o /app/publish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<ProjectReference Include="..\..\HwProj.AuthService\HwProj.AuthService.Client\HwProj.AuthService.Client.csproj" />
<ProjectReference Include="..\..\HwProj.Common\HwProj.Repositories\HwProj.Repositories.csproj" />
<ProjectReference Include="..\..\HwProj.Common\HwProj.Utils\HwProj.Utils.csproj" />
<ProjectReference Include="..\..\HwProj.NotificationsService\HwProj.NotificationService.Events\HwProj.NotificationService.Events.csproj" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties properties_4launchsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Transactions;
using System.Threading.Tasks;
using HwProj.CoursesService.API.Events;
using HwProj.CoursesService.API.Models;
using HwProj.CoursesService.API.Repositories;
using HwProj.CoursesService.API.Repositories.Groups;
Expand All @@ -14,6 +13,7 @@
using HwProj.CoursesService.API.Domains;
using HwProj.Models.CoursesService.DTO;
using HwProj.Models.Roles;
using HwProj.NotificationService.Events.CoursesService;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
using HwProj.CoursesService.API.Models;
using HwProj.CoursesService.API.Repositories;
using HwProj.EventBus.Client.Interfaces;
using HwProj.CoursesService.API.Events;
using HwProj.CoursesService.API.Domains;
using HwProj.Models;
using HwProj.Models.CoursesService.ViewModels;
using HwProj.NotificationService.Events.CoursesService;

namespace HwProj.CoursesService.API.Services
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Threading.Tasks;
using HwProj.CoursesService.API.Events;
using HwProj.CoursesService.API.Models;
using HwProj.CoursesService.API.Repositories;
using HwProj.EventBus.Client.Interfaces;
using HwProj.CoursesService.API.Domains;
using System.Linq;
using HwProj.Models;
using HwProj.NotificationService.Events.CoursesService;

namespace HwProj.CoursesService.API.Services
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.NotificationService.Events.CoursesService
{
public class LecturerAcceptToCourseEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.NotificationService.Events.CoursesService
{
public class LecturerInvitedToCourseEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.NotificationService.Events.CoursesService
{
public class LecturerRejectToCourseEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.NotificationService.Events.CoursesService
{
public class NewCourseMateEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.NotificationService.Events.CoursesService
{
public class NewHomeworkEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.NotificationService.Events.CoursesService
{
public class NewHomeworkTaskEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.NotificationService.Events.CoursesService
{
public class UpdateHomeworkEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.NotificationService.Events.CoursesService
{
public class UpdateSolutionMaxRatingEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.NotificationService.Events.CoursesService
{
public class UpdateTaskMaxRatingEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\HwProj.Common\HwProj.Models\HwProj.Models.csproj" />
<ProjectReference Include="..\..\HwProj.EventBus\HwProj.EventBus.Client\HwProj.EventBus.Client.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using HwProj.Models.CoursesService.ViewModels;
using HwProj.Models.SolutionsService;

namespace HwProj.SolutionsService.API.Events
namespace HwProj.NotificationService.Events.SolutionsService
{
public class RateEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using HwProj.Models.CoursesService.ViewModels;
using HwProj.Models.SolutionsService;

namespace HwProj.SolutionsService.API.Events
namespace HwProj.NotificationService.Events.SolutionsService
{
public class StudentPassTaskEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutoMapper;
using HwProj.Models.NotificationsService;
using HwProj.NotificationsService.API.Models;

namespace HwProj.NotificationsService.API
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Threading.Tasks;
using HwProj.Models.NotificationsService;
using HwProj.NotificationsService.API.Repositories;
using HwProj.NotificationsService.API.Services;
using Microsoft.AspNetCore.Mvc;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

COPY ["Directory.Build.props", "Directory.Build.props"]

COPY ["HwProj.NotificationsService/HwProj.NotificationsService.API/", "HwProj.NotificationsService/HwProj.NotificationsService.API/"]
COPY ["HwProj.NotificationsService/HwProj.NotificationService.Events/", "HwProj.NotificationsService/HwProj.NotificationService.Events/"]
COPY ["HwProj.Common/HwProj.Utils/", "HwProj.Common/HwProj.Utils/"]
COPY ["HwProj.Common/HwProj.Common.Net8/", "HwProj.Common/HwProj.Common.Net8/"]
COPY ["HwProj.EventBus/HwProj.EventBus.Client/", "HwProj.EventBus/HwProj.EventBus.Client/"]
COPY ["HwProj.Common/HwProj.Models/", "HwProj.Common/HwProj.Models/"]
COPY ["HwProj.Common/HwProj.Repositories/", "HwProj.Common/HwProj.Repositories/"]
COPY ["HwProj.SolutionsService/HwProj.SolutionsService.API/", "HwProj.SolutionsService/HwProj.SolutionsService.API/"]
COPY ["HwProj.Common/HwProj.Repositories.Net8/", "HwProj.Common/HwProj.Repositories.Net8/"]
COPY ["HwProj.SolutionsService/HwProj.SolutionsService.Client/", "HwProj.SolutionsService/HwProj.SolutionsService.Client/"]
COPY ["HwProj.Common/HwProj.Exceptions/", "HwProj.Common/HwProj.Exceptions/"]
COPY ["HwProj.Common/HwProj.HttpUtils/", "HwProj.Common/HwProj.HttpUtils/"]
Expand All @@ -22,7 +22,7 @@ COPY ["HwProj.CoursesService/HwProj.CoursesService.API/", "HwProj.CoursesService
WORKDIR "/src/HwProj.NotificationsService/HwProj.NotificationsService.API"
RUN dotnet publish "HwProj.NotificationsService.API.csproj" -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS final
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app

COPY --from=build /app/publish .
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Threading.Tasks;
using HwProj.AuthService.Client;
using HwProj.EventBus.Client.Interfaces;
using HwProj.Models.NotificationsService;
using HwProj.NotificationService.Events.AuthService;
using HwProj.NotificationsService.API.Models;
using HwProj.NotificationsService.API.Repositories;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Threading.Tasks;
using HwProj.AuthService.Client;
using HwProj.CoursesService.API.Events;
using HwProj.EventBus.Client.Interfaces;
using HwProj.Models.NotificationsService;
using HwProj.NotificationService.Events.CoursesService;
using HwProj.NotificationsService.API.Models;
using HwProj.NotificationsService.API.Repositories;
using HwProj.NotificationsService.API.Services;
using Microsoft.Extensions.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Threading.Tasks;
using HwProj.CoursesService.API.Events;
using HwProj.EventBus.Client.Interfaces;
using HwProj.Models.NotificationsService;
using HwProj.NotificationService.Events.CoursesService;
using HwProj.NotificationsService.API.Models;
using HwProj.NotificationsService.API.Repositories;
using HwProj.NotificationsService.API.Services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Threading.Tasks;
using HwProj.AuthService.Client;
using HwProj.CoursesService.API.Events;
using HwProj.EventBus.Client.Interfaces;
using HwProj.Models.NotificationsService;
using HwProj.NotificationService.Events.CoursesService;
using HwProj.NotificationsService.API.Models;
using HwProj.NotificationsService.API.Repositories;
using HwProj.NotificationsService.API.Services;
using Microsoft.Extensions.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Threading.Tasks;
using HwProj.AuthService.Client;
using HwProj.CoursesService.API.Events;
using HwProj.EventBus.Client.Interfaces;
using HwProj.Models.NotificationsService;
using HwProj.NotificationService.Events.CoursesService;
using HwProj.NotificationsService.API.Models;
using HwProj.NotificationsService.API.Repositories;
using HwProj.NotificationsService.API.Services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Threading.Tasks;
using HwProj.AuthService.Client;
using HwProj.EventBus.Client.Interfaces;
using HwProj.Models.NotificationsService;
using HwProj.NotificationService.Events.CoursesService;
using HwProj.NotificationsService.API.Models;
using HwProj.NotificationsService.API.Repositories;
using HwProj.CoursesService.API.Events;
using HwProj.NotificationsService.API.Services;
using Microsoft.Extensions.Configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Threading.Tasks;
using HwProj.AuthService.Client;
using HwProj.EventBus.Client.Interfaces;
using HwProj.Models.NotificationsService;
using HwProj.NotificationService.Events.CoursesService;
using HwProj.NotificationsService.API.Models;
using HwProj.NotificationsService.API.Repositories;
using HwProj.CoursesService.API.Events;
using HwProj.NotificationsService.API.Services;
using Microsoft.Extensions.Configuration;

Expand Down
Loading
Loading