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 31, 2024
1 parent 8e28481 commit acb1fe2
Show file tree
Hide file tree
Showing 63 changed files with 534 additions and 78 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@
<artifactId>elasticsearch-configuration-jar</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-security</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bloggios/user/configuration/Beans.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Owner - Rohit Parihar
* Author - rohit
* Project - auth-provider-application
* Package - com.bloggios.auth.provider.configuration
* Package - com.bloggios.user.provider.configuration
* Created_on - 30 November-2023
* Created_at - 19 : 53
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* Owner - Rohit Parihar
* Author - rohit
* Project - auth-provider-application
* Package - com.bloggios.auth.provider.configuration
* Package - com.bloggios.user.provider.configuration
* Created_on - 02 December-2023
* Created_at - 13 : 26
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* Owner - Rohit Parihar
* Author - rohit
* Project - auth-provider-application
* Package - com.bloggios.auth.provider.configuration
* Package - com.bloggios.user.provider.configuration
* Created_on - 02 December-2023
* Created_at - 23 : 17
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.bloggios.user.configuration;

import com.bloggios.user.properties.SwaggerConfigProperties;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* Owner - Rohit Parihar
* Author - rohit
* Project - blog-provider-application
* Package - com.bloggios.user.configuration
* Created_on - August 30 - 2024
* Created_at - 01:19
*/

@Configuration
@RequiredArgsConstructor
public class SwaggerConfiguration {

private final SwaggerConfigProperties swaggerConfigProperties;

@Bean
public GroupedOpenApi api() {
return GroupedOpenApi.builder()
.group(swaggerConfigProperties.getGroupName().getDefinition())
.packagesToScan(swaggerConfigProperties.getGroupName().getScanPackages())
.build();
}

@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info()
.title(swaggerConfigProperties.getInfo().getTitle())
.version(swaggerConfigProperties.getInfo().getVersion())
.description(swaggerConfigProperties.getInfo().getDescription())
.license(new License().name(swaggerConfigProperties.getInfo().getLicense().getName()).url(swaggerConfigProperties.getInfo().getLicense().getUrl()))
.contact(new Contact().name(swaggerConfigProperties.getInfo().getContact().getName()).email(swaggerConfigProperties.getInfo().getContact().getEmail()).url(swaggerConfigProperties.getInfo().getContact().getUrl())))
.servers(getServers())
.components(new Components()
.addSecuritySchemes(
"bearerAuth",
new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("bearer").bearerFormat("JWT")
.name("bearerAuth")
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")
.in(SecurityScheme.In.HEADER)
.description("JWT Authentication")));
}

public List<Server> getServers(){
Map<String, SwaggerConfigProperties.Server> servers = swaggerConfigProperties.getServers();
List<Server> serversList = new ArrayList<>();
for (String server : servers.keySet()){
SwaggerConfigProperties.Server getServer = servers.get(server);
serversList.add(new Server().description(getServer.getName()).url(getServer.getUrl()));
}
return serversList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* Owner - Rohit Parihar
* Author - rohit
* Project - auth-provider-application
* Package - com.bloggios.auth.provider.configuration
* Package - com.bloggios.user.provider.configuration
* Created_on - 29 November-2023
* Created_at - 15 : 13
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Owner - Rohit Parihar
* Author - rohit
* Project - auth-provider-application
* Package - com.bloggios.auth.provider.constants
* Package - com.bloggios.user.provider.constants
* Created_on - 29 November-2023
* Created_at - 15 : 13
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Owner - Rohit Parihar
* Author - rohit
* Project - auth-provider-application
* Package - com.bloggios.auth.provider.constants
* Package - com.bloggios.user.provider.constants
* Created_on - 28 May-2024
* Created_at - 20 : 34
*/
Expand All @@ -56,16 +56,13 @@ public static class ProfileAuthController {
public static class FollowController {
public static final String BASE_PATH = "/follow";
public static final String HANDLE_FOLLOW = "/handle-follow/{userId}";
public static final String COUNT_FOLLOW = "/count";
}

public static class OpenController {
public static final String BASE_PATH = "/unauth";
public static final String PROFILE_INTERNAL_RESPONSE = "/profile-internal-response/{userId}";

public static class Follow {
public static final String COUNT_FOLLOW = "/count-follow";
}

public static class Profile {
public static final String USER_PROFILE = "/user-profile";
public static final String FETCH_PROFILES_USERNAME = "/get-username-profiles-list";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Owner - Rohit Parihar
* Author - rohit
* Project - auth-provider-application
* Package - com.bloggios.auth.provider.constants
* Package - com.bloggios.user.provider.constants
* Created_on - 29 November-2023
* Created_at - 00 : 58
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Owner - Rohit Parihar
* Author - rohit
* Project - auth-provider-application
* Package - com.bloggios.auth.provider.constants
* Package - com.bloggios.user.provider.constants
* Created_on - 29 November-2023
* Created_at - 13 : 57
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Owner - Rohit Parihar
* Author - rohit
* Project - auth-provider-application
* Package - com.bloggios.auth.provider.constants
* Package - com.bloggios.user.provider.constants
* Created_on - 07 December-2023
* Created_at - 12 : 30
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Owner - Rohit Parihar
* Author - rohit
* Project - auth-provider-application
* Package - com.bloggios.auth.provider.constants
* Package - com.bloggios.user.provider.constants
* Created_on - 29 November-2023
* Created_at - 23 : 46
*/
Expand Down
59 changes: 58 additions & 1 deletion src/main/java/com/bloggios/user/controller/FollowController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@

import com.bloggios.authenticationconfig.payload.AuthenticatedUser;
import com.bloggios.user.constants.EndpointConstants;
import com.bloggios.user.payload.response.ExceptionResponse;
import com.bloggios.user.payload.response.FollowCountResponse;
import com.bloggios.user.payload.response.FollowResponse;
import com.bloggios.user.service.FollowService;
import com.bloggios.user.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 io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* Owner - Rohit Parihar and Bloggios
Expand All @@ -22,12 +33,58 @@
@RestController
@RequestMapping(EndpointConstants.FollowController.BASE_PATH)
@RequiredArgsConstructor
@Tag(
name = "Follow Controller",
description = "Controller responsible for handler user followers, followings, etc"
)
public class FollowController {

private final FollowService followService;

@GetMapping(EndpointConstants.FollowController.HANDLE_FOLLOW)
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = FollowResponse.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<FollowResponse> handleFollow(@PathVariable String userId, @AuthenticationPrincipal AuthenticatedUser authenticatedUser) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(followService.handleFollow(userId, authenticatedUser)));
}

@GetMapping(EndpointConstants.FollowController.COUNT_FOLLOW)
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = FollowCountResponse.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<FollowCountResponse> followCount(@AuthenticationPrincipal AuthenticatedUser authenticatedUser) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(followService.countFollowerFollowing(authenticatedUser)));
}
}
61 changes: 54 additions & 7 deletions src/main/java/com/bloggios/user/controller/OpenController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import com.bloggios.authenticationconfig.payload.AuthenticatedUser;
import com.bloggios.elasticsearch.configuration.payload.response.ListResponse;
import com.bloggios.user.constants.EndpointConstants;
import com.bloggios.user.payload.response.FollowCountResponse;
import com.bloggios.user.payload.response.ProfileResponse;
import com.bloggios.user.payload.response.ExceptionResponse;
import com.bloggios.user.payload.response.ProfileInternalResponse;
import com.bloggios.user.payload.response.ProfileResponse;
import com.bloggios.user.service.FollowService;
import com.bloggios.user.service.ProfileService;
import com.bloggios.user.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 lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -32,21 +36,64 @@ public class OpenController {
private final FollowService followService;

@GetMapping(EndpointConstants.OpenController.PROFILE_INTERNAL_RESPONSE)
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = ProfileInternalResponse.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<ProfileInternalResponse> getProfileInternalResponse(@PathVariable String userId) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(profileService.getProfileInternalResponse(userId)));
}

@GetMapping(EndpointConstants.OpenController.Follow.COUNT_FOLLOW)
public ResponseEntity<FollowCountResponse> followCount(@AuthenticationPrincipal AuthenticatedUser authenticatedUser) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(followService.countFollowerFollowing(authenticatedUser)));
}

@GetMapping(EndpointConstants.OpenController.Profile.USER_PROFILE)
@Operation(
responses = {
@ApiResponse(description = "SUCCESS", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = ProfileResponse.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<ProfileResponse> getUserProfile(@RequestParam String username, @AuthenticationPrincipal AuthenticatedUser authenticatedUser) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(profileService.getUserProfile(username, authenticatedUser)));
}

@GetMapping(EndpointConstants.OpenController.Profile.FETCH_PROFILES_USERNAME)
@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> fetchProfilesUsingUsername(@RequestParam String username) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(profileService.fetchProfilesUsingUsername(username)));
}
Expand Down
Loading

0 comments on commit acb1fe2

Please sign in to comment.