implementation/add-data-classes #1

Merged
VsevolodKozlov123 merged 10 commits from implementation/add-data-classes into master 2024-12-12 16:11:43 +00:00
17 changed files with 277 additions and 4 deletions
Showing only changes of commit aa10135caa - Show all commits

View File

@ -0,0 +1,35 @@
using domain.Service;
using domain.UseCase;
using Microsoft.AspNetCore.Mvc;
using Presence.Api.Response;
namespace Presence.Api.Controllers
{
[ApiController]
[Route("[controller]/api")]
public class GroupController: ControllerBase
{
private readonly IGroupUseCase _groupService;
public GroupController(IGroupUseCase groupService)
{
_groupService = groupService;
}
[HttpGet]
public ActionResult<GroupResponse> GetAllGroups()
{
var result = _groupService
.GetGroupsWithStudents()
.Select(group => new GroupResponse {
Id = group.Id,
Name = group.Name,
Users = group.Users.Select(user => new UserResponse {
Guid = user.Guid,
Name = user.Name
}).Take(10).ToList(),
}).ToList();
return Ok(new GroupResponse());
}
}
}

View File

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
namespace Presence.Api.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}

View File

@ -0,0 +1,20 @@
using data;
using data.Repository;
using domain.Service;
using domain.UseCase;
using Presence.Api.Controllers;
namespace Presence.Api.Extensions
{
public static class ServiceCollectionsExtension
{
public static void AddCommomService(this IServiceCollection services)
{
services
.AddDbContext<RemoteDatabaseContext>()
.AddScoped<IGroupRepository, SQLGroupRepository>()
.AddScoped<IGroupUseCase, GroupService>()
.AddScoped<GroupController>();
}
}
}

View File

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\domain\domain.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Request\" />
<Folder Include="ServiceCollectionsExtension\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
@Presence.Api_HostAddress = http://localhost:5028
GET {{Presence.Api_HostAddress}}/weatherforecast/
Accept: application/json
###

29
Presence.Api/Program.cs Normal file
View File

@ -0,0 +1,29 @@
using Presence.Api.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddCommomService();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:32613",
"sslPort": 44302
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5028",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7098;http://localhost:5028",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,9 @@
namespace Presence.Api.Response
{
public class GroupResponse
{
public int Id { get; set; }
public string Name { get; set; }
public IEnumerable<UserResponse>? Users { get; set; } = null;
}
}

View File

@ -0,0 +1,8 @@
namespace Presence.Api.Response
{
public class UserResponse
{
public Guid Guid { get; set; }
public string Name { get; set; }
}
}

View File

@ -0,0 +1,13 @@
namespace Presence.Api
{
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@ -1,4 +1,5 @@
using data.DAO;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
@ -30,7 +31,7 @@ namespace data.Repository
{
try
{
return dbContext.groups.ToList();
return dbContext.groups.Include(group => group.Users).ToList();
}
catch (Exception ex) {
return new List<GroupDAO>();

View File

@ -6,11 +6,11 @@ using System.Threading.Tasks;
namespace domain.Entity
{
internal class GroupEntity
public class GroupEntity
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public IEnumerable<UserEntity> Users { get; set; } = null;
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace domain.Entity
{
public class UserEntity
{
public Guid Guid { get; set; }
public string Name { get; set; }
public GroupEntity Group { get; set; }
}
}

View File

@ -1,5 +1,6 @@
using data.DAO;
using data.Repository;
using domain.Entity;
using domain.Request;
using domain.UseCase;
using System;
@ -30,5 +31,26 @@ namespace domain.Service
.ToList();
_groupRepository.addGroupWithStudents(groupDAO, users);
}
public IEnumerable<GroupEntity> GetGroupsWithStudents()
{
return _groupRepository.getAllGroup().Select(
group => new GroupEntity()
{
Id = group.Id,
Name = group.Name,
Users = group.Users.Select(
user => new UserEntity
{
Guid = user.Guid,
Name = user.Name,
Group = new GroupEntity
{
Id = group.Id,
Name = group.Name,
}
}).ToList()
}).ToList();
}
}
}

View File

@ -1,4 +1,5 @@
using domain.Request;
using domain.Entity;
using domain.Request;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,6 +10,7 @@ namespace domain.UseCase
{
public interface IGroupUseCase
{
public IEnumerable<GroupEntity> GetGroupsWithStudents();
public void AddGroup(AddGroupRequest addGroupRequest);
public void AddGroupWithStudents(AddGroupWithStudentsRequest addGroupWithStudents);
}