-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Added associate entity for Doctor
- Loading branch information
1 parent
b75a601
commit 8c63da2
Showing
12 changed files
with
274 additions
and
3 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
pemits-api/src/main/java/com/pemits/webcare/api/doctor/entity/Doctor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.pemits.webcare.api.doctor.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.api.department.entity.Department; | ||
import com.pemits.webcare.api.user.entity.User; | ||
import com.pemits.webcare.core.entity.AppUser; | ||
import com.pemits.webcare.core.entity.BaseEntity; | ||
import com.pemits.webcare.core.enums.UserType; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/1/2020 | ||
*/ | ||
@Entity | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(callSuper = true) | ||
public class Doctor extends BaseEntity<Long> implements AppUser { | ||
|
||
@OneToOne | ||
private User user; | ||
|
||
@OneToOne | ||
private Department department; | ||
|
||
private String specializationField; | ||
|
||
@Override | ||
public UserType getUserType() { | ||
return UserType.DOCTOR; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
pemits-api/src/main/java/com/pemits/webcare/api/doctor/repository/DoctorRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.pemits.webcare.api.doctor.repository; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import com.pemits.webcare.api.doctor.entity.Doctor; | ||
import com.pemits.webcare.core.repository.BaseRepository; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/1/2020 | ||
*/ | ||
@Repository | ||
public interface DoctorRepository extends BaseRepository<Doctor, Long> { | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
pemits-api/src/main/java/com/pemits/webcare/api/doctor/repository/spec/DoctorSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.pemits.webcare.api.doctor.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.doctor.entity.Doctor; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/1/2020 | ||
*/ | ||
public class DoctorSpec implements Specification<Doctor> { | ||
|
||
private static final String FILTER_BY_NAME = "user.name"; | ||
|
||
private final String property; | ||
private final String value; | ||
|
||
public DoctorSpec(String property, String value) { | ||
this.property = property; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Predicate toPredicate(Root<Doctor> root, CriteriaQuery<?> criteriaQuery, | ||
CriteriaBuilder criteriaBuilder) { | ||
switch (property) { | ||
case FILTER_BY_NAME: | ||
return criteriaBuilder.like(root.join("user").get("name"), "%" + value + "%"); | ||
default: | ||
return null; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ts-api/src/main/java/com/pemits/webcare/api/doctor/repository/spec/DoctorSpecBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.pemits.webcare.api.doctor.repository.spec; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import com.pemits.webcare.api.doctor.entity.Doctor; | ||
import com.pemits.webcare.core.repository.BaseSpecBuilder; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/1/2020 | ||
*/ | ||
public class DoctorSpecBuilder extends BaseSpecBuilder<Doctor> { | ||
|
||
public DoctorSpecBuilder(Map<String, String> params) { | ||
super(params); | ||
} | ||
|
||
@Override | ||
protected Specification<Doctor> getSpecification(String property, String filterValue) { | ||
return new DoctorSpec(property, filterValue); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
pemits-api/src/main/java/com/pemits/webcare/api/doctor/service/DoctorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.pemits.webcare.api.doctor.service; | ||
|
||
import com.pemits.webcare.api.doctor.entity.Doctor; | ||
import com.pemits.webcare.core.service.BaseService; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/1/2020 | ||
*/ | ||
public interface DoctorService extends BaseService<Doctor, Long> { | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
pemits-api/src/main/java/com/pemits/webcare/api/doctor/service/DoctorServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.pemits.webcare.api.doctor.service; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.pemits.webcare.api.doctor.entity.Doctor; | ||
import com.pemits.webcare.api.doctor.repository.DoctorRepository; | ||
import com.pemits.webcare.api.doctor.repository.spec.DoctorSpecBuilder; | ||
import com.pemits.webcare.core.repository.BaseSpecBuilder; | ||
import com.pemits.webcare.core.service.BaseServiceImpl; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/1/2020 | ||
*/ | ||
@Service | ||
public class DoctorServiceImpl extends BaseServiceImpl<Doctor, Long> implements DoctorService { | ||
|
||
private final DoctorRepository repository; | ||
|
||
protected DoctorServiceImpl( | ||
DoctorRepository repository) { | ||
super(repository); | ||
this.repository = repository; | ||
} | ||
|
||
@Override | ||
protected BaseSpecBuilder<Doctor> getSpec(Map<String, String> filterParams) { | ||
return new DoctorSpecBuilder(filterParams); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
pemits-core/src/main/java/com/pemits/webcare/core/entity/AppUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.pemits.webcare.core.entity; | ||
|
||
import com.pemits.webcare.core.enums.UserType; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/1/2020 | ||
*/ | ||
public interface AppUser { | ||
|
||
default UserType getUserType() { | ||
return UserType.SUPER_ADMINISTRATOR; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
pemits-web/src/main/java/com/pemits/webcare/web/doctor/DoctorController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.pemits.webcare.web.doctor; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.pemits.webcare.api.doctor.entity.Doctor; | ||
import com.pemits.webcare.api.doctor.service.DoctorService; | ||
import com.pemits.webcare.core.controller.BaseController; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/1/2020 | ||
*/ | ||
@RestController | ||
@RequestMapping(DoctorController.URL) | ||
@Slf4j | ||
public class DoctorController extends BaseController<Doctor, Long> { | ||
|
||
static final String URL = "/v1/doctors"; | ||
private final DoctorService service; | ||
|
||
public DoctorController(DoctorService service) { | ||
super(service, log.getClass()); | ||
this.service = service; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters