created api for user

This commit is contained in:
Dasha06 2024-11-16 17:13:06 +03:00
parent 4bdc422ce8
commit 5b98b00367
44 changed files with 59 additions and 23 deletions

View File

@ -8,7 +8,6 @@ namespace presence.data.RemoteData.RemoteDataBase.DAO
public class UserDao public class UserDao
{ {
public required string FIO {get; set; } public required string FIO {get; set; }
public Guid UserGuid { get; set; }
public int UserId { get; set; } public int UserId { get; set; }
public required int GroupId {get; set;} public required int GroupId {get; set;}
public GroupDao Group {get; set;} public GroupDao Group {get; set;}

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("data")] [assembly: System.Reflection.AssemblyCompanyAttribute("data")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4bdc422ce8c208f21ae34f3d9f1cc61a98a48a3c")]
[assembly: System.Reflection.AssemblyProductAttribute("data")] [assembly: System.Reflection.AssemblyProductAttribute("data")]
[assembly: System.Reflection.AssemblyTitleAttribute("data")] [assembly: System.Reflection.AssemblyTitleAttribute("data")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
6741393a5fe1cc20988265f6fd0e8bdd33ee4b9cc7b9e110a41e548fdd825a94 f31721b3835e5b512a8546f19c261266dec727598bee64acedc7558f74f5abd0

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -7,6 +7,8 @@ namespace domain.Models.ResponseModels
{ {
public class UserResponse public class UserResponse
{ {
public required string FIO {get; set; }
public int Id {get; set;}
public required GroupResponse Group {get; set;}
} }
} }

View File

@ -8,7 +8,7 @@ namespace presence.domain.Models
{ {
public class User{ public class User{
public required string FIO {get; set; } public required string FIO {get; set; }
public Guid Guid {get; set;} public int Id {get; set;}
public required Group GroupId {get; set;} public required Group GroupId {get; set;}
} }
} }

View File

@ -32,7 +32,7 @@ namespace presence.domain.UseCase
.Where(x => users.Any(user => user.UserId == x.UserId)) .Where(x => users.Any(user => user.UserId == x.UserId))
.Select(presence => new Presence{ .Select(presence => new Presence{
User = new User{ User = new User{
Guid = presence.UserGuid, Id = presence.UserId,
GroupId = new Group{Id = groupId, Name = _groupRepository.GetGroupById(groupId).Name}, GroupId = new Group{Id = groupId, Name = _groupRepository.GetGroupById(groupId).Name},
FIO = users.First(user => user.UserId == presence.UserId).FIO, FIO = users.First(user => user.UserId == presence.UserId).FIO,
}, },
@ -50,7 +50,7 @@ namespace presence.domain.UseCase
.Where(x => users.Any(user => user.UserId == x.UserId && x.Date == date)) .Where(x => users.Any(user => user.UserId == x.UserId && x.Date == date))
.Select(presence => new Presence{ .Select(presence => new Presence{
User = new User{ User = new User{
Guid = presence.UserGuid, Id = presence.UserId,
GroupId = new Group{Id = groupId, Name = _groupRepository.GetGroupById(groupId).Name}, GroupId = new Group{Id = groupId, Name = _groupRepository.GetGroupById(groupId).Name},
FIO = users.First(user => user.UserId == presence.UserId).FIO, FIO = users.First(user => user.UserId == presence.UserId).FIO,
}, },
@ -74,7 +74,7 @@ namespace presence.domain.UseCase
foreach (var user in users) foreach (var user in users)
{ {
Presence pres = new Presence{ClassNumber = i, Date = date, Presence pres = new Presence{ClassNumber = i, Date = date,
User = new User{Guid = user.UserGuid, User = new User{Id = user.UserId,
FIO = user.FIO, FIO = user.FIO,
GroupId = new Group{Id = groupId, GroupId = new Group{Id = groupId,
Name = _groupRepository.GetGroupById(groupId).Name}}}; Name = _groupRepository.GetGroupById(groupId).Name}}};

View File

@ -1,3 +1,4 @@
using domain.Models.ResponseModels;
using presence.data.LocalData.Entity; using presence.data.LocalData.Entity;
using presence.data.RemoteData.RemoteDataBase.DAO; using presence.data.RemoteData.RemoteDataBase.DAO;
using presence.data.Repository; using presence.data.Repository;
@ -25,14 +26,14 @@ namespace presence.domain.UseCase
private List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup() private List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUser() public List<UserResponse> GetAllUsers() => _repositoryUserImpl.GetAllUser()
.Join(_repositoryGroupImpl.GetAllGroup(), .Join(_repositoryGroupImpl.GetAllGroup(),
user => user.GroupId, user => user.GroupId,
group => group.Id, group => group.Id,
(user, group) => (user, group) =>
new User { FIO = user.FIO, new UserResponse { FIO = user.FIO,
Guid = user.UserGuid, Id = user.UserId,
GroupId = new Group{Id = group.Id, Name = group.Name}} Group = new GroupResponse{Id = group.Id, Name = group.Name}}
).ToList(); ).ToList();
@ -48,7 +49,7 @@ namespace presence.domain.UseCase
return new User return new User
{ {
FIO = _repositoryUserImpl.GetUserById(userId).FIO, FIO = _repositoryUserImpl.GetUserById(userId).FIO,
Guid = _repositoryUserImpl.GetUserById(userId).UserGuid, Id = _repositoryUserImpl.GetUserById(userId).UserId,
GroupId = new Group { Id = _repositoryUserImpl.GetUserById(userId).GroupId, Name = _repositoryGroupImpl.GetGroupById(userId).Name } GroupId = new Group { Id = _repositoryUserImpl.GetUserById(userId).GroupId, Name = _repositoryGroupImpl.GetGroupById(userId).Name }
}; };
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,10 +13,10 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("domain")] [assembly: System.Reflection.AssemblyCompanyAttribute("domain")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4bdc422ce8c208f21ae34f3d9f1cc61a98a48a3c")]
[assembly: System.Reflection.AssemblyProductAttribute("domain")] [assembly: System.Reflection.AssemblyProductAttribute("domain")]
[assembly: System.Reflection.AssemblyTitleAttribute("domain")] [assembly: System.Reflection.AssemblyTitleAttribute("domain")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class. // Создано классом WriteCodeFragment MSBuild.

View File

@ -1 +1 @@
50afef9105125301dd1c05ea9fb1e5f605a3f79c6aca753bbf0156749546e4dd a093ba0bf5d64479b23b12bae8cbb0ec7eeab3342133eaa4fe9b892857454774

View File

@ -1 +1 @@
1b5f775f605de28ca409be1a9c13a6df3b2f5c3132bcb56f78dabcfec73e7ace a9b24df1a9b756a44c00b9ae5110f480b03594c888c3659dbb3f3845f84a2ce4

Binary file not shown.

Binary file not shown.

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using presence.data.RemoteData.RemoteDataBase.DAO;
using presence.domain.Models; using presence.domain.Models;
using presence.domain.UseCase; using presence.domain.UseCase;

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using presence.domain.Models;
using presence.domain.UseCase;
namespace presence_api.Controllers.UserController;
[ApiController]
[Route("api/[controller]")]
public class UserController: ControllerBase
{
private readonly UserUseCase _userUseCase;
public UserController(UserUseCase userUseCase)
{
_userUseCase = userUseCase;
}
[HttpGet]
public ActionResult<IEnumerable<User>> GetAllUser()
{
return Ok(_userUseCase.GetAllUsers());
}
}

View File

@ -9,6 +9,7 @@ builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
builder.Services.ConfigureGroup(); builder.Services.ConfigureGroup();
builder.Services.ConfigureUser();
var app = builder.Build(); var app = builder.Build();

View File

@ -15,5 +15,12 @@ namespace presence_api.ServiceExtensions
.AddScoped<IGroupRepository, SQLGroupRepositoryImpl>() .AddScoped<IGroupRepository, SQLGroupRepositoryImpl>()
.AddScoped<GroupUseCase>(); .AddScoped<GroupUseCase>();
} }
public static void ConfigureUser(this IServiceCollection services)
{
services
.AddScoped<IUserRepository, SQLUserRepositoryImpl>()
.AddScoped<UserUseCase>();
}
} }
} }

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("presence_api")] [assembly: System.Reflection.AssemblyCompanyAttribute("presence_api")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4bdc422ce8c208f21ae34f3d9f1cc61a98a48a3c")]
[assembly: System.Reflection.AssemblyProductAttribute("presence_api")] [assembly: System.Reflection.AssemblyProductAttribute("presence_api")]
[assembly: System.Reflection.AssemblyTitleAttribute("presence_api")] [assembly: System.Reflection.AssemblyTitleAttribute("presence_api")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
1f62ae9533a734c74ec1f7ca641bc5e1622b77bd7c65110c6691cbb61403c74b d346aa73c391eb0ef182af766d6332e886a863e9a1d1a8b4618c0041ef8db1f6

View File

@ -1 +1 @@
4152a8bc96237f2bf065859d8e800c5b4c5df2743d3a00d9b60e07b905443a33 6c572403d26fc1fb9b48c0e23b3616f42e8d5076d149940e6b0f5e2bd64da14b

View File

@ -26,7 +26,7 @@ namespace presence.ui
StringBuilder userOutput = new StringBuilder(); StringBuilder userOutput = new StringBuilder();
foreach (var user in _userUseCase.GetAllUsers()) foreach (var user in _userUseCase.GetAllUsers())
{ {
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupId}"); userOutput.AppendLine($"{user.Id}\t{user.FIO}\t{user.Group}");
} }
Console.WriteLine(userOutput); Console.WriteLine(userOutput);
} }
@ -34,7 +34,7 @@ namespace presence.ui
public void GetUserById(int userId) { public void GetUserById(int userId) {
StringBuilder userOutput = new StringBuilder(); StringBuilder userOutput = new StringBuilder();
var user = _userUseCase.GetUserById(userId); var user = _userUseCase.GetUserById(userId);
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupId}"); userOutput.AppendLine($"{user.Id}\t{user.FIO}\t{user.GroupId}");
Console.WriteLine(userOutput); Console.WriteLine(userOutput);
} }