-
Notifications
You must be signed in to change notification settings - Fork 4
Adjusted code to add new endpoint #105
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System; | ||
| using MediatR; | ||
| using Web.Api.Features.Companies.CreateCompany; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainUsing the same request model for create and update operations. The reuse of 🏁 Script executed: #!/bin/bash
# Check if EditCompanyBodyRequest was renamed from CreateCompanyBodyRequest
git log -p -- "src/Web.Api/Features/Companies/CreateCompany/EditCompanyBodyRequest.cs" | grep -A 10 -B 10 "CreateCompanyBodyRequest"Length of output: 0 🏁 Script executed: #!/bin/bash
# Locate the file that defines EditCompanyBodyRequest
file=$(rg -l "class EditCompanyBodyRequest" -n .)
echo "Found file: $file"
# Check its Git history (including renames) for occurrences of CreateCompanyBodyRequest
git log --follow --name-status -- "$file" | grep -E "^(R[0-9]+|[AMDR]\s)" | sed -n '1,20p'
git log --follow -p -- "$file" | grep -C 5 "CreateCompanyBodyRequest"Length of output: 87 🏁 Script executed: #!/bin/bash
# 1. List all BodyRequest classes in the repository
echo "=== All BodyRequest class definitions ==="
rg --ignore-case -n "class .*BodyRequest" -t cs || true
echo
# 2. List files in the CreateCompany feature folder
echo "=== Files in src/Web.Api/Features/Companies/CreateCompany ==="
find src/Web.Api/Features/Companies/CreateCompany -maxdepth 1 -type f -name "*.cs" -printf '%f\n' || true
echo
# 3. Show the top of UpdateCompanyCommand.cs to inspect its usings
echo "=== UpdateCompanyCommand.cs imports ==="
update_file=$(rg -l "class UpdateCompanyCommand" -n .)
if [ -n "$update_file" ]; then
sed -n '1,20p' "$update_file"
else
echo "UpdateCompanyCommand.cs not found"
fiLength of output: 712 Standardize the shared request model and clarify its intent The
- using Web.Api.Features.Companies.CreateCompany;
+ using Web.Api.Features.Companies.Models;This will make its purpose clear, reduce coupling between feature folders, and improve maintainability.
|
||
|
|
||
| namespace Web.Api.Features.Companies.UpdateCompany; | ||
|
|
||
| public record UpdateCompanyCommand : IRequest<Unit> | ||
| { | ||
| public UpdateCompanyCommand( | ||
| Guid companyId, | ||
| EditCompanyBodyRequest body) | ||
| { | ||
| CompanyId = companyId; | ||
| Body = body; | ||
| } | ||
|
|
||
| public Guid CompanyId { get; } | ||
|
|
||
| public EditCompanyBodyRequest Body { get; } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Domain.Entities.Companies; | ||
| using Domain.Validation; | ||
| using Domain.Validation.Exceptions; | ||
| using Infrastructure.Database; | ||
| using MediatR; | ||
| using Microsoft.EntityFrameworkCore; | ||
|
|
||
| namespace Web.Api.Features.Companies.UpdateCompany; | ||
|
|
||
| public record UpdateCompanyHandler : IRequestHandler<UpdateCompanyCommand, Unit> | ||
| { | ||
| private readonly DatabaseContext _context; | ||
|
|
||
| public UpdateCompanyHandler( | ||
| DatabaseContext context) | ||
| { | ||
| _context = context; | ||
| } | ||
|
|
||
| public async Task<Unit> Handle( | ||
| UpdateCompanyCommand request, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| request.Body.ThrowIfInvalid(); | ||
|
|
||
| var company = await _context.Companies.FirstOrDefaultAsync( | ||
| c => c.Id == request.CompanyId, | ||
| cancellationToken) | ||
| ?? throw NotFoundException.CreateFromEntity<Company>(request.CompanyId); | ||
|
|
||
| company.Update( | ||
| request.Body.Name, | ||
| request.Body.Description, | ||
| request.Body.LogoUrl, | ||
| request.Body.Links); | ||
|
|
||
| await _context.TrySaveChangesAsync(cancellationToken); | ||
| return Unit.Value; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add check for deleted companies in Update method.
The
Updatemethod implementation looks good with proper validation and normalization of inputs. However, unlike other methods that modify the entity (AddReview,ApproveReview,MarkReviewAsOutdated), it doesn't check if the company has been deleted.Consider adding a call to
NotDeletedOrFail()at the beginning of the method:public void Update( string name, string description, string logoUrl, List<string> links) { + NotDeletedOrFail(); + name = name?.Trim(); description = description?.Trim(); // rest of the method... }