Skip to content

Commit

Permalink
Merge pull request #17 from CheckMate-sookmyung/feat/event
Browse files Browse the repository at this point in the history
[Feat] 이벤트 등록시 ResponseDto 수정
  • Loading branch information
dudrhy12 authored May 9, 2024
2 parents 9b60698 + fcb0d9f commit c5bf11a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@ public EventDetailResponseDto postEvent(MultipartFile eventImage, MultipartFile
.eventEndTime(eventScheduleRequestDto.getEventEndTime())
.event(savedEvent)
.build();
eventScheduleRepository.save(eventSchedule);
try {
eventAttendanceListService.readAndSaveAttendanceList(attendanceListFile, eventSchedule);
List<EventAttendanceList> savedEventAttendanceLists = eventAttendanceListService.readAndSaveAttendanceList(attendanceListFile, eventSchedule);
eventSchedule.setEventAttendanceLists(savedEventAttendanceLists);
} catch (IOException e) {
throw new RuntimeException(e);
}
return eventSchedule;
})
.collect(Collectors.toList());

savedEvent.postFileAndAttendanceList(imageUrl, attendanceListUrl, savedEventSchedules);
eventRepository.save(savedEvent);
savedEvent.postFileAndAttendanceList(imageUrl, attendanceListUrl, savedEventSchedules); //이거 해줘야 함
eventRepository.save(savedEvent);

return EventDetailResponseDto.of(savedEvent);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package checkmate.com.checkmate.eventattendanceList.dto;

import checkmate.com.checkmate.eventattendanceList.domain.EventAttendanceList;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import static lombok.AccessLevel.PRIVATE;

@Getter
@RequiredArgsConstructor(access=PRIVATE)
public class EventAttendanceListResponseDto {
private final String studentName;
private final int studentNumber;
private final String major;

public static EventAttendanceListResponseDto of(EventAttendanceList eventAttendanceList){
return new EventAttendanceListResponseDto(
eventAttendanceList.getName(),
eventAttendanceList.getStudentNumber(),
eventAttendanceList.getMajor()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;

Expand Down Expand Up @@ -57,14 +58,15 @@ public void postSign(Long userId, Long eventId, Long studentInfoId, MultipartFil
eventAttendanceList.updateAttendance(imageUrl);
}

@Async
public Future<Void> readAndSaveAttendanceList(MultipartFile attendanceListFile, EventSchedule eventSchedule) throws IOException {
@Transactional
public List<EventAttendanceList> readAndSaveAttendanceList(MultipartFile attendanceListFile, EventSchedule eventSchedule) throws IOException {
List<EventAttendanceList> eventAttendanceLists = new ArrayList<>();
try {
excelReader.readAndSaveAttendanceList(eventAttendanceListRepository,convertMultiPartToFile(attendanceListFile), eventSchedule);
eventAttendanceLists = excelReader.readAndSaveAttendanceList(eventAttendanceListRepository, convertMultiPartToFile(attendanceListFile), eventSchedule);
} catch (IOException e) {
e.printStackTrace();
}
return new AsyncResult<>(null);
return eventAttendanceLists;
}

private File convertMultiPartToFile(MultipartFile file) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
package checkmate.com.checkmate.eventschedule.dto;

import checkmate.com.checkmate.eventattendanceList.dto.EventAttendanceListResponseDto;
import checkmate.com.checkmate.eventattendanceList.dto.StudentInfoResponseDto;
import checkmate.com.checkmate.eventschedule.domain.EventSchedule;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.List;
import java.util.stream.Collectors;

import static lombok.AccessLevel.PRIVATE;
import static org.apache.commons.collections4.CollectionUtils.collect;

@Getter
@RequiredArgsConstructor(access=PRIVATE)
public class EventScheduleResponseDto {
private final String eventDate;
private final String eventStartTime;
private final String eventEndTime;
private final List<EventAttendanceListResponseDto> eventAttendanceListResponseDtos;

public static EventScheduleResponseDto of(EventSchedule eventSchedule){
List<EventAttendanceListResponseDto> eventAttendanceListResponses = eventSchedule.getEventAttendanceLists().stream()
.map(EventAttendanceListResponseDto::of)
.collect(Collectors.toList());
return new EventScheduleResponseDto(
eventSchedule.getEventDate(),
eventSchedule.getEventStartTime(),
eventSchedule.getEventEndTime()
eventSchedule.getEventEndTime(),
eventAttendanceListResponses
);

}
}
9 changes: 6 additions & 3 deletions src/main/java/checkmate/com/checkmate/global/ExcelReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Component
public class ExcelReader {

public static void readAndSaveAttendanceList(EventAttendanceListRepository eventAttendanceListRepository, File attendanceFile, EventSchedule schedule) throws IOException {
public static List<EventAttendanceList> readAndSaveAttendanceList(EventAttendanceListRepository eventAttendanceListRepository, File attendanceFile, EventSchedule schedule) throws IOException {
EventSchedule eventSchedule = schedule;
List<EventAttendanceList> eventAttendanceLists = new ArrayList<>();

Workbook workbook = WorkbookFactory.create(attendanceFile);
Sheet sheet = workbook.getSheetAt(0); // 첫 번째 시트 가져오기
Expand Down Expand Up @@ -75,11 +78,11 @@ public static void readAndSaveAttendanceList(EventAttendanceListRepository event
.eventSchedule(eventSchedule)
.build();
eventAttendanceListRepository.save(attendanceList);
// 생성된 객체를 데이터베이스에 저장
System.out.println("ID가"+attendanceList.getEventAttendanceListId());
eventAttendanceLists.add(attendanceList);
}
workbook.close();

return eventAttendanceLists;
}

}

0 comments on commit c5bf11a

Please sign in to comment.