Skip to content

Commit

Permalink
feat: 새로운 pointer api 반영되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
shinsj4653 committed Feb 21, 2024
1 parent 17358bc commit ea587d0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 48 deletions.
10 changes: 5 additions & 5 deletions src/main/java/gdsc/pointer/controller/ImageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public ResponseEntity<?> boundingPoly(ImageUploadDto dto) throws Exception {
return ResponseEntity.ok(ResultDto.res(HttpStatus.OK, "이미지 텍스트 좌표 값 반환", result));
}

// @PostMapping("pointer")
// public ResponseEntity<?> pointer(PointerDto dto) throws Exception {
// PointerResponseDto result = imageService.getWordsWithPointer(dto);
// return ResponseEntity.ok(ResultDto.res(HttpStatus.OK, "손가락 좌표에 해당하는 단어 반환", result));
// }
@PostMapping("pointer")
public ResponseEntity<?> pointer(PointerDto dto) throws Exception {
String result = imageService.getWordWithPointer(dto);
return ResponseEntity.ok(ResultDto.res(HttpStatus.OK, "손가락이 가리키는 텍스트 반환", result));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
@AllArgsConstructor
public class PointerAIDto {
private String imageUrl;
private int x;
private int y;
}
4 changes: 1 addition & 3 deletions src/main/java/gdsc/pointer/dto/request/image/PointerDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class PointerDto {
private MultipartFile file;
private int x;
private int y;
private MultipartFile image;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
@Getter
@AllArgsConstructor
public class PointerResponseDto {
private List<String> words;
private String response;
}
70 changes: 33 additions & 37 deletions src/main/java/gdsc/pointer/service/ImageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,43 +119,39 @@ public PolyResponseDto getImageTextBoundingPoly(MultipartFile file) throws IOExc
return responseDto.getBody();
}

// public PointerResponseDto getWordsWithPointer(PointerDto dto) throws IOException {
//
// // GCS 사진 업로드 후, 공개 이미지 url 반환
// String image_url = uploadImage(dto.getFile());
//
// //String image_url = dto.getImageUrl();
// int x = dto.getX();
// int y = dto.getY();
// ResponseEntity<PointerResponseDto> response = postPointer(image_url, x, y);
// return response.getBody();
// }
//
// private ResponseEntity<PointerResponseDto> postPointer(String url, int x, int y) {
//
// URI uri = UriComponentsBuilder
// .fromUriString(aiServerUrl)
// .path("/image/pointer")
// .encode()
// .build()
// .toUri();
//
// PointerAIDto pointerAIDto = new PointerAIDto();
// pointerAIDto.setImageUrl(url);
// pointerAIDto.setX(x);
// pointerAIDto.setY(y);
//
//
// RestTemplate restTemplate = new RestTemplate();
//
// ResponseEntity<PointerResponseDto> responseEntity = restTemplate.postForEntity(
// uri, pointerAIDto, PointerResponseDto.class
// );
// System.out.println(responseEntity);
//
// return responseEntity;
//
// }
public String getWordWithPointer(PointerDto dto) throws IOException {

// GCS 사진 업로드 후, 공개 이미지 url 반환
String image_url = uploadImage(dto.getImage());

//String image_url = dto.getImageUrl();
ResponseEntity<String> response = postPointer(image_url);
return response.getBody();
}

private ResponseEntity<String> postPointer(String url) {

URI uri = UriComponentsBuilder
.fromUriString(aiServerUrl)
.path("/image/pointer")
.encode()
.build()
.toUri();

PointerAIDto pointerAIDto = new PointerAIDto();
pointerAIDto.setImageUrl(url);


RestTemplate restTemplate = new RestTemplate();

ResponseEntity<String> responseEntity = restTemplate.postForEntity(
uri, pointerAIDto, String.class
);
System.out.println(responseEntity);

return responseEntity;

}

private ResponseEntity<PolyResponseDto> postImageBoundingPoly(String url) {
URI uri = UriComponentsBuilder
Expand Down

0 comments on commit ea587d0

Please sign in to comment.