redirect on invalid paste
This commit is contained in:
parent
b2c034df5f
commit
0e585ed1cd
@ -1,5 +1,6 @@
|
|||||||
package cc.fascinated.backend.controller;
|
package cc.fascinated.backend.controller;
|
||||||
|
|
||||||
|
import cc.fascinated.backend.exception.impl.ResourceNotFoundException;
|
||||||
import cc.fascinated.backend.model.Paste;
|
import cc.fascinated.backend.model.Paste;
|
||||||
import cc.fascinated.backend.service.PasteService;
|
import cc.fascinated.backend.service.PasteService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -30,18 +31,29 @@ public class IndexController {
|
|||||||
|
|
||||||
@GetMapping(value = "/{id}")
|
@GetMapping(value = "/{id}")
|
||||||
public String paste(@PathVariable String id, Model model) {
|
public String paste(@PathVariable String id, Model model) {
|
||||||
Paste paste = pasteService.getPaste(id);
|
try {
|
||||||
model.addAttribute("paste", paste);
|
Paste paste = pasteService.getPaste(id);
|
||||||
model.addAttribute("title", "Paste - " + paste.getId());
|
if (paste == null) { // If the paste does not exist, redirect to the home page
|
||||||
model.addAttribute("rawUrl", "/raw/" + paste.getId());
|
return "redirect:/";
|
||||||
return "paste";
|
}
|
||||||
|
model.addAttribute("paste", paste);
|
||||||
|
model.addAttribute("title", "Paste - " + paste.getId());
|
||||||
|
model.addAttribute("rawUrl", "/raw/" + paste.getId());
|
||||||
|
return "paste";
|
||||||
|
} catch (ResourceNotFoundException ex) {
|
||||||
|
return "redirect:/";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/raw/{id}")
|
@GetMapping(value = "/raw/{id}")
|
||||||
public String pasteRaw(@PathVariable String id, Model model) {
|
public String pasteRaw(@PathVariable String id, Model model) {
|
||||||
Paste paste = pasteService.getPaste(id);
|
try {
|
||||||
model.addAttribute("paste", paste);
|
Paste paste = pasteService.getPaste(id);
|
||||||
model.addAttribute("title", "Paste - " + paste.getId() + " (Raw)");
|
model.addAttribute("paste", paste);
|
||||||
return "paste-raw";
|
model.addAttribute("title", "Paste - " + paste.getId() + " (Raw)");
|
||||||
|
return "paste-raw";
|
||||||
|
} catch (ResourceNotFoundException ex) {
|
||||||
|
return "redirect:/";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user