Skip to content

Commit

Permalink
Merge pull request #198 from ITA-OneByte/dev
Browse files Browse the repository at this point in the history
[Refactor] 드라이브 프론트 요구사항
  • Loading branch information
dpfls0922 authored Jan 14, 2025
2 parents 72de0ee + c18080d commit ef6c4c5
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class DriveFolderService {
private String bucketName;

public String createFolder(Member member, DriveType driveType, String folderName, String folderPath) {
if (folderName == null || folderName.trim().isEmpty()) {
throw new IllegalArgumentException("폴더 이름은 비어 있을 수 없습니다.");
}
String uniqueFolderName = generateUniqueFolderName(member, driveType, folderName, folderPath);
String fullFolderPath = generateFolderKey(member, driveType, uniqueFolderName, folderPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ public List<FileResponse> getFilesFromS3(Member member, DriveType driveType, Str
String prefix = DriveUtil.buildPrefix(driveType, member, folderPath);
List<S3ObjectSummary> objectSummaries = getS3ObjectList(prefix);

String folderPathWithSlash = folderPath.isEmpty() ? folderPath : folderPath + "/";
for (S3ObjectSummary summary : objectSummaries) {
FileResponse fileInfo = buildFileInfo(summary);
files.add(fileInfo);
if (!fileInfo.fileName().equals(folderPathWithSlash)) {
files.add(fileInfo);
}
}
return files;
}
Expand All @@ -41,9 +44,14 @@ public List<FileResponse> searchFilesByName(Member member, DriveType driveType,
ListObjectsV2Request request = createListObjectsRequest(driveType, member, folderPath);
ListObjectsV2Result result = amazonS3.listObjectsV2(request);

String folderPathWithSlash = folderPath.isEmpty() ? folderPath : folderPath + "/";
return result.getObjectSummaries().stream()
.map(this::buildFileInfo)
.filter(fileInfo -> normalize(fileInfo.fileName()).contains(normalize(fileName))) // 정규화하여 필터링
.filter(fileInfo -> {
boolean isFolder = fileInfo.fileName().equals(folderPathWithSlash);
boolean matchesFileName = fileName.isEmpty() || normalize(fileInfo.fileName()).contains(normalize(fileName));
return !isFolder && matchesFileName;
})
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -72,8 +80,7 @@ private Map<String, String> getTagsForS3Object(String objectKey) {

private ListObjectsV2Request createListObjectsRequest(DriveType driveType, Member member, String folderPath) {
ListObjectsV2Request request = new ListObjectsV2Request()
.withBucketName(bucketName)
.withDelimiter("/");
.withBucketName(bucketName);

String prefix = DriveUtil.buildPrefix(driveType, member, folderPath);
request.setPrefix(prefix);
Expand All @@ -88,11 +95,13 @@ public List<FileResponse> classifyFilesByType(Member member, DriveType driveType
ListObjectsV2Request request = createListObjectsRequest(driveType, member, folderPath);
ListObjectsV2Result result = amazonS3.listObjectsV2(request);

String folderPathWithSlash = folderPath.isEmpty() ? folderPath : folderPath + "/";
return result.getObjectSummaries().stream()
.map(this::buildFileInfo)
.filter(fileInfo -> {
FileType fileType = DriveUtil.getFileType(fileInfo.fileName());
return fileType.equals(filterFileType);
boolean isFolder = fileInfo.fileName().equals(folderPathWithSlash);
boolean matchesFileType = DriveUtil.getFileType(fileInfo.fileName()).equals(filterFileType);
return !isFolder && matchesFileType;
})
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private void addTagsToS3Object(String objectKey, Member member, String folderPat
LocalDateTime now = LocalDateTime.now();
String formattedDate = now.format(DateTimeFormatter.ISO_DATE_TIME);
String finalFolderPath = folderPath != null && !folderPath.trim().isEmpty() ? folderPath : "";
finalFolderPath = finalFolderPath + "/";

List<Tag> tags = List.of(
new Tag("folderPath", finalFolderPath),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import classfit.example.classfit.common.ApiResponse;
import classfit.example.classfit.event.dto.request.EventCreateRequest;
import classfit.example.classfit.event.dto.response.EventModalResponse;
import classfit.example.classfit.event.dto.response.EventMontylyResponse;
import classfit.example.classfit.event.dto.response.EventMonthlyResponse;
import classfit.example.classfit.event.dto.response.EventResponse;
import classfit.example.classfit.event.service.EventService;
import classfit.example.classfit.member.domain.Member;
Expand Down Expand Up @@ -54,12 +54,12 @@ public ApiResponse<List<AcademyMemberResponse>> getAcademyMembers(@AuthMember Me

@GetMapping("/monthly")
@Operation(summary = "월별 일정 조회", description = "월별 일정들을 조회하는 api 입니다.")
public ApiResponse<List<EventMontylyResponse>> getMonthlyEvents(
public ApiResponse<List<EventMonthlyResponse>> getMonthlyEvents(
@RequestParam CalendarType calendarType,
@RequestParam int year,
@RequestParam int month
) {
List<EventMontylyResponse> events = eventService.getMonthlyEventsByCalendarType(calendarType, year, month);
List<EventMonthlyResponse> events = eventService.getMonthlyEventsByCalendarType(calendarType, year, month);
return ApiResponse.success(events, 200, "SUCCESS");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public static EventModalResponse buildModalEventResponse(Event event) {
return EventModalResponse.of(
event.getId(),
event.getName(),
event.getMemberCalendar().getType(),
event.getEventType(),
event.getStartDate(),
event.getEndDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import classfit.example.classfit.event.domain.EventRepeatType;
import classfit.example.classfit.event.domain.EventType;
import classfit.example.classfit.memberCalendar.domain.CalendarType;
import java.time.LocalDateTime;

public record EventModalResponse
(
Long id,
String name,
CalendarType calendarType,
EventType eventType,
LocalDateTime startDate,
LocalDateTime endDate,
Expand All @@ -16,7 +18,7 @@ public record EventModalResponse
LocalDateTime repeatEndDate,
boolean isAllDay
) {
public static EventModalResponse of(final Long id, final String name, final EventType eventType, final LocalDateTime startDate, final LocalDateTime endDate, final Long categoryId, final EventRepeatType eventRepeatType, final LocalDateTime repeatEndDate, final boolean isAllDay) {
return new EventModalResponse(id, name, eventType, startDate, endDate, categoryId, eventRepeatType, repeatEndDate, isAllDay);
public static EventModalResponse of(final Long id, final String name, final CalendarType calendarType, final EventType eventType, final LocalDateTime startDate, final LocalDateTime endDate, final Long categoryId, final EventRepeatType eventRepeatType, final LocalDateTime repeatEndDate, final boolean isAllDay) {
return new EventModalResponse(id, name, calendarType, eventType, startDate, endDate, categoryId, eventRepeatType, repeatEndDate, isAllDay);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package classfit.example.classfit.event.dto.response;

public record EventMontylyResponse
public record EventMonthlyResponse
(
String id,
String name,
Expand All @@ -9,7 +9,7 @@ public record EventMontylyResponse
String startDate,
String endDate
) {
public static EventMontylyResponse of(final String id, final String name, final String color, final String eventType, final String startDate, final String endDate) {
return new EventMontylyResponse(id, name, color, eventType, startDate, endDate);
public static EventMonthlyResponse of(final String id, final String name, final String color, final String eventType, final String startDate, final String endDate) {
return new EventMonthlyResponse(id, name, color, eventType, startDate, endDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import classfit.example.classfit.common.exception.ClassfitException;
import classfit.example.classfit.event.domain.Event;
import classfit.example.classfit.event.dto.response.EventModalResponse;
import classfit.example.classfit.event.dto.response.EventMontylyResponse;
import classfit.example.classfit.event.dto.response.EventResponse;
import classfit.example.classfit.event.dto.response.EventMonthlyResponse;
import classfit.example.classfit.event.repository.EventRepository;
import classfit.example.classfit.memberCalendar.domain.CalendarType;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -35,19 +34,19 @@ private Event getEventById(long eventId) {
}

@Transactional(readOnly = true)
public List<EventMontylyResponse> getMonthlyEventsByCalendarType(CalendarType calendarType, int year, int month) {
public List<EventMonthlyResponse> getMonthlyEventsByCalendarType(CalendarType calendarType, int year, int month) {
LocalDateTime startOfMonth = LocalDateTime.of(year, month, 1, 0, 0, 0, 0);
LocalDateTime endOfMonth = startOfMonth.plusMonths(1).minusSeconds(1);

List<Event> events = eventRepository.findByCalendarTypeAndStartDateBetween(calendarType, startOfMonth, endOfMonth);
return mapToEventCreateResponse(events);
}

private List<EventMontylyResponse> mapToEventCreateResponse(List<Event> events) {
private List<EventMonthlyResponse> mapToEventCreateResponse(List<Event> events) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

return events.stream()
.map(event -> EventMontylyResponse.of(
.map(event -> EventMonthlyResponse.of(
String.valueOf(event.getId()),
event.getName(),
event.getCategory() != null ? String.valueOf(event.getCategory().getColor().getHexCode()) : "000000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private Event buildModalEventWithUpdatedDates(
.eventRepeatType(request.eventRepeatType())
.repeatEndDate(request.repeatEndDate().orElse(null))
.build();
event.setDates(request.isAllDay(), request.startDate(), request.getEndDate());
event.setDates(request.isAllDay(), currentStartDate, currentEndDate);
return event;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import classfit.example.classfit.event.dto.request.EventDragUpdate;
import classfit.example.classfit.event.dto.request.EventModalRequest;
import classfit.example.classfit.event.dto.response.EventModalResponse;
import classfit.example.classfit.event.dto.response.EventMontylyResponse;
import classfit.example.classfit.event.dto.response.EventMonthlyResponse;
import classfit.example.classfit.event.dto.response.EventResponse;
import classfit.example.classfit.event.repository.EventRepository;
import classfit.example.classfit.member.domain.Member;
Expand Down Expand Up @@ -43,7 +43,7 @@ public EventModalResponse getEvent(long eventId) {
return eventGetService.getEvent(eventId);
}

public List<EventMontylyResponse> getMonthlyEventsByCalendarType(
public List<EventMonthlyResponse> getMonthlyEventsByCalendarType(
CalendarType calendarType,
int year,
int month
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package classfit.example.classfit.member.domain;

import classfit.example.classfit.academy.domain.Academy;
import classfit.example.classfit.category.domain.MainClass;
import classfit.example.classfit.common.domain.BaseEntity;
import classfit.example.classfit.member.dto.request.MemberUpdateInfoRequest;
import jakarta.persistence.*;
import java.time.LocalDate;
import lombok.*;

import java.util.List;
import java.time.LocalDate;

@Entity
@Getter
Expand Down Expand Up @@ -41,10 +39,10 @@ public class Member extends BaseEntity {
@Column(columnDefinition = "VARCHAR(20)", nullable = false)
private MemberStatus status;

@Column(nullable = false)
@Column(length = 20)
private LocalDate birthDate;

@Column(nullable = false)
@Column(length = 20)
private String subject;

@ManyToOne(fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package classfit.example.classfit.student.controller;

import classfit.example.classfit.auth.annotation.AuthMember;
import classfit.example.classfit.common.ApiResponse;
import classfit.example.classfit.member.domain.Member;
import classfit.example.classfit.student.dto.request.StudentRequest;
import classfit.example.classfit.student.dto.request.StudentUpdateRequest;
import classfit.example.classfit.student.dto.response.StudentInfoResponse;
Expand All @@ -18,7 +20,7 @@
@RequestMapping("/api/v1/student")
@RequiredArgsConstructor
@Tag(name = "학생 컨트롤러", description = "학생 관련 API")
public class StudentControllerImpl {
public class StudentController {

private final StudentService studentService;

Expand All @@ -32,9 +34,9 @@ public ApiResponse<StudentResponse> registerStudent(@RequestBody @Valid StudentR

@GetMapping("/")
@Operation(summary = "학생 정보 조회", description = "전체 학생 정보 조회하는 API 입니다. ")
public ApiResponse<List<StudentResponse>> studentInfoAll() {
public ApiResponse<List<StudentResponse>> studentInfoAll(@AuthMember Member member) {

List<StudentResponse> studentList = studentService.studentInfoAll();
List<StudentResponse> studentList = studentService.studentInfoAll(member);
return ApiResponse.success(studentList, 200, "FIND STUDENTS");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Student extends BaseEntity {
@Column(nullable = false, length = 14)
private String parentNumber;

@Column(nullable = false, length = 10)
@Column(nullable = false, length = 20)
private String grade;

@Column(nullable = false, length = 100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ public interface StudentRepository extends JpaRepository<Student, Long> {
List<String> findSubClassesByStudentId(@Param("studentId") Long studentId);

Optional<List<Student>> findAllByName(String studentName);

@Query("SELECT s FROM Student s " +
"JOIN FETCH ClassStudent cs ON s.id = cs.student.id " +
"JOIN FETCH SubClass sc ON cs.subClass.id = sc.id " +
"JOIN FETCH MainClass mc ON sc.mainClass.id = mc.id " +
"JOIN FETCH Academy a ON mc.academy.id = a.id " +
"WHERE a.id = :academyId")
List<Student> findStudentsByAcademyId(Long academyId);
}
Loading

0 comments on commit ef6c4c5

Please sign in to comment.