Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
school-portal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Muhammad Suleman
school-portal
Commits
30782061
Commit
30782061
authored
Aug 12, 2022
by
Muhammad Suleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
used-querydsl
parent
738a421e
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
92 additions
and
17 deletions
+92
-17
pom.xml
pom.xml
+34
-0
QueryDslController.java
...ava/com/school/project/controller/QueryDslController.java
+25
-0
StudentRepository.java
...java/com/school/project/repository/StudentRepository.java
+7
-5
UserRepository.java
...l/project/repository/userRegistration/UserRepository.java
+5
-1
OAuth2ServerConfiguration.java
...om/school/project/security/OAuth2ServerConfiguration.java
+1
-1
StudentService.java
...va/com/school/project/service/student/StudentService.java
+4
-0
StudentServiceImpl.java
...om/school/project/service/student/StudentServiceImpl.java
+7
-0
application.properties
src/main/resources/application.properties
+9
-10
No files found.
pom.xml
View file @
30782061
...
@@ -111,6 +111,24 @@
...
@@ -111,6 +111,24 @@
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
<version>
42.4.1
</version>
</dependency>
<dependency>
<groupId>
com.querydsl
</groupId>
<artifactId>
querydsl-apt
</artifactId>
<version>
5.0.0
</version>
</dependency>
<dependency>
<groupId>
com.querydsl
</groupId>
<artifactId>
querydsl-jpa
</artifactId>
<version>
5.0.0
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
@@ -145,6 +163,22 @@
...
@@ -145,6 +163,22 @@
</configuration>
</configuration>
</plugin>
</plugin>
<plugin>
<groupId>
com.mysema.maven
</groupId>
<artifactId>
apt-maven-plugin
</artifactId>
<version>
1.1.3
</version>
<executions>
<execution>
<goals>
<goal>
process
</goal>
</goals>
<configuration>
<outputDirectory>
target/generated-sources/java
</outputDirectory>
<processor>
com.querydsl.apt.jpa.JPAAnnotationProcessor
</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</plugins>
</build>
</build>
...
...
src/main/java/com/school/project/controller/QueryDslController.java
0 → 100644
View file @
30782061
package
com
.
school
.
project
.
controller
;
import
com.querydsl.core.types.Predicate
;
import
com.school.project.model.Student
;
import
com.school.project.service.student.StudentService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.querydsl.binding.QuerydslPredicate
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/query"
)
public
class
QueryDslController
{
@Autowired
private
StudentService
studentService
;
@GetMapping
public
Iterable
<
Student
>
getStudent
(
@QuerydslPredicate
(
root
=
Student
.
class
)
Predicate
predicate
)
{
return
studentService
.
getStudentByPredicate
(
predicate
);
}
}
src/main/java/com/school/project/repository/StudentRepository.java
View file @
30782061
...
@@ -2,14 +2,16 @@ package com.school.project.repository;
...
@@ -2,14 +2,16 @@ package com.school.project.repository;
import
com.school.project.model.Student
;
import
com.school.project.model.Student
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.querydsl.QuerydslPredicateExecutor
;
import
java.util.List
;
public
interface
StudentRepository
extends
JpaRepository
<
Student
,
Long
>
{
public
interface
StudentRepository
extends
JpaRepository
<
Student
,
Long
>
,
QuerydslPredicateExecutor
<
Student
>
{
Student
findByStudentId
(
Long
id
);
Student
findByStudentId
(
Long
id
);
Student
findByStudentName
(
String
name
);
Student
findByStudentName
(
String
name
);
Student
findByRollNumber
(
String
rollNumber
);
Student
findByRollNumber
(
String
rollNumber
);
}
}
src/main/java/com/school/project/repository/userRegistration/UserRepository.java
View file @
30782061
...
@@ -2,12 +2,16 @@ package com.school.project.repository.userRegistration;
...
@@ -2,12 +2,16 @@ package com.school.project.repository.userRegistration;
import
com.school.project.model.userRegistration.User
;
import
com.school.project.model.userRegistration.User
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.querydsl.QuerydslPredicateExecutor
;
import
org.springframework.data.querydsl.binding.QuerydslBinderCustomizer
;
import
org.springframework.data.querydsl.binding.QuerydslPredicateBuilder
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.stereotype.Repository
;
import
java.util.Optional
;
import
java.util.Optional
;
@Repository
@Repository
public
interface
UserRepository
extends
JpaRepository
<
User
,
Long
>
{
public
interface
UserRepository
extends
JpaRepository
<
User
,
Long
>
,
QuerydslPredicateExecutor
<
User
>
{
Optional
<
User
>
findUserByEmail
(
String
email
);
Optional
<
User
>
findUserByEmail
(
String
email
);
User
findOneByUserId
(
Long
id
);
User
findOneByUserId
(
Long
id
);
}
}
src/main/java/com/school/project/security/OAuth2ServerConfiguration.java
View file @
30782061
...
@@ -49,7 +49,7 @@ public class OAuth2ServerConfiguration {
...
@@ -49,7 +49,7 @@ public class OAuth2ServerConfiguration {
.
and
()
.
and
()
.
authorizeRequests
()
.
authorizeRequests
()
.
antMatchers
(
"/register/**"
).
permitAll
()
.
antMatchers
(
"/register/**"
).
permitAll
()
.
antMatchers
(
"/student/**"
).
hasAuthority
(
"STUDENT"
)
.
antMatchers
(
"/student/**"
)
.
hasAuthority
(
"STUDENT"
)
.
antMatchers
(
"/department/**"
,
"/course/**"
,
"/admin/**"
).
hasAuthority
(
"ADMIN"
);
.
antMatchers
(
"/department/**"
,
"/course/**"
,
"/admin/**"
).
hasAuthority
(
"ADMIN"
);
}
}
}
}
...
...
src/main/java/com/school/project/service/student/StudentService.java
View file @
30782061
package
com
.
school
.
project
.
service
.
student
;
package
com
.
school
.
project
.
service
.
student
;
import
com.querydsl.core.types.Predicate
;
import
com.school.project.dto.student.StudentCoursesDTO
;
import
com.school.project.dto.student.StudentCoursesDTO
;
import
com.school.project.dto.student.StudentViewDataDTO
;
import
com.school.project.dto.student.StudentViewDataDTO
;
import
com.school.project.model.Student
;
public
interface
StudentService
{
public
interface
StudentService
{
...
@@ -10,4 +12,6 @@ public interface StudentService {
...
@@ -10,4 +12,6 @@ public interface StudentService {
public
Long
getUserId
(
String
username
);
public
Long
getUserId
(
String
username
);
public
StudentCoursesDTO
viewCourses
(
Long
id
);
public
StudentCoursesDTO
viewCourses
(
Long
id
);
Iterable
<
Student
>
getStudentByPredicate
(
Predicate
predicate
);
}
}
src/main/java/com/school/project/service/student/StudentServiceImpl.java
View file @
30782061
package
com
.
school
.
project
.
service
.
student
;
package
com
.
school
.
project
.
service
.
student
;
import
com.querydsl.core.types.Predicate
;
import
com.school.project.dto.student.StudentCoursesDTO
;
import
com.school.project.dto.student.StudentCoursesDTO
;
import
com.school.project.dto.student.StudentViewDataDTO
;
import
com.school.project.dto.student.StudentViewDataDTO
;
import
com.school.project.mapper.StudentCoursesMapper
;
import
com.school.project.mapper.StudentCoursesMapper
;
import
com.school.project.mapper.StudentViewDataMapper
;
import
com.school.project.mapper.StudentViewDataMapper
;
import
com.school.project.model.Student
;
import
com.school.project.model.userRegistration.User
;
import
com.school.project.model.userRegistration.User
;
import
com.school.project.repository.StudentRepository
;
import
com.school.project.repository.StudentRepository
;
import
com.school.project.repository.userRegistration.UserRepository
;
import
com.school.project.repository.userRegistration.UserRepository
;
...
@@ -47,6 +49,11 @@ public class StudentServiceImpl implements StudentService {
...
@@ -47,6 +49,11 @@ public class StudentServiceImpl implements StudentService {
return
studentCoursesMapper
.
modelToDto
(
studentRepository
.
findByStudentId
(
id
));
return
studentCoursesMapper
.
modelToDto
(
studentRepository
.
findByStudentId
(
id
));
}
}
@Override
public
Iterable
<
Student
>
getStudentByPredicate
(
Predicate
predicate
)
{
return
studentRepository
.
findAll
(
predicate
);
}
}
}
src/main/resources/application.properties
View file @
30782061
spring.jpa.hibernate.ddl-auto
=
update
spring.jpa.hibernate.ddl-auto
=
update
spring.datasource.url
=
jdbc:mysql://localhost:3306/school-portal
spring.datasource.url
=
jdbc:postgresql://localhost:5432/school-portal
spring.datasource.username
=
root
spring.datasource.username
=
postgres
spring.datasource.password
=
charlie123
spring.datasource.password
=
root
spring.jpa.database
=
postgresql
spring.jpa.properties.hibernate.default_schema
=
public
spring.security.user.name
=
sulemantalpur6@gmail.com
#spring.sql.init.mode=always
spring.jpa.defer-datasource-initialization
=
true
spring.datasource.data
=
classpath:data.sql
spring.security.user.name
=
sulemantalpur6@gmail.com
spring.security.user.password
=
charlie
spring.security.user.password
=
charlie
spring.autoconfigure.exclude
=
org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration
spring.autoconfigure.exclude
=
org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration
spring.mvc.view.prefix
=
/static
spring.mvc.view.prefix
=
/static
server.error.include-message
=
always
server.error.include-message
=
always
spring.datasource.data
=
classpath:data.sql
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment