48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
import re
|
|
|
|
with open('kifi-api/src/main/java/com/kifi/api/controller/ProjectController.java', 'r') as f:
|
|
content = f.read()
|
|
|
|
# Add import
|
|
content = content.replace(
|
|
'import com.kifi.api.entity.project.ProjectTask;',
|
|
'import com.kifi.api.entity.project.ProjectTask;\nimport com.kifi.api.entity.project.ProjectTaskComment;'
|
|
)
|
|
|
|
# Add endpoints
|
|
endpoints = """
|
|
@GetMapping("/tasks/{taskId}/comments")
|
|
public Flux<ProjectTaskComment> getComments(@PathVariable Long taskId) {
|
|
return projectService.getCommentsForTask(taskId);
|
|
}
|
|
|
|
@PostMapping("/tasks/{taskId}/comments")
|
|
public Mono<ProjectTaskComment> addComment(
|
|
@PathVariable Long taskId,
|
|
@RequestBody CreateCommentRequest request,
|
|
Authentication authentication) {
|
|
Long userId = Long.valueOf(authentication.getDetails().toString());
|
|
return projectService.addComment(taskId, userId, request.getContent(), request.getImagesJson());
|
|
}
|
|
|
|
@Data
|
|
static class CreateProjectRequest {
|
|
"""
|
|
|
|
content = content.replace(' @Data\n static class CreateProjectRequest {', endpoints)
|
|
|
|
# Add request class
|
|
request_class = """
|
|
@Data
|
|
static class CreateCommentRequest {
|
|
private String content;
|
|
private String imagesJson;
|
|
}
|
|
}
|
|
"""
|
|
|
|
content = re.sub(r'}\s*$', request_class.strip() + '\n', content)
|
|
|
|
with open('kifi-api/src/main/java/com/kifi/api/controller/ProjectController.java', 'w') as f:
|
|
f.write(content)
|