dddddddd
Java
code posted
created at 26 May 06:05
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
package ru.omickron.rest; import com.google.common.collect.ImmutableMap; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import lombok.AllArgsConstructor; import lombok.NonNull; import lombok.SneakyThrows; import org.apache.commons.io.IOUtils; import org.asciidoctor.Asciidoctor; import org.asciidoctor.OptionsBuilder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import ru.omickron.beans.CurrentUser; import ru.omickron.exception.BadRequestException; import ru.omickron.service.FeedbackService; import ru.omickron.system.permissions.Anonymous; import ru.omickron.util.Const; import static java.util.Objects.isNull; @RestController @RequestMapping(Const.REST + "/docs") @Anonymous @AllArgsConstructor public class DocsFacade { @NonNull private final Asciidoctor asciidoctor; @NonNull private final CurrentUser currentUser; @NonNull private final FeedbackService feedbackService; @PostMapping("/request") public void requestDocs( @RequestParam("id") String id ) { String message = String.format( "Привет, разработчики!\n\nБыло бы здорово увидеть документацию по разделу %s.\n\nСпасибо!", id ); feedbackService.createForUser( currentUser.getUser(), message ); } @GetMapping(value = "/content/**") @SneakyThrows public Map<String, String> getDocs( @Context HttpServletRequest request ) { String name = request.getRequestURI().replaceFirst( Const.REST + "/docs/content", "/docs" ); InputStream inputStream = getClass().getResourceAsStream( name + ".adoc" ); if (isNull( inputStream )) { throw new BadRequestException( "No document found for '%s'", name ); } String adocContent = IOUtils.toString( inputStream, StandardCharsets.UTF_8 ); return ImmutableMap.of( "html", asciidoctor.convert( adocContent, OptionsBuilder.options() ) ); } } |
2.27 KB in 3 ms with coderay