22
33import clap .server .adapter .outbound .api .dto .PushNotificationTemplate ;
44import clap .server .adapter .outbound .persistense .entity .notification .constant .NotificationType ;
5+ import clap .server .application .port .inbound .domain .TaskService ;
56import clap .server .application .port .outbound .webhook .SendAgitPort ;
67import clap .server .application .service .task .UpdateTaskService ;
78import clap .server .common .annotation .architecture .ExternalApiAdapter ;
89import clap .server .domain .model .task .Task ;
10+ import clap .server .exception .ApplicationException ;
11+ import clap .server .exception .code .NotificationErrorCode ;
12+ import com .fasterxml .jackson .core .JsonProcessingException ;
13+ import com .fasterxml .jackson .databind .JsonNode ;
14+ import com .fasterxml .jackson .databind .ObjectMapper ;
915import lombok .RequiredArgsConstructor ;
1016import org .springframework .beans .factory .annotation .Value ;
1117import org .springframework .http .HttpEntity ;
@@ -21,8 +27,9 @@ public class AgitClient implements SendAgitPort {
2127 @ Value ("${webhook.agit.url}" )
2228 private String AGIT_WEBHOOK_URL ;
2329
24- private final UpdateTaskService updateTaskService ;
2530 private final AgitTemplateBuilder agitTemplateBuilder ;
31+ private final ObjectMapper objectMapper ;
32+ private final TaskService taskService ;
2633
2734 @ Override
2835 public void sendAgit (PushNotificationTemplate request , Task task ) {
@@ -33,10 +40,20 @@ public void sendAgit(PushNotificationTemplate request, Task task) {
3340 if (request .notificationType () == NotificationType .TASK_REQUESTED ) {
3441 ResponseEntity <String > responseEntity = restTemplate .exchange (
3542 AGIT_WEBHOOK_URL , HttpMethod .POST , entity , String .class );
36- updateTaskService . updateAgitPostId (responseEntity , task );
43+ updateAgitPostId (responseEntity , task );
3744 }
3845 else {
3946 restTemplate .exchange (AGIT_WEBHOOK_URL , HttpMethod .POST , entity , String .class );
4047 }
4148 }
49+
50+ private void updateAgitPostId (ResponseEntity <String > responseEntity , Task task ) {
51+ try {
52+ JsonNode jsonNode = objectMapper .readTree (responseEntity .getBody ());
53+ task .updateAgitPostId (jsonNode .get ("id" ).asLong ());
54+ taskService .upsert (task );
55+ } catch (JsonProcessingException e ) {
56+ throw new ApplicationException (NotificationErrorCode .AGIT_SEND_FAILED );
57+ }
58+ }
4259}
0 commit comments