Skip to content
Merged
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,5 +1,6 @@
package io.papermc.patchroulette.controller;

import io.papermc.patchroulette.config.ApplicationConfig;
import io.papermc.patchroulette.model.Patch;
import io.papermc.patchroulette.model.PatchId;
import io.papermc.patchroulette.model.Status;
Expand All @@ -18,6 +19,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -31,10 +33,17 @@
public class ApiController {

private final PatchService patchService;
private final ApplicationConfig applicationConfig;
private final PasswordEncoder passwordEncoder;

@Autowired
public ApiController(final PatchService patchService) {
public ApiController(
final PatchService patchService,
final ApplicationConfig applicationConfig,
final PasswordEncoder passwordEncoder) {
this.patchService = patchService;
this.applicationConfig = applicationConfig;
this.passwordEncoder = passwordEncoder;
}

@PreAuthorize("hasRole('PATCH')")
Expand Down Expand Up @@ -143,6 +152,38 @@ public ResponseEntity<List<String>> getMinecraftVersions() {
return ResponseEntity.ok(minecraftVersions);
}

public record LegacyUser(String username, String passwordHash) {}

public record ExportPatch(
String minecraftVersion,
String path,
String status,
String responsibleUser,
long lastUpdated,
Long duration) {}

public record LegacyDataExport(
long exportedAt, List<LegacyUser> legacyUsers, List<ExportPatch> patches) {}

@PreAuthorize("hasRole('PATCH')")
@GetMapping(value = "/export-legacy-data", produces = "application/json")
public ResponseEntity<LegacyDataExport> exportLegacyData() {
final List<LegacyUser> legacyUsers = this.applicationConfig.users().stream()
.map(user -> new LegacyUser(user.username(), this.passwordEncoder.encode(user.password())))
.toList();
Comment thread
jpenilla marked this conversation as resolved.
final List<ExportPatch> patches = this.patchService.getAllPatches().stream()
.map(patch -> new ExportPatch(
patch.getMinecraftVersion(),
patch.getPath(),
patch.getStatus().name(),
patch.getResponsibleUser(),
patch.getLastUpdated().toEpochMilli(),
patch.getDuration() == null ? null : patch.getDuration().toMillis()))
Comment thread
jpenilla marked this conversation as resolved.
.toList();
return ResponseEntity.ok(
new LegacyDataExport(System.currentTimeMillis(), legacyUsers, patches));
}

@PreAuthorize("hasRole('PATCH')")
@PostMapping(value = "/test-login", produces = "text/plain")
public ResponseEntity<String> testLogin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.papermc.patchroulette.repository.PatchRepository;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -46,6 +47,13 @@ public List<Patch> getAllPatches(final String minecraftVersion) {
return this.patchRepository.getPatchesByMinecraftVersion(minecraftVersion);
}

@Transactional(readOnly = true)
public List<Patch> getAllPatches() {
return this.patchRepository.findAll().stream()
.sorted(Comparator.comparing(Patch::getMinecraftVersion).thenComparing(Patch::getPath))
.toList();
}
Comment thread
jpenilla marked this conversation as resolved.

@Transactional
public List<String> startWorkOnPatches(
final String minecraftVersion, final List<String> patches, final String user) {
Expand Down
Loading