-
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
crud operations #4
Conversation
public interface TaxiTripsRepository extends JpaRepository<TaxiTripsModel, Long> { | ||
@Query(value = "select tableData from TaxiTripsModel tableData where tableData.taxiID = :taxiID", | ||
countQuery = "select count(tableData) from TaxiTripsModel tableData where tableData.taxiID = :taxiID") | ||
Page<TaxiTripsModel> searchByTaxiID(@Param("taxiID") Long taxiID, Pageable pageable); |
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.
this is not a search, i believe we have getOne here : https://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/JpaRepository.html#getOne-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.
@vanduc1102 I already have findById , i think it's similar to getOne ? Just i receiving Optional instead of null if row not found
This method just searching by other field, not included to JPA Repo
@Autowired | ||
private TaxiTripsService mTaxiTripsService; | ||
|
||
@GetMapping(value = "all") |
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.
we dont need to add all
or delete
in REST we have a convention to use HTTP verb
eg:
GET /
to findAll
GET /{id}
getOne
POST /
to create an object
PUT /
to update an object
DELETE /{id}
to detele an object
please go through the article here : https://hackernoon.com/restful-api-designing-guidelines-the-best-practices-60e1d954e7c9
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.
Done
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.
please push your changes :)
|
||
@RestController | ||
@RequestMapping("/v1/taxitrips") | ||
public class CrudAPIController { |
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 be TaxiTripController
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.
Done
@@ -3,13 +3,11 @@ | |||
import com.apac.test.apactakehometest.async.AsyncService; |
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.
we should move the implementation here into TaxiTripController
under a path
POST /import-csv
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.
Done
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.
Need to update code to compliant with REST guide line
and fineOne method,
@@ -0,0 +1,68 @@ | |||
package com.apac.test.apactakehometest.controller; |
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.
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.
Added CRUD operations:
Moved all operations to separate Service