Skip to content

Commit

Permalink
Merge pull request #54 from nikanique/develop
Browse files Browse the repository at this point in the history
fix/ NotEqual operand
  • Loading branch information
birddevelper authored Dec 24, 2024
2 parents cd494d4 + 6765ccf commit b2291c1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 21 deletions.
44 changes: 29 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ framework.
## Features

- **Developer-Friendly**: Effortlessly generates web APIs while eliminating the need for
boilerplate code, simplifying the task of exposing standard endpoints (GET, POST, PUT, PATCH) for each ORM entity.
boilerplate code, simplifying the task of exposing standard endpoints (GET, POST, PUT, PATCH) for ORM entity.
- **Serialization**: The comprehensive and flexible serializer, integrated with Spring Data JPA, assists developers in
customizing the input and output in web APIs.
- **Filters**: Offers flexibility and powerful filtering in APIs to query data from database.
Expand Down Expand Up @@ -45,7 +45,7 @@ To install the Spring REST Framework, include the following dependencies in your
<dependency>
<groupId>io.github.nikanique</groupId>
<artifactId>spring-rest-framework</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
</dependencies>
```
Expand Down Expand Up @@ -79,6 +79,10 @@ To start using the library, follow these steps:
private String fullName;
private Integer age;
private String major;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "school_id")
private School school;

}

Expand Down Expand Up @@ -106,11 +110,14 @@ To start using the library, follow these steps:
@Data
public class StudentDto extends Dto{
@Expose(source = "name")
private String firstName;
@Expose(source = "fullName")
private String name;
private Integer age;
private String major;
@Expose(source = "school__name")
private String SchoolName;
@ReadOnly
private Long id;
}
Expand All @@ -129,15 +136,15 @@ To start using the library, follow these steps:
@Override
protected Class<?> getDTO() {
return Student.class;
return StudentDto.class;
}
}
```
Add desired filters to the endpoint by using **FilterSet** class:
```java
import io.github.nikanique.springrestframework.web.controllers.GenericQueryController;
import io.github.nikanique.springrestframework.common.FieldType;import io.github.nikanique.springrestframework.filter.FilterOperation;import io.github.nikanique.springrestframework.web.controllers.GenericQueryController;
@RequestMapping("/student")
@RestController
Expand All @@ -149,18 +156,20 @@ To start using the library, follow these steps:
@Override
protected Class<?> getDTO() {
return Student.class;
return StudentDto.class;
}
@Override
protected FilterSet configFilterSet() {
// Filters student with age greater than given value and school name contains given string
return FilterSet.builder()
.addFilter("name", FilterOperation.CONTAINS, FieldType.STRING)
.build();
.addFilter("age", FilterOperation.GREATER, FieldType.INTEGER)
.addFilter("schoolName","school__name", FilterOperation.CONTAINS, FieldType.STRING)
.build();
}
}
```
Specify allowed fields to order the result by using **configAllowedOrderByFields** method:
Specify allowed fields to order the result using **configAllowedOrderByFields** method:
```java
import io.github.nikanique.springrestframework.web.controllers.GenericQueryController;
Expand All @@ -175,12 +184,12 @@ To start using the library, follow these steps:
@Override
protected Class<?> getDTO() {
return Student.class;
return StudentDto.class;
}
@Override
protected FilterSet configFilterSet() {
return FilterSet.builder()
.addFilter("name", FilterOperation.CONTAINS, FieldType.STRING)
.addFilter("name", "fullName", FilterOperation.CONTAINS, FieldType.STRING)
.build();
}
Expand All @@ -193,7 +202,12 @@ To start using the library, follow these steps:
```
4. Run your application, and enjoy your APIs:
![spring-rest-framework-api.jpg](smaple_images/spring-rest-framework-api.jpg)
![spring-rest-framework-api.png](smaple_images/spring-rest-framework-api.png)
## Documentation
For detailed documentation and examples, visit the
project's [Documentation](https://spring-rest-framework-tutorial.readthedocs.io/en/latest/).

## License

Expand All @@ -202,4 +216,4 @@ This project is licensed under the BSD 3-Clause License.
## Contact & Issues

For any questions or feedback, please contact the author at nikanique.org@gmail.com. If you
encounter any problems or bugs with the library, kindly create an issue to report them.
encounter any problems or bugs with the library, kindly create an issue to report them.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>io.github.nikanique</groupId>
<artifactId>spring-rest-framework</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<packaging>jar</packaging>
<name>spring-rest-framework</name>
<description>
Expand Down
Binary file removed smaple_images/spring-rest-framework-api.jpg
Binary file not shown.
Binary file added smaple_images/spring-rest-framework-api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public enum FilterOperation {
EQUAL,
NOT_EQUAL,
GREATER,
GREATER_OR_EQUAL,
LESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public Predicate toPredicate(Root<Model> root, CriteriaQuery<?> query, CriteriaB
return createLessThanOrEqualToPredicate(builder, path, attributeType, value);
case EQUAL:
return builder.equal(path, value);
case NOT_EQUAL:
return builder.notEqual(path, value);
case CONTAINS:
if (attributeType == String.class) {
return builder.like(path.as(String.class), "%" + value + "%");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ protected String getQueryMethodName() {
private void postConstruct() {
this.queryService = QueryService.getInstance(this.getModel(), this.repository, this.context);
}


protected Class<?> getListResponseDTO() {
return getDTO();
}


protected Class<?> getRetrieveResponseDTO() {
return getDTO();
Expand Down

0 comments on commit b2291c1

Please sign in to comment.