11package life .qbic .projectmanagement .application .api ;
22
3+ import static java .util .Objects .nonNull ;
4+
5+ import java .util .Optional ;
6+ import java .util .UUID ;
37import reactor .core .publisher .Mono ;
48
59/**
@@ -62,6 +66,24 @@ sealed interface UpdateResponseBody permits ProjectDesign {
6266
6367 }
6468
69+ /**
70+ * Cacheable requests provide a unique identifier so cache implementations can unambiguously
71+ * manage the requests.
72+ *
73+ * @since 1.9.0
74+ */
75+ sealed interface CacheableRequest permits ProjectUpdateRequest {
76+
77+ /**
78+ * Returns an ID that is unique to the request.
79+ *
80+ * @return the id
81+ * @since 1.9.0
82+ */
83+ String requestId ();
84+
85+ }
86+
6587 /**
6688 * Container for passing information in an {@link UpdateRequestBody} or
6789 * {@link UpdateResponseBody}.
@@ -82,8 +104,17 @@ record ProjectDesign(String title, String objective) implements UpdateRequestBod
82104 * @param requestBody the information to be updated.
83105 * @since 1.9.0
84106 */
85- record ProjectUpdateRequest (String projectId , UpdateRequestBody requestBody ) {
107+ record ProjectUpdateRequest (String projectId , UpdateRequestBody requestBody , String id ) implements
108+ CacheableRequest {
86109
110+ public ProjectUpdateRequest (String projectId , UpdateRequestBody requestBody ) {
111+ this (projectId , requestBody , UUID .randomUUID ().toString ());
112+ }
113+
114+ @ Override
115+ public String requestId () {
116+ return id ;
117+ }
87118 }
88119
89120 /**
@@ -93,8 +124,43 @@ record ProjectUpdateRequest(String projectId, UpdateRequestBody requestBody) {
93124 * @param responseBody the information that was updated.
94125 * @since 1.9.0
95126 */
96- record ProjectUpdateResponse (String projectId , UpdateResponseBody responseBody ) {
127+ record ProjectUpdateResponse (String projectId , UpdateResponseBody responseBody , String requestId ) {
128+
129+ public ProjectUpdateResponse {
130+ if (projectId == null ) {
131+ throw new IllegalArgumentException ("Project ID cannot be null" );
132+ }
133+ if (projectId .isBlank ()) {
134+ throw new IllegalArgumentException ("Project ID cannot be blank" );
135+ }
136+ if (requestId != null && requestId .isBlank ()) {
137+ requestId = null ;
138+ }
139+ }
97140
141+ /**
142+ * Retrieves the request id associated with this response. May be {@link Optional#empty()} but
143+ * never null.
144+ *
145+ * @return an Optional with the requestId; {@link Optional#empty()} otherwise.
146+ */
147+ public Optional <String > retrieveRequestId () {
148+ return Optional .ofNullable (requestId );
149+ }
150+
151+ /**
152+ * Returns the requestId, can be null.
153+ *
154+ * @return Returns the requestId, if no requestId is set, returns null.
155+ */
156+ @ Override
157+ public String requestId () {
158+ return requestId ;
159+ }
160+
161+ boolean hasRequestId () {
162+ return nonNull (requestId );
163+ }
98164 }
99165
100166 /**
0 commit comments