Правки по ревью

This commit is contained in:
Olga Nemt 2023-10-13 16:58:27 +05:00
parent 8bc215ad85
commit 47dca967ae
8 changed files with 8815 additions and 54 deletions

View File

@ -29,28 +29,32 @@ namespace AsbCloudApp.Data.User
/// </summary>
[Required]
[StringLength(260, MinimumLength = 0, ErrorMessage = "Допустимая длина ФИО от 1 до 260 символов")]
public string FIO { get; set; } = null!;
public string FullName { get; set; } = null!;
/// <summary>
/// Email
/// </summary>
[Required]
[StringLength(260, MinimumLength = 3, ErrorMessage = "Допустимая длина email от 3 до 260 символов")]
[RegularExpression(
@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$",
ErrorMessage = "Некорректный email")]
public string Email { get; set; } = null!;
/// <summary>
/// Phone
/// </summary>
[Required]
[StringLength(50, MinimumLength = 1, ErrorMessage = "Допустимая длина телефона от 1 до 50 символов")]
[RegularExpression(
@"^(?:\+7|8)\s?(?:\(\d{3}\)|\d{3})\s?\d{3}-?\d{2}-?\d{2}$",
ErrorMessage = "Некорректный номер телефона")]
public string Phone { get; set; } = null!;
/// <summary>
/// Должность
/// </summary>
[Required]
[StringLength(100, MinimumLength = 1, ErrorMessage = "Допустимая длина должности от 1 до 100 символов")]
public string Position { get; set; } = null;
[StringLength(260, MinimumLength = 1, ErrorMessage = "Допустимая длина должности от 1 до 260 символов")]
public string Position { get; set; } = null!;
/// <summary>
/// Компания

View File

@ -21,7 +21,7 @@ namespace AsbCloudApp.Services
Task<IEnumerable<ContactDto>> GetAllAsync(int idWell, int contactTypeId, CancellationToken token);
/// <summary>
/// Получение пользователя по ключу
/// Получение контакта по ключу
/// </summary>
/// <param name="idWell">ключ скважины</param>
/// <param name="id">тип пользователя</param>
@ -32,10 +32,9 @@ namespace AsbCloudApp.Services
/// <summary>
/// Получение типов контактов
/// </summary>
/// <param name="idWell">ключ скважины</param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<CompanyTypeDto>> GetTypesAsync(int idWell, CancellationToken token);
Task<IEnumerable<CompanyTypeDto>> GetTypesAsync(CancellationToken token);
/// <summary>
/// Добавление контакта

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class Update_WellContacts_Set_FullName : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "fio",
table: "t_contact",
newName: "full_name");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "full_name",
table: "t_contact",
newName: "fio");
}
}
}

View File

@ -177,11 +177,11 @@ namespace AsbCloudDb.Migrations
.HasColumnName("email")
.HasComment("email");
b.Property<string>("FIO")
b.Property<string>("FullName")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasColumnName("fio")
.HasColumnName("full_name")
.HasComment("ФИО");
b.Property<int>("IdCompanyType")

View File

@ -20,9 +20,9 @@ namespace AsbCloudDb.Model
[StringLength(255)]
public int IdWell { get; set; }
[Column("fio"), Comment("ФИО")]
[Column("full_name"), Comment("ФИО")]
[StringLength(255)]
public string FIO { get; set; } = string.Empty;
public string FullName { get; set; } = string.Empty;
[Column("email"), Comment("email")]
[StringLength(255)]

View File

@ -3,10 +3,8 @@ using AsbCloudApp.Data.User;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using DocumentFormat.OpenXml.Office2019.Excel.RichData2;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@ -46,7 +44,7 @@ namespace AsbCloudInfrastructure.Services
return result;
}
public async Task<IEnumerable<CompanyTypeDto>> GetTypesAsync(int idWell, CancellationToken token)
public async Task<IEnumerable<CompanyTypeDto>> GetTypesAsync(CancellationToken token)
{
var query = db.CompaniesTypes
.Where(t => t.IsContact)

View File

@ -1,15 +1,10 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.User;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Repository;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading;
using System.Threading.Tasks;
@ -18,8 +13,8 @@ namespace AsbCloudWebApi.Controllers
/// <summary>
/// контроллер с контактной информацией по скважине
/// </summary>
[Route("api/well/{idWell}/[controller]")]
[ApiController]
[Route("api/[controller]")]
[Authorize]
public class WellContactController : ControllerBase
{
@ -35,16 +30,13 @@ namespace AsbCloudWebApi.Controllers
/// <summary>
/// получение списка типов контактов
/// </summary>
/// <param name="idWell">ключ скважины</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("api/well/{idWell}/contacts/types")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[HttpGet("types")]
[ProducesResponseType(typeof(IEnumerable<CompanyTypeDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetTypesAsync(int idWell, CancellationToken token)
public async Task<IActionResult> GetTypesAsync(CancellationToken token)
{
var result = await wellContactsRepository.GetTypesAsync(idWell, token).ConfigureAwait(false);
var result = await wellContactsRepository.GetTypesAsync(token);
return Ok(result);
}
@ -55,16 +47,14 @@ namespace AsbCloudWebApi.Controllers
/// <param name="contactTypeId">тип контакта</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("api/well/{idWell}/contactType/{contactTypeId}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[HttpGet("contactType/{contactTypeId}")]
[ProducesResponseType(typeof(IEnumerable<ContactDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAllAsync(int idWell, int contactTypeId, CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await wellContactsRepository.GetAllAsync(idWell, contactTypeId, token).ConfigureAwait(false);
var result = await wellContactsRepository.GetAllAsync(idWell, contactTypeId, token);
return Ok(result);
}
@ -75,16 +65,14 @@ namespace AsbCloudWebApi.Controllers
/// <param name="id">ключ контакта</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("api/well/{idWell}/contact/{id}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(IEnumerable<ContactDto>), (int)System.Net.HttpStatusCode.OK)]
[HttpGet("{id}")]
[ProducesResponseType(typeof(ContactDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAsync(int idWell, int id, CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await wellContactsRepository.GetAsync(idWell, id, token).ConfigureAwait(false);
var result = await wellContactsRepository.GetAsync(idWell, id, token);
return Ok(result);
}
@ -97,8 +85,6 @@ namespace AsbCloudWebApi.Controllers
[HttpPost]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> InsertAsync(
[FromBody] ContactDto contactDto,
CancellationToken token)
@ -106,8 +92,7 @@ namespace AsbCloudWebApi.Controllers
if (!await CanUserAccessToWellAsync(contactDto.IdWell, token).ConfigureAwait(false))
return Forbid();
var result = await wellContactsRepository.InsertAsync(contactDto, token)
.ConfigureAwait(false);
var result = await wellContactsRepository.InsertAsync(contactDto, token);
return Ok(result);
}
@ -121,8 +106,6 @@ namespace AsbCloudWebApi.Controllers
[HttpPut]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> UpdateAsync(
[FromBody] ContactDto contactDto,
CancellationToken token)
@ -130,8 +113,7 @@ namespace AsbCloudWebApi.Controllers
if (!await CanUserAccessToWellAsync(contactDto.IdWell, token).ConfigureAwait(false))
return Forbid();
var result = await wellContactsRepository.UpdateAsync(contactDto, token)
.ConfigureAwait(false);
var result = await wellContactsRepository.UpdateAsync(contactDto, token);
return Ok(result);
}
@ -144,18 +126,15 @@ namespace AsbCloudWebApi.Controllers
/// <param name="id">id контакта</param>
/// <param name="token">Токен отмены задачи</param>
/// <returns>Количество удаленных из БД строк</returns>
[HttpDelete("api/well/{idWell}/contact/{id}")]
[HttpDelete("{id}")]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> DeleteAsync(int idWell, int id, CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await wellContactsRepository.DeleteAsync(id, token)
.ConfigureAwait(false);
var result = await wellContactsRepository.DeleteAsync(id, token);
return Ok(result);
}
@ -163,11 +142,7 @@ namespace AsbCloudWebApi.Controllers
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)
{
int? idCompany = User.GetCompanyId();
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
}
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token);
}
}
}