Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.crowfunder.cogmaster.Assets;

import com.crowfunder.cogmaster.Utils.StringResult;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.crowfunder.cogmaster.Assets;

import com.crowfunder.cogmaster.CogmasterConfig;
import com.crowfunder.cogmaster.Translations.TranslationsRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;

@ConfigurationProperties(prefix = "cogmaster")
public record CogmasterConfig(Translations translations, Routers routers, Parsers parsers, Assets assets) {

Expand Down
2 changes: 0 additions & 2 deletions api/src/main/java/com/crowfunder/cogmaster/Configs/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import java.util.Optional;
import java.util.Set;

/**
* @deprecated use {@link IndexController2} instead.
*/
@Deprecated
@RestController
@RequestMapping("api/v1/index")
public class IndexController {
Expand All @@ -19,38 +23,63 @@ public IndexController(IndexService indexService) {
this.indexService = indexService;
}

/**
* @deprecated use {@link IndexController2#resolveConfigByPath(String, String)}
* instead.
*/
@Deprecated
@GetMapping("config/{configName}")
public ResponseEntity<ConfigEntry> resolveConfigByPath(@PathVariable("configName") String configName, @RequestParam String path) {
public ResponseEntity<ConfigEntry> resolveConfigByPath(@PathVariable("configName") String configName,
@RequestParam String path) {
Optional<ConfigEntry> resolvedConfig = Optional.ofNullable(indexService.resolveConfig(configName, path));
return resolvedConfig.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

/**
* @deprecated use {@link IndexController2#resolveConfigByName(String)} instead.
*/
@Deprecated
@GetMapping("search")
public ResponseEntity<List<ConfigEntry>> resolveConfigByName(@RequestParam String q) {
Optional<List<ConfigEntry>> resolvedConfigs = Optional.ofNullable(indexService.resolveConfigByName(q));
return resolvedConfigs.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

/**
* @deprecated use {@link IndexController2#getAllConfigNames()} instead.
*/
@Deprecated
@GetMapping("info/config/names")
public ResponseEntity<Set<String>> getAllConfigNames() {
Optional<Set<String>> resolvedConfigs = Optional.ofNullable(indexService.getAllConfigNames());
return resolvedConfigs.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

/**
* @deprecated use {@link IndexController2#getAllConfigPaths()} instead.
*/
@Deprecated
@GetMapping("info/config/paths")
public ResponseEntity<Set<String>> getAllConfigPaths() {
Optional<Set<String>> resolvedConfigs = Optional.ofNullable(indexService.getAllConfigPaths());
return resolvedConfigs.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

/**
* @deprecated use {@link IndexController2#getConfigPathsMap()} instead.
*/
@GetMapping("info/config/map")
public ResponseEntity<Map<String, Set<String>>> getConfigPathsMap() {
Optional<Map<String, Set<String>>> resolvedConfigs = Optional.ofNullable(indexService.getConfigPathsMap());
return resolvedConfigs.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

/**
* @deprecated use {@link IndexController2#getAllEntryNames(boolean)} instead.
*/
@GetMapping("info/search/names")
public ResponseEntity<Set<String>> getAllEntryNames(@RequestParam(name= "tradeable", required = false, defaultValue = "false") boolean tradeable) {
public ResponseEntity<Set<String>> getAllEntryNames(
@RequestParam(name = "tradeable", required = false, defaultValue = "false") boolean tradeable) {
Optional<Set<String>> resolvedConfigs;
if (tradeable) {
resolvedConfigs = Optional.ofNullable(indexService.getTradeableEntryNames());
Expand All @@ -60,6 +89,9 @@ public ResponseEntity<Set<String>> getAllEntryNames(@RequestParam(name= "tradeab
return resolvedConfigs.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

/**
* @deprecated use {@link IndexController2#getStats()} instead.
*/
@GetMapping("info/stats")
public ResponseEntity<Map<String, Integer>> getStats() {
Optional<Map<String, Integer>> resolvedConfigs = Optional.ofNullable(indexService.getIndexStats());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.crowfunder.cogmaster.Index;

import com.crowfunder.cogmaster.Parseable.NameIndexService;
import com.crowfunder.cogmaster.Parseable.NewConfigEntry;
import com.crowfunder.cogmaster.Parseable.ParseableGraphRepository;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

@RestController
@RequestMapping("api/v2/index")
public class IndexController2 {

private final ParseableGraphRepository graphRepo;
private final IndexService2 indexService;
private final NameIndexService nameIndexService;

public IndexController2(ParseableGraphRepository graphRepo, IndexService2 indexService,
NameIndexService nameIndexService) {
this.graphRepo = graphRepo;
this.indexService = indexService;
this.nameIndexService = nameIndexService;
}

@GetMapping("config/{configName}")
public ResponseEntity<NewConfigEntry> resolveConfigByPath(@PathVariable("configName") String configName,
@RequestParam String path) {
return graphRepo.resolveConfig(configName, path).map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.notFound().build());
}

@GetMapping("search")
public ResponseEntity<List<NewConfigEntry>> resolveConfigByName(@RequestParam String q) {
return ResponseEntity.ok(indexService.resolveConfigByName(q));
}

@GetMapping("info/config/names")
public ResponseEntity<Set<String>> getAllConfigNames() {
return ResponseEntity.ok(indexService.getAllConfigFileNames());
}

@GetMapping("info/config/paths")
public ResponseEntity<Set<String>> getAllConfigPaths() {
return ResponseEntity.ok(indexService.getAllConfigEntryKeys());
}

@GetMapping("info/config/map")
public ResponseEntity<Map<String, Set<String>>> getConfigPathsMap() {
Optional<Map<String, Set<String>>> resolvedConfigs = Optional
.ofNullable(indexService.getAllConfigIndexKeysMapped());
return resolvedConfigs.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

@GetMapping("info/search/names")
public ResponseEntity<Set<String>> getAllEntryNames(
@RequestParam(name = "tradeable", required = false, defaultValue = "false") boolean tradeable) {
Optional<Set<String>> resolvedConfigs;
if (tradeable) {
resolvedConfigs = Optional.ofNullable(indexService.getTradeableEntryNames());
} else {
resolvedConfigs = Optional.ofNullable(nameIndexService.getNameIndexKeysPretty());
}
return resolvedConfigs.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

@GetMapping("info/stats")
public ResponseEntity<Map<String, Integer>> getStats() {
return ResponseEntity.ok(indexService.getIndexStats());
}

}
Loading