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

w22-6pm-3 Profits #43

Merged
merged 30 commits into from
Mar 12, 2022
Merged

w22-6pm-3 Profits #43

merged 30 commits into from
Mar 12, 2022

Conversation

eambriz27
Copy link
Contributor

@eambriz27 eambriz27 commented Mar 9, 2022

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.

image

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:
Screen Shot 2022-03-11 at 3 28 05 PM

Maven test results:
Screen Shot 2022-03-11 at 2 49 28 PM

Jest coverage results:
Screen Shot 2022-03-11 at 2 49 37 PM

@codecov
Copy link

codecov bot commented Mar 9, 2022

Codecov Report

Merging #43 (fc2d903) into main (661f4a1) will increase coverage by 1.79%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             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              
Impacted Files Coverage Δ
frontend/src/main/components/Commons/Profits.js 100.00% <100.00%> (ø)
frontend/src/main/pages/PlayPage.js 100.00% <100.00%> (ø)
...156/happiercows/controllers/ProfitsController.java 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 661f4a1...fc2d903. Read the comment docs.

@eambriz27 eambriz27 marked this pull request as draft March 9, 2022 07:35
@eambriz27 eambriz27 requested review from bzamora020 and removed request for btk5h March 9, 2022 08:00
@bzamora020 bzamora020 added Attn-peer-CR At least one team member should do a code review before the staff Attn-respond-to-CR Please address changes requested in code review labels Mar 9, 2022
Copy link
Contributor

@gama-A gama-A left a 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?

@eambriz27 eambriz27 changed the title Profits Backend done with the exception of 100% jacoco coverage Profits Mar 11, 2022
Copy link
Contributor

@pconrad pconrad left a 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.

frontend/package.json Outdated Show resolved Hide resolved
frontend/src/main/components/Commons/Profits.js Outdated Show resolved Hide resolved
@eambriz27 eambriz27 temporarily deployed to team04-w22-6pm-3 March 11, 2022 19:13 Inactive
@eambriz27 eambriz27 changed the title Profits w22-6pm-3 Profits Mar 11, 2022
@eambriz27 eambriz27 temporarily deployed to team04-w22-6pm-3 March 11, 2022 19:58 Inactive
@eambriz27 eambriz27 temporarily deployed to team04-w22-6pm-3 March 11, 2022 20:12 Inactive
@eambriz27 eambriz27 temporarily deployed to team04-w22-6pm-3 March 11, 2022 20:43 Inactive
@eambriz27 eambriz27 temporarily deployed to team04-w22-6pm-3 March 11, 2022 21:54 Inactive
@eambriz27 eambriz27 temporarily deployed to team04-w22-6pm-3 March 11, 2022 22:02 Inactive
Copy link
Contributor

@pconrad pconrad left a 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?

Comment on lines 160 to 179
@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;
}

Copy link
Contributor

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.

Comment on lines 193 to 209
@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));
}
}
Copy link
Contributor

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();
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines 125 to 142
@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;
}
Copy link
Contributor

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?

@eambriz27 eambriz27 requested a review from pconrad March 12, 2022 19:18
Copy link
Contributor

@pconrad pconrad left a comment

Choose a reason for hiding this comment

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

LGTM

@pconrad pconrad temporarily deployed to team04-w22-6pm-3-qa March 12, 2022 19:25 Inactive
@pconrad pconrad temporarily deployed to team04-w22-6pm-3-qa March 12, 2022 20:30 Inactive
@pconrad pconrad added 20 10 and removed Attn-respond-to-CR Please address changes requested in code review Attn-peer-CR At least one team member should do a code review before the staff labels Mar 12, 2022
@pconrad pconrad merged commit 0b7a9ba into main Mar 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
w22-6pm-3
Awaiting triage
Development

Successfully merging this pull request may close these issues.

None yet

6 participants