Skip to content

Commit

Permalink
Merge pull request #219 from WE-ARE-RACCOONS/RAC-341
Browse files Browse the repository at this point in the history
RAC-341 fix : QA μˆ˜μ •μ‚¬ν•­
  • Loading branch information
ywj9811 authored Apr 11, 2024
2 parents a49c721 + 3f1142f commit f674e44
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void refundMentoring(User user, Long mentoringId) {
if (mentoring.getStatus() == DONE) {
Senior senior = mentoring.getSenior();
Salary salary = salaryGetService.bySenior(senior);
salaryUpdateService.minusTotalAmount(salary);
salaryUpdateService.minusTotalAmount(salary, mentoring.calculateForSenior());
}
mentoringUpdateService.updateCancel(mentoring);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void refundPayment(User user, Long paymentId) {
mentoringUpdateService.updateCancel(mentoring);
Senior senior = mentoring.getSenior();
Salary salary = salaryGetService.bySenior(senior);
salaryUpdateService.minusTotalAmount(salary);
salaryUpdateService.minusTotalAmount(salary, mentoring.calculateForSenior());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void updateCancel(User user, Long mentoringId) {
public void updateDone(User user, Long mentoringId) {
Mentoring mentoring = mentoringGetService.byIdAndUserAndExpected(mentoringId, user);
Salary salary = salaryGetService.bySenior(mentoring.getSenior());
salaryUpdateService.plusTotalAmount(salary);
salaryUpdateService.plusTotalAmount(salary, mentoring.calculateForSenior());
mentoringUpdateService.updateDone(mentoring, salary);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void updateDoneWithAuto(Mentoring mentoring) {
Mentoring doneMentoring = mentoringGetService.byMentoringIdWithLazy(mentoring.getMentoringId());
Senior senior = mentoring.getSenior();
Salary salary = salaryGetService.bySenior(senior);
salaryUpdateService.plusTotalAmount(salary);
salaryUpdateService.plusTotalAmount(salary, doneMentoring.calculateForSenior());
mentoringUpdateService.updateDone(doneMentoring, salary);
log.info("mentoringId : {} μžλ™ μ™„λ£Œ", mentoring.getMentoringId());
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.time.format.DateTimeFormatter;

import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.WAITING;
import static com.postgraduate.domain.mentoring.domain.entity.constant.TermUnit.SHORT;
import static java.time.LocalDateTime.now;
import static java.time.LocalDateTime.parse;
import static java.time.format.DateTimeFormatter.ofPattern;
Expand Down Expand Up @@ -86,4 +87,9 @@ public boolean checkAutoDone() {
return now().minusDays(3)
.isAfter(doneDate);
}

public int calculateForSenior() {
int pay = this.payment.getPay();
return pay - SHORT.getCharge();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.postgraduate.domain.mentoring.domain.entity.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public enum TermUnit {
SHORT(30, 1900);

private final int term;
private final int charge;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
@Service
@RequiredArgsConstructor
public class SalaryUpdateService {
private static final int AMOUNT = 20000; //todo : λ””ν΄νŠΈ 20000원 이후 μˆ˜μ •

public void updateDone(Salary salary) {
salary.updateStatus(true);
}
Expand All @@ -18,12 +16,12 @@ public void updateNot(Salary salary) {
salary.updateStatus(false);
}

public void plusTotalAmount(Salary salary) {
salary.plusAmount(AMOUNT);
public void plusTotalAmount(Salary salary, int amount) {
salary.plusAmount(amount);
}

public void minusTotalAmount(Salary salary) {
salary.minusAmount(AMOUNT);
public void minusTotalAmount(Salary salary, int amount) {
salary.minusAmount(amount);
}

public void updateAccount(Salary salary, SalaryAccount account) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.postgraduate.domain.senior.application.dto.res;

public record SeniorProfileUpdateResponse(Long seniorId) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.postgraduate.domain.salary.domain.service.SalaryGetService;
import com.postgraduate.domain.salary.domain.service.SalaryUpdateService;
import com.postgraduate.domain.senior.application.dto.req.*;
import com.postgraduate.domain.senior.application.dto.res.SeniorProfileUpdateResponse;
import com.postgraduate.domain.senior.application.utils.SeniorUtils;
import com.postgraduate.domain.senior.domain.entity.Profile;
import com.postgraduate.domain.senior.domain.entity.Senior;
Expand Down Expand Up @@ -76,7 +77,7 @@ public void saveAccount(User user, SeniorAccountRequest accountRequest) {
updateSalaryAccount(senior, account);
}

public void updateSeniorMyPageProfile(User user, SeniorMyPageProfileRequest myPageProfileRequest) {
public SeniorProfileUpdateResponse updateSeniorMyPageProfile(User user, SeniorMyPageProfileRequest myPageProfileRequest) {
seniorUtils.checkKeyword(myPageProfileRequest.keyword());
Senior senior = seniorGetService.byUser(user);
Profile profile = mapToProfile(myPageProfileRequest);
Expand All @@ -85,6 +86,7 @@ public void updateSeniorMyPageProfile(User user, SeniorMyPageProfileRequest myPa
List<AvailableCreateRequest> availableCreateRequests = myPageProfileRequest.times();
List<Available> sortedAvailable = sortAvailable(availableCreateRequests, senior);
sortedAvailable.forEach(availableSaveService::save);
return new SeniorProfileUpdateResponse(senior.getSeniorId());
}

public void updateSeniorMyPageUserAccount(User user, SeniorMyPageUserAccountRequest myPageUserAccountRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public List<Senior> findAllSenior() {
.leftJoin(senior.user, user)
.fetchJoin()
.where(senior.user.isDelete.eq(FALSE))
.orderBy(senior.user.nickName.asc())
.orderBy(senior.createdAt.desc())
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public ResponseDto<SeniorMyPageProfileResponse> getSeniorProfile(@Authentication

@PatchMapping("/me/profile")
@Operation(summary = "λŒ€ν•™μ›μƒ λ§ˆμ΄νŽ˜μ΄μ§€ ν”„λ‘œν•„ μˆ˜μ • | 토큰 ν•„μš”")
public ResponseDto<Void> updateSeniorProfile(@AuthenticationPrincipal User user,
public ResponseDto<SeniorProfileUpdateResponse> updateSeniorProfile(@AuthenticationPrincipal User user,
@RequestBody @Valid SeniorMyPageProfileRequest myPageProfileRequest) {
seniorManageUseCase.updateSeniorMyPageProfile(user, myPageProfileRequest);
return ResponseDto.create(SENIOR_UPDATE.getCode(), UPDATE_MYPAGE_PROFILE.getMessage());
SeniorProfileUpdateResponse updateResponse = seniorManageUseCase.updateSeniorMyPageProfile(user, myPageProfileRequest);
return ResponseDto.create(SENIOR_UPDATE.getCode(), UPDATE_MYPAGE_PROFILE.getMessage(), updateResponse);
}

@GetMapping("/me/account")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public List<Wish> findAllWish() {
.leftJoin(wish.user, user)
.fetchJoin()
.where(wish.user.isDelete.isFalse())
.orderBy(wish.user.createdAt.desc())
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void updateDone() {
verify(mentoringUpdateService)
.updateDone(mentoring, salary);
verify(salaryUpdateService)
.plusTotalAmount(salary);
.plusTotalAmount(salary, mentoring.calculateForSenior());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.postgraduate.domain.salary.domain.service;

import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.salary.domain.entity.Salary;
import com.postgraduate.domain.salary.domain.entity.SalaryAccount;
import com.postgraduate.domain.senior.domain.entity.Senior;
Expand All @@ -15,7 +16,9 @@
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
class SalaryUpdateServiceTest {
Expand All @@ -34,17 +37,4 @@ void updateStatusTRUE() {
assertThat(salary.status())
.isTrue();
}

@Test
@DisplayName("μ •μ‚° κΈˆμ•‘ 증가 ν…ŒμŠ€νŠΈ")
void updateStatusFALSE() {
Senior senior = mock(Senior.class);
SalaryAccount salaryAccount = new SalaryAccount("bank", "1234", "holder");
Salary salary = new Salary(1L, TRUE, senior, 0, LocalDate.now(), LocalDateTime.now(), salaryAccount);

salaryUpdateService.plusTotalAmount(salary);

assertThat(salary.getTotalAmount())
.isEqualTo(20000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.postgraduate.domain.salary.domain.service.SalaryGetService;
import com.postgraduate.domain.salary.domain.service.SalaryUpdateService;
import com.postgraduate.domain.senior.application.dto.req.*;
import com.postgraduate.domain.senior.application.dto.res.SeniorProfileUpdateResponse;
import com.postgraduate.domain.senior.application.utils.SeniorUtils;
import com.postgraduate.domain.senior.domain.entity.Info;
import com.postgraduate.domain.senior.domain.entity.Profile;
Expand Down Expand Up @@ -39,6 +40,7 @@
import static com.postgraduate.domain.senior.domain.entity.constant.Status.APPROVE;
import static com.postgraduate.domain.user.domain.entity.constant.Role.SENIOR;
import static java.lang.Boolean.TRUE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.BDDMockito.*;

Expand Down Expand Up @@ -182,12 +184,14 @@ void updateSeniorMyPage() {
given(seniorGetService.byUser(user))
.willReturn(senior);

seniorManageUseCase.updateSeniorMyPageProfile(user, request);
SeniorProfileUpdateResponse response = seniorManageUseCase.updateSeniorMyPageProfile(user, request);

verify(seniorUpdateService, times(1))
.updateMyPageProfile(any(Senior.class), any(SeniorMyPageProfileRequest.class), any(Profile.class));
verify(availableDeleteService, times(1))
.delete(senior);
assertThat(response.seniorId())
.isEqualTo(senior.getSeniorId());
}

@Test
Expand Down

0 comments on commit f674e44

Please sign in to comment.