Skip to content

feature changes#3

Open
gonzalo-bl wants to merge 1 commit intomainfrom
rate-and-block-workers
Open

feature changes#3
gonzalo-bl wants to merge 1 commit intomainfrom
rate-and-block-workers

Conversation

@gonzalo-bl
Copy link
Contributor

Implementing requested feature.

},
constraints: table =>
{
table.PrimaryKey("PK_ShiftRatings", x => new { x.ShiftId, x.WorkerId });

Choose a reason for hiding this comment

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

Should the FacilityId be included as a part of the PK?

[HttpGet("facilities/list")]
public async Task<IActionResult> GetFacilities([FromBody] RateWorkerRequest request)
{
return await _dbContext.Facilities.ToListAsync();
Copy link

@EscobarMirandaK EscobarMirandaK Nov 20, 2025

Choose a reason for hiding this comment

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

To follow the standard as the rest of the code, this should be moved to the repository, a handler and return the appropriate type.

}

[HttpGet("facilities/list")]
public async Task<IActionResult> GetFacilities([FromBody] RateWorkerRequest request)

Choose a reason for hiding this comment

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

This is a get method. Request should not have a body.

{
try
{
_workerRepository.BlockWorker(request.WorkerId, request.FacilityId);

Choose a reason for hiding this comment

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

A return needs to be added in the try statement.
if the BlockWorker is async, an await needs to be added.

[HttpPost("facilities/rate-worker")]
public async Task<IActionResult> RateWorker([FromBody] RateWorkerRequest request)
{
return await _rateWorkerHandler.HandleAsync(request);

Choose a reason for hiding this comment

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

No validations in any part of the code to make sure the data will be properly saved.

[HttpPost("facilities/block-worker")]
public async Task<IActionResult> BlockWorker([FromBody] BlockWorkerRequest request)
{
return await _blockWorkerHandler.HandleAsync(request);

Choose a reason for hiding this comment

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

No validations in any part of the code to make sure the data will be properly saved.

Score = request.Score
};

_dbContext.ShiftRatings.Add(shiftRating);

Choose a reason for hiding this comment

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

this is calling the DB directly instead following the structure of the BlockWorkerHandler that uses a repository.

{
try
{
_workerRepository.BlockWorker(request.WorkerId, request.FacilityId);

Choose a reason for hiding this comment

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

A validation needs to be added to avoid duplicate records.

Score = request.Score
};

_dbContext.ShiftRatings.Add(shiftRating);

Choose a reason for hiding this comment

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

A validation needs to be added to avoid duplicate records.

}
catch (Exception e)
{
return new JsonResult(new { error = e.Message });

Choose a reason for hiding this comment

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

Logs need to be added for debugging purposes.

}
catch (Exception e)
{
return new JsonResult(new { error = e.Message });

Choose a reason for hiding this comment

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

Logs need to be added for debugging purposes.

constraints: table =>
{
table.PrimaryKey("PK_ShiftRatings", x => new { x.ShiftId, x.WorkerId });
table.ForeignKey("FK_ShiftRatings_Shifts_ShiftId", x => x.ShiftId, "Shifts", "Id", onDelete: ReferentialAction.Cascade);

Choose a reason for hiding this comment

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

Remove extra spaces

{
table.PrimaryKey("PK_ShiftRatings", x => new { x.ShiftId, x.WorkerId });
table.ForeignKey("FK_ShiftRatings_Shifts_ShiftId", x => x.ShiftId, "Shifts", "Id", onDelete: ReferentialAction.Cascade);
table.ForeignKey("FK_ShiftRatings_Facilities_FacilityId", x => x.FacilityId, "Facilities", "Id", onDelete: ReferentialAction.Cascade);

Choose a reason for hiding this comment

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

Remove extra spaces

_blockWorkerHandler = blockWorkerHandler;
}

[HttpGet("facilities/list")]

Choose a reason for hiding this comment

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

Route is duplicating the "facilities" part.

return await _dbContext.Facilities.ToListAsync();
}

[HttpPost("facilities/rate-worker")]

Choose a reason for hiding this comment

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

Route is duplicating the "facilities" part.

return await _rateWorkerHandler.HandleAsync(request);
}

[HttpPost("facilities/block-worker")]

Choose a reason for hiding this comment

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

Route is duplicating the "facilities" part.

}
catch (Exception e)
{
return new JsonResult(new { error = e.Message });

Choose a reason for hiding this comment

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

Depends on the complexity of the API and how public it is, this error message should not be returned.
A GUID or an identifier should be returned and saved anywhere using the identifier to search it.

}
catch (Exception e)
{
return new JsonResult(new { error = e.Message });

Choose a reason for hiding this comment

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

Depends on the complexity of the API and how public it is, this error message should not be returned.
A GUID or an identifier should be returned and saved anywhere using the identifier to search it.

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