#5 fixed ChatDto.writeToFile

This commit is contained in:
2026-08-06 20:23:08 +02:00
parent 6a85d6e1d8
commit f625e58453
5 changed files with 35 additions and 11 deletions

View File

@@ -4,22 +4,30 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import de.derpandaa.plinfa.projects.GenericProject;
import tools.jackson.core.JacksonException;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.ObjectMapper;
public class ChatDto {
public static String PROJECT_DIR;
private String name;
private GenericProject parent;
List<MessageDto> messages;
private ChatDto(GenericProject parent) {
this.parent = parent;
}
public ChatDto() {
this(null);
messages = new ArrayList<MessageDto>();
}
public ChatDto(File f) {
public ChatDto(File f, GenericProject parent) {
this(parent);
loadFromFile(f);
}
@@ -57,7 +65,7 @@ public class ChatDto {
return;
}
ObjectMapper mapper = new ObjectMapper();
File f = new File(String.format("%s/%s.json", PROJECT_DIR, name));
File f = new File(getPath());
mapper.writeValue(f.getAbsoluteFile(), messages);
}
@@ -65,4 +73,8 @@ public class ChatDto {
public String toString() {
return name;
}
private String getPath() {
return String.format("%s/%s.json", parent.getFullName(),name);
}
}