mirror of
https://gitea.gofwd.group/Forward_Group/ballistic-builder-spring.git
synced 2026-01-20 16:51:03 -05:00
small fix
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
package group.goforward.battlbuilder.controllers;
|
||||
|
||||
import group.goforward.battlbuilder.model.ShortLink;
|
||||
import group.goforward.battlbuilder.repos.ShortLinkRepository;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
@Controller
|
||||
public class GoController {
|
||||
|
||||
private final ShortLinkRepository repo;
|
||||
|
||||
public GoController(ShortLinkRepository repo) {
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
@GetMapping("/go/{code}")
|
||||
public ResponseEntity<Void> go(@PathVariable String code) {
|
||||
ShortLink link = repo.findByCodeAndIsActiveTrue(code).orElse(null);
|
||||
if (link == null) return ResponseEntity.notFound().build();
|
||||
|
||||
String dest = link.getDestinationUrl();
|
||||
|
||||
// Future: BUILD share links can compute a frontend URL here
|
||||
// if ("BUILD".equalsIgnoreCase(link.getType()) && link.getBuildUuid() != null) {
|
||||
// dest = "https://app.battlbuilder.com/build/" + link.getBuildUuid();
|
||||
// }
|
||||
|
||||
if (dest == null || dest.isBlank()) return ResponseEntity.notFound().build();
|
||||
|
||||
return ResponseEntity.status(302)
|
||||
.header(HttpHeaders.LOCATION, dest)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@ package group.goforward.battlbuilder.controllers;
|
||||
import group.goforward.battlbuilder.repos.ShortLinkRepository;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -22,27 +24,28 @@ public class ShortLinkRedirectController {
|
||||
var link = repo.findByCodeAndIsActiveTrue(code)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
|
||||
if (!"BUY".equals(link.getType()) || link.getDestinationUrl() == null) {
|
||||
String dest;
|
||||
|
||||
if ("BUY".equalsIgnoreCase(link.getType())) {
|
||||
dest = link.getDestinationUrl();
|
||||
if (dest == null || dest.isBlank()) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
} else if ("BUILD".equalsIgnoreCase(link.getType())) {
|
||||
if (link.getBuildUuid() == null) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
// ✅ Adjust to your actual frontend route + base URL if needed (dev vs prod)
|
||||
dest = "/builds/" + link.getBuildUuid();
|
||||
|
||||
} else {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.FOUND)
|
||||
.location(URI.create(link.getDestinationUrl()))
|
||||
.build();
|
||||
}
|
||||
|
||||
@GetMapping("/b/{code}")
|
||||
public ResponseEntity<Void> build(@PathVariable String code) {
|
||||
var link = repo.findByCodeAndIsActiveTrue(code)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
|
||||
if (!"BUILD".equals(link.getType()) || link.getBuildUuid() == null) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
// Adjust to your actual frontend route
|
||||
return ResponseEntity.status(HttpStatus.FOUND)
|
||||
.location(URI.create("/builds/" + link.getBuildUuid()))
|
||||
.location(URI.create(dest))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user