PAN-50 Created the findByBranch method

This commit is contained in:
2019-03-07 10:50:22 -07:00
parent d6b18c2279
commit 11aa1f1cf7
8 changed files with 40 additions and 10 deletions
@@ -41,6 +41,30 @@ public class TheoremController {
return new ResponseEntity<>(listOfTheorems, HttpStatus.OK);
}
@GetMapping("/{branch}")
public @ResponseBody
ResponseEntity<List<TheoremDto>> getAllTheoremsByBranch(@PathVariable("branch") final String branch) {
LOG.info("Received request to query for theorems related to the " + branch + " branch of mathematics");
if (branch == null) {
LOG.error("ERROR: branch was null");
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
LOG.debug("Querying for theorems with branch " + branch);
final StopWatch stopWatch = new StopWatch();
stopWatch.start();
final List<TheoremDto> listOfTheorems = theoremRepository.findByBranch(branch);
stopWatch.stop();
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
LOG.info("Returning list of all theorems with size " + listOfTheorems.size());
return new ResponseEntity<>(listOfTheorems, HttpStatus.OK);
}
@GetMapping("/{id}")
public @ResponseBody
ResponseEntity<TheoremDto> getTheoremById(@PathVariable("id") final Integer id) {
@@ -4,10 +4,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@@ -24,7 +21,12 @@ public class AccountDto extends BaseDto implements Serializable {
@NotNull private boolean administrator_status;
@Temporal(TemporalType.DATE) private Date last_login;
public static final long serialVersionUID = 7095627971593953734L;
private static final long serialVersionUID = 7095627971593953734L;
public interface Insert {}
@PrePersist
public void prePersist() {
last_login = new Date();
}
}
@@ -36,5 +36,5 @@ public class BaseDto implements Serializable {
@Version
private Integer version;
public static final long serialVersionUID = -1686252381978213945L;
private static final long serialVersionUID = -1686252381978213945L;
}
@@ -13,5 +13,5 @@ import java.util.List;
public class Definition implements Serializable {
private List<String> definitions;
public static final long serialVersionUID = -2208496232532214840L;
private static final long serialVersionUID = -2208496232532214840L;
}
@@ -28,7 +28,7 @@ public class DefinitionDto extends BaseDto implements Serializable {
@Type(type = "json") @Column(columnDefinition = "jsonb") private Notation notation;
public static final long serialVersionUID = -5314619286352932857L;
private static final long serialVersionUID = -5314619286352932857L;
public interface Insert {}
}
@@ -12,5 +12,5 @@ import java.util.List;
@ToString
public class Notation implements Serializable {
private List<String> notations;
public static final long serialVersionUID = 2301438318932336121L;
private static final long serialVersionUID = 2301438318932336121L;
}
@@ -26,5 +26,5 @@ public class TheoremDto extends BaseDto implements Serializable {
@Type(type = "json") @Column(columnDefinition = "jsonb") private List<String> referenced_theorems;
@NotNull private boolean proven_status;
public static final long serialVersionUID = 1545568391140364425L;
private static final long serialVersionUID = 1545568391140364425L;
}
@@ -4,6 +4,10 @@ import edu.msudenver.tsp.persistence.dto.TheoremDto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface TheoremRepository extends JpaRepository<TheoremDto, Integer> {
public List<TheoremDto> findByBranch(String branch);
}