AhmedAbouseda1 / kpishelper

0 stars 0 forks source link

Sweep : create dashboard endpoint #6

Open AhmedAbouseda1 opened 6 months ago

AhmedAbouseda1 commented 6 months ago

I want to create backend dashboard API, it should return the following dto get the collection size and the recorded date from collection entity and recorded_date ,total_activities, total_participants from activities entity the entities called collection and activities the endpoints should be allocated under com.kpis.helper.web.rest RequestMapping should be "/api/dashboard"

Checklist - [X] Create `src/main/java/com/kpis/helper/service/dto/DashboardDTO.java` ✓ https://github.com/AhmedAbouseda1/kpishelper/commit/793adc9f93ffddd134b14e03beaee34ef8a0c721 [Edit](https://github.com/AhmedAbouseda1/kpishelper/edit/sweep/create_dashboard_endpoint/src/main/java/com/kpis/helper/service/dto/DashboardDTO.java) - [X] Modify `src/main/java/com/kpis/helper/repository/ActivitiesRepository.java` ✓ https://github.com/AhmedAbouseda1/kpishelper/commit/793adc9f93ffddd134b14e03beaee34ef8a0c721 [Edit](https://github.com/AhmedAbouseda1/kpishelper/edit/sweep/create_dashboard_endpoint/src/main/java/com/kpis/helper/repository/ActivitiesRepository.java) - [X] Modify `src/main/java/com/kpis/helper/service/CollectionService.java` ✓ https://github.com/AhmedAbouseda1/kpishelper/commit/793adc9f93ffddd134b14e03beaee34ef8a0c721 [Edit](https://github.com/AhmedAbouseda1/kpishelper/edit/sweep/create_dashboard_endpoint/src/main/java/com/kpis/helper/service/CollectionService.java) - [X] Modify `src/main/java/com/kpis/helper/web/rest/CollectionResource.java` ✓ https://github.com/AhmedAbouseda1/kpishelper/commit/793adc9f93ffddd134b14e03beaee34ef8a0c721 [Edit](https://github.com/AhmedAbouseda1/kpishelper/edit/sweep/create_dashboard_endpoint/src/main/java/com/kpis/helper/web/rest/CollectionResource.java)
sweep-ai[bot] commented 6 months ago

🚀 Here's the PR! #7

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: 072b9c7859)
Install Sweep Configs: Pull Request

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/AhmedAbouseda1/kpishelper/blob/60a7949ce53c6e6e0decb108c279f98dac0a6f80/src/main/java/com/kpis/helper/web/rest/CollectionResource.java#L1-L170 https://github.com/AhmedAbouseda1/kpishelper/blob/60a7949ce53c6e6e0decb108c279f98dac0a6f80/src/test/java/com/kpis/helper/web/rest/CollectionResourceIT.java#L1-L519

Step 2: ⌨️ Coding

private Long collectionSize;
private Instant collectionRecordedDate; 
private Instant activitiesRecordedDate;
private Long totalActivities;
private Long totalParticipants;

Generate getters and setters for these fields.

Add the following query method to retrieve the most recent recorded date:

@Query("select max(a.recordedDate) from Activities a")
Instant findMaxRecordedDate();

Add a new method to retrieve the dashboard data at the end of the CollectionService class:

// Existing code... // Add the new getDashboardData() method here } // Existing code... public DashboardDTO getDashboardData() { DashboardDTO dashboardDTO = new DashboardDTO(); dashboardDTO.setCollectionSize(collectionRepository.count()); dashboardDTO.setCollectionRecordedDate(collectionRepository.findTopByOrderByRecordedDateDesc().getRecordedDate()); dashboardDTO.setActivitiesRecordedDate(activitiesRepository.findMaxRecordedDate()); dashboardDTO.setTotalActivities(activitiesRepository.count()); dashboardDTO.setTotalParticipants(activitiesRepository.sumParticipants()); return dashboardDTO; } }

private final CollectionService collectionService; private final CollectionRepository collectionRepository; public CollectionResource(CollectionService collectionService, CollectionRepository collectionRepository) { this.collectionService = collectionService; this.collectionRepository = collectionRepository; } private final CollectionService collectionService; private final CollectionRepository collectionRepository; private final ActivitiesRepository activitiesRepository; public CollectionResource(CollectionService collectionService, CollectionRepository collectionRepository, ActivitiesRepository activitiesRepository) { this.collectionService = collectionService; this.collectionRepository = collectionRepository; this.activitiesRepository = activitiesRepository; } @GetMapping("/api/dashboard") public DashboardDTO getDashboardData() { log.debug("REST request to get dashboard data"); return collectionService.getDashboardData(); }


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/create_dashboard_endpoint.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.

This is an automated message generated by Sweep AI.