fixed a few issues with the competencies, started working on notes. still wip

This commit is contained in:
2026-01-03 20:04:21 +00:00
parent 2fc5ad92d2
commit 95286ae6dd
6 changed files with 170 additions and 20 deletions

View File

@@ -0,0 +1,34 @@
package org.zaine.app.controller;
import java.lang.System.Logger;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.zaine.app.model.Comments;
import org.zaine.app.service.CommentsService;
@RestController
public class CommentsController {
private static final Logger logger = System.getLogger(CommentsController.class.getName());
@Autowired
private CommentsService commentsService;
@GetMapping("/{page_slug}")
public List<Comments> getAllCommentsBySlug(@PathVariable String page_slug) {
List<Comments> allComments = commentsService;
}
@GetMapping("/comments/item/{id}")
public Comments getCommentById(@PathVariable Long id) {
return commentsService.getCommentById(id);
}
}

View File

@@ -1,17 +1,17 @@
package org.zaine.app.controller; package org.zaine.app.controller;
import java.lang.System.Logger;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import org.zaine.app.model.Competencies; import org.zaine.app.model.Competencies;
import org.zaine.app.service.CompetenciesService; import org.zaine.app.service.CompetenciesService;
import java.lang.System.Logger;
@RestController @RestController
public class CompetenciesController { public class CompetenciesController {
@@ -20,15 +20,15 @@ public class CompetenciesController {
private CompetenciesService competenciesService; private CompetenciesService competenciesService;
@GetMapping("/competencies/items") @GetMapping("/competencies/items")
public List<Competencies> getAllCompetencies() { public List<Competencies> getAllCompetencies() {
return competenciesService.getAllCompetencies(); return competenciesService.getAllCompetencies();
} }
@GetMapping("/competencies/item/{id}") @GetMapping("/competencies/item/{id}")
public Competencies getCompetencyById(@PathVariable Long id) { public Competencies getCompetencyById(@PathVariable Long id) {
return competenciesService.getCompetencyById(id); return competenciesService.getCompetencyById(id);
} }
@PostMapping("/competencies/items/{id}/state") @PostMapping("/competencies/items/{id}/state")
@@ -36,7 +36,7 @@ public class CompetenciesController {
logger.log(System.Logger.Level.INFO, "Received request to update competency id " + id + " to new state: " + newState); logger.log(System.Logger.Level.INFO, "Received request to update competency id " + id + " to new state: " + newState);
competenciesService.updateCompetencyState(id, newState); competenciesService.updateCompetencyState(id, newState);
} }
} }

View File

@@ -0,0 +1,72 @@
package org.zaine.app.model;
import java.time.Instant;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "comments")
public class Comments {
@Id
@GeneratedValue
@Column(name = "id")
private Long id;
@Column(name = "page_slug")
private String pageSlug;
@Column(name="author")
private String author;
@Column(name="content")
private String content;
@Column(name="created_at")
private Instant createdAt;
@Column(name="parent_id")
private Long parentId;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getPageSlug() {
return pageSlug;
}
public void setPageSlug(String pageSlug) {
this.pageSlug = pageSlug;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
}

View File

@@ -0,0 +1,8 @@
package org.zaine.app.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import org.zaine.app.model.Comments;
public interface CommentsRepository extends JpaRepository<Comments, Long> {
}

View File

@@ -0,0 +1,36 @@
package org.zaine.app.service;
import java.lang.System.Logger;
import java.util.List;
import org.springframework.stereotype.Service;
import org.zaine.app.model.Comments;
import org.zaine.app.repositories.CommentsRepository;
import java.util.stream.*;
@Service
public class CommentsService {
private static final Logger logger = System.getLogger(CommentsService.class.getName());
private final CommentsRepository commentsRepository;
public CommentsService(CommentsRepository commentsRepository) {
this.commentsRepository = commentsRepository;
}
public List<Comments> getAllComments() {
return commentsRepository.findAll();
}
public List<Comments> getAllCommentsBySlug(String page_slug) {
logger.log(System.Logger.Level.INFO, "Entering getAllCommentsBySlug with slug: " + page_slug);
return commentsRepository.findAll().stream()
.filter(comment -> page_slug.equals(comment.getPageSlug()))
.toList();
}
public Comments getCommentById(Long id) {
logger.log(System.Logger.Level.INFO, "Entering getCommentById with id: " + id);
return commentsRepository.findById(id).get();
}
}

View File

@@ -2,8 +2,6 @@ package org.zaine.app.service;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.util.List; import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.zaine.app.model.Competencies; import org.zaine.app.model.Competencies;
import org.zaine.app.repositories.CompetenciesRepository; import org.zaine.app.repositories.CompetenciesRepository;
@@ -15,14 +13,10 @@ public class CompetenciesService {
private final CompetenciesRepository competenciesRepository; private final CompetenciesRepository competenciesRepository;
private static final List<String> ALLOWED_STATES = List.of( private static final List<String> ALLOWED_STATES =
"completed", List.of("completed", "manager_review", "in_progress", "not_started", "comments");
"manager_review",
"in_progress",
"not_started",
"comments"
);
public CompetenciesService(CompetenciesRepository competenciesRepository) { public CompetenciesService(CompetenciesRepository competenciesRepository) {
this.competenciesRepository = competenciesRepository; this.competenciesRepository = competenciesRepository;
} }
@@ -42,6 +36,12 @@ public class CompetenciesService {
public void updateCompetencyState(Long id, String newState) { public void updateCompetencyState(Long id, String newState) {
Competencies competency = getCompetencyById(id); Competencies competency = getCompetencyById(id);
if (!ALLOWED_STATES.contains(newState)) {
logger.log(System.Logger.Level.WARNING, "Invalid state: " + newState);
throw new IllegalArgumentException("Invalid state: " + newState);
}
if (competency != null) { if (competency != null) {
competency.setState(newState); competency.setState(newState);
competenciesRepository.save(competency); competenciesRepository.save(competency);