updated java doc in templating

This commit is contained in:
Sheldan
2020-05-26 12:40:06 +02:00
parent 6908a7da85
commit b554419381
4 changed files with 44 additions and 1 deletions

View File

@@ -33,7 +33,6 @@ public class TemplateServiceBean implements TemplateService {
@Autowired
private Gson gson;
/**
* Formats the passed passed count with the embed used for formatting pages.
* @param count The index of the page you want formated.
@@ -169,11 +168,21 @@ public class TemplateServiceBean implements TemplateService {
}
}
/**
* Renders a simple template identified by key without any model. This will cause exceptions in case there are references to a model in the provided template.
* @param key The key of the template to be rendered
* @return The rendered template as a string
*/
@Override
public String renderSimpleTemplate(String key) {
return renderTemplate(key, new Object());
}
/**
* Renders the {@link Templatable} object using the template key and the model and returns it as a string.
* @param templatable The {@link Templatable} object to be rendered
* @return The rendered {@link Templatable} as a string
*/
@Override
public String renderTemplatable(Templatable templatable) {
return renderTemplate(templatable.getTemplateName(), templatable.getTemplateModel());

View File

@@ -20,16 +20,32 @@ public class TemplateManagementServiceBean implements TemplateManagementService
@Autowired
private TemplateRepository repository;
/**
* Returns the template from the database by key
* @param key They template key to search for
* @return An {@link Optional} containing the {@link Template} if any was found.
*/
@Override
public Optional<Template> getTemplateByKey(String key) {
return repository.findById(key);
}
/**
* Returns whether or not the template identified by the key exists in the database
* @param key They key of the template to search for
* @return Whether or not the template exists in the database
*/
@Override
public boolean templateExists(String key) {
return repository.existsById(key);
}
/**
* Creates a {@link Template} object and stores it in the database. Returns the newly created object.
* @param key They key of the template to create.
* @param content The content the template should have
* @return The {@link Template} which was created
*/
@Override
public Template createTemplate(String key, String content) {
Template build = Template.builder().key(key).content(content).lastModified(Instant.now()).build();

View File

@@ -42,6 +42,9 @@ public class Template {
@Getter
private Instant lastModified;
/**
* The time this template was created in the database
*/
@Column(name = "created")
private Instant created;
@@ -50,6 +53,9 @@ public class Template {
this.created = Instant.now();
}
/**
* The time this template was updated in the database, only works when using the bot, does not work with triggers.
*/
@Column(name = "updated")
private Instant updated;

View File

@@ -33,7 +33,19 @@ public interface TemplateService {
* @return The template rendered as string.
*/
String renderTemplate(String key, Object model);
/**
* Renders the template without considering any model to be used. If a property is used in the given template, this will throw an exception.
* This is just a quick way to render templates, which do not *need* a model.
* @param key The key of the template to be rendered
* @return The template rendered as string
*/
String renderSimpleTemplate(String key);
/**
* Renders the given {@link Templatable} object, which means it retrieves the template key and renders the given template key with the given model.
* @param templatable The {@link Templatable} object to be rendered
* @return The template rendered as string
*/
String renderTemplatable(Templatable templatable);
}