Skip to content

Commit

Permalink
temp disable word search api
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Jan 25, 2025
1 parent a04c717 commit 83fc264
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 122 deletions.
200 changes: 100 additions & 100 deletions src/main/java/vc/controller/ChatsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,104 +176,104 @@ public ResponseEntity<ChatWindowResponse> chatWindow(
}
}

@GetMapping("/chats/word-count")
@RateLimiter(name = "main")
@Cacheable("chats-word-count")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "Counts the number of times a word has appeared in chat",
content = {
@Content(
mediaType = "application/json",
schema = @Schema(implementation = WordCount.class)
)
}
),
@ApiResponse(
responseCode = "400",
description = "Bad request. The word must be between 4 and 30 characters.",
content = @Content
)
})
public ResponseEntity<WordCount> wordCount(
@RequestParam(value = "word", required = true) String word
) {
if (word == null || word.length() < 3 || word.length() > 50) {
return ResponseEntity.badRequest().build();
}
var count = dsl.selectCount()
.from(CHATS)
.where(CHATS.CHAT.likeIgnoreCase("%" + word + "%"))
.fetchOneInto(Integer.class);
if (count == null) count = 0;
return ResponseEntity.ok(new WordCount(count));
}

@GetMapping("/chats/search")
@RateLimiter(name = "main")
@Cacheable("chats-search")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "Find chat messages containing a specific word",
content = {
@Content(
mediaType = "application/json",
schema = @Schema(implementation = ChatSearchResponse.class)
)
}
),
@ApiResponse(
responseCode = "204",
description = "No data",
content = @Content
),
@ApiResponse(
responseCode = "400",
description = "Bad request.",
content = @Content
)
})
public ResponseEntity<ChatSearchResponse> chatSearch(
@RequestParam(value = "word", required = true) String word,
@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
@RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
@RequestParam(value = "pageSize", required = false) Integer pageSize,
@RequestParam(value = "page", required = false) Integer page
) {
if (pageSize != null && pageSize > 100) {
return ResponseEntity.badRequest().build();
}
if (word == null || word.length() < 4 || word.length() > 50) {
return ResponseEntity.badRequest().build();
}
final int size = pageSize == null ? 25 : pageSize;
var baseQuery = dsl
.select(CHATS.PLAYER_NAME, CHATS.PLAYER_UUID, CHATS.TIME, CHATS.CHAT)
.from(CHATS)
.where(CHATS.CHAT.likeIgnoreCase("%" + word + "%"));
if (startDate != null) {
baseQuery = baseQuery.and(CHATS.TIME.greaterOrEqual(startDate.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime()));
}
if (endDate != null) {
baseQuery = baseQuery.and(CHATS.TIME.lessOrEqual(endDate.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime()));
}
Long rowCount = dsl.selectCount()
.from(baseQuery)
.fetchOneInto(Long.class);
if (rowCount == null) rowCount = 0L;
var offset = (page == null ? 0 : Math.max(0, page - 1)) * size;
List<PlayerChat> chats = baseQuery
.orderBy(CHATS.TIME.desc())
.limit(size)
.offset(offset)
.fetch()
.into(PlayerChat.class);
if (chats.isEmpty()) {
return ResponseEntity.noContent().build();
} else {
return ResponseEntity.ok(new ChatSearchResponse(chats, rowCount.intValue(), (int) Math.ceil(rowCount / (double) size)));
}
}
// @GetMapping("/chats/word-count")
// @RateLimiter(name = "main")
// @Cacheable("chats-word-count")
// @ApiResponses(value = {
// @ApiResponse(
// responseCode = "200",
// description = "Counts the number of times a word has appeared in chat",
// content = {
// @Content(
// mediaType = "application/json",
// schema = @Schema(implementation = WordCount.class)
// )
// }
// ),
// @ApiResponse(
// responseCode = "400",
// description = "Bad request. The word must be between 4 and 30 characters.",
// content = @Content
// )
// })
// public ResponseEntity<WordCount> wordCount(
// @RequestParam(value = "word", required = true) String word
// ) {
// if (word == null || word.length() < 3 || word.length() > 50) {
// return ResponseEntity.badRequest().build();
// }
// var count = dsl.selectCount()
// .from(CHATS)
// .where(CHATS.CHAT.likeIgnoreCase("%" + word + "%"))
// .fetchOneInto(Integer.class);
// if (count == null) count = 0;
// return ResponseEntity.ok(new WordCount(count));
// }
//
// @GetMapping("/chats/search")
// @RateLimiter(name = "main")
// @Cacheable("chats-search")
// @ApiResponses(value = {
// @ApiResponse(
// responseCode = "200",
// description = "Find chat messages containing a specific word",
// content = {
// @Content(
// mediaType = "application/json",
// schema = @Schema(implementation = ChatSearchResponse.class)
// )
// }
// ),
// @ApiResponse(
// responseCode = "204",
// description = "No data",
// content = @Content
// ),
// @ApiResponse(
// responseCode = "400",
// description = "Bad request.",
// content = @Content
// )
// })
// public ResponseEntity<ChatSearchResponse> chatSearch(
// @RequestParam(value = "word", required = true) String word,
// @RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
// @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
// @RequestParam(value = "pageSize", required = false) Integer pageSize,
// @RequestParam(value = "page", required = false) Integer page
// ) {
// if (pageSize != null && pageSize > 100) {
// return ResponseEntity.badRequest().build();
// }
// if (word == null || word.length() < 4 || word.length() > 50) {
// return ResponseEntity.badRequest().build();
// }
// final int size = pageSize == null ? 25 : pageSize;
// var baseQuery = dsl
// .select(CHATS.PLAYER_NAME, CHATS.PLAYER_UUID, CHATS.TIME, CHATS.CHAT)
// .from(CHATS)
// .where(CHATS.CHAT.likeIgnoreCase("%" + word + "%"));
// if (startDate != null) {
// baseQuery = baseQuery.and(CHATS.TIME.greaterOrEqual(startDate.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime()));
// }
// if (endDate != null) {
// baseQuery = baseQuery.and(CHATS.TIME.lessOrEqual(endDate.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime()));
// }
// Long rowCount = dsl.selectCount()
// .from(baseQuery)
// .fetchOneInto(Long.class);
// if (rowCount == null) rowCount = 0L;
// var offset = (page == null ? 0 : Math.max(0, page - 1)) * size;
// List<PlayerChat> chats = baseQuery
// .orderBy(CHATS.TIME.desc())
// .limit(size)
// .offset(offset)
// .fetch()
// .into(PlayerChat.class);
// if (chats.isEmpty()) {
// return ResponseEntity.noContent().build();
// } else {
// return ResponseEntity.ok(new ChatSearchResponse(chats, rowCount.intValue(), (int) Math.ceil(rowCount / (double) size)));
// }
// }
}
44 changes: 22 additions & 22 deletions src/test/java/vc/ApiTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,28 @@ public void chatWindowMissingStartDateTest() {
assertEquals("startDate is required", chatWindowResponse);
}

@Test
public void wordCountApiTest() {
var wordCountResponse = httpRequest("/chats/word-count?word={word}",
ChatsController.WordCount.class,
Map.of(
"word", "test"
));
assertNotNull(wordCountResponse);
assertTrue(wordCountResponse.count() > 0);
}

@Test
public void wordSearchApiTest() {
var wordSearchResponse = httpRequest("/chats/search?word={word}&endDate={endDate}",
ChatsController.ChatSearchResponse.class,
Map.of(
"word", "test",
"endDate", "2021-01-01"
));
assertNotNull(wordSearchResponse);
assertTrue(wordSearchResponse.total() > 0);
}
// @Test
// public void wordCountApiTest() {
// var wordCountResponse = httpRequest("/chats/word-count?word={word}",
// ChatsController.WordCount.class,
// Map.of(
// "word", "test"
// ));
// assertNotNull(wordCountResponse);
// assertTrue(wordCountResponse.count() > 0);
// }
//
// @Test
// public void wordSearchApiTest() {
// var wordSearchResponse = httpRequest("/chats/search?word={word}&endDate={endDate}",
// ChatsController.ChatSearchResponse.class,
// Map.of(
// "word", "test",
// "endDate", "2021-01-01"
// ));
// assertNotNull(wordSearchResponse);
// assertTrue(wordSearchResponse.total() > 0);
// }

@Test
public void connectionsApiTest() {
Expand Down

0 comments on commit 83fc264

Please sign in to comment.