Skip to content

Commit

Permalink
Merge pull request #260 from U2DJ2/backend-main
Browse files Browse the repository at this point in the history
[BE] main branch 병합
  • Loading branch information
320Hwany authored Aug 30, 2024
2 parents 3953a46 + 8c5750f commit bba2e9c
Show file tree
Hide file tree
Showing 91 changed files with 794 additions and 577 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import moim_today.dto.member.MemberResponse;
import moim_today.global.error.ForbiddenException;
import moim_today.persistence.entity.member.MemberJpaEntity;
import moim_today.persistence.repository.meeting.joined_meeting.JoinedMeetingRepository;
import moim_today.persistence.repository.member.MemberRepository;
import moim_today.global.spring_event.event.AdminMemberDeleteEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -16,13 +17,13 @@
public class AdminMemberService {

private final MemberRepository memberRepository;
private final JoinedMeetingRepository joinedMeetingRepository;
private final ApplicationEventPublisher applicationEventPublisher;

public AdminMemberService(final MemberRepository memberRepository,
final JoinedMeetingRepository joinedMeetingRepository
final ApplicationEventPublisher applicationEventPublisher
) {
this.memberRepository = memberRepository;
this.joinedMeetingRepository = joinedMeetingRepository;
this.applicationEventPublisher = applicationEventPublisher;
}

@Transactional(readOnly = true)
Expand All @@ -38,7 +39,8 @@ public void deleteMember(final long universityId, final long memberId) {
throw new ForbiddenException(ADMIN_FORBIDDEN_ERROR.message());
}

joinedMeetingRepository.deleteAllByMemberId(memberId);
AdminMemberDeleteEvent adminMemberDeleteEvent = new AdminMemberDeleteEvent(memberId);
applicationEventPublisher.publishEvent(adminMemberDeleteEvent);
member.changeToUnknownMember();
}
}
27 changes: 6 additions & 21 deletions backend/src/main/java/moim_today/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;
import static moim_today.global.constant.NumberConstant.MOIM_SCHEDULE_FIRST_IDX;
import static java.util.stream.Collectors.*;


@Builder
public record Member(
Expand All @@ -18,24 +16,11 @@ public record Member(
String memberProfileImageUrl
) {

public static Map<Long, List<MoimScheduleResponse>> groupSchedulesByMember(final List<MoimScheduleResponse> moimScheduleResponses) {

return moimScheduleResponses.stream()
.collect(Collectors.groupingBy(MoimScheduleResponse::memberId));
}

public static List<Member> filterByDateTime(final Map<Long, List<MoimScheduleResponse>> schedulesByMember,
public static List<Member> filterByDateTime(final List<MoimScheduleResponse> moimScheduleResponses,
final LocalDateTime startDateTime, final LocalDateTime endDateTime) {
return schedulesByMember.values().stream()
.filter(
moimScheduleResponses -> moimScheduleResponses.stream()
.noneMatch(
moimScheduleResponse -> isScheduleConflicting(moimScheduleResponse, startDateTime, endDateTime))
)
.map(moimScheduleResponses -> {
MoimScheduleResponse moimScheduleResponse = moimScheduleResponses.get(MOIM_SCHEDULE_FIRST_IDX.value());
return moimScheduleResponse.toDomain();
})
return moimScheduleResponses.stream()
.filter(schedule -> !isScheduleConflicting(schedule, startDateTime, endDateTime))
.map(MoimScheduleResponse::toDomain)
.collect(toList());
}

Expand Down

This file was deleted.

48 changes: 23 additions & 25 deletions backend/src/main/java/moim_today/domain/schedule/AvailableTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import static moim_today.global.constant.NumberConstant.AVAILABLE_TIME_OFFSET;
import static moim_today.global.constant.NumberConstant.SCHEDULE_TIME_START_IDX;


Expand All @@ -27,35 +27,16 @@ public static AvailableTime toDomain(final List<Member> members, final LocalDate
public static List<AvailableTime> calculateAvailableTimes(final List<MoimScheduleResponse> moimScheduleResponses,
final LocalDate startDate) {
ScheduleLocalDate scheduleLocalDate = ScheduleLocalDate.from(startDate);
LocalDateTime start = scheduleLocalDate.atWeeklyStartDateTime();
LocalDateTime end = scheduleLocalDate.atWeeklyEndDateTime();

Map<Long, List<MoimScheduleResponse>> schedulesByMember = Member.groupSchedulesByMember(moimScheduleResponses);

List<LocalDateTime> allTimes = getAllTimes(moimScheduleResponses, start, end);
List<AvailableTime> availableTimes = new ArrayList<>();

for (int i = 0; i < allTimes.size() - 1; i++) {
LocalDateTime startDateTime = allTimes.get(i);
LocalDateTime endDateTime = allTimes.get(i + 1);

List<Member> availableMembers = Member.filterByDateTime(schedulesByMember, startDateTime, endDateTime);

if (!availableMembers.isEmpty()) {
availableTimes.add(AvailableTime.toDomain(availableMembers, startDateTime, endDateTime));
}
}

return availableTimes;
List<LocalDateTime> allTimes = getAllTimes(moimScheduleResponses, scheduleLocalDate);
return getAvailableTimes(allTimes, moimScheduleResponses);
}

private static List<LocalDateTime> getAllTimes(final List<MoimScheduleResponse> moimScheduleResponses,
final LocalDateTime startTime,
final LocalDateTime endTime) {
final ScheduleLocalDate scheduleLocalDate) {
List<LocalDateTime> times = getTimesFromSchedules(moimScheduleResponses);
List<LocalDateTime> allTimes = new ArrayList<>(times);
allTimes.add(SCHEDULE_TIME_START_IDX.value(), startTime);
allTimes.add(endTime);
allTimes.add(SCHEDULE_TIME_START_IDX.value(), scheduleLocalDate.atWeeklyStartDateTime());
allTimes.add(scheduleLocalDate.atWeeklyEndDateTime());

return allTimes;
}
Expand All @@ -67,4 +48,21 @@ private static List<LocalDateTime> getTimesFromSchedules(final List<MoimSchedule
.sorted()
.toList();
}

private static List<AvailableTime> getAvailableTimes(final List<LocalDateTime> allTimes,
final List<MoimScheduleResponse> moimScheduleResponses) {
List<AvailableTime> availableTimes = new ArrayList<>();

for (int i = 0; i < allTimes.size() - AVAILABLE_TIME_OFFSET.value(); i++) {
LocalDateTime startDateTime = allTimes.get(i);
LocalDateTime endDateTime = allTimes.get(i + AVAILABLE_TIME_OFFSET.value());
List<Member> availableMembers = Member.filterByDateTime(moimScheduleResponses, startDateTime, endDateTime);

if (!availableMembers.isEmpty()) {
availableTimes.add(AvailableTime.toDomain(availableMembers, startDateTime, endDateTime));
}
}

return availableTimes;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package moim_today.dto.admin.auth;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;

import static moim_today.global.constant.exception.ValidationExceptionConstant.ADMIN_PASSWORD_BLANK_ERROR;
import static moim_today.global.constant.exception.ValidationExceptionConstant.UNIVERSITY_ID_MIN_ERROR;


public record AdminLoginRequest(
long universityId,
String adminPassword
@Min(value = 0, message = UNIVERSITY_ID_MIN_ERROR) long universityId,
@NotBlank(message = ADMIN_PASSWORD_BLANK_ERROR) String adminPassword
) {

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package moim_today.dto.admin.user_inquiry;

import jakarta.validation.constraints.Min;
import lombok.Builder;

import static moim_today.global.constant.exception.ValidationExceptionConstant.USER_INQUIRY_ID_MIN_ERROR;

@Builder
public record UserInquiryAnswerRequest(
long userInquiryId,
@Min(value = 0, message = USER_INQUIRY_ID_MIN_ERROR) long userInquiryId,
boolean answerComplete
) {

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package moim_today.dto.admin.user_inquiry;

import jakarta.validation.constraints.NotBlank;
import moim_today.persistence.entity.admin.UserInquiryJpaEntity;

import static moim_today.global.constant.exception.ValidationExceptionConstant.INQUIRY_CONTENT_BLANK_ERROR;
import static moim_today.global.constant.exception.ValidationExceptionConstant.INQUIRY_TITLE_BLANK_ERROR;

public record UserInquiryRequest (
String inquiryTitle,
String inquiryContent
@NotBlank(message = INQUIRY_TITLE_BLANK_ERROR) String inquiryTitle,
@NotBlank(message = INQUIRY_CONTENT_BLANK_ERROR) String inquiryContent
){

public UserInquiryJpaEntity toEntity(final long memberId, final long universityId, final long departmentId){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package moim_today.dto.admin.user_inquiry;

import lombok.ToString;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import moim_today.dto.mail.MailSendRequest;

import java.util.List;

import static moim_today.global.constant.exception.ValidationExceptionConstant.*;

public record UserInquiryRespondRequest(
long userInquiryId,
long memberId,
String responseContent
@Min(value = 0, message = USER_INQUIRY_ID_MIN_ERROR) long userInquiryId,
@Min(value = 0, message = MEMBER_ID_MIN_ERROR) long memberId,
@NotBlank(message = USER_INQUIRY_RESPONSE_CONTENT_BLANK_ERROR) String responseContent
) {

public MailSendRequest toMailSendRequest(final String subject, final String userEmail){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package moim_today.dto.auth;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;

import static moim_today.global.constant.exception.ValidationExceptionConstant.*;

public record MemberLoginRequest(
String email,
String password,
@Email(message = EMAIL_INVALID_ERROR) @NotBlank(message = EMAIL_BLANK_ERROR) String email,
@NotBlank(message = MEMBER_PASSWORD_BLANK_ERROR) String password,
boolean isKeepLogin
) {

}
24 changes: 10 additions & 14 deletions backend/src/main/java/moim_today/dto/auth/MemberSignUpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
Expand All @@ -11,26 +12,21 @@
import java.time.LocalDate;

import static moim_today.global.constant.MemberConstant.DEFAULT_PROFILE_URL;
import static moim_today.global.constant.exception.ValidationExceptionConstant.*;

@Builder
public record MemberSignUpRequest(
long universityId,
long departmentId,
@Email(message = INVALID_EMAIL_FORMAT) @NotBlank(message = NO_EMAIL) String email,
@NotBlank(message = NO_PASSWORD) String password,
@NotBlank(message = NO_USERNAME) String username,
@NotBlank String studentId,
@Min(value = 0, message = UNIVERSITY_ID_MIN_ERROR) long universityId,
@Min(value = 0, message = DEPARTMENT_ID_MIN_ERROR) long departmentId,
@Email(message = EMAIL_INVALID_ERROR) @NotBlank(message = EMAIL_BLANK_ERROR) String email,
@NotBlank(message = MEMBER_PASSWORD_BLANK_ERROR) String password,
@NotBlank(message = USERNAME_BLANK_ERROR) String username,
@NotBlank(message = STUDENT_ID_BLANK_ERROR) String studentId,

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-M-d", timezone = "Asia/Seoul")
@NotNull(message = NO_BIRTH_DATE_ERROR) LocalDate birthDate,
@NotNull(message = NO_GENDER_ENUM_ERROR) Gender gender
@NotNull(message = BIRTH_DATE_NULL_ERROR) LocalDate birthDate,
@NotNull(message = GENDER_NULL_ERROR) Gender gender
) {
public static final String NO_PASSWORD = "패스워드가 없습니다.";
public static final String NO_USERNAME = "사용자 이름이 없습니다.";
public static final String NO_EMAIL = "이메일이 없습니다.";
public static final String INVALID_EMAIL_FORMAT = "이메일 형식이 올바르지 않습니다.";
public static final String NO_BIRTH_DATE_ERROR = "birthDate 값이 없습니다.";
public static final String NO_GENDER_ENUM_ERROR = "GENDER 값이 없습니다.";

public MemberJpaEntity toEntity(final String encodedPassword) {
return MemberJpaEntity.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package moim_today.dto.certification;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;

import static moim_today.global.constant.exception.ValidationExceptionConstant.EMAIL_BLANK_ERROR;
import static moim_today.global.constant.exception.ValidationExceptionConstant.EMAIL_INVALID_ERROR;

public record CompleteEmailCertificationRequest(
String email
@Email(message = EMAIL_INVALID_ERROR) @NotBlank(message = EMAIL_BLANK_ERROR) String email
) {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package moim_today.dto.certification;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;

import static moim_today.global.constant.exception.ValidationExceptionConstant.EMAIL_BLANK_ERROR;
import static moim_today.global.constant.exception.ValidationExceptionConstant.EMAIL_INVALID_ERROR;

public record EmailCertificationRequest(
String email
@Email(message = EMAIL_INVALID_ERROR) @NotBlank(message = EMAIL_BLANK_ERROR) String email
) {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package moim_today.dto.certification;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;

import static moim_today.global.constant.exception.ValidationExceptionConstant.EMAIL_BLANK_ERROR;
import static moim_today.global.constant.exception.ValidationExceptionConstant.EMAIL_INVALID_ERROR;

public record PasswordFindRequest(
String email
@Email(message = EMAIL_INVALID_ERROR) @NotBlank(message = EMAIL_BLANK_ERROR) String email
) {

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package moim_today.dto.department;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.Builder;
import moim_today.persistence.entity.department.request_deparment.RequestDepartmentJpaEntity;

import static moim_today.global.constant.exception.ValidationExceptionConstant.DEPARTMENT_NAME_BLANK_ERROR;
import static moim_today.global.constant.exception.ValidationExceptionConstant.UNIVERSITY_ID_MIN_ERROR;

@Builder
public record AddDepartmentRequest(
long universityId,
String departmentName
@Min(value = 0, message = UNIVERSITY_ID_MIN_ERROR) long universityId,
@NotBlank(message = DEPARTMENT_NAME_BLANK_ERROR) String departmentName
) {

public RequestDepartmentJpaEntity toEntity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package moim_today.dto.department;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.Builder;

import static moim_today.global.constant.exception.ValidationExceptionConstant.*;

@Builder
public record ApproveRequestDepartmentRequest(
long requestDepartmentId,
long universityId,
String requestDepartmentName
@Min(value = 0, message = DEPARTMENT_ID_MIN_ERROR) long requestDepartmentId,
@Min(value = 0, message = UNIVERSITY_ID_MIN_ERROR) long universityId,
@NotBlank(message = DEPARTMENT_NAME_BLANK_ERROR) String requestDepartmentName
) {

}
10 changes: 8 additions & 2 deletions backend/src/main/java/moim_today/dto/file/FileDeleteRequest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package moim_today.dto.file;

import jakarta.validation.constraints.NotBlank;

import static moim_today.global.constant.exception.ValidationExceptionConstant.FILENAME_BLANK_ERROR;
import static moim_today.global.constant.exception.ValidationExceptionConstant.UPLOAD_FILE_PATH_BLANK_ERROR;

public record FileDeleteRequest(
String uploadFilePath,
String fileName
@NotBlank(message = UPLOAD_FILE_PATH_BLANK_ERROR) String uploadFilePath,
@NotBlank(message = FILENAME_BLANK_ERROR) String fileName
) {

}
Loading

0 comments on commit bba2e9c

Please sign in to comment.