feat: event lead rows carry attendance and source, with an attended filter
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
cba2929a00
commit
3af5cccd59
16 files changed
+160
-55
No files matched your search
+3
-1
@@ -22,5 +22,7 @@ public record EventLeadDetail(
|
||||
String notes,
|
||||
LocalDateTime capturedAt,
|
||||
List<Long> interestIds,
|
||||
Long companyId
|
||||
Long companyId,
|
||||
LocalDateTime attendedAt,
|
||||
String source
|
||||
) {}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
package com.solvway.services.counter.dto;
|
||||
|
||||
/** One event's leads, filtered; null or blank filters are ignored. page is 0-based. companyId null means all companies. */
|
||||
/** One event's leads, filtered; null or blank filters are ignored; attended true or false keeps only attended or not attended. page is 0-based. companyId null means all companies. */
|
||||
public record EventLeadSearchRequest(Long companyId, long eventUuid, Long salespersonUserId, String temperature,
|
||||
String status, Long interestId, String leadType, int page, int size) {}
|
||||
String status, Long interestId, String leadType, Boolean attended, int page, int size) {}
|
||||
+3
-1
@@ -29,6 +29,8 @@ public interface EventLeadRepository extends JpaRepository<EventLead, Long> {
|
||||
+ " AND (:temperature IS NULL OR e.temperature = :temperature)"
|
||||
+ " AND (:status IS NULL OR e.status = :status)"
|
||||
+ " AND (:leadType IS NULL OR e.leadType = :leadType)"
|
||||
+ " AND (:attended IS NULL OR (:attended = true AND e.attendedAt IS NOT NULL)"
|
||||
+ " OR (:attended = false AND e.attendedAt IS NULL))"
|
||||
+ " AND (:interestId IS NULL OR EXISTS (SELECT 1 FROM EventLeadInterest i"
|
||||
+ " WHERE i.id.eventLeadId = e.id AND i.id.interestId = :interestId))";
|
||||
|
||||
@@ -38,7 +40,7 @@ public interface EventLeadRepository extends JpaRepository<EventLead, Long> {
|
||||
Page<Object[]> search(@Param("companyId") Long companyId, @Param("eventUuid") long eventUuid,
|
||||
@Param("salespersonUserId") Long salespersonUserId, @Param("temperature") String temperature,
|
||||
@Param("status") String status, @Param("interestId") Long interestId,
|
||||
@Param("leadType") String leadType, Pageable pageable);
|
||||
@Param("leadType") String leadType, @Param("attended") Boolean attended, Pageable pageable);
|
||||
|
||||
long countByEventUuidAndAttendedAtIsNotNull(long eventUuid);
|
||||
|
||||
|
||||
+3
-2
@@ -163,7 +163,7 @@ public class EventLeadService {
|
||||
Pageable pageable = PageRequest.of(Math.max(req.page(), 0), Math.min(Math.max(req.size(), 1), MAX_PAGE_SIZE),
|
||||
Sort.by(Sort.Order.desc("capturedAt"), Sort.Order.desc("id")));
|
||||
Page<Object[]> rows = eventLeadRepository.search(req.companyId(), req.eventUuid(), req.salespersonUserId(),
|
||||
blankToNull(req.temperature()), blankToNull(req.status()), req.interestId(), blankToNull(req.leadType()), pageable);
|
||||
blankToNull(req.temperature()), blankToNull(req.status()), req.interestId(), blankToNull(req.leadType()), req.attended(), pageable);
|
||||
if (rows.isEmpty()) return rows.map(r -> null);
|
||||
Map<Long, List<Long>> interests = eventLeadInterestRepository
|
||||
.findByIdEventLeadIdIn(rows.map(r -> ((EventLead) r[0]).getId()).getContent()).stream()
|
||||
@@ -235,7 +235,8 @@ public class EventLeadService {
|
||||
private static EventLeadDetail detail(EventLead e, Lead l, List<Long> interestIds) {
|
||||
return new EventLeadDetail(e.getUuid(), e.getEventUuid(), l.getUuid(), l.getName(), l.getMobileE164(),
|
||||
l.getEmailNormalised(), l.getCompanyName(), l.getJobTitle(), e.getLeadType(), e.getSalespersonUserId(),
|
||||
e.getTemperature(), e.getStatus(), e.getNextFollowUpDate(), e.getNotes(), e.getCapturedAt(), interestIds, e.getCompanyId());
|
||||
e.getTemperature(), e.getStatus(), e.getNextFollowUpDate(), e.getNotes(), e.getCapturedAt(), interestIds, e.getCompanyId(),
|
||||
e.getAttendedAt(), e.getSource());
|
||||
}
|
||||
|
||||
private static void fillBlank(String current, String offered, Consumer<String> setter) {
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ class EventLeadControllerTest {
|
||||
|
||||
@Test
|
||||
void findByEventDelegates() {
|
||||
EventLeadSearchRequest req = new EventLeadSearchRequest(42L, 1L, null, null, null, null, null, 0, 20);
|
||||
EventLeadSearchRequest req = new EventLeadSearchRequest(42L, 1L, null, null, null, null, null, null, 0, 20);
|
||||
Page<EventLeadDetail> out = Page.empty();
|
||||
when(service.search(req)).thenReturn(out);
|
||||
|
||||
|
||||
+58
-11
@@ -34,6 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyCollection;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -61,13 +62,13 @@ class EventLeadListAndUpdateTest {
|
||||
|
||||
@Test
|
||||
void listingPassesEveryFilterAndPagesNewestCaptureFirstWithIdTieBreak() {
|
||||
when(eventLeadRepository.search(eq(COMPANY), eq(EVENT), eq(11L), eq("HOT"), eq("OPEN"), eq(3L), eq("NEW"), any()))
|
||||
when(eventLeadRepository.search(eq(COMPANY), eq(EVENT), eq(11L), eq("HOT"), eq("OPEN"), eq(3L), eq("NEW"), eq(null), any()))
|
||||
.thenReturn(Page.empty());
|
||||
|
||||
service.search(new EventLeadSearchRequest(COMPANY, EVENT, 11L, "HOT", "OPEN", 3L, "NEW", 2, 25));
|
||||
service.search(new EventLeadSearchRequest(COMPANY, EVENT, 11L, "HOT", "OPEN", 3L, "NEW", null, 2, 25));
|
||||
|
||||
ArgumentCaptor<Pageable> pageable = ArgumentCaptor.forClass(Pageable.class);
|
||||
verify(eventLeadRepository).search(eq(COMPANY), eq(EVENT), eq(11L), eq("HOT"), eq("OPEN"), eq(3L), eq("NEW"), pageable.capture());
|
||||
verify(eventLeadRepository).search(eq(COMPANY), eq(EVENT), eq(11L), eq("HOT"), eq("OPEN"), eq(3L), eq("NEW"), eq(null), pageable.capture());
|
||||
assertThat(pageable.getValue().getPageNumber()).isEqualTo(2);
|
||||
assertThat(pageable.getValue().getPageSize()).isEqualTo(25);
|
||||
assertThat(pageable.getValue().getSort().toString()).isEqualTo("capturedAt: DESC,id: DESC");
|
||||
@@ -75,13 +76,13 @@ class EventLeadListAndUpdateTest {
|
||||
|
||||
@Test
|
||||
void blankFiltersAreIgnoredAndPageSizeIsBounded() {
|
||||
when(eventLeadRepository.search(eq(COMPANY), eq(EVENT), eq(null), eq(null), eq(null), eq(null), eq(null), any()))
|
||||
when(eventLeadRepository.search(eq(COMPANY), eq(EVENT), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), any()))
|
||||
.thenReturn(Page.empty());
|
||||
|
||||
service.search(new EventLeadSearchRequest(COMPANY, EVENT, null, " ", "", null, null, -1, 1000));
|
||||
service.search(new EventLeadSearchRequest(COMPANY, EVENT, null, " ", "", null, null, null, -1, 1000));
|
||||
|
||||
ArgumentCaptor<Pageable> pageable = ArgumentCaptor.forClass(Pageable.class);
|
||||
verify(eventLeadRepository).search(eq(COMPANY), eq(EVENT), eq(null), eq(null), eq(null), eq(null), eq(null), pageable.capture());
|
||||
verify(eventLeadRepository).search(eq(COMPANY), eq(EVENT), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), pageable.capture());
|
||||
assertThat(pageable.getValue().getPageNumber()).isZero();
|
||||
assertThat(pageable.getValue().getPageSize()).isEqualTo(100);
|
||||
}
|
||||
@@ -92,12 +93,12 @@ class EventLeadListAndUpdateTest {
|
||||
EventLead b = eventLead(2L, 502L);
|
||||
Lead la = lead(501L, "Aisyah");
|
||||
Lead lb = lead(502L, "Ahmad");
|
||||
when(eventLeadRepository.search(eq(COMPANY), eq(EVENT), any(), any(), any(), any(), any(), any()))
|
||||
when(eventLeadRepository.search(eq(COMPANY), eq(EVENT), any(), any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(new PageImpl<>(List.of(new Object[]{a, la}, new Object[]{b, lb}), PageRequest.of(0, 20), 2));
|
||||
when(eventLeadInterestRepository.findByIdEventLeadIdIn(anyCollection()))
|
||||
.thenReturn(List.of(row(1L, 3L), row(1L, 4L), row(2L, 3L)));
|
||||
|
||||
Page<EventLeadDetail> page = service.search(new EventLeadSearchRequest(COMPANY, EVENT, null, null, null, null, null, 0, 20));
|
||||
Page<EventLeadDetail> page = service.search(new EventLeadSearchRequest(COMPANY, EVENT, null, null, null, null, null, null, 0, 20));
|
||||
|
||||
assertThat(page.getTotalElements()).isEqualTo(2);
|
||||
assertThat(page.getContent()).extracting(EventLeadDetail::name).containsExactly("Aisyah", "Ahmad");
|
||||
@@ -107,10 +108,56 @@ class EventLeadListAndUpdateTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyPageSkipsTheInterestQuery() {
|
||||
when(eventLeadRepository.search(eq(COMPANY), eq(EVENT), any(), any(), any(), any(), any(), any())).thenReturn(Page.empty());
|
||||
void attendedFilterIsPassedToTheQuery() {
|
||||
when(eventLeadRepository.search(any(), anyLong(), any(), any(), any(), any(), any(), any(), any())).thenReturn(Page.empty());
|
||||
|
||||
assertThat(service.search(new EventLeadSearchRequest(COMPANY, EVENT, null, null, null, null, null, 0, 20)).getContent()).isEmpty();
|
||||
service.search(new EventLeadSearchRequest(COMPANY, EVENT, null, null, null, null, null, true, 0, 20));
|
||||
|
||||
verify(eventLeadRepository).search(eq(COMPANY), eq(EVENT), eq(null), eq(null), eq(null), eq(null), eq(null), eq(true), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void notAttendedFilterIsPassedToTheQuery() {
|
||||
when(eventLeadRepository.search(any(), anyLong(), any(), any(), any(), any(), any(), any(), any())).thenReturn(Page.empty());
|
||||
|
||||
service.search(new EventLeadSearchRequest(COMPANY, EVENT, null, null, null, null, null, false, 0, 20));
|
||||
|
||||
verify(eventLeadRepository).search(eq(COMPANY), eq(EVENT), eq(null), eq(null), eq(null), eq(null), eq(null), eq(false), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listingRowsReportAttendanceAndSource() {
|
||||
EventLead a = eventLead(1L, 501L);
|
||||
a.setAttendedAt(java.time.LocalDateTime.of(2027, 1, 20, 9, 30));
|
||||
a.setSource("INVITE");
|
||||
when(eventLeadRepository.search(any(), anyLong(), any(), any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(new PageImpl<>(List.<Object[]>of(new Object[]{a, lead(501L, "Aisyah")}), PageRequest.of(0, 20), 1));
|
||||
when(eventLeadInterestRepository.findByIdEventLeadIdIn(anyCollection())).thenReturn(List.of());
|
||||
|
||||
EventLeadDetail d = service.search(new EventLeadSearchRequest(COMPANY, EVENT, null, null, null, null, null, null, 0, 20)).getContent().get(0);
|
||||
|
||||
assertThat(d.attendedAt()).isEqualTo(java.time.LocalDateTime.of(2027, 1, 20, 9, 30));
|
||||
assertThat(d.source()).isEqualTo("INVITE");
|
||||
}
|
||||
|
||||
@Test
|
||||
void detailReportsNoAttendanceAndDefaultSource() {
|
||||
EventLead e = eventLead(1L, 501L);
|
||||
when(eventLeadRepository.findByUuidAndCompanyId(7L, COMPANY)).thenReturn(java.util.Optional.of(e));
|
||||
when(leadRepository.findByUuidAndCompanyId(501L, COMPANY)).thenReturn(java.util.Optional.of(lead(501L, "Aisyah")));
|
||||
when(eventLeadInterestRepository.findByIdEventLeadId(1L)).thenReturn(List.of());
|
||||
|
||||
EventLeadDetail d = service.findByUuid(COMPANY, 7L);
|
||||
|
||||
assertThat(d.attendedAt()).isNull();
|
||||
assertThat(d.source()).isEqualTo("STAFF");
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyPageSkipsTheInterestQuery() {
|
||||
when(eventLeadRepository.search(eq(COMPANY), eq(EVENT), any(), any(), any(), any(), any(), any(), any())).thenReturn(Page.empty());
|
||||
|
||||
assertThat(service.search(new EventLeadSearchRequest(COMPANY, EVENT, null, null, null, null, null, null, 0, 20)).getContent()).isEmpty();
|
||||
verify(eventLeadInterestRepository, never()).findByIdEventLeadIdIn(anyCollection());
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -96,18 +96,18 @@ class LeadCompanyScopeTest {
|
||||
|
||||
@Test
|
||||
void eventLeadSearchWithoutCompanyPassesNullMeaningAll() {
|
||||
when(eventLeadRepository.search(any(), anyLong(), any(), any(), any(), any(), any(), any(Pageable.class)))
|
||||
when(eventLeadRepository.search(any(), anyLong(), any(), any(), any(), any(), any(), any(), any(Pageable.class)))
|
||||
.thenReturn(Page.empty());
|
||||
eventLeadService.search(new EventLeadSearchRequest(null, 9L, null, null, null, null, null, 0, 20));
|
||||
verify(eventLeadRepository).search(eq(null), eq(9L), any(), any(), any(), any(), any(), any(Pageable.class));
|
||||
eventLeadService.search(new EventLeadSearchRequest(null, 9L, null, null, null, null, null, null, 0, 20));
|
||||
verify(eventLeadRepository).search(eq(null), eq(9L), any(), any(), any(), any(), any(), any(), any(Pageable.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventLeadSearchWithCompanyStillFilters() {
|
||||
when(eventLeadRepository.search(any(), anyLong(), any(), any(), any(), any(), any(), any(Pageable.class)))
|
||||
when(eventLeadRepository.search(any(), anyLong(), any(), any(), any(), any(), any(), any(), any(Pageable.class)))
|
||||
.thenReturn(Page.empty());
|
||||
eventLeadService.search(new EventLeadSearchRequest(COMPANY, 9L, null, null, null, null, null, 0, 20));
|
||||
verify(eventLeadRepository).search(eq(COMPANY), eq(9L), any(), any(), any(), any(), any(), any(Pageable.class));
|
||||
eventLeadService.search(new EventLeadSearchRequest(COMPANY, 9L, null, null, null, null, null, null, 0, 20));
|
||||
verify(eventLeadRepository).search(eq(COMPANY), eq(9L), any(), any(), any(), any(), any(), any(), any(Pageable.class));
|
||||
}
|
||||
|
||||
// --- detail ---
|
||||
|
||||
Reference in new issue
Block a user