Skip to content

Commit 9fbc99d

Browse files
committed
#36 Add logging to API calls
1 parent 774a753 commit 9fbc99d

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

src/main/java/team/deployservice/controller/v1/DeploymentControllerV1.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import io.swagger.annotations.Api;
44
import io.swagger.annotations.ApiOperation;
55
import io.swagger.annotations.ApiParam;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
68
import org.springframework.beans.factory.annotation.Autowired;
79
import org.springframework.format.annotation.DateTimeFormat;
810
import org.springframework.http.HttpStatus;
@@ -16,6 +18,7 @@
1618
import java.time.LocalDate;
1719
import java.time.ZoneOffset;
1820
import java.time.ZonedDateTime;
21+
import java.time.format.DateTimeFormatter;
1922
import java.util.Date;
2023
import java.util.List;
2124
import java.util.Optional;
@@ -25,6 +28,8 @@
2528
@Api
2629
public class DeploymentControllerV1
2730
{
31+
32+
private static final Logger log = LoggerFactory.getLogger(DeploymentControllerV1.class);
2833

2934
private final DeploymentService deploymentService;
3035

@@ -38,48 +43,58 @@ public DeploymentControllerV1(DeploymentService deploymentService)
3843
@ResponseStatus(HttpStatus.CREATED)
3944
@ApiOperation(value = "Store a deployment", notes = "Store a single deployment", response = Deployment.class)
4045
public Deployment store(@Valid @RequestBody Deployment deployment){
46+
log.info("Store deployment with id {}", deployment.getDeploymentId());
4147
return deploymentService.store(deployment);
4248
}
4349

4450
@GetMapping("/deployment")
4551
@ResponseStatus(HttpStatus.OK)
4652
@ApiOperation(value = "List all deployments", notes = "List all deployments without filtering", response = Deployment.class, responseContainer = "List")
4753
public List<Deployment> list(){
54+
log.info("List all deployments");
4855
return deploymentService.list();
4956
}
5057

5158
@GetMapping("/deployment/{id}")
5259
@ResponseStatus(HttpStatus.OK)
5360
@ApiOperation(value = "Get a specific deployment specified by it's id", response = Deployment.class)
5461
public Optional<Deployment> show(@PathVariable @ApiParam(value = "The deployment id", required = true) String id){
62+
log.info("Show deployment with id {}", id);
5563
return deploymentService.get(id);
5664
}
5765

5866
@DeleteMapping("/deployment/{id}")
5967
@ResponseStatus(HttpStatus.OK)
6068
@ApiOperation(value = "Delete a specific deployment specified by it's id", response = Deployment.class)
61-
public String delete(@PathVariable @ApiParam(value = "The deployment id", required = true) String id) { return deploymentService.delete(id); }
69+
public String delete(@PathVariable @ApiParam(value = "The deployment id", required = true) String id) {
70+
log.info("Delete deployment with id {}", id);
71+
return deploymentService.delete(id);
72+
}
6273

6374
@GetMapping("/deployment/application/{id}")
6475
@ResponseStatus(HttpStatus.OK)
6576
@ApiOperation(value = "List all deployments for an application", notes = "List all deployments filtered by application id", response = Deployment.class, responseContainer = "List")
6677
public List<Deployment> listForApp(@PathVariable @ApiParam(value = "The application id", required = true) String id){
78+
log.info("List deployments for application with id {}", id);
6779
return deploymentService.listAllForApplication(id);
6880
}
6981

7082
@GetMapping("/deployment/hierarchy/{id}")
7183
@ResponseStatus(HttpStatus.OK)
7284
@ApiOperation(value = "List all deployments for a hierarchy", notes = "List all deployments in a hierarchy starting at node with application id", response = Deployment.class, responseContainer = "List")
7385
public List<Deployment> listForHierarchy(@PathVariable @ApiParam(value = "The application id", required = true) String id){
86+
log.info("List all deployments for a team hierarchy starting at application with id {}", id);
7487
return deploymentService.listAllForHierarchy(id);
7588
}
7689

7790
@GetMapping("/deployment/application/{id}/date/{date}")
7891
@ResponseStatus(HttpStatus.OK)
7992
@ApiOperation(value = "List all deployments for an application and date combination", notes = "List all deployments filtered by application id and date", response = Deployment.class, responseContainer = "List")
8093
public List<Deployment> listForAppAndDate(@PathVariable @ApiParam(value = "The application id", required = true) String id, @PathVariable @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @ApiParam(value = "The deployment date in ISO Date format YYYY-MM-dd", required = true) LocalDate date){
81-
Date reportingDate = Date.from(date.atStartOfDay(ZoneOffset.UTC).toInstant());
82-
return deploymentService.listAllForApplication(id, reportingDate);
94+
ZonedDateTime reportingDate = date.atStartOfDay(ZoneOffset.UTC);
95+
Date rDate = Date.from(reportingDate.toInstant());
96+
log.info("List all deployments with application id {} for date {}", id, DateTimeFormatter.ISO_LOCAL_DATE.format(reportingDate));
97+
return deploymentService.listAllForApplication(id, rDate);
8398
}
8499

85100
@GetMapping("/deployment/application/{id}/frequency")
@@ -88,15 +103,18 @@ public List<Deployment> listForAppAndDate(@PathVariable @ApiParam(value = "The a
88103
public DeploymentFrequency calculateDeployFreq(@PathVariable @ApiParam(value = "The application id", required = true) String id){
89104
ZonedDateTime date = LocalDate.now().minusDays(1).atStartOfDay(ZoneOffset.UTC);
90105
Date reportingDate = Date.from(date.toInstant());
106+
log.info("Calculate deployment frequency for application id {} from date {}", id, DateTimeFormatter.ISO_LOCAL_DATE.format(date));
91107
return deploymentService.calculateDeployFreq(id, reportingDate);
92108
}
93109

94110
@GetMapping("/deployment/application/{id}/frequency/{date}")
95111
@ResponseStatus(HttpStatus.OK)
96112
@ApiOperation(value = "Calculate deployment frequency for an application for the date specified", response = DeploymentFrequency.class)
97113
public DeploymentFrequency calculateDeployFreq(@PathVariable @ApiParam(value = "The application id", required = true) String id, @PathVariable @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @ApiParam(value = "The deployment date in ISO Date format YYYY-MM-dd", required = true) LocalDate date){
98-
Date reportingDate = Date.from(date.atStartOfDay(ZoneOffset.UTC).toInstant());
99-
return deploymentService.calculateDeployFreq(id, reportingDate);
114+
ZonedDateTime reportingDate = date.atStartOfDay(ZoneOffset.UTC);
115+
Date rDate = Date.from(reportingDate.toInstant());
116+
log.info("Calculate deployment frequency for application id {} from date {}", id, DateTimeFormatter.ISO_LOCAL_DATE.format(reportingDate));
117+
return deploymentService.calculateDeployFreq(id, rDate);
100118
}
101119

102120
@GetMapping("/deployment/application/{id}/lead_time")
@@ -105,14 +123,17 @@ public DeploymentFrequency calculateDeployFreq(@PathVariable @ApiParam(value = "
105123
public LeadTime calculateLeadTime(@PathVariable @ApiParam(value = "The application id", required = true) String id){
106124
ZonedDateTime date = LocalDate.now().minusDays(1).atStartOfDay(ZoneOffset.UTC);
107125
Date reportingDate = Date.from(date.toInstant());
126+
log.info("Calculate lead time for application id {} from date {}", id, DateTimeFormatter.ISO_LOCAL_DATE.format(date));
108127
return deploymentService.calculateLeadTime(id, reportingDate);
109128
}
110129

111130
@GetMapping("/deployment/application/{id}/lead_time/{date}")
112131
@ResponseStatus(HttpStatus.OK)
113132
@ApiOperation(value = "Calculate lead time for an application for the date specified", response = LeadTime.class)
114133
public LeadTime calculateLeadTime(@PathVariable @ApiParam(value = "The application id", required = true) String id, @PathVariable @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @ApiParam(value = "The deployment date in ISO Date format YYYY-MM-dd", required = true) LocalDate date){
115-
Date reportingDate = Date.from(date.atStartOfDay(ZoneOffset.UTC).toInstant());
116-
return deploymentService.calculateLeadTime(id, reportingDate);
134+
ZonedDateTime reportingDate = date.atStartOfDay(ZoneOffset.UTC);
135+
Date rDate = Date.from(date.atStartOfDay(ZoneOffset.UTC).toInstant());
136+
log.info("Calculate lead time for application id {} from date {}", id, DateTimeFormatter.ISO_LOCAL_DATE.format(reportingDate));
137+
return deploymentService.calculateLeadTime(id, rDate);
117138
}
118139
}

0 commit comments

Comments
 (0)