From fc5c8a86ee3b2a19b78e8d345ca59fe1b738218e Mon Sep 17 00:00:00 2001 From: Antonio Escobedo Date: Mon, 26 Jun 2023 22:23:20 -0600 Subject: [PATCH] Controller, Models and Repostory Controller, Models and Repostory --- src/main/java/META-INF/MANIFEST.MF | 3 + .../CandidateChallengeController.java | 60 +++++++++++++ .../model/EmployeeEntity.java | 64 ++++++++++++++ .../model/PropertyEntity.java | 87 +++++++++++++++++++ .../repository/EmployeeRepository.java | 12 +++ .../repository/PropertyRepository.java | 9 ++ src/main/resources/application.properties | 10 +++ 7 files changed, 245 insertions(+) create mode 100644 src/main/java/META-INF/MANIFEST.MF create mode 100644 src/main/java/com/zoomcare/candidatechallenge/controller/CandidateChallengeController.java create mode 100644 src/main/java/com/zoomcare/candidatechallenge/model/EmployeeEntity.java create mode 100644 src/main/java/com/zoomcare/candidatechallenge/model/PropertyEntity.java create mode 100644 src/main/java/com/zoomcare/candidatechallenge/repository/EmployeeRepository.java create mode 100644 src/main/java/com/zoomcare/candidatechallenge/repository/PropertyRepository.java create mode 100644 src/main/resources/application.properties diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/src/main/java/com/zoomcare/candidatechallenge/controller/CandidateChallengeController.java b/src/main/java/com/zoomcare/candidatechallenge/controller/CandidateChallengeController.java new file mode 100644 index 0000000..523c0b7 --- /dev/null +++ b/src/main/java/com/zoomcare/candidatechallenge/controller/CandidateChallengeController.java @@ -0,0 +1,60 @@ +package com.zoomcare.candidatechallenge.controller; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.zoomcare.candidatechallenge.model.EmployeeEntity; +import com.zoomcare.candidatechallenge.repository.EmployeeRepository; +import com.zoomcare.candidatechallenge.repository.PropertyRepository; + +@CrossOrigin(origins = "http://localhost:8080") +@RestController +@RequestMapping("/api") +public class CandidateChallengeController { + + @Autowired + EmployeeRepository employeeRepository; + + @Autowired + PropertyRepository propertiesRepository; + + @GetMapping("/employees") + public ResponseEntity> getAllEmployees(@RequestParam(required = false) String title) { + try { + List employeeData = new ArrayList(); + employeeRepository.findAll().forEach(employeeData::add); + + if (employeeData.isEmpty()) { + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + return new ResponseEntity<>(employeeData, HttpStatus.OK); + } catch (Exception e) { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + @GetMapping("/employees/{id}") + public ResponseEntity getEmployeeById(@PathVariable("id") long id) { + Optional employeeData = employeeRepository.findById(id); + + if (employeeData.isPresent()) { + return new ResponseEntity<>(employeeData.get(), HttpStatus.OK); + } else { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } + + + +} diff --git a/src/main/java/com/zoomcare/candidatechallenge/model/EmployeeEntity.java b/src/main/java/com/zoomcare/candidatechallenge/model/EmployeeEntity.java new file mode 100644 index 0000000..cc7adfb --- /dev/null +++ b/src/main/java/com/zoomcare/candidatechallenge/model/EmployeeEntity.java @@ -0,0 +1,64 @@ +package com.zoomcare.candidatechallenge.model; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "employee") +public class EmployeeEntity implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @Column(name = "supervisor_id") + private Long supervisorId; + + public EmployeeEntity() { + + } + + public EmployeeEntity(Long id, Long supervisorId) { + this.id = id; + this.supervisorId = supervisorId; + } + + /** + * @return the id + */ + public Long getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(Long id) { + this.id = id; + } + + /** + * @return the supervisorId + */ + public Long getSupervisorId() { + return supervisorId; + } + + /** + * @param supervisorId the supervisorId to set + */ + public void setSupervisorId(Long supervisorId) { + this.supervisorId = supervisorId; + } +} \ No newline at end of file diff --git a/src/main/java/com/zoomcare/candidatechallenge/model/PropertyEntity.java b/src/main/java/com/zoomcare/candidatechallenge/model/PropertyEntity.java new file mode 100644 index 0000000..8c7d66d --- /dev/null +++ b/src/main/java/com/zoomcare/candidatechallenge/model/PropertyEntity.java @@ -0,0 +1,87 @@ +package com.zoomcare.candidatechallenge.model; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "property") +public class PropertyEntity implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "employee_id") + private Long employeeId; + + @Column(name = "key") + private String keyValue; + + @Column(name = "value") + private String valueDescription; + + public PropertyEntity() { + + } + + public PropertyEntity(Long employeeId, String keyValue, String valueDescription) { + this.employeeId = employeeId; + this.keyValue = keyValue; + this.valueDescription = valueDescription; + } + + /** + * @return the employeeId + */ + public Long getEmployeeId() { + return employeeId; + } + + /** + * @param employeeId the employeeId to set + */ + public void setEmployeeId(Long employeeId) { + this.employeeId = employeeId; + } + + /** + * @return the keyValue + */ + public String getKeyValue() { + return keyValue; + } + + /** + * @param keyValue the keyValue to set + */ + public void setKeyValue(String keyValue) { + this.keyValue = keyValue; + } + + /** + * @return the valueDescription + */ + public String getValueDescription() { + return valueDescription; + } + + /** + * @param valueDescription the valueDescription to set + */ + public void setValueDescription(String valueDescription) { + this.valueDescription = valueDescription; + } + + /** + * @return the serialversionuid + */ + public static long getSerialversionuid() { + return serialVersionUID; + } +} \ No newline at end of file diff --git a/src/main/java/com/zoomcare/candidatechallenge/repository/EmployeeRepository.java b/src/main/java/com/zoomcare/candidatechallenge/repository/EmployeeRepository.java new file mode 100644 index 0000000..48277e7 --- /dev/null +++ b/src/main/java/com/zoomcare/candidatechallenge/repository/EmployeeRepository.java @@ -0,0 +1,12 @@ +package com.zoomcare.candidatechallenge.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.company.model.EmployeeEntity; + +@SuppressWarnings("unused") +public interface EmployeeRepository extends JpaRepository { + +} diff --git a/src/main/java/com/zoomcare/candidatechallenge/repository/PropertyRepository.java b/src/main/java/com/zoomcare/candidatechallenge/repository/PropertyRepository.java new file mode 100644 index 0000000..23f98a8 --- /dev/null +++ b/src/main/java/com/zoomcare/candidatechallenge/repository/PropertyRepository.java @@ -0,0 +1,9 @@ +package com.zoomcare.candidatechallenge.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.company.model.PropertiesEntity; + +public interface PropertyRepository extends JpaRepository { + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..bf0d79e --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,10 @@ +server.port=8080 + +spring.datasource.url: jdbc:h2:mem:testdb +spring.datasource.driverClassName: org.h2.Driver +spring.datasource.username: sa +spring.datasource.password: password +spring.jpa.database-platform: org.hibernate.dialect.H2Dialect +spring.h2.console.enabled: true + +spring.jpa.defer-datasource-initialization=true \ No newline at end of file