1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66package com.transport.controller;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.transport.entities.ReturnTruckDetails;
import com.transport.payloads.NewReturnTruckDetail;
import com.transport.services.DriverService;
@RestController
@RequestMapping(path="/api/driver/")
public class DriverController {
Logger logger = LoggerFactory.getLogger(DriverController.class);
@Autowired
DriverService driverService;
/**
* Posting new return truck details.
*
*/
@PostMapping(path = "/truck")
public ResponseEntity<ReturnTruckDetails> postNewTruckDetails(@RequestBody NewReturnTruckDetail newReturnTruckDetail, Authentication authentication){
// logging
logger.info("method=postNewTruckDetails | request=/truck | newReturnTruckDetail: "+ newReturnTruckDetail);
if(newReturnTruckDetail == null) {
return ResponseEntity.badRequest().build();
}
// call the services.
String principalUser = authentication.getPrincipal().toString();
ReturnTruckDetails postedReturnTruckDetails = driverService.postReturnTruckDetails(newReturnTruckDetail, authentication);
// return ResponseEntity.status(HttpStatus.CREATED).body(postedReturnTruckDetails);
return new ResponseEntity<ReturnTruckDetails>(postedReturnTruckDetails, HttpStatus.CREATED);
}
/**
* Get all truck details associated with user id.
*
*/
@GetMapping(path = "/truck")
public ResponseEntity<List<ReturnTruckDetails>> getAllReturnTruckDetails(Authentication authentication){
logger.info("method=getAllReturnTruckDetails | request=/truck | authentication: "+ authentication);
List<ReturnTruckDetails> allReturnTruckDetails = driverService.getAllReturnTruckDetails(authentication);
return new ResponseEntity<>(allReturnTruckDetails, HttpStatus.OK);
}
}