-
Notifications
You must be signed in to change notification settings - Fork 0
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
w22-6pm-3 Profits #43
Conversation
Codecov Report
@@ Coverage Diff @@
## main #43 +/- ##
============================================
+ Coverage 79.30% 81.09% +1.79%
- Complexity 61 75 +14
============================================
Files 51 52 +1
Lines 401 439 +38
Branches 10 12 +2
============================================
+ Hits 318 356 +38
Misses 83 83
Continue to review full report at Codecov.
|
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.
Are profits not a variable of user commons? How are the profits in the table here connected to each individual user?
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.
So this is a lot of work!
Please, next time, parse this out in smaller pieces! We've been trying to model that throughout the course, separating the front end into little small bits. Separating it from the backend. Doing the backend a little at a time.
Because this is so big, we are going to need a bit more of a description than what you've provided. Normally, this would be 4 or 5 pull requests, and there would be screenshots with each and every one of them.
By combining everything together, it makes is much much harder for us to know how many points to assign. Most other teams get 10 points for this, 10 points for that... one PR at a time.
Please see if you can remove the dependency on moment, and also see if you can edit the description to help us through what you've done here.
…ent back to add more tests to get to 100%
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.
I'm really confused by this. Why should individual game players have the ability to generate profits out of thin air?
Surely this seems like it should be an admin only function?
@ApiOperation(value = "Update a single profit as user") | ||
@PreAuthorize("hasRole('ROLE_USER')") | ||
@PutMapping("") | ||
public Profit putProfitById( | ||
@ApiParam("id") @RequestParam Long id, | ||
@RequestBody @Valid Profit newProfit) { | ||
Long userId = getCurrentUser().getUser().getId(); | ||
|
||
Profit profit = profitRepository.findById(id).orElseThrow(() -> new EntityNotFoundException(Profit.class, id)); | ||
if (userId != profit.getUserCommons().getUserId()) | ||
throw new EntityNotFoundException(Profit.class, id); | ||
|
||
profit.setProfit(newProfit.getProfit()); | ||
profit.setTimestamp(newProfit.getTimestamp()); | ||
|
||
profitRepository.save(profit); | ||
|
||
return profit; | ||
} | ||
|
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.
What is the use case for a user to update their own profit?
This seems like a way that a user could cheat and just give themselves more money.
@ApiOperation(value = "Delete a Profit of the user") | ||
@PreAuthorize("hasRole('ROLE_USER')") | ||
@DeleteMapping("") | ||
public Object deleteProfit( | ||
@ApiParam("id") @RequestParam Long id) { | ||
Long userId = getCurrentUser().getUser().getId(); | ||
|
||
Profit profit = profitRepository.findById(id).orElseThrow(() -> new EntityNotFoundException(Profit.class, id)); | ||
|
||
if (userId != profit.getUserCommons().getUserId()) | ||
throw new EntityNotFoundException(Profit.class, id); | ||
|
||
profitRepository.delete(profit); | ||
|
||
return genericMessage("Profit with id %s deleted".formatted(id)); | ||
} | ||
} |
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.
What is the user case for a user to delete their own profit?
Shouldnt' this be an admin only function?
|
||
@Repository | ||
public interface ProfitRepository extends CrudRepository<Profit, Long> { | ||
//Iterable<Profit> findAll(); |
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.
What is this commented out line of code doing here?
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.
Apologies, I meant to take it out after testing as I found the CrudRepository already comes with findAll();, it will take it out.
@ApiOperation(value = "Create a new Profit as user") | ||
@PreAuthorize("hasRole('ROLE_USER')") | ||
@PostMapping("/post") | ||
public Profit postProfit( | ||
@ApiParam("profit") @RequestParam long profit, | ||
@ApiParam("timestamp") @RequestParam long timestamp, | ||
@ApiParam("userCommonsId") @RequestParam long userCommonsId) { | ||
|
||
Long userId = getCurrentUser().getUser().getId(); | ||
UserCommons userCommons = userCommonsRepository.findById(userCommonsId).orElseThrow(() -> new EntityNotFoundException(UserCommons.class, userCommonsId)); | ||
|
||
Profit createdProfit = new Profit(); | ||
createdProfit.setProfit(profit); | ||
createdProfit.setUserCommons(userCommons); | ||
createdProfit.setTimestamp(timestamp); | ||
Profit savedProfit = profitRepository.save(createdProfit); | ||
return savedProfit; | ||
} |
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.
What is the user case for a user to create a profit?
Doesn't that just give users the ability to cheat and give themselves money any time they want?
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.
LGTM
Overview
In this PR, we implemented the entity, repository, and controller for the Profits. We also implemented a test suite for all backend components to reach full code coverage for all new code written. We also implemented all the frontend components necessary for our backend components to be visible in the profits table.
Issues Addressed
This issue addresses issue #21.
Details
Backend Development:
Our goal during developing the backend for this issue was to create a Profits Controller that supported CRUD operations. This included creating an entity, repository, and controller for the Profits component.
The API endpoints created in the Profits Controller are as follows:
Get /api/profits: Gets a single profit for a user
Get /api/profits/admin: Gets a single profit as admin
Get /api/profits/admin/all: lists all profits
Get /api/profits/admin/all/commons: gets all profits belonging to a user as an admin
Get /api/profits/all/commons: Get all profits belonging to a user commons as an admin
Put /api/profits/admin: Updates a single profit as an admin
Delete /api/profits/admin: Deletes other users profit as admin
Post /api/profits/admin: Creates a new profit as admin
These endpoints can also be seen in the swagger-ui.
We then implemented tests for the Profits controller, focusing on writing tests for each CRUD operation, with both admin and user roles.
Above shows 100% jacoco coverage for the Profits controller.
Frontend Development:
The issues addressed in the frontend portion of this PR are as follows:
Created fixtures for Profits and ProfitsTable
Profits table is visible to the user with correct formatting
Profits table shows the correct profit values
Profits table displays formatted dates using profit timestamps
Profits table updates profit values
Profits table works with no profits
Wrote tests for Profits and ProfitsTable functionality
Profits table functionality:
Maven test results:
Jest coverage results: