fixed a few issues with the competencies, started working on notes. still wip
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
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.springframework.web.bind.annotation.PathVariable;
|
||||
import org.zaine.app.model.Competencies;
|
||||
import org.zaine.app.service.CompetenciesService;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
|
||||
@RestController
|
||||
public class CompetenciesController {
|
||||
|
||||
|
||||
72
src/main/java/org/zaine/app/model/Comments.java
Normal file
72
src/main/java/org/zaine/app/model/Comments.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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> {
|
||||
|
||||
}
|
||||
36
src/main/java/org/zaine/app/service/CommentsService.java
Normal file
36
src/main/java/org/zaine/app/service/CommentsService.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,8 +2,6 @@ package org.zaine.app.service;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.zaine.app.model.Competencies;
|
||||
import org.zaine.app.repositories.CompetenciesRepository;
|
||||
@@ -15,13 +13,9 @@ public class CompetenciesService {
|
||||
|
||||
private final CompetenciesRepository competenciesRepository;
|
||||
|
||||
private static final List<String> ALLOWED_STATES = List.of(
|
||||
"completed",
|
||||
"manager_review",
|
||||
"in_progress",
|
||||
"not_started",
|
||||
"comments"
|
||||
);
|
||||
private static final List<String> ALLOWED_STATES =
|
||||
List.of("completed", "manager_review", "in_progress", "not_started", "comments");
|
||||
|
||||
|
||||
public CompetenciesService(CompetenciesRepository competenciesRepository) {
|
||||
this.competenciesRepository = competenciesRepository;
|
||||
@@ -42,6 +36,12 @@ public class CompetenciesService {
|
||||
|
||||
public void updateCompetencyState(Long id, String newState) {
|
||||
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) {
|
||||
competency.setState(newState);
|
||||
competenciesRepository.save(competency);
|
||||
|
||||
Reference in New Issue
Block a user