-
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
jc - Add parameters to Commons type. #30
Conversation
Codecov Report
@@ Coverage Diff @@
## main #30 +/- ##
============================================
+ Coverage 66.85% 67.40% +0.55%
Complexity 42 42
============================================
Files 47 47
Lines 353 359 +6
Branches 9 9
============================================
+ Hits 236 242 +6
Misses 116 116
Partials 1 1
Continue to review full report at Codecov.
|
This comment was marked as outdated.
This comment was marked as outdated.
src/main/java/edu/ucsb/cs156/happiercows/models/CreateCommonsParams.java
Outdated
Show resolved
Hide resolved
private String cowPrice; | ||
private String milkPrice; | ||
private String startingBalance; |
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.
Should these be numeric values instead of strings?
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.
They have type String
because of the @RequestBody
annotation. My first try resulted in a type error. I thought Spring would coerce them like it does for query parameters but I guess not.
@ApiParam("request body") @RequestBody CreateCommonsParams params
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.
Interesting, what types did you try to use? RequestBody should use the same HttpMessageConverter used by other parts of Spring, so I'm surprised that it's not supported.
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 may have used primitives.
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.
You may need @DateTimeFormat
and @NumberFormat
to get those to work?
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.
Oh my gosh Bryan thank you! My only concern now is that the Commons
and CreateCommonsParams
types only differ by an id
field and their respective annotations.
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 think it's natural to be concerned about code duplication, but there's a case to be made about decoupling the database internals from the public-facing API. For simple use cases, the model and entity will usually look very similar, but that may change as new fields and relations are added. Having a separate model and entity also allows us to freely make changes to database persistence without requiring any changes on the frontend.
You might find better resources about this design pattern if you try reading up on Data Transfer Objects (DTOs). There are libraries that make this model/DTO <-> entity conversion much simpler, though we don't currently have that set up in these projects.
Thanks Bryan. That took far too long. |
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.
Nice, ended up being a larger task than expected. Good job maintaining coverage.
May we merge? @btk5h |
Adds the fields specified in
gamePlay.md
to theCommons
type, and modifies the controller to allow them to be passed in a GET request to/api/commons/new
.Internally,
startingDate
is aDate
type, which Spring seems to know how to serialize. TheDate
is constructed from aGregorianCalendar
using the 'default time zone' which I believe is the system's time zone, which may not be ideal if this game is running on a cluster in Vermont.GregorianCalendar
has a constructor that accepts aTimeZone
but my eyes kind of glazed over.