Skip to content

BarAPI#2

Open
hekcalion wants to merge 25 commits intoAshasTob:mainfrom
hekcalion:main
Open

BarAPI#2
hekcalion wants to merge 25 commits intoAshasTob:mainfrom
hekcalion:main

Conversation

@hekcalion
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown
Owner

@AshasTob AshasTob left a comment

Choose a reason for hiding this comment

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

Very good PR overall. Solid changes.
A couple of "just in my taste" kind of comments here
A couple of "typo here" kind of comments
A couple of "should be async" comments :)
Also a bit of Exception vs Result thing going on in a repository.

Comment thread BarAPI/Controllers/MenuController.cs
Comment thread BarAPI/Controllers/MenuController.cs
Comment thread BarAPI/Controllers/OrderController.cs
Comment thread BarAPI/Controllers/OrderController.cs Outdated
return BadRequest(ModelState);
}
int affacted = await _orderRepository.Upsert(item);
if(affacted == -201)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

typo? 'affected'

Comment thread DataAccess/Repository/MenuRepository.cs Outdated
Comment thread DataAccess/Repository/MenuRepository.cs Outdated
}
else
{
return null;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't like signature of this repository. Here's fun article (its old)
https://hinchman-amanda.medium.com/null-pointer-references-the-billion-dollar-mistake-1e616534d485

Basically returning null here makes app layer more difficult.

Personally, I , in this case would be using a Failed state of Result object (from suggested comment above)
Alternatively an exception.


public async Task<int> Upsert(Order order)
{
bool ord = _barDataBase.Orders.Contains(order);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I am not EF proficient user here.
But if this method goes to database it should be async. Why not use "Get" method from above? If it does not go to database - then i dont understand how it works.

I think something wrong is going on here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I make method async because I use async method like FindAsync() , SaveChangesAsync(). But there are appropriate non-async method.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

have you tested this method? Does it work as intended?
I still think that all operations with external dependencies(such as SQL DB) should be done asynchronously

Comment thread DataAccess/Repository/OrderRepository.cs Outdated
Comment thread OrderTimeOutService/OrderTimeOut.cs Outdated
{
public class OrderTimeOut
{
private readonly BarDataBase _barDataBase;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This works.

But if we are using repository approach, i think an Order repository should be referenced here. It is very important to be super consistent in your application to avoid unexpected regressions later on

Comment thread OrderTimeOutService/OrderTimeOut.cs Outdated
public async Task<Order> Get(int id)
public Task<Order> Get(int id)
{
Order order = await _barDataBase.Orders.FindAsync(id);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

а чому ти вирішив перейти від асинхронного FindAsync до синхронного Find?
мені здається що так як було - функціонально працювало так само, але було асинхронно тобто більш оптимізовано

_barDataBase.Orders.Update(ord);
order.Status = OrderStatus.Finalized;
finalizedOrdersSum += order.TotalPrice;
await _orderRepository.Upsert(order);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Є одна проблема тут.
У тебе виходить що на приклад якщо є 10 замовлень і ти закривав вже 5 з них в циклі, а потім 6тий запит до бази падає по якійсь причині. На приклад мережа, або навантаження. виходить що ти зробив тільки половину роботи і стан який ти зберіг в базу - є не фінальним.
часто зберігати "частково" правильний результат - гірше ніж не зберігати нічого взагалі.

Я вважаю, що це не критично в даному випадку але почитай про патерн UnitOfWork
https://www.c-sharpcorner.com/UploadFile/b1df45/unit-of-work-in-repository-pattern/


public BlobStorage()
{
_blobServiceClient = new BlobServiceClient(GetEnvironmentVariable("BlobStorageConnectionString", EnvironmentVariableTarget.Process));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

а як ти ці конфіги передаєш у функцію? у Ажур порталі?
Це буде працювати :)

але це не ідеальний спосіб. Тепер твій клас BlobStorage має пряму залежність на змінні середовища.
Як би я це робив:

  1. Зробив би окремий клас ReportRepositorySettings чи щось таке
  2. На стартапі в цей клас би записував дві проперті BlobStorageConnectionString, OrderTimeOutReportContainer
  3. BlobStorage би залежав на ReportRepositorySettings і юзав вже ці проперті

Із таким апроачем ми можемо заповнювати оці 2 проперті без залежності того звідки вони йдуть

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.

2 participants