Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] 2차 기능 리팩토링 #241

Merged
merged 6 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.security.Principal;

import org.sopt.makers.operation.app.attendance.dto.request.AttendanceRequest;
import org.sopt.makers.operation.app.attendance.dto.request.LectureAttendRequest;
import org.sopt.makers.operation.dto.BaseResponse;
import org.springframework.http.ResponseEntity;

Expand Down Expand Up @@ -36,6 +36,6 @@ public interface AppAttendanceApi {
}
)
ResponseEntity<BaseResponse<?>> attend(
@RequestBody AttendanceRequest request,
@RequestBody LectureAttendRequest request,
@Parameter(hidden = true) @NonNull Principal principal);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.security.Principal;

import org.sopt.makers.operation.app.attendance.dto.request.AttendanceRequest;
import org.sopt.makers.operation.app.attendance.dto.request.LectureAttendRequest;
import org.sopt.makers.operation.app.attendance.service.AppAttendanceService;
import org.sopt.makers.operation.common.util.CommonUtils;
import org.sopt.makers.operation.util.ApiResponseUtil;
Expand All @@ -15,7 +15,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.val;

Expand All @@ -29,7 +28,7 @@ public class AppAttendanceApiController implements AppAttendanceApi {

@Override
@PostMapping("/attend")
public ResponseEntity<BaseResponse<?>> attend(@RequestBody AttendanceRequest request, @NonNull Principal principal) {
public ResponseEntity<BaseResponse<?>> attend(@RequestBody LectureAttendRequest request, Principal principal) {
val memberId = utils.getMemberId(principal);
val response = attendanceService.attend(memberId, request);
return ApiResponseUtil.success(SUCCESS_ATTEND, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.NonNull;

public record AttendanceRequest(
public record LectureAttendRequest(
long subLectureId,
@NonNull String code
) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.sopt.makers.operation.app.attendance.dto.response;

import lombok.Builder;
import org.sopt.makers.operation.attendance.domain.SubAttendance;

@Builder
dragontaek-lee marked this conversation as resolved.
Show resolved Hide resolved
public record LectureAttendResponse(
Long subLectureId
dragontaek-lee marked this conversation as resolved.
Show resolved Hide resolved
) {
public static LectureAttendResponse of(SubAttendance subAttendance) {
return LectureAttendResponse.builder()
.subLectureId(subAttendance.getSubLecture().getId())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.sopt.makers.operation.app.attendance.service;

import org.sopt.makers.operation.app.attendance.dto.request.AttendanceRequest;
import org.sopt.makers.operation.app.attendance.dto.response.AttendanceResponse;
import org.sopt.makers.operation.app.attendance.dto.request.LectureAttendRequest;
import org.sopt.makers.operation.app.attendance.dto.response.LectureAttendResponse;

public interface AppAttendanceService {
AttendanceResponse attend(long memberId, AttendanceRequest request);
LectureAttendResponse attend(long memberId, LectureAttendRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import static org.sopt.makers.operation.code.failure.lecture.LectureFailureCode.*;
import static org.sopt.makers.operation.code.failure.subLecture.subLectureFailureCode.*;

import org.sopt.makers.operation.app.attendance.dto.request.AttendanceRequest;
import org.sopt.makers.operation.app.attendance.dto.response.AttendanceResponse;
import org.sopt.makers.operation.app.attendance.dto.request.LectureAttendRequest;
import org.sopt.makers.operation.app.attendance.dto.response.LectureAttendResponse;
import org.sopt.makers.operation.attendance.domain.Attendance;
import org.sopt.makers.operation.attendance.domain.SubAttendance;
import org.sopt.makers.operation.attendance.repository.attendance.AttendanceRepository;
Expand Down Expand Up @@ -39,10 +39,10 @@ public class AppAttendanceServiceImpl implements AppAttendanceService {

@Override
@Transactional
public AttendanceResponse attend(long playgroundId, AttendanceRequest request) {
public LectureAttendResponse attend(long playgroundId, LectureAttendRequest request) {
val subAttendance = getSubAttendance(request.subLectureId(), request.code(), playgroundId);
subAttendance.updateStatus(ATTENDANCE);
return AttendanceResponse.of(subAttendance);
return LectureAttendResponse.of(subAttendance);
}

private SubAttendance getSubAttendance(long subLectureId, String code, long playgroundId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ public TodayLectureResponse getTodayLecture(long memberPlaygroundId) {
}

val subAttendances = attendance.getSubAttendances();
val subAttendance = lecture.isFirst() ? subAttendances.get(0) : subAttendances.get(1);
return getTodayLectureResponse(subAttendance, responseType, lecture);

if (lecture.isFirst()) {
return getTodayFirstLectureResponse(subAttendances.get(0), responseType, lecture);
}

return getTodaySecondLectureResponse(subAttendances, responseType, lecture);
}

private TodayLectureResponse getEmptyResponse() {
Expand Down Expand Up @@ -104,7 +108,7 @@ private String getMessage(Attribute attribute) {
};
}

private TodayLectureResponse getTodayLectureResponse(SubAttendance subAttendance, LectureResponseType responseType, Lecture lecture) {
private TodayLectureResponse getTodayFirstLectureResponse(SubAttendance subAttendance, LectureResponseType responseType, Lecture lecture) {
val subLecture = subAttendance.getSubLecture();
val isOnAttendanceCheck = LocalDateTime.now().isBefore(subLecture.getStartAt().plusMinutes(10));
val message = getMessage(lecture.getAttribute());
Expand All @@ -114,6 +118,21 @@ private TodayLectureResponse getTodayLectureResponse(SubAttendance subAttendance
return TodayLectureResponse.of(responseType, lecture, message, Collections.singletonList(subAttendance));
}

private TodayLectureResponse getTodaySecondLectureResponse(
List<SubAttendance> subAttendances,
LectureResponseType responseType,
Lecture lecture
) {
val subAttendance = subAttendances.get(1);
val subLecture = subAttendance.getSubLecture();
val isOnAttendanceCheck = LocalDateTime.now().isBefore(subLecture.getStartAt().plusMinutes(10));
val message = getMessage(lecture.getAttribute());
if (isOnAttendanceCheck && subAttendance.getStatus().equals(ABSENT)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if문 안의 코드를 별도 메소드로 묶어내면 가독성이 더 좋아질 것 같아요!

return TodayLectureResponse.of(responseType, lecture, message, Collections.singletonList(subAttendances.get(0)));
}
return TodayLectureResponse.of(responseType, lecture, message, subAttendances);
}

@Override
public LectureCurrentRoundResponse getCurrentLectureRound(long lectureId) {
val lecture = findLecture(lectureId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;

import org.sopt.makers.operation.app.attendance.dto.response.AttendanceTotalVO;
import org.sopt.makers.operation.common.domain.Part;
import org.sopt.makers.operation.member.domain.Member;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.makers.operation.app.attendance.dto.response;
package org.sopt.makers.operation.app.member.dto.response;

import java.time.format.DateTimeFormatter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;

import org.sopt.makers.operation.app.member.dto.response.AttendanceTotalResponseDTO;
import org.sopt.makers.operation.app.attendance.dto.response.AttendanceTotalVO;
import org.sopt.makers.operation.app.member.dto.response.AttendanceTotalVO;
import org.sopt.makers.operation.app.member.dto.response.MemberScoreGetResponse;
import org.sopt.makers.operation.attendance.repository.attendance.AttendanceRepository;
import org.sopt.makers.operation.config.ValueConfig;
Expand Down
Loading