Skip to content

Commit

Permalink
Merge pull request #133 from Team-Smeme/unan#132
Browse files Browse the repository at this point in the history
[REFACTOR] 학습 목표 타입만 request body에 들어오는 경우 처리
  • Loading branch information
thguss authored Aug 8, 2023
2 parents 8bf9b14 + 0cb6eaf commit 34dcfc4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.smeme.server.model.goal.GoalType;
import io.swagger.v3.oas.annotations.media.Schema;


@Schema(description = "사용자 학습 계획 수정 요청")
public record MemberPlanUpdateRequestDTO(
@Schema(description = "목표 타입", example = "HOBBY")
GoalType target,
Expand All @@ -12,6 +14,6 @@ public record MemberPlanUpdateRequestDTO(
TrainingTimeRequestDTO trainingTime,

@Schema(description = "알람 여부", example = "true")
boolean hasAlarm
Boolean hasAlarm
) {
}
18 changes: 14 additions & 4 deletions src/main/java/com/smeme/server/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

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

import static java.util.Objects.nonNull;


@Service
@Transactional(readOnly = true)
Expand Down Expand Up @@ -77,10 +80,17 @@ public MemberGetResponseDTO getMember(Long memberId) {
public void updateMemberPlan(Long memberId, MemberPlanUpdateRequestDTO requestDTO) {
Member member = getMemberById(memberId);

if (!Objects.isNull(requestDTO.target())) member.updateGoal(requestDTO.target());
member.updateHasAlarm(requestDTO.hasAlarm());
trainingTimeRepository.deleteAll(member.getTrainingTimes());
if (!requestDTO.trainingTime().day().equals("")) { updateMemberTrainingTime(member, requestDTO);}
if (nonNull(requestDTO.target())) {
member.updateGoal(requestDTO.target());
}

if (nonNull(requestDTO.hasAlarm())) {
member.updateHasAlarm(requestDTO.hasAlarm());
}

if (nonNull(requestDTO.trainingTime()) && StringUtils.hasText(requestDTO.trainingTime().day())) {
updateMemberTrainingTime(member, requestDTO);
}
}

public MemberNameResponseDTO checkDuplicatedName(String name) {
Expand Down

0 comments on commit 34dcfc4

Please sign in to comment.