Skip to content

Commit

Permalink
Merge branch 'main' into renovate/jakarta.annotation-jakarta.annotati…
Browse files Browse the repository at this point in the history
…on-api-3.x
  • Loading branch information
rajadilipkolli authored Jul 20, 2024
2 parents 20562f3 + bb13051 commit d437f2a
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 82 deletions.
78 changes: 41 additions & 37 deletions graphql/boot-graphql-querydsl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,39 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>net.ttddyy</groupId>
<artifactId>datasource-proxy</artifactId>
<version>1.10</version>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi.version}</version>
</dependency>

<!-- Mapstruct -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<!-- End Mapstruct -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand All @@ -73,57 +106,28 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>

<!-- Start QueryDSL for JPA -->
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa-codegen</artifactId>
<classifier>jakarta</classifier>
<version>${querydsl.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<classifier>jakarta</classifier>
<version>${querydsl.version}</version>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>net.ttddyy</groupId>
<artifactId>datasource-proxy</artifactId>
<version>1.10</version>
</dependency>

<!-- Mapstruct -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<!-- End Mapstruct -->
<!-- End QueryDSL for JPA -->

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@ControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class GlobalExceptionHandler {
class GlobalExceptionHandler {

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Slf4j
@Configuration(proxyBeanMethods = false)
public class GraphQLConfiguration {
class GraphQLConfiguration {

@Bean
GraphQlSourceBuilderCustomizer inspectionCustomizer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Component
@RequiredArgsConstructor
@Slf4j
public class Initializer implements CommandLineRunner {
class Initializer implements CommandLineRunner {

private final PostRepository postRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

@Configuration(proxyBeanMethods = false)
@OpenAPIDefinition(info = @Info(title = "boot-graphql-querydsl", version = "v1"), servers = @Server(url = "/"))
public class SwaggerConfig {}
class SwaggerConfig {}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Aspect
@Component
public class LoggingAspect {
class LoggingAspect {

private final Logger log = LoggerFactory.getLogger(this.getClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostResponse> getPostsByUserName(@Argument("name") String name) {
List<PostResponse> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostComment, Long> {}
public interface PostCommentRepository
extends JpaRepository<PostComment, Long>, QuerydslPredicateExecutor<PostComment> {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

public interface PostRepository
extends JpaRepository<Post, Long>, QuerydslPredicateExecutor<Post>, QuerydslBinderCustomizer<QPost> {

@Override
default void customize(QuerydslBindings bindings, QPost root) {
bindings.bind(String.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<PostCommentResponse> getAllPostComments(
PagedResult<PostCommentResponse> 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,
Expand All @@ -44,15 +44,15 @@ public PagedResult<PostCommentResponse> getAllPostComments(
}

@GetMapping("/{id}")
public ResponseEntity<PostCommentResponse> getPostCommentById(@PathVariable Long id) {
ResponseEntity<PostCommentResponse> getPostCommentById(@PathVariable Long id) {
return postCommentService
.findPostCommentById(id)
.map(ResponseEntity::ok)
.orElseThrow(() -> new PostCommentNotFoundException(id));
}

@PostMapping
public ResponseEntity<PostCommentResponse> createPostComment(
ResponseEntity<PostCommentResponse> createPostComment(
@RequestBody @Validated CreatePostCommentRequest createPostCommentRequest) {
PostCommentResponse response = postCommentService.savePostComment(createPostCommentRequest);
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
Expand All @@ -63,13 +63,13 @@ public ResponseEntity<PostCommentResponse> createPostComment(
}

@PutMapping("/{id}")
public ResponseEntity<PostCommentResponse> updatePostComment(
ResponseEntity<PostCommentResponse> updatePostComment(
@PathVariable Long id, @RequestBody @Valid PostCommentRequest postCommentRequest) {
return ResponseEntity.ok(postCommentService.updatePostComment(id, postCommentRequest));
}

@DeleteMapping("/{id}")
public ResponseEntity<PostCommentResponse> deletePostComment(@PathVariable Long id) {
ResponseEntity<PostCommentResponse> deletePostComment(@PathVariable Long id) {
return postCommentService
.findPostCommentById(id)
.map(postComment -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<PostResponse> getAllPosts(
PagedResult<PostResponse> 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,
Expand All @@ -44,12 +44,12 @@ public PagedResult<PostResponse> getAllPosts(
}

@GetMapping("/{id}")
public ResponseEntity<PostResponse> getPostById(@PathVariable Long id) {
ResponseEntity<PostResponse> getPostById(@PathVariable Long id) {
return postService.findPostById(id).map(ResponseEntity::ok).orElseThrow(() -> new PostNotFoundException(id));
}

@PostMapping
public ResponseEntity<PostResponse> createPost(@RequestBody @Validated CreatePostRequest createPostRequest) {
ResponseEntity<PostResponse> createPost(@RequestBody @Validated CreatePostRequest createPostRequest) {
PostResponse response = postService.savePost(createPostRequest);
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/api/posts/{id}")
Expand All @@ -59,13 +59,12 @@ public ResponseEntity<PostResponse> createPost(@RequestBody @Validated CreatePos
}

@PutMapping("/{id}")
public ResponseEntity<PostResponse> updatePost(
@PathVariable Long id, @RequestBody @Valid UpdatePostRequest postRequest) {
ResponseEntity<PostResponse> updatePost(@PathVariable Long id, @RequestBody @Valid UpdatePostRequest postRequest) {
return ResponseEntity.ok(postService.updatePost(id, postRequest));
}

@DeleteMapping("/{id}")
public ResponseEntity<PostResponse> deletePost(@PathVariable Long id) {
ResponseEntity<PostResponse> deletePost(@PathVariable Long id) {
return postService
.findPostById(id)
.map(post -> {
Expand Down
Loading

0 comments on commit d437f2a

Please sign in to comment.