Skip to content

Commit

Permalink
feature/swagger-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-zip committed Aug 30, 2024
1 parent 9e94b9c commit 4bfc333
Show file tree
Hide file tree
Showing 13 changed files with 326 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public static class BlogData {
public static final String BLOGS_LIST = BASE_PATH + "/list";
public static final String BLOG_COUNT_INTERNAL_RESPONSE = "/count-blogs";
}

public static class LikeData {
public static final String COUNT_LIKES = "/count-likes";
}
}

public static class FeignClient {
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/com/bloggios/blog/controller/BlogController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
import com.bloggios.blog.constants.EndpointConstants;
import com.bloggios.blog.payload.request.BlogListRequest;
import com.bloggios.blog.payload.request.BlogRequest;
import com.bloggios.blog.payload.response.ExceptionResponse;
import com.bloggios.blog.payload.response.LikeResponse;
import com.bloggios.blog.payload.response.ModuleResponse;
import com.bloggios.blog.service.BlogService;
import com.bloggios.blog.utils.AsyncUtils;
import com.bloggios.elasticsearch.configuration.payload.response.ListResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -42,6 +49,27 @@ public BlogController(
}

@PostMapping
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = ModuleResponse.class)
)),
@ApiResponse(description = "No Content", responseCode = "401", content = {
@Content(schema = @Schema(implementation = Void.class))
}),
@ApiResponse(description = "FORBIDDEN", responseCode = "403", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = String.class))
}),
@ApiResponse(description = "BAD REQUEST", responseCode = "400", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))
})
},
security = {
@SecurityRequirement(
name = "bearerAuth"
)
}
)
public ResponseEntity<ModuleResponse> addBlog(
@RequestPart(required = false) List<MultipartFile> images,
@RequestParam(required = true) String title,
Expand Down Expand Up @@ -77,6 +105,27 @@ public ResponseEntity<ModuleResponse> addBlog(
}

@PostMapping(EndpointConstants.BlogController.BLOG_LIST)
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = ListResponse.class)
)),
@ApiResponse(description = "No Content", responseCode = "401", content = {
@Content(schema = @Schema(implementation = Void.class))
}),
@ApiResponse(description = "FORBIDDEN", responseCode = "403", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = String.class))
}),
@ApiResponse(description = "BAD REQUEST", responseCode = "400", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))
})
},
security = {
@SecurityRequirement(
name = "bearerAuth"
)
}
)
public ResponseEntity<ListResponse> getBlogList(@RequestBody BlogListRequest blogListRequest) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(blogService.blogList(blogListRequest)));
}
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/bloggios/blog/controller/ChapterController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
import com.bloggios.authenticationconfig.payload.AuthenticatedUser;
import com.bloggios.blog.constants.EndpointConstants;
import com.bloggios.blog.payload.request.ChapterRequest;
import com.bloggios.blog.payload.response.ExceptionResponse;
import com.bloggios.blog.payload.response.ModuleResponse;
import com.bloggios.blog.service.ChapterService;
import com.bloggios.blog.utils.AsyncUtils;
import com.bloggios.elasticsearch.configuration.payload.response.ListResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -36,6 +42,27 @@ public ChapterController(
}

@PostMapping
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = ModuleResponse.class)
)),
@ApiResponse(description = "No Content", responseCode = "401", content = {
@Content(schema = @Schema(implementation = Void.class))
}),
@ApiResponse(description = "FORBIDDEN", responseCode = "403", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = String.class))
}),
@ApiResponse(description = "BAD REQUEST", responseCode = "400", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))
})
},
security = {
@SecurityRequirement(
name = "bearerAuth"
)
}
)
public ResponseEntity<ModuleResponse> addChapter(
@RequestParam String chapterName,
@RequestPart(required = false) MultipartFile coverImage,
Expand All @@ -55,6 +82,27 @@ public ResponseEntity<ModuleResponse> addChapter(
}

@GetMapping
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = ListResponse.class)
)),
@ApiResponse(description = "No Content", responseCode = "401", content = {
@Content(schema = @Schema(implementation = Void.class))
}),
@ApiResponse(description = "FORBIDDEN", responseCode = "403", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = String.class))
}),
@ApiResponse(description = "BAD REQUEST", responseCode = "400", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))
})
},
security = {
@SecurityRequirement(
name = "bearerAuth"
)
}
)
public ResponseEntity<ListResponse> getUserChapters(@AuthenticationPrincipal AuthenticatedUser authenticatedUser) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(chapterService.getUserChapters(authenticatedUser)));
}
Expand Down
35 changes: 31 additions & 4 deletions src/main/java/com/bloggios/blog/controller/LikeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

import com.bloggios.authenticationconfig.payload.AuthenticatedUser;
import com.bloggios.blog.constants.EndpointConstants;
import com.bloggios.blog.payload.response.CountResponse;
import com.bloggios.blog.payload.response.ExceptionResponse;
import com.bloggios.blog.payload.response.LikeResponse;
import com.bloggios.blog.service.LikeService;
import com.bloggios.blog.utils.AsyncUtils;
import com.bloggios.elasticsearch.configuration.payload.response.ListResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

/**
* Owner - Rohit Parihar and Bloggios
Expand All @@ -30,6 +36,27 @@ public class LikeController {
private final LikeService likeService;

@PostMapping
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = LikeResponse.class)
)),
@ApiResponse(description = "No Content", responseCode = "401", content = {
@Content(schema = @Schema(implementation = Void.class))
}),
@ApiResponse(description = "FORBIDDEN", responseCode = "403", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = String.class))
}),
@ApiResponse(description = "BAD REQUEST", responseCode = "400", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))
})
},
security = {
@SecurityRequirement(
name = "bearerAuth"
)
}
)
public ResponseEntity<LikeResponse> handleLike(@RequestParam String destinationId, @RequestParam String likeFor, @AuthenticationPrincipal AuthenticatedUser authenticatedUser) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(likeService.handleLike(destinationId, likeFor, authenticatedUser)));
}
Expand Down
79 changes: 77 additions & 2 deletions src/main/java/com/bloggios/blog/controller/OpenController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.bloggios.blog.controller;

import com.bloggios.blog.constants.EndpointConstants;
import com.bloggios.blog.payload.response.BlogCountResponse;
import com.bloggios.blog.payload.response.BlogResponse;
import com.bloggios.blog.payload.response.*;
import com.bloggios.blog.service.BlogService;
import com.bloggios.blog.service.LikeService;
import com.bloggios.blog.utils.AsyncUtils;
import com.bloggios.elasticsearch.configuration.payload.response.ListResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -28,8 +33,25 @@
public class OpenController {

private final BlogService blogService;
private final LikeService likeService;

@GetMapping(EndpointConstants.OpenController.BlogData.BLOGS_LIST)
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = ListResponse.class)
)),
@ApiResponse(description = "No Content", responseCode = "401", content = {
@Content(schema = @Schema(implementation = Void.class))
}),
@ApiResponse(description = "FORBIDDEN", responseCode = "403", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = String.class))
}),
@ApiResponse(description = "BAD REQUEST", responseCode = "400", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))
})
}
)
public ResponseEntity<ListResponse> blogsList(
@RequestParam Integer page,
@RequestParam(required = false) String userId,
Expand All @@ -41,14 +63,67 @@ public ResponseEntity<ListResponse> blogsList(
}

@GetMapping(EndpointConstants.OpenController.BlogData.BASE_PATH)
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = BlogResponse.class)
)),
@ApiResponse(description = "No Content", responseCode = "401", content = {
@Content(schema = @Schema(implementation = Void.class))
}),
@ApiResponse(description = "FORBIDDEN", responseCode = "403", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = String.class))
}),
@ApiResponse(description = "BAD REQUEST", responseCode = "400", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))
})
}
)
public ResponseEntity<BlogResponse> getUnauthBlog(
@RequestParam String blogId
) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(blogService.getUnauthBlog(blogId)));
}

@GetMapping(EndpointConstants.OpenController.BlogData.BLOG_COUNT_INTERNAL_RESPONSE)
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = BlogCountResponse.class)
)),
@ApiResponse(description = "No Content", responseCode = "401", content = {
@Content(schema = @Schema(implementation = Void.class))
}),
@ApiResponse(description = "FORBIDDEN", responseCode = "403", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = String.class))
}),
@ApiResponse(description = "BAD REQUEST", responseCode = "400", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))
})
}
)
public ResponseEntity<BlogCountResponse> countBlogInternalResponse(@RequestParam String userId) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(blogService.countBlog(userId)));
}

@GetMapping(EndpointConstants.OpenController.LikeData.COUNT_LIKES)
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = LikeResponse.class)
)),
@ApiResponse(description = "No Content", responseCode = "401", content = {
@Content(schema = @Schema(implementation = Void.class))
}),
@ApiResponse(description = "FORBIDDEN", responseCode = "403", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = String.class))
}),
@ApiResponse(description = "BAD REQUEST", responseCode = "400", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))
})
}
)
public ResponseEntity<CountResponse> getLikesCount(@RequestParam String destinationId) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(likeService.countLikes(destinationId)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public class SchedulerController {

@GetMapping
@Operation(
requestBody = @RequestBody(
required = false
),
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = ListResponse.class)
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/bloggios/blog/controller/TopicsController.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.bloggios.blog.controller;

import com.bloggios.blog.constants.EndpointConstants;
import com.bloggios.blog.payload.response.ExceptionResponse;
import com.bloggios.blog.payload.response.ModuleResponse;
import com.bloggios.blog.payload.response.TopicsListResponse;
import com.bloggios.blog.service.TopicsService;
import com.bloggios.blog.utils.AsyncUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -31,6 +38,22 @@ public TopicsController(
}

@GetMapping
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = TopicsListResponse.class)
)),
@ApiResponse(description = "No Content", responseCode = "401", content = {
@Content(schema = @Schema(implementation = Void.class))
}),
@ApiResponse(description = "FORBIDDEN", responseCode = "403", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = String.class))
}),
@ApiResponse(description = "BAD REQUEST", responseCode = "400", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))
})
}
)
public ResponseEntity<TopicsListResponse> getTags() {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(topicsService.tagsList()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ public Optional<LikeDocument> findByDestinationIdAndUserId(String destinationId,
public void deleteByDocument(LikeDocument likeDocument) {
repository.delete(likeDocument);
}

public long countLikeDocumentByDestinationId(String destinationId) {
return repository.countLikeDocumentByDestinationId(destinationId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
public interface LikeDocumentRepository extends ElasticsearchRepository<LikeDocument, String> {

Optional<LikeDocument> findByDestinationIdAndUserId(String destinationId, String userId);
long countLikeDocumentByDestinationId(String destinationId);
}
Loading

0 comments on commit 4bfc333

Please sign in to comment.