Skip to content

Commit

Permalink
Merge pull request #40 from elwyncrestha/feature/appointment-report
Browse files Browse the repository at this point in the history
Feature: Added APIs for AppointmentReport
  • Loading branch information
elwyncrestha committed Jul 19, 2020
2 parents 990c6d5 + 5dfbe30 commit bd1658b
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.pemits.webcare.api.appointment.entity;

import javax.persistence.Entity;
import javax.persistence.OneToOne;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import com.pemits.webcare.core.entity.BaseEntity;

/**
* @author Elvin Shrestha on 7/19/2020
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class AppointmentReport extends BaseEntity<Long> {

@OneToOne
private Appointment appointment;

private String data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.pemits.webcare.api.appointment.repository;

import org.springframework.stereotype.Repository;

import com.pemits.webcare.api.appointment.entity.AppointmentReport;
import com.pemits.webcare.core.repository.BaseRepository;

/**
* @author Elvin Shrestha on 7/19/2020
*/
@Repository
public interface AppointmentReportRepository extends BaseRepository<AppointmentReport, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.pemits.webcare.api.appointment.repository.spec;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.data.jpa.domain.Specification;

import com.pemits.webcare.api.appointment.entity.AppointmentReport;

/**
* @author Elvin Shrestha on 7/19/2020
*/
public class AppointmentReportSpec implements Specification<AppointmentReport> {

private static final String FILTER_BY_APPOINTMENT_ID = "appointment.id";

private final String property;
private final String value;

public AppointmentReportSpec(String property, String value) {
this.property = property;
this.value = value;
}

@Override
public Predicate toPredicate(Root<AppointmentReport> root, CriteriaQuery<?> criteriaQuery,
CriteriaBuilder criteriaBuilder) {
switch (property) {
case FILTER_BY_APPOINTMENT_ID:
return criteriaBuilder
.equal(root.join("appointment").get("id"), Long.valueOf(value));
default:
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.pemits.webcare.api.appointment.repository.spec;

import java.util.Map;

import org.springframework.data.jpa.domain.Specification;

import com.pemits.webcare.api.appointment.entity.AppointmentReport;
import com.pemits.webcare.core.repository.BaseSpecBuilder;

/**
* @author Elvin Shrestha on 7/19/2020
*/
public class AppointmentReportSpecBuilder extends BaseSpecBuilder<AppointmentReport> {

public AppointmentReportSpecBuilder(Map<String, String> params) {
super(params);
}

@Override
protected Specification<AppointmentReport> getSpecification(String property,
String filterValue) {
return new AppointmentReportSpec(property, filterValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.pemits.webcare.api.appointment.service;

import com.pemits.webcare.api.appointment.entity.AppointmentReport;
import com.pemits.webcare.core.service.BaseService;

/**
* @author Elvin Shrestha on 7/19/2020
*/
public interface AppointmentReportService extends BaseService<AppointmentReport, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.pemits.webcare.api.appointment.service;

import java.util.Map;

import org.springframework.stereotype.Service;

import com.pemits.webcare.api.appointment.entity.AppointmentReport;
import com.pemits.webcare.api.appointment.repository.AppointmentReportRepository;
import com.pemits.webcare.api.appointment.repository.spec.AppointmentReportSpecBuilder;
import com.pemits.webcare.core.repository.BaseSpecBuilder;
import com.pemits.webcare.core.service.BaseServiceImpl;

/**
* @author Elvin Shrestha on 7/19/2020
*/
@Service
public class AppointmentReportServiceImpl extends BaseServiceImpl<AppointmentReport, Long> implements AppointmentReportService {

protected AppointmentReportServiceImpl(
AppointmentReportRepository repository) {
super(repository);
}

@Override
protected BaseSpecBuilder<AppointmentReport> getSpec(Map<String, String> filterParams) {
return new AppointmentReportSpecBuilder(filterParams);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.pemits.webcare.web.appointment;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pemits.webcare.api.appointment.entity.AppointmentReport;
import com.pemits.webcare.api.appointment.service.AppointmentReportService;
import com.pemits.webcare.core.controller.BaseController;

/**
* @author Elvin Shrestha on 7/19/2020
*/
@RestController
@RequestMapping(AppointmentReportController.URL)
@Slf4j
public class AppointmentReportController extends BaseController<AppointmentReport, Long> {

static final String URL = "/v1/appointment-report";

protected AppointmentReportController(
AppointmentReportService service) {
super(service, log.getClass());
}
}
30 changes: 30 additions & 0 deletions pemits-web/src/main/resources/db/changelog/changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,34 @@
</createTable>
</changeSet>

<changeSet id="13-create-appointment_report" author="Elvin Shrestha">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="appointment_report"/>
</not>
</preConditions>

<createTable tableName="appointment_report">
<column name="id" type="BIGINT" autoIncrement="true">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_APPOINTMENT_REPORT"/>
</column>
<column name="created_at" type="DATETIME">
<constraints nullable="false"/>
</column>
<column name="last_modified_at" type="DATETIME">
<constraints nullable="false"/>
</column>
<column name="created_by" type="BIGINT"/>
<column name="last_modified_by" type="BIGINT"/>
<column name="version" type="INT"/>
<column name="appointment_id" type="BIGINT">
<constraints nullable="false"
foreignKeyName="fk_appointment_report_appointment_id_appointment_id"
referencedTableName="appointment"
referencedColumnNames="id"/>
</column>
<column name="data" type="LONGTEXT"/>
</createTable>
</changeSet>

</databaseChangeLog>

0 comments on commit bd1658b

Please sign in to comment.