Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dzhus/organization(provider) update #53

Merged
merged 61 commits into from
Mar 16, 2021

Conversation

VyacheslavDzhus
Copy link
Contributor

No description provided.

[TestFixture]
public class Tests
{
private readonly ILogger<ProviderController> _logger;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not use underscore naming

{
bool IsUnique(Organization entity);
bool IsNotUnique(Provider entity);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the old name 'IsUnique' was better
the rule is to not create negating names
imagine how it will look like '!IsNotUnique' how hard it would be to figure out what is the the result of the operation

@@ -0,0 +1,26 @@
using Microsoft.Extensions.Logging;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we have 2 files ProviderControllerTest.cs
could you check which one is not needed?

@@ -42,7 +64,8 @@ public void ConfigureServices(IServiceCollection services)
});

services.AddCors(confg =>
confg.AddPolicy("AllowAll",
confg.AddPolicy(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because of the StyleCope


// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen();

services.AddAutoMapper(typeof(Startup));
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this method removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not removed, i put this method over ConfigureServices, because of the StyleCope

}
catch (ArgumentNullException ex)
{
throw new ArgumentNullException(nameof(id), ex.Message);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we throw the same exception and we loose stacktrace here


return provider.ToModel();
}
catch (Exception ex)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not catch base Exception type

public async Task<ProviderDto> GetById(long id)
{
var provider = await repository.GetById(id).ConfigureAwait(false);
if (provider == null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline


if (repository.Exists(provider))
{
throw new ArgumentException("There is already an providerDto with such data");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should not write 'providerDto' here
it is more clear for the user to see just 'provider'

{
if (dto == null)
{
throw new ArgumentNullException(nameof(dto), "Provider was null.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provider was null. -> Provider is null.

@@ -19,7 +16,8 @@ public class WorkshopDTO

[DataType(DataType.PhoneNumber)]
[Required(ErrorMessage = "Phone number is required")]
[RegularExpression(@"([\d]{9})",
[RegularExpression(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because of the StyleCope

[MinLength(1)]
public string Title { get; set; }

[Required(ErrorMessage = "Title is required")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ShortTitle is required"

public string Website { get; set; } = string.Empty;

[DataType(DataType.Url)]
[MaxLength(30)]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 30?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#54 Max 30 characters

return BadRequest(ModelState);
}

return Ok(await providerService.Update(providerDTO).ConfigureAwait(false));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please return CreatedAtAction as Mykhailo suggested

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He said to use CreatedAtAction with Post method, here we have the Put method


if (providerDTO == null)
{
return BadRequest(providerDTO);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does any error message needed here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will user understand what went wrong in this case?

/// <summary>
/// Initializes a new instance of the <see cref="ProviderController"/> class.
/// </summary>
/// <param name="logger">Logging mechanism.</param>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe "Logger instance" sounds better

@mmmpolishchuk mmmpolishchuk self-requested a review March 16, 2021 08:49

[Required(ErrorMessage = "Title is required")]
[DataType(DataType.Text)]
public string Title { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be like this: public string Title { get; set; } = string.Empty ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided not to use this for properties with attribute Required

@@ -59,7 +59,7 @@ public async Task<ActionResult> GetWorkshopById(long id)
/// </summary>
/// <param name="workshopDto">Entity to add.</param>
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
[Authorize(Roles = "organization,admin")]
[Authorize(Roles = "provider,admin")]
[HttpPost]
public async Task<ActionResult> CreateWorkshop(WorkshopDTO workshopDto)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stick to the rule: actions from our controllers should return IActionResult

@sonarqubecloud
Copy link

@dmitrykiev dmitrykiev merged commit f9307b5 into develop Mar 16, 2021
@dmitrykiev dmitrykiev deleted the Dzhus/Organization(Provider)_Update branch March 16, 2021 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants