Skip to content

Commit 325b494

Browse files
committed
feat: update client
1 parent f997dcc commit 325b494

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

backend/src/main/java/ch/xxx/aidoclibchat/adapter/client/TmdbRestClient.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
import org.slf4j.Logger;
1616
import org.slf4j.LoggerFactory;
1717
import org.springframework.beans.factory.annotation.Value;
18+
import org.springframework.boot.context.event.ApplicationReadyEvent;
1819
import org.springframework.stereotype.Component;
1920
import org.springframework.web.client.RestClient;
2021

22+
import com.fasterxml.jackson.core.JsonProcessingException;
23+
import com.fasterxml.jackson.databind.ObjectMapper;
24+
2125
import ch.xxx.aidoclibchat.domain.client.TmdbClient;
2226

2327
@Component
@@ -32,6 +36,13 @@ public TmdbRestClient(RestClient restClient) {
3236
this.restClient = restClient;
3337
}
3438

39+
//@EventListener
40+
public void onApplicationEvent(ApplicationReadyEvent event) {
41+
var request = new Request("Alien");
42+
var response = this.apply(request);
43+
LOG.info("TMDB Response: {}", toJson(response));
44+
}
45+
3546
@Override
3647
public Response apply(Request request) {
3748
var url = BASE_URL + "search/movie?query=" + request.query();
@@ -40,9 +51,19 @@ public Response apply(Request request) {
4051
.header("accept", "application/json")
4152
.header("Authorization", "Bearer "+this.apiKey)
4253
.retrieve()
43-
.body(Response.class);
44-
LOG.info("Response from TMDB: {}", response);
54+
.body(Response.class);
55+
//LOG.info("TMDB Response: {}", toJson(response));
4556
return response;
4657
}
4758

59+
private static String toJson(Object obj) {
60+
var result = "";
61+
try {
62+
result = new ObjectMapper().writeValueAsString(obj);
63+
} catch (JsonProcessingException e) {
64+
LOG.error("Error converting object to JSON", e);
65+
}
66+
return result;
67+
}
68+
4869
}

backend/src/main/java/ch/xxx/aidoclibchat/domain/client/TmdbClient.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
/*
2-
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3-
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
1+
/**
2+
* Copyright 2023 Sven Loesekann
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
412
*/
5-
613
package ch.xxx.aidoclibchat.domain.client;
714

815
import java.util.Map;

0 commit comments

Comments
 (0)