Skip to content

Commit

Permalink
feat(teammanagementlastactivity): added new endpoint for testing (#1525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Graeimh authored Jun 26, 2024
1 parent 8e0e940 commit 4e57809
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.xpeho.yaki_admin_backend.data.services;

import com.xpeho.yaki_admin_backend.data.sources.DeclarationJpaRepository;
import com.xpeho.yaki_admin_backend.domain.entities.LastActivityEntity;
import com.xpeho.yaki_admin_backend.domain.entities.statistics.*;
import com.xpeho.yaki_admin_backend.data.sources.TeamJpaRepository;
import com.xpeho.yaki_admin_backend.data.sources.TeammateJpaRepository;
Expand Down Expand Up @@ -173,4 +174,47 @@ public ArrayList<PerWeekdayStatisticsEntity> getPerWeekDayStatistics(StatisticsR
}
return perWeekdayStatisticsEntities;
}

@Override
public List<LastActivityEntity> getLastTeamsActivityByCustomerId(Integer targetId) {
List<Object[]> results = declarationJpaRepository.getLastTeamActivityById(
targetId);

ArrayList<LastActivityEntity> customerActivityData = new ArrayList<>();

for (Object[] result : results) {
String teamId = result[0].toString();
LocalDateTime latestActivity = ((Timestamp) result[1]).toLocalDateTime();

LastActivityEntity teamActivityData = new LastActivityEntity(
teamId,
latestActivity);

customerActivityData.add(teamActivityData);
}

return customerActivityData;
}

@Override
public List<LastActivityEntity> getLastTeamActivityById(Integer targetId) {

List<Object[]> results = declarationJpaRepository.getLastTeamActivityById(
targetId);

ArrayList<LastActivityEntity> teamActivityData = new ArrayList<>();

for (Object[] result : results) {
String teamId = result[0].toString();
LocalDateTime latestActivity = ((Timestamp) result[1]).toLocalDateTime();

LastActivityEntity soleTeamActivityData = new LastActivityEntity(
teamId,
latestActivity);

teamActivityData.add(soleTeamActivityData);
}

return teamActivityData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,21 @@ SELECT fd.week_day, count(*) as absence_count
+ PER_WEEKDAY_COUNTS
+ PER_WEEKDAY_MAIN_QUERY, nativeQuery = true)
List<Object[]> getPerWeekDayStatisticsByCustomerId(LocalDate periodStart, LocalDate periodEnd, int customerId);
}

@Query(value = """
---------------------------------- LATEST ACTIVITY IN A TEAM
SELECT declaration_team_id, MAX(declaration_date)
FROM declaration
WHERE declaration_team_id = ?1
GROUP BY declaration_team_id""", nativeQuery = true)
List<Object[]> getLastTeamActivityById(Integer targetId);

@Query(value = """
---------------------------------- LATEST ACTIVITY IN A TEAM
SELECT team.team_id, MAX(declaration_date)
FROM declaration
INNER JOIN team ON declaration.declaration_team_id = team.team_id
WHERE team.team_customer_id = ?1
GROUP BY team.team_id""", nativeQuery = true)
List<Object[]> getLastTeamsActivityByCustomerId(Integer targetId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.xpeho.yaki_admin_backend.domain.entities;

import java.time.LocalDateTime;

public class LastActivityEntity {
String teamId;
LocalDateTime lastActivityDate;

public LastActivityEntity() {
}

public LastActivityEntity(String teamId, LocalDateTime lastActivityDate) {
this.teamId = teamId;
this.lastActivityDate = lastActivityDate;
}

public String getTeamId() {
return teamId;
}

public void setTeamId(String teamId) {
this.teamId = teamId;
}

public LocalDateTime getLastActivityDate() {
return lastActivityDate;
}

public void setLastActivityDate(LocalDateTime lastActivityDate) {
this.lastActivityDate = lastActivityDate;
}

}

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.xpeho.yaki_admin_backend.domain.services;

import com.xpeho.yaki_admin_backend.domain.entities.LastActivityEntity;
import com.xpeho.yaki_admin_backend.domain.entities.statistics.*;

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

public interface StatisticsService {
BasicStatisticsEntity getBasicStatistics(StatisticsRequestEntity requestEntity);
Expand All @@ -11,4 +13,6 @@ public interface StatisticsService {
ArrayList<PerTeammateStatisticsEntity> getPerTeammateStatistics(StatisticsRequestEntity requestEntity);
ArrayList<PerTeamStatisticsEntity> getPerTeamStatistics(StatisticsRequestEntity requestEntity);
ArrayList<PerWeekdayStatisticsEntity> getPerWeekDayStatistics(StatisticsRequestEntity requestEntity);
List<LastActivityEntity> getLastTeamsActivityByCustomerId (Integer customerId);
List<LastActivityEntity> getLastTeamActivityById (Integer teamId);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.xpeho.yaki_admin_backend.presentation.controllers;


import com.xpeho.yaki_admin_backend.domain.entities.LastActivityEntity;
import com.xpeho.yaki_admin_backend.domain.entities.statistics.*;
import com.xpeho.yaki_admin_backend.domain.services.StatisticsService;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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


@CrossOrigin
@RestController
Expand All @@ -23,6 +28,29 @@ public StatisticsController(StatisticsService statisticsService) {
this.statisticsService = statisticsService;
}

/**
* Returns the latest activity of a singular team, or of a customer's list of teams
*
* @param customerId : id of the customer
* @param teamId : id of the team, if a customerId is given, the teamId is ignored
* @return a list of objects {teamId: String, lastActivityDate: LocalDateTime}, or a code 400 if no parameter is given
*/
@GetMapping("lastActivity")
public ResponseEntity<List<LastActivityEntity>> getLatestTeamActivity(
@RequestParam(required = false) Integer customerId,
@RequestParam(required = false) Integer teamId)
{
if (customerId != null) {
return new ResponseEntity<>(statisticsService.getLastTeamsActivityByCustomerId(customerId), HttpStatus.OK);
} else if (teamId != null) {
return new ResponseEntity<>(statisticsService.getLastTeamActivityById(teamId), HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}

}


@PostMapping("basic")
public BasicStatisticsEntity getBasicStatistics(@RequestBody StatisticsRequestEntity requestEntity) {
checkRequestEntity(requestEntity);
Expand Down

0 comments on commit 4e57809

Please sign in to comment.