From 14103659ae80b530b4460fa012cc7bf230a055a7 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sat, 20 Jul 2024 06:23:18 +0000 Subject: [PATCH 1/2] feat : fix issue with querydsl classifier --- graphql/boot-graphql-querydsl/pom.xml | 76 ++++++++++--------- .../DatasourceProxyBeanPostProcessor.java | 2 +- .../config/GlobalExceptionHandler.java | 2 +- .../querydsl/config/GraphQLConfiguration.java | 2 +- .../graphql/querydsl/config/Initializer.java | 2 +- .../querydsl/config/SwaggerConfig.java | 2 +- .../graphql/querydsl/config/WebMvcConfig.java | 5 +- .../config/logging/LoggingAspect.java | 2 +- .../querydsl/gql/PostControllerQL.java | 16 ++-- .../repositories/PostCommentRepository.java | 4 +- .../querydsl/repositories/PostRepository.java | 1 + .../controllers/PostCommentController.java | 20 ++--- .../web/controllers/PostController.java | 21 +++-- .../web/controllers/TagController.java | 18 +++-- 14 files changed, 94 insertions(+), 79 deletions(-) diff --git a/graphql/boot-graphql-querydsl/pom.xml b/graphql/boot-graphql-querydsl/pom.xml index f9d606e72..ee28cc99f 100644 --- a/graphql/boot-graphql-querydsl/pom.xml +++ b/graphql/boot-graphql-querydsl/pom.xml @@ -57,22 +57,6 @@ org.springframework.boot spring-boot-starter-web - - org.springframework.boot - spring-boot-devtools - runtime - true - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.projectlombok - lombok - true - org.springframework.boot spring-boot-starter-data-jpa @@ -86,20 +70,10 @@ org.liquibase liquibase-core - - - com.querydsl - querydsl-jpa-codegen - jakarta - ${querydsl.version} - provided - - - com.querydsl - querydsl-jpa - jakarta - ${querydsl.version} + net.ttddyy + datasource-proxy + 1.10 @@ -111,11 +85,6 @@ org.apache.commons commons-lang3 - - net.ttddyy - datasource-proxy - 1.10 - @@ -125,6 +94,45 @@ + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.projectlombok + lombok + true + + + + + com.querydsl + querydsl-jpa-codegen + jakarta + ${querydsl.version} + provided + + + com.querydsl + querydsl-jpa + + + + + com.querydsl + querydsl-jpa + jakarta + ${querydsl.version} + + + org.springframework.boot spring-boot-starter-test diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/DatasourceProxyBeanPostProcessor.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/DatasourceProxyBeanPostProcessor.java index 9cb2ddfe1..ba1f0524e 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/DatasourceProxyBeanPostProcessor.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/DatasourceProxyBeanPostProcessor.java @@ -13,7 +13,7 @@ import org.springframework.util.ReflectionUtils; @Component -public class DatasourceProxyBeanPostProcessor implements BeanPostProcessor { +class DatasourceProxyBeanPostProcessor implements BeanPostProcessor { @Override public Object postProcessAfterInitialization(Object bean, String beanName) { diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/GlobalExceptionHandler.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/GlobalExceptionHandler.java index 5f841fed4..ef79004ad 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/GlobalExceptionHandler.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/GlobalExceptionHandler.java @@ -19,7 +19,7 @@ @ControllerAdvice @Order(Ordered.HIGHEST_PRECEDENCE) -public class GlobalExceptionHandler { +class GlobalExceptionHandler { @ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/GraphQLConfiguration.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/GraphQLConfiguration.java index 3aaca0531..83eb902e1 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/GraphQLConfiguration.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/GraphQLConfiguration.java @@ -7,7 +7,7 @@ @Slf4j @Configuration(proxyBeanMethods = false) -public class GraphQLConfiguration { +class GraphQLConfiguration { @Bean GraphQlSourceBuilderCustomizer inspectionCustomizer() { diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/Initializer.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/Initializer.java index dfde48c02..9108d5ed0 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/Initializer.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/Initializer.java @@ -13,7 +13,7 @@ @Component @RequiredArgsConstructor @Slf4j -public class Initializer implements CommandLineRunner { +class Initializer implements CommandLineRunner { private final PostRepository postRepository; diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/SwaggerConfig.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/SwaggerConfig.java index dbd768855..bfc7441a8 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/SwaggerConfig.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/SwaggerConfig.java @@ -7,4 +7,4 @@ @Configuration(proxyBeanMethods = false) @OpenAPIDefinition(info = @Info(title = "boot-graphql-querydsl", version = "v1"), servers = @Server(url = "/")) -public class SwaggerConfig {} +class SwaggerConfig {} diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/WebMvcConfig.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/WebMvcConfig.java index 88a57dbaf..693a9e6a5 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/WebMvcConfig.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/WebMvcConfig.java @@ -5,9 +5,10 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -@Configuration +@Configuration(proxyBeanMethods = false) @RequiredArgsConstructor -public class WebMvcConfig implements WebMvcConfigurer { +class WebMvcConfig implements WebMvcConfigurer { + private final ApplicationProperties properties; @Override diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/logging/LoggingAspect.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/logging/LoggingAspect.java index 94706631b..99fe77b21 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/logging/LoggingAspect.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/config/logging/LoggingAspect.java @@ -15,7 +15,7 @@ @Aspect @Component -public class LoggingAspect { +class LoggingAspect { private final Logger log = LoggerFactory.getLogger(this.getClass()); diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/gql/PostControllerQL.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/gql/PostControllerQL.java index d94844038..4a036137c 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/gql/PostControllerQL.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/gql/PostControllerQL.java @@ -5,35 +5,37 @@ import com.example.graphql.querydsl.model.response.PostResponse; import com.example.graphql.querydsl.services.PostService; import java.util.List; -import lombok.RequiredArgsConstructor; import org.springframework.graphql.data.method.annotation.Argument; import org.springframework.graphql.data.method.annotation.MutationMapping; import org.springframework.graphql.data.method.annotation.QueryMapping; import org.springframework.stereotype.Controller; @Controller -@RequiredArgsConstructor -public class PostControllerQL { +class PostControllerQL { private final PostService postService; + PostControllerQL(PostService postService) { + this.postService = postService; + } + @QueryMapping - public Long countPosts() { + Long countPosts() { return this.postService.totalPosts(); } @QueryMapping - public List getPostsByUserName(@Argument("name") String name) { + List getPostsByUserName(@Argument("name") String name) { return this.postService.getPostsByUserName(name); } @MutationMapping - public PostResponse createPost(@Argument("createPostRequest") CreatePostRequest createPostRequest) { + PostResponse createPost(@Argument("createPostRequest") CreatePostRequest createPostRequest) { return this.postService.savePost(createPostRequest); } @MutationMapping - public PostResponse addTagsToPost(@Argument("addTagRequest") AddTagRequest addTagRequest) { + PostResponse addTagsToPost(@Argument("addTagRequest") AddTagRequest addTagRequest) { return this.postService.addTagsToPost(addTagRequest); } } diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostCommentRepository.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostCommentRepository.java index d8cf83822..ff30116ad 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostCommentRepository.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostCommentRepository.java @@ -2,5 +2,7 @@ import com.example.graphql.querydsl.entities.PostComment; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; -public interface PostCommentRepository extends JpaRepository {} +public interface PostCommentRepository + extends JpaRepository, QuerydslPredicateExecutor {} diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostRepository.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostRepository.java index 8463164c8..bbd10562d 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostRepository.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostRepository.java @@ -15,6 +15,7 @@ public interface PostRepository extends JpaRepository, QuerydslPredicateExecutor, QuerydslBinderCustomizer { + @Override default void customize(QuerydslBindings bindings, QPost root) { bindings.bind(String.class) diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/web/controllers/PostCommentController.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/web/controllers/PostCommentController.java index f22941303..344eb0a69 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/web/controllers/PostCommentController.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/web/controllers/PostCommentController.java @@ -10,8 +10,6 @@ import com.example.graphql.querydsl.utils.AppConstants; import jakarta.validation.Valid; import java.net.URI; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; @@ -27,14 +25,16 @@ @RestController @RequestMapping("/api/posts/comments") -@Slf4j -@RequiredArgsConstructor -public class PostCommentController { +class PostCommentController { private final PostCommentService postCommentService; + PostCommentController(PostCommentService postCommentService) { + this.postCommentService = postCommentService; + } + @GetMapping - public PagedResult getAllPostComments( + PagedResult getAllPostComments( @RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_NUMBER, required = false) int pageNo, @RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_SIZE, required = false) int pageSize, @RequestParam(defaultValue = AppConstants.DEFAULT_SORT_BY, required = false) String sortBy, @@ -44,7 +44,7 @@ public PagedResult getAllPostComments( } @GetMapping("/{id}") - public ResponseEntity getPostCommentById(@PathVariable Long id) { + ResponseEntity getPostCommentById(@PathVariable Long id) { return postCommentService .findPostCommentById(id) .map(ResponseEntity::ok) @@ -52,7 +52,7 @@ public ResponseEntity getPostCommentById(@PathVariable Long } @PostMapping - public ResponseEntity createPostComment( + ResponseEntity createPostComment( @RequestBody @Validated CreatePostCommentRequest createPostCommentRequest) { PostCommentResponse response = postCommentService.savePostComment(createPostCommentRequest); URI location = ServletUriComponentsBuilder.fromCurrentRequest() @@ -63,13 +63,13 @@ public ResponseEntity createPostComment( } @PutMapping("/{id}") - public ResponseEntity updatePostComment( + ResponseEntity updatePostComment( @PathVariable Long id, @RequestBody @Valid PostCommentRequest postCommentRequest) { return ResponseEntity.ok(postCommentService.updatePostComment(id, postCommentRequest)); } @DeleteMapping("/{id}") - public ResponseEntity deletePostComment(@PathVariable Long id) { + ResponseEntity deletePostComment(@PathVariable Long id) { return postCommentService .findPostCommentById(id) .map(postComment -> { diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/web/controllers/PostController.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/web/controllers/PostController.java index fe3163e93..470bc35e2 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/web/controllers/PostController.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/web/controllers/PostController.java @@ -10,8 +10,6 @@ import com.example.graphql.querydsl.utils.AppConstants; import jakarta.validation.Valid; import java.net.URI; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; @@ -27,14 +25,16 @@ @RestController @RequestMapping("/api/posts") -@Slf4j -@RequiredArgsConstructor -public class PostController { +class PostController { private final PostService postService; + PostController(PostService postService) { + this.postService = postService; + } + @GetMapping - public PagedResult getAllPosts( + PagedResult getAllPosts( @RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_NUMBER, required = false) int pageNo, @RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_SIZE, required = false) int pageSize, @RequestParam(defaultValue = AppConstants.DEFAULT_SORT_BY, required = false) String sortBy, @@ -44,12 +44,12 @@ public PagedResult getAllPosts( } @GetMapping("/{id}") - public ResponseEntity getPostById(@PathVariable Long id) { + ResponseEntity getPostById(@PathVariable Long id) { return postService.findPostById(id).map(ResponseEntity::ok).orElseThrow(() -> new PostNotFoundException(id)); } @PostMapping - public ResponseEntity createPost(@RequestBody @Validated CreatePostRequest createPostRequest) { + ResponseEntity createPost(@RequestBody @Validated CreatePostRequest createPostRequest) { PostResponse response = postService.savePost(createPostRequest); URI location = ServletUriComponentsBuilder.fromCurrentRequest() .path("/api/posts/{id}") @@ -59,13 +59,12 @@ public ResponseEntity createPost(@RequestBody @Validated CreatePos } @PutMapping("/{id}") - public ResponseEntity updatePost( - @PathVariable Long id, @RequestBody @Valid UpdatePostRequest postRequest) { + ResponseEntity updatePost(@PathVariable Long id, @RequestBody @Valid UpdatePostRequest postRequest) { return ResponseEntity.ok(postService.updatePost(id, postRequest)); } @DeleteMapping("/{id}") - public ResponseEntity deletePost(@PathVariable Long id) { + ResponseEntity deletePost(@PathVariable Long id) { return postService .findPostById(id) .map(post -> { diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/web/controllers/TagController.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/web/controllers/TagController.java index 9814b5458..0417ecb8f 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/web/controllers/TagController.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/web/controllers/TagController.java @@ -9,7 +9,6 @@ import com.example.graphql.querydsl.utils.AppConstants; import jakarta.validation.Valid; import java.net.URI; -import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; @@ -25,13 +24,16 @@ @RestController @RequestMapping("/api/tags") -@RequiredArgsConstructor -public class TagController { +class TagController { private final TagService tagService; + TagController(TagService tagService) { + this.tagService = tagService; + } + @GetMapping - public PagedResult getAllTags( + PagedResult getAllTags( @RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_NUMBER, required = false) int pageNo, @RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_SIZE, required = false) int pageSize, @RequestParam(defaultValue = AppConstants.DEFAULT_SORT_BY, required = false) String sortBy, @@ -41,12 +43,12 @@ public PagedResult getAllTags( } @GetMapping("/{id}") - public ResponseEntity getTagById(@PathVariable Long id) { + ResponseEntity getTagById(@PathVariable Long id) { return tagService.findTagById(id).map(ResponseEntity::ok).orElseThrow(() -> new TagNotFoundException(id)); } @PostMapping - public ResponseEntity createTag(@RequestBody @Validated TagRequest tagRequest) { + ResponseEntity createTag(@RequestBody @Validated TagRequest tagRequest) { TagResponse response = tagService.saveTag(tagRequest); URI location = ServletUriComponentsBuilder.fromCurrentRequest() .path("/api/tags/{id}") @@ -56,12 +58,12 @@ public ResponseEntity createTag(@RequestBody @Validated TagRequest } @PutMapping("/{id}") - public ResponseEntity updateTag(@PathVariable Long id, @RequestBody @Valid TagRequest tagRequest) { + ResponseEntity updateTag(@PathVariable Long id, @RequestBody @Valid TagRequest tagRequest) { return ResponseEntity.ok(tagService.updateTag(id, tagRequest)); } @DeleteMapping("/{id}") - public ResponseEntity deleteTag(@PathVariable Long id) { + ResponseEntity deleteTag(@PathVariable Long id) { return tagService .findTagById(id) .map(tag -> { From bb130511efc2b1c0826bd3cc3ca1de5d33a5bb5d Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sat, 20 Jul 2024 06:25:12 +0000 Subject: [PATCH 2/2] chore(deps) : removes unnecessary dependency --- graphql/boot-graphql-querydsl/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/graphql/boot-graphql-querydsl/pom.xml b/graphql/boot-graphql-querydsl/pom.xml index ee28cc99f..f6047604e 100644 --- a/graphql/boot-graphql-querydsl/pom.xml +++ b/graphql/boot-graphql-querydsl/pom.xml @@ -81,10 +81,6 @@ springdoc-openapi-starter-webmvc-ui ${springdoc-openapi.version} - - org.apache.commons - commons-lang3 -