-
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.
- Loading branch information
1 parent
cec5e92
commit 834b665
Showing
11 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
pemits-api/src/main/java/com/pemits/webcare/api/feedback/entity/Feedback.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,22 @@ | ||
package com.pemits.webcare.api.feedback.entity; | ||
|
||
import com.pemits.webcare.core.entity.BaseEntity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.Entity; | ||
|
||
@Entity | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@EqualsAndHashCode(callSuper = true) | ||
public class Feedback extends BaseEntity<Long> { | ||
|
||
private String fullName; | ||
private String phoneNo; | ||
private String email; | ||
private String message; | ||
} |
9 changes: 9 additions & 0 deletions
9
pemits-api/src/main/java/com/pemits/webcare/api/feedback/repository/FeedbackRepository.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,9 @@ | ||
package com.pemits.webcare.api.feedback.repository; | ||
|
||
import com.pemits.webcare.api.feedback.entity.Feedback; | ||
import com.pemits.webcare.core.repository.BaseRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface FeedbackRepository extends BaseRepository<Feedback, Long> { | ||
} |
35 changes: 35 additions & 0 deletions
35
pemits-api/src/main/java/com/pemits/webcare/api/feedback/repository/spec/FeedbackSpec.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,35 @@ | ||
package com.pemits.webcare.api.feedback.repository.spec; | ||
|
||
import com.pemits.webcare.api.feedback.entity.Feedback; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import javax.persistence.criteria.CriteriaBuilder; | ||
import javax.persistence.criteria.CriteriaQuery; | ||
import javax.persistence.criteria.Predicate; | ||
import javax.persistence.criteria.Root; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/30/2020 | ||
*/ | ||
public class FeedbackSpec implements Specification<Feedback> { | ||
|
||
static final String FILTER_BY_FULL_NAME = "fullName"; | ||
|
||
private final String property; | ||
private final String value; | ||
|
||
public FeedbackSpec(String property, String value) { | ||
this.property = property; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Predicate toPredicate(Root<Feedback> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) { | ||
switch (property) { | ||
case FILTER_BY_FULL_NAME: | ||
return criteriaBuilder.like(root.get(FILTER_BY_FULL_NAME), "%" + value + "%"); | ||
} | ||
return null; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...pi/src/main/java/com/pemits/webcare/api/feedback/repository/spec/FeedbackSpecBuilder.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.feedback.repository.spec; | ||
|
||
import com.pemits.webcare.api.feedback.entity.Feedback; | ||
import com.pemits.webcare.core.repository.BaseSpecBuilder; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/30/2020 | ||
*/ | ||
public class FeedbackSpecBuilder extends BaseSpecBuilder<Feedback> { | ||
|
||
public FeedbackSpecBuilder(Map<String, String> params) { | ||
super(params); | ||
} | ||
|
||
@Override | ||
protected Specification<Feedback> getSpecification(String property, String filterValue) { | ||
return new FeedbackSpec(property, filterValue); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
pemits-api/src/main/java/com/pemits/webcare/api/feedback/service/FeedbackService.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,7 @@ | ||
package com.pemits.webcare.api.feedback.service; | ||
|
||
import com.pemits.webcare.api.feedback.entity.Feedback; | ||
import com.pemits.webcare.core.service.BaseService; | ||
|
||
public interface FeedbackService extends BaseService<Feedback, Long> { | ||
} |
23 changes: 23 additions & 0 deletions
23
pemits-api/src/main/java/com/pemits/webcare/api/feedback/service/FeedbackServiceImpl.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.feedback.service; | ||
|
||
import com.pemits.webcare.api.feedback.entity.Feedback; | ||
import com.pemits.webcare.api.feedback.repository.FeedbackRepository; | ||
import com.pemits.webcare.api.feedback.repository.spec.FeedbackSpecBuilder; | ||
import com.pemits.webcare.core.repository.BaseSpecBuilder; | ||
import com.pemits.webcare.core.service.BaseServiceImpl; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Map; | ||
|
||
@Service | ||
public class FeedbackServiceImpl extends BaseServiceImpl<Feedback, Long> implements FeedbackService { | ||
|
||
public FeedbackServiceImpl(FeedbackRepository repository) { | ||
super(repository); | ||
} | ||
|
||
@Override | ||
protected BaseSpecBuilder<Feedback> getSpec(Map<String, String> filterParams) { | ||
return new FeedbackSpecBuilder(filterParams); | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...-api/src/test/java/com/pemits/webcare/api/feedback/repository/FeedbackRepositoryTest.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,113 @@ | ||
package com.pemits.webcare.api.feedback.repository; | ||
|
||
import com.github.springtestdbunit.annotation.DatabaseSetup; | ||
import com.pemits.webcare.BaseJpaTest; | ||
import com.pemits.webcare.api.feedback.entity.Feedback; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/31/2020 | ||
*/ | ||
public class FeedbackRepositoryTest extends BaseJpaTest { | ||
|
||
private static final long MOCK_FEEDBACK_ID_1 = 1L; | ||
private static final long MOCK_FEEDBACK_ID_2 = 2L; | ||
|
||
@Autowired | ||
private FeedbackRepository repository; | ||
|
||
@Test | ||
public void testSaveShouldReturnSavedFeedback() { | ||
Feedback feedback = new Feedback(); | ||
feedback.setFullName("John Doe"); | ||
feedback.setPhoneNo("1234567890"); | ||
feedback.setEmail("[email protected]"); | ||
feedback.setMessage("This is my message"); | ||
Feedback saved = repository.save(feedback); | ||
|
||
assertThat(saved.getId(), notNullValue()); | ||
} | ||
|
||
@Test | ||
public void testSaveAllShouldReturnAllSavedFeedback() { | ||
Feedback feedback1 = new Feedback(); | ||
feedback1.setFullName("John Doe"); | ||
feedback1.setPhoneNo("1234567890"); | ||
feedback1.setEmail("[email protected]"); | ||
feedback1.setMessage("This is my message"); | ||
|
||
Feedback feedback2 = new Feedback(); | ||
feedback2.setFullName("Jack Smith"); | ||
feedback2.setPhoneNo("1234567890"); | ||
feedback2.setEmail("[email protected]"); | ||
feedback2.setMessage("This is my feedback"); | ||
|
||
List<Feedback> saved = repository.saveAll(Arrays.asList(feedback1, feedback2)); | ||
|
||
assertThat(saved, hasSize(2)); | ||
assertThat(saved.get(0).getId(), notNullValue()); | ||
assertThat(saved.get(1).getId(), notNullValue()); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/feedback/feedback-config.xml") | ||
public void testFindFeedbackByIdShouldReturnFeedback() { | ||
final Optional<Feedback> feedback = repository.findById(MOCK_FEEDBACK_ID_1); | ||
|
||
assertThat(feedback.isPresent(), equalTo(true)); | ||
assertThat(feedback.get().getFullName(), is("John Doe")); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/feedback/feedback-config.xml") | ||
public void testFindAllShouldReturnNotEmptyList() { | ||
final List<Feedback> feedbackList = repository.findAll(); | ||
|
||
assertThat(feedbackList.size(), greaterThan(0)); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/feedback/feedback-config.xml") | ||
public void testGetOneShouldReturnFeedback() { | ||
final Feedback feedback = repository.getOne(MOCK_FEEDBACK_ID_2); | ||
|
||
assertThat(feedback.getFullName(), is("Jack Smith")); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/feedback/feedback-config.xml") | ||
public void testDeleteByIdShouldDeleteFeedback() { | ||
long count = repository.count(); | ||
|
||
repository.deleteById(MOCK_FEEDBACK_ID_1); | ||
|
||
assertThat(repository.findAll(), hasSize((int) count - 1)); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/feedback/feedback-config.xml") | ||
public void testDeleteShouldDeleteFeedback() { | ||
long count = repository.count(); | ||
|
||
final Feedback feedback = repository.getOne(MOCK_FEEDBACK_ID_2); | ||
repository.delete(feedback); | ||
|
||
assertThat(repository.findAll(), hasSize((int) count - 1)); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/feedback/feedback-config.xml") | ||
public void testDeleteAllShouldReturnCountZero() { | ||
repository.deleteAll(); | ||
assertThat(repository.findAll(), hasSize(0)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
pemits-api/src/test/resources/dataset/feedback/feedback-config.xml
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,22 @@ | ||
<dataset> | ||
<feedback | ||
id="1" | ||
created_at="2020-07-31 15:30:00" | ||
last_modified_at="2020-07-31 15:30:00" | ||
version="0" | ||
full_name="John Doe" | ||
phone_no="1234567890" | ||
email="[email protected]" | ||
message="This is my message" | ||
/> | ||
<feedback | ||
id="2" | ||
created_at="2020-07-31 15:30:00" | ||
last_modified_at="2020-07-31 15:30:00" | ||
version="0" | ||
full_name="Jack Smith" | ||
phone_no="1234567890" | ||
email="[email protected]" | ||
message="This is my feedback" | ||
/> | ||
</dataset> |
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
22 changes: 22 additions & 0 deletions
22
pemits-web/src/main/java/com/pemits/webcare/web/feedback/FeedbackController.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,22 @@ | ||
package com.pemits.webcare.web.feedback; | ||
|
||
import com.pemits.webcare.api.feedback.entity.Feedback; | ||
import com.pemits.webcare.api.feedback.service.FeedbackService; | ||
import com.pemits.webcare.core.controller.BaseController; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static com.pemits.webcare.web.feedback.FeedbackController.URL; | ||
|
||
@RestController | ||
@RequestMapping(URL) | ||
@Slf4j | ||
public class FeedbackController extends BaseController<Feedback, Long> { | ||
|
||
static final String URL = "/v1/feedback"; | ||
|
||
public FeedbackController(FeedbackService feedbackService) { | ||
super(feedbackService, log.getClass()); | ||
} | ||
} |
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