PAN-50 Created the findByBranch method
This commit is contained in:
+24
@@ -41,6 +41,30 @@ public class TheoremController {
|
|||||||
return new ResponseEntity<>(listOfTheorems, HttpStatus.OK);
|
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}")
|
@GetMapping("/{id}")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<TheoremDto> getTheoremById(@PathVariable("id") final Integer id) {
|
ResponseEntity<TheoremDto> getTheoremById(@PathVariable("id") final Integer id) {
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import lombok.Data;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.*;
|
||||||
import javax.persistence.EntityListeners;
|
|
||||||
import javax.persistence.Temporal;
|
|
||||||
import javax.persistence.TemporalType;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
@@ -24,7 +21,12 @@ public class AccountDto extends BaseDto implements Serializable {
|
|||||||
@NotNull private boolean administrator_status;
|
@NotNull private boolean administrator_status;
|
||||||
@Temporal(TemporalType.DATE) private Date last_login;
|
@Temporal(TemporalType.DATE) private Date last_login;
|
||||||
|
|
||||||
public static final long serialVersionUID = 7095627971593953734L;
|
private static final long serialVersionUID = 7095627971593953734L;
|
||||||
|
|
||||||
public interface Insert {}
|
public interface Insert {}
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
public void prePersist() {
|
||||||
|
last_login = new Date();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,5 +36,5 @@ public class BaseDto implements Serializable {
|
|||||||
@Version
|
@Version
|
||||||
private Integer 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 {
|
public class Definition implements Serializable {
|
||||||
private List<String> definitions;
|
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;
|
@Type(type = "json") @Column(columnDefinition = "jsonb") private Notation notation;
|
||||||
|
|
||||||
public static final long serialVersionUID = -5314619286352932857L;
|
private static final long serialVersionUID = -5314619286352932857L;
|
||||||
|
|
||||||
public interface Insert {}
|
public interface Insert {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ import java.util.List;
|
|||||||
@ToString
|
@ToString
|
||||||
public class Notation implements Serializable {
|
public class Notation implements Serializable {
|
||||||
private List<String> notations;
|
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;
|
@Type(type = "json") @Column(columnDefinition = "jsonb") private List<String> referenced_theorems;
|
||||||
@NotNull private boolean proven_status;
|
@NotNull private boolean proven_status;
|
||||||
|
|
||||||
public static final long serialVersionUID = 1545568391140364425L;
|
private static final long serialVersionUID = 1545568391140364425L;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -4,6 +4,10 @@ import edu.msudenver.tsp.persistence.dto.TheoremDto;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface TheoremRepository extends JpaRepository<TheoremDto, Integer> {
|
public interface TheoremRepository extends JpaRepository<TheoremDto, Integer> {
|
||||||
|
|
||||||
|
public List<TheoremDto> findByBranch(String branch);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user