fix warnings, mainly unused imports
there are 3 remaining but that's for later
This commit is contained in:
parent
fd2afd72b5
commit
8cbbaca653
9 changed files with 36 additions and 44 deletions
|
@ -1,24 +1,16 @@
|
|||
package eu.m724.talkpages;
|
||||
|
||||
import eu.m724.talkpages.orm.entity.Account;
|
||||
import eu.m724.talkpages.orm.entity.Page;
|
||||
import eu.m724.talkpages.orm.entity.PageRevision;
|
||||
import io.quarkus.hibernate.orm.panache.Panache;
|
||||
import io.quarkus.qute.CheckedTemplate;
|
||||
import io.quarkus.qute.TemplateInstance;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.transaction.Transactional;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.jboss.resteasy.reactive.RestResponse;
|
||||
import org.jboss.resteasy.reactive.RestResponse.Status;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Random;
|
||||
|
||||
@Path("/")
|
||||
public class IndexResource {
|
||||
@Inject
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package eu.m724.talkpages.orm.entity;
|
||||
|
||||
import io.quarkus.hibernate.orm.panache.PanacheEntity;
|
||||
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
|
@ -2,7 +2,6 @@ package eu.m724.talkpages.orm.generator;
|
|||
|
||||
import eu.m724.talkpages.orm.entity.Page;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.annotations.IdGeneratorType;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package eu.m724.talkpages.page;
|
||||
|
||||
import eu.m724.talkpages.RedirectService;
|
||||
import eu.m724.talkpages.orm.entity.Page;
|
||||
import eu.m724.talkpages.orm.entity.PageRevision;
|
||||
import io.quarkus.qute.CheckedTemplate;
|
||||
import io.quarkus.qute.TemplateInstance;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
@ -13,9 +10,6 @@ import jakarta.ws.rs.core.Response;
|
|||
@Path("/edit")
|
||||
@Produces(MediaType.TEXT_HTML)
|
||||
public class EditResource {
|
||||
@Inject
|
||||
RedirectService redirectService;
|
||||
|
||||
@CheckedTemplate
|
||||
public static class Templates {
|
||||
public static native TemplateInstance edit(Page page, String content, String name);
|
||||
|
@ -25,7 +19,7 @@ public class EditResource {
|
|||
@GET
|
||||
@Path("/")
|
||||
public Response editPageBlank() {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(Templates.create("", "198.51.100.42")).build();
|
||||
return Response.ok().entity(Templates.create("", "198.51.100.42")).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package eu.m724.talkpages.page;
|
||||
|
||||
import eu.m724.talkpages.TemplateExtensions;
|
||||
import eu.m724.talkpages.RedirectService;
|
||||
import eu.m724.talkpages.orm.entity.Page;
|
||||
import eu.m724.talkpages.orm.entity.PageRevision;
|
||||
|
|
|
@ -3,7 +3,6 @@ package eu.m724.talkpages.page.action;
|
|||
import eu.m724.talkpages.RedirectService;
|
||||
import eu.m724.talkpages.orm.entity.Account;
|
||||
import eu.m724.talkpages.orm.entity.Page;
|
||||
import eu.m724.talkpages.orm.entity.PageRevision;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.transaction.Transactional;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
|
@ -46,27 +45,16 @@ public class ActionResource {
|
|||
return redirectService.page(page)
|
||||
.cookie(new NewCookie.Builder("prefilledContent").value("").maxAge(0).build())
|
||||
.status(RestResponse.Status.SEE_OTHER).build();
|
||||
} catch (IllegalArgumentException e) { // TODO I could reduce all this code
|
||||
} catch (UnacceptableDataException | DuplicateException e) { // TODO I could reduce all this code
|
||||
// illegal title
|
||||
String encodedMessage = URLEncoder.encode(e.getMessage(), StandardCharsets.UTF_8);
|
||||
return Response
|
||||
.temporaryRedirect(URI.create("/edit/" + title + "?errorType=1&error=" + encodedMessage))
|
||||
.cookie(new NewCookie.Builder("prefilledContent").path("/edit/" + title).value(content).build()) // TODO find a better way
|
||||
.status(Response.Status.SEE_OTHER).build();
|
||||
} catch (IllegalStateException e) {
|
||||
// page already exists
|
||||
String encodedMessage = URLEncoder.encode(e.getMessage(), StandardCharsets.UTF_8);
|
||||
return Response
|
||||
.temporaryRedirect(URI.create("/edit/" + title + "?errorType=2&error=" + encodedMessage))
|
||||
.cookie(new NewCookie.Builder("prefilledContent").path("/edit/" + title).value(content).build())
|
||||
.status(Response.Status.SEE_OTHER).build();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Response
|
||||
.temporaryRedirect(URI.create("/edit/" + title + "?errorType=0&error=Server+error"))
|
||||
.cookie(new NewCookie.Builder("prefilledContent").path("/edit/" + title).value(content).build())
|
||||
.status(Response.Status.SEE_OTHER).build();
|
||||
int errorType = e instanceof UnacceptableDataException ? 1 : 2;
|
||||
|
||||
return Response
|
||||
.temporaryRedirect(URI.create("/edit/%s?errorType=%d&error=%s".formatted(title, errorType, encodedMessage)))
|
||||
.cookie(new NewCookie.Builder("prefilledContent").path("/edit/" + title).value(content).build())
|
||||
.status(Response.Status.SEE_OTHER).build();
|
||||
// TODO find a better, more concise way. Also maybe create a different type for each error. And consider if I should catch all Exceptions
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ public class ActionService {
|
|||
Page createPage(String title, String content, Account account) {
|
||||
// title and content is sanitized so only prohibit if necessary
|
||||
if (title.contains("/")) {
|
||||
throw new IllegalArgumentException("Title cannot contain slashes (/). Those are used for sub-pages.");
|
||||
throw new UnacceptableDataException("Title cannot contain slashes (/). Those are used for sub-pages.");
|
||||
} else if (Page.findByTitle(title) != null) {
|
||||
throw new IllegalStateException("Page already exists, I made you edit it.");
|
||||
throw new DuplicateException("Page already exists, I made you edit it.");
|
||||
}
|
||||
|
||||
Page page = new Page(title);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package eu.m724.talkpages.page.action;
|
||||
|
||||
/**
|
||||
* Page you tried to create already exists<br>
|
||||
* TODO find a better name
|
||||
*/
|
||||
public class DuplicateException extends RuntimeException {
|
||||
public DuplicateException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package eu.m724.talkpages.page.action;
|
||||
|
||||
/**
|
||||
* Title or content or other data are unacceptable, don't fit constraints.<br>
|
||||
* TODO find a better name
|
||||
*/
|
||||
public class UnacceptableDataException extends RuntimeException {
|
||||
public UnacceptableDataException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue