1
+ package com .objectcomputing .checkins .services .checkins ;
2
+
3
+ import java .net .URI ;
4
+ import java .util .List ;
5
+ import java .util .UUID ;
6
+
7
+ import javax .annotation .Nullable ;
8
+ import javax .validation .Valid ;
9
+
10
+ import com .objectcomputing .checkins .services .checkins .CheckIns ;
11
+
12
+ import io .micronaut .http .HttpResponse ;
13
+ import io .micronaut .http .annotation .Body ;
14
+ import io .micronaut .http .annotation .Controller ;
15
+ import io .micronaut .http .annotation .Get ;
16
+ import io .micronaut .http .annotation .Post ;
17
+ import io .micronaut .http .annotation .Put ;
18
+
19
+ @ Controller ("/check-in" )
20
+ public class CheckInsController {
21
+
22
+ protected final CheckInsRepository checkInsRepository ;
23
+
24
+ public CheckInsController (CheckInsRepository checkInsRepository ){
25
+ this .checkInsRepository = checkInsRepository ;
26
+ }
27
+
28
+ @ Get ("/{?teamMemberId,targetYear,targetQtr,pdlId}" )
29
+ public List <CheckIns > findByValue (@ Nullable UUID teamMemberId , @ Nullable String targetYear , @ Nullable UUID pdlId
30
+ ,@ Nullable String targetQtr ) {
31
+
32
+ if (teamMemberId != null ) {
33
+ return checkInsRepository .findByName (teamMemberId );
34
+ } else if (targetYear != null ) {
35
+ return checkInsRepository .findByTargetQuarter (targetYear ,targetQtr );
36
+ } else if (pdlId != null ) {
37
+ return checkInsRepository .findByPdlId (pdlId );
38
+ } else {
39
+ return checkInsRepository .findAll ();
40
+ }
41
+ }
42
+
43
+
44
+ @ Post ("/" )
45
+ public HttpResponse <CheckIns > save (@ Body @ Valid CheckIns checkIns ) {
46
+ CheckIns newMemberCheckIn = checkInsRepository .save (checkIns );
47
+
48
+ return HttpResponse .created (newMemberCheckIn )
49
+ .headers (headers -> headers .location (location (newMemberCheckIn .getPdlId ())));
50
+ }
51
+
52
+
53
+ @ Put ("/" )
54
+ public HttpResponse <?> update (@ Body @ Valid CheckIns checkIn ) {
55
+
56
+ if (null != checkIn .getTeamMemberId ()){
57
+ CheckIns updatedMemberCheckIn = checkInsRepository .update (checkIn );
58
+ return HttpResponse
59
+ .ok ()
60
+ .headers (headers -> headers .location (location (updatedMemberCheckIn .getTeamMemberId ())))
61
+ .body (updatedMemberCheckIn );
62
+
63
+ }
64
+
65
+ return HttpResponse .badRequest ();
66
+ }
67
+
68
+ private URI location (UUID pdlId ) {
69
+ return URI .create ("/check-in/" + pdlId );
70
+ }
71
+
72
+ }
0 commit comments