Search in sources :

Example 1 with IfRecord

use of com.faendir.zachtronics.bot.inf.model.IfRecord in project zachtronics-leaderboard-bot by F43nd1r.

the class IfController method getRecord.

@GetMapping(path = "/puzzle/{puzzleId}/category/{categoryId}/record", produces = MediaType.APPLICATION_JSON_VALUE)
public IfRecordDTO getRecord(@PathVariable String puzzleId, @PathVariable String categoryId) {
    IfPuzzle puzzle = findPuzzle(puzzleId);
    IfCategory category = findCategory(categoryId);
    IfRecord record = repository.find(puzzle, category);
    if (record != null)
        return IfRecordDTO.fromCategoryRecord(new CategoryRecord<>(record, EnumSet.of(category)));
    else
        return null;
}
Also used : IfRecord(com.faendir.zachtronics.bot.inf.model.IfRecord) IfPuzzle(com.faendir.zachtronics.bot.inf.model.IfPuzzle) IfCategory(com.faendir.zachtronics.bot.inf.model.IfCategory) CategoryRecord(com.faendir.zachtronics.bot.repository.CategoryRecord)

Example 2 with IfRecord

use of com.faendir.zachtronics.bot.inf.model.IfRecord in project zachtronics-leaderboard-bot by F43nd1r.

the class IfRecordDTO method fromCategoryRecord.

@NotNull
public static IfRecordDTO fromCategoryRecord(@NotNull CategoryRecord<IfRecord, IfCategory> categoryRecord) {
    IfRecord record = categoryRecord.getRecord();
    Set<IfCategory> categories = categoryRecord.getCategories();
    return new IfRecordDTO(IfScoreDTO.fromScore(record.getScore()), record.getScore().toDisplayString(DisplayContext.plainText()), record.getAuthor(), record.getDataLink(), UtilsKt.smartFormat(categories, UtilsKt.toMetricsTree(record.getPuzzle().getSupportedCategories())));
}
Also used : IfRecord(com.faendir.zachtronics.bot.inf.model.IfRecord) IfCategory(com.faendir.zachtronics.bot.inf.model.IfCategory) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IfCategory (com.faendir.zachtronics.bot.inf.model.IfCategory)2 IfRecord (com.faendir.zachtronics.bot.inf.model.IfRecord)2 IfPuzzle (com.faendir.zachtronics.bot.inf.model.IfPuzzle)1 CategoryRecord (com.faendir.zachtronics.bot.repository.CategoryRecord)1 NotNull (org.jetbrains.annotations.NotNull)1