feat: add /get for invitations that gets the invite and its attendees.
This commit is contained in:
parent
2f7bc9e6c5
commit
05e9261f62
@ -14,6 +14,7 @@ public class InvitationResponse {
|
|||||||
private TagDto tag;
|
private TagDto tag;
|
||||||
private UserDto creator;
|
private UserDto creator;
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
|
private java.util.List<AttendeeDto> attendees;
|
||||||
|
|
||||||
public InvitationResponse() {}
|
public InvitationResponse() {}
|
||||||
|
|
||||||
@ -97,6 +98,14 @@ public class InvitationResponse {
|
|||||||
this.createdAt = createdAt;
|
this.createdAt = createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public java.util.List<AttendeeDto> getAttendees() {
|
||||||
|
return attendees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttendees(java.util.List<AttendeeDto> attendees) {
|
||||||
|
this.attendees = attendees;
|
||||||
|
}
|
||||||
|
|
||||||
public static class TagDto {
|
public static class TagDto {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String name;
|
private String name;
|
||||||
@ -169,4 +178,45 @@ public class InvitationResponse {
|
|||||||
this.avatar = avatar;
|
this.avatar = avatar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class AttendeeDto {
|
||||||
|
private Long id;
|
||||||
|
private String displayName;
|
||||||
|
private String avatar;
|
||||||
|
private LocalDateTime joinedAt;
|
||||||
|
|
||||||
|
public AttendeeDto() {}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplayName(String displayName) {
|
||||||
|
this.displayName = displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAvatar() {
|
||||||
|
return avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAvatar(String avatar) {
|
||||||
|
this.avatar = avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getJoinedAt() {
|
||||||
|
return joinedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJoinedAt(LocalDateTime joinedAt) {
|
||||||
|
this.joinedAt = joinedAt;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -3,9 +3,12 @@ package online.wesal.wesal.repository;
|
|||||||
import online.wesal.wesal.entity.Attendee;
|
import online.wesal.wesal.entity.Attendee;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface AttendeeRepository extends JpaRepository<Attendee, Long> {
|
public interface AttendeeRepository extends JpaRepository<Attendee, Long> {
|
||||||
|
|
||||||
boolean existsByInvitationIdAndUserId(Long invitationId, Long userId);
|
boolean existsByInvitationIdAndUserId(Long invitationId, Long userId);
|
||||||
|
|
||||||
|
List<Attendee> findByInvitationId(Long invitationId);
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ public class InvitationService {
|
|||||||
|
|
||||||
public Optional<InvitationResponse> getInvitationById(Long id) {
|
public Optional<InvitationResponse> getInvitationById(Long id) {
|
||||||
return invitationRepository.findById(id)
|
return invitationRepository.findById(id)
|
||||||
.map(this::mapToResponse);
|
.map(this::mapToResponseWithAttendees);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<InvitationResponse> getAvailableInvitations() {
|
public List<InvitationResponse> getAvailableInvitations() {
|
||||||
@ -146,4 +146,23 @@ public class InvitationService {
|
|||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private InvitationResponse mapToResponseWithAttendees(Invitation invitation) {
|
||||||
|
InvitationResponse response = mapToResponse(invitation);
|
||||||
|
|
||||||
|
List<Attendee> attendees = attendeeRepository.findByInvitationId(invitation.getId());
|
||||||
|
List<InvitationResponse.AttendeeDto> attendeeDtos = attendees.stream()
|
||||||
|
.map(attendee -> {
|
||||||
|
InvitationResponse.AttendeeDto dto = new InvitationResponse.AttendeeDto();
|
||||||
|
dto.setId(attendee.getUser().getId());
|
||||||
|
dto.setDisplayName(attendee.getUser().getDisplayName());
|
||||||
|
dto.setAvatar(attendee.getUser().getAvatar());
|
||||||
|
dto.setJoinedAt(attendee.getJoinedAt());
|
||||||
|
return dto;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
response.setAttendees(attendeeDtos);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user