-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/com/bloggios/blog/controller/SchedulerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.bloggios.blog.controller; | ||
|
||
import com.bloggios.authenticationconfig.payload.AuthenticatedUser; | ||
import com.bloggios.blog.constants.EndpointConstants; | ||
import com.bloggios.blog.service.SchedulerService; | ||
import com.bloggios.blog.utils.AsyncUtils; | ||
import com.bloggios.elasticsearch.configuration.payload.response.ListResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* Owner - Rohit Parihar | ||
* Author - rohit | ||
* Project - blog-provider-application | ||
* Package - com.bloggios.blog.controller | ||
* Created_on - August 30 - 2024 | ||
* Created_at - 00:44 | ||
*/ | ||
|
||
@RestController | ||
@RequestMapping(EndpointConstants.SchedulerController.BASE_PATH) | ||
@RequiredArgsConstructor | ||
public class SchedulerController { | ||
|
||
private final SchedulerService schedulerService; | ||
|
||
@GetMapping | ||
public ResponseEntity<ListResponse> getUserScheduledBlogs(@AuthenticationPrincipal AuthenticatedUser authenticatedUser) { | ||
return ResponseEntity.ok(AsyncUtils.getAsyncResult(schedulerService.getUserScheduler(authenticatedUser))); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/bloggios/blog/implementation/SchedulerServiceImplementation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.bloggios.blog.implementation; | ||
|
||
import com.bloggios.authenticationconfig.payload.AuthenticatedUser; | ||
import com.bloggios.blog.constants.BeanConstants; | ||
import com.bloggios.blog.dao.implementation.pgsqlimplementation.SchedulerDataDao; | ||
import com.bloggios.blog.modal.SchedulerData; | ||
import com.bloggios.blog.service.SchedulerService; | ||
import com.bloggios.elasticsearch.configuration.payload.response.ListResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Owner - Rohit Parihar | ||
* Author - rohit | ||
* Project - blog-provider-application | ||
* Package - com.bloggios.blog.implementation | ||
* Created_on - August 30 - 2024 | ||
* Created_at - 00:50 | ||
*/ | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class SchedulerServiceImplementation implements SchedulerService { | ||
|
||
private final SchedulerDataDao schedulerDataDao; | ||
|
||
@Override | ||
@Async(BeanConstants.ASYNC_TASK_EXTERNAL_POOL) | ||
public CompletableFuture<ListResponse> getUserScheduler(AuthenticatedUser authenticatedUser) { | ||
long startTime = System.currentTimeMillis(); | ||
List<SchedulerData> byUserId = schedulerDataDao.findByUserId(authenticatedUser.getUserId()); | ||
ListResponse listResponse = ListResponse | ||
.builder() | ||
.page(0) | ||
.size(byUserId.size()) | ||
.object(byUserId) | ||
.totalRecordsCount(byUserId.size()) | ||
.build(); | ||
log.info("Execution time (Add Blog) : {}ms", System.currentTimeMillis() - startTime); | ||
return CompletableFuture.completedFuture(listResponse); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/bloggios/blog/service/SchedulerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.bloggios.blog.service; | ||
|
||
import com.bloggios.authenticationconfig.payload.AuthenticatedUser; | ||
import com.bloggios.elasticsearch.configuration.payload.response.ListResponse; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Owner - Rohit Parihar | ||
* Author - rohit | ||
* Project - blog-provider-application | ||
* Package - com.bloggios.blog.service | ||
* Created_on - August 30 - 2024 | ||
* Created_at - 00:49 | ||
*/ | ||
|
||
public interface SchedulerService { | ||
|
||
CompletableFuture<ListResponse> getUserScheduler(AuthenticatedUser authenticatedUser); | ||
} |