Skip to content

Commit

Permalink
Merge pull request #292 from WE-ARE-RACCOONS/RAC-403
Browse files Browse the repository at this point in the history
RAC-403 fix : μ„ λ°° μ‘°νšŒμ‹œ λ©˜ν† λ§ 진행 횟수 μš°μ„  μ •λ ¬ μˆ˜μ •
  • Loading branch information
ywj9811 authored Jul 2, 2024
2 parents d155ff0 + 27748a8 commit ae9608c
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.postgraduate.domain.payment.domain.entity.Payment;
import com.postgraduate.domain.payment.domain.service.PaymentGetService;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorUpdateService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage;
import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage;
Expand All @@ -26,6 +27,7 @@
@Transactional
public class MentoringApplyingUseCase {
private final PaymentGetService paymentGetService;
private final SeniorUpdateService seniorUpdateService;
private final MentoringGetService mentoringGetService;
private final MentoringSaveService mentoringSaveService;
private final AccountGetService accountGetService;
Expand All @@ -41,9 +43,14 @@ public ApplyingResponse applyMentoringWithPayment(User user, MentoringApplyReque
Senior senior = payment.getSenior();
Mentoring mentoring = MentoringMapper.mapToMentoring(user, senior, payment, request);
mentoringSaveService.save(mentoring);
seniorUpdateService.plusMentoring(senior);
Optional<Account> account = accountGetService.bySenior(senior);
sendMessage(user, senior);
return new ApplyingResponse(account.isPresent());
}

private void sendMessage(User user, Senior senior) {
bizppurioJuniorMessage.mentoringApply(user);
bizppurioSeniorMessage.mentoringApply(senior.getUser());
return new ApplyingResponse(account.isPresent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.postgraduate.domain.salary.domain.service.SalaryUpdateService;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.senior.domain.service.SeniorUpdateService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage;
import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage;
Expand Down Expand Up @@ -47,6 +48,7 @@ public class MentoringManageUseCase {
private final RefuseSaveService refuseSaveService;
private final AccountGetService accountGetService;
private final SeniorGetService seniorGetService;
private final SeniorUpdateService seniorUpdateService;
private final SalaryGetService salaryGetService;
private final SalaryUpdateService salaryUpdateService;
private final PaymentManageUseCase paymentManageUseCase;
Expand Down Expand Up @@ -76,6 +78,7 @@ public void updateCancel(User user, Long mentoringId) {
Payment payment = mentoring.getPayment();
paymentManageUseCase.refundPayByUser(user, payment.getOrderId());
mentoringUpdateService.updateCancel(mentoring);
seniorUpdateService.minusMentoring(senior);
bizppurioSeniorMessage.mentoringRefund(senior.getUser());
}

Expand All @@ -98,6 +101,7 @@ public void updateRefuse(User user, Long mentoringId, MentoringRefuseRequest req
Payment payment = mentoring.getPayment();
paymentManageUseCase.refundPayBySenior(senior, payment.getOrderId());
mentoringUpdateService.updateRefuse(mentoring);
seniorUpdateService.minusMentoring(senior);
bizppurioJuniorMessage.mentoringRefuse(mentoring.getUser());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Info {
@Builder.Default
private Boolean etcPostgradu = false;

@Column(nullable = false, columnDefinition = "TEXT")
@Column(nullable = false, length = 500)
private String totalInfo; // λͺ¨λ“  Info정보 String으둜 κ°€μ§€λŠ” 컬럼 - κ²€μƒ‰μ‹œ μ‚¬μš©

@Column(columnDefinition = "TEXT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
@Index(name = "senior_field_index", columnList = "field"),
@Index(name = "senior_etc_field_index", columnList = "etcField"),
@Index(name = "senior_postgradu_index", columnList = "postgradu"),
@Index(name = "senior_etc_postgradu_index", columnList = "etcPostgradu")
@Index(name = "senior_etc_postgradu_index", columnList = "etcPostgradu"),
@Index(name = "senior_mentoring_hit_index", columnList = "mentoringHit")
})
@Builder
@AllArgsConstructor
Expand All @@ -48,6 +49,9 @@ public class Senior {
@Column(nullable = false)
private int hit;

@Column(nullable = false)
private int mentoringHit;

@Embedded
private Info info;

Expand Down Expand Up @@ -80,4 +84,12 @@ public void updateStatus(Status status) {
public void updateHit() {
this.hit++;
}

public void plusMentoringHit() {
this.mentoringHit++;
}

public void minusMentoringHit() {
this.mentoringHit--;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SeniorDslRepositoryImpl implements SeniorDslRepository{

@Override
public Page<Senior> findAllBySearchSenior(String search, String sort, Pageable pageable) {
List<Tuple> results = queryFactory.select(senior.seniorId, senior.user.nickName, senior.hit)
List<Tuple> results = queryFactory.select(senior.seniorId, senior.user.nickName, senior.hit, senior.mentoringHit)
.from(senior)
.distinct()
.leftJoin(senior.user, user)
Expand All @@ -46,7 +46,8 @@ public Page<Senior> findAllBySearchSenior(String search, String sort, Pageable p
.or(senior.user.nickName.like("%" + search + "%")),
senior.user.isDelete.eq(FALSE)
)
.orderBy(orderSpecifier(sort))
.orderBy(mentoringOrderSpecifier(sort))
.orderBy(hitOrderSpecifier(sort))
.orderBy(senior.user.nickName.asc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
Expand All @@ -62,7 +63,8 @@ public Page<Senior> findAllBySearchSenior(String search, String sort, Pageable p
.toList()))
.leftJoin(senior.user, user)
.fetchJoin()
.orderBy(orderSpecifier(sort))
.orderBy(mentoringOrderSpecifier(sort))
.orderBy(hitOrderSpecifier(sort))
.orderBy(senior.user.nickName.asc())
.fetch();

Expand All @@ -81,17 +83,26 @@ public Page<Senior> findAllBySearchSenior(String search, String sort, Pageable p
return new PageImpl<>(seniors, pageable, total);
}

private OrderSpecifier<?> orderSpecifier(String sort) {
private OrderSpecifier<?> hitOrderSpecifier(String sort) {
if (sort == null)
return new OrderSpecifier<>(DESC, senior.hit);
if (sort.equals("low"))
return new OrderSpecifier<>(ASC, senior.hit);
return new OrderSpecifier<>(DESC, senior.hit);
}

private OrderSpecifier<?> mentoringOrderSpecifier(String sort) {
if (sort == null)
return new OrderSpecifier<>(DESC, senior.mentoringHit);
if (sort.equals("low"))
return new OrderSpecifier<>(ASC, senior.mentoringHit);
return new OrderSpecifier<>(DESC, senior.mentoringHit);
}


@Override
public Page<Senior> findAllByFieldSenior(String field, String postgradu, Pageable pageable) {
List<Tuple> results = queryFactory.select(senior.seniorId, senior.user.nickName, senior.hit)
List<Tuple> results = queryFactory.select(senior.seniorId, senior.user.nickName, senior.hit, senior.mentoringHit)
.from(senior)
.distinct()
.leftJoin(senior.user, user)
Expand All @@ -100,6 +111,7 @@ public Page<Senior> findAllByFieldSenior(String field, String postgradu, Pageabl
postgraduSpecifier(postgradu),
senior.user.isDelete.eq(FALSE)
)
.orderBy(senior.mentoringHit.desc())
.orderBy(senior.hit.desc())
.orderBy(senior.user.nickName.asc())
.offset(pageable.getOffset())
Expand All @@ -116,6 +128,7 @@ public Page<Senior> findAllByFieldSenior(String field, String postgradu, Pageabl
.toList()))
.leftJoin(senior.user, user)
.fetchJoin()
.orderBy(senior.mentoringHit.desc())
.orderBy(senior.hit.desc())
.orderBy(senior.user.nickName.asc())
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public void updateMyPageProfile(Senior senior, Info info, Profile profile) {
senior.updateInfo(info);
}

public void plusMentoring(Senior senior) {
senior.plusMentoringHit();
}

public void minusMentoring(Senior senior) {
senior.minusMentoringHit();
}

public void updateHit(Senior senior) {
senior.updateHit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void setting() {
1, USER, TRUE, LocalDateTime.now(), LocalDateTime.now(), FALSE);
wish = new Wish(1L, "major", "field", TRUE, user, Status.WAITING);
senior = new Senior(1L, user, "a",
APPROVE, 1, info, profile,
APPROVE,1, 1, info, profile,
LocalDateTime.now(), LocalDateTime.now());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.postgraduate.domain.senior.domain.entity.Info;
import com.postgraduate.domain.senior.domain.entity.Profile;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorUpdateService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage;
import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage;
Expand Down Expand Up @@ -54,6 +55,8 @@ class MentoringApplyingUseTypeTest {
@Mock
private AccountGetService accountGetService;
@Mock
private SeniorUpdateService seniorUpdateService;
@Mock
private BizppurioSeniorMessage bizppurioSeniorMessage;
@Mock
private BizppurioJuniorMessage bizppurioJuniorMessage;
Expand All @@ -80,7 +83,7 @@ void setting() {
"a", "123", "a",
0, USER, TRUE, LocalDateTime.now(), LocalDateTime.now(), TRUE);
senior = new Senior(-1L, user, "a",
APPROVE, 1, info, profile,
APPROVE,1, 1, info, profile,
LocalDateTime.now(), LocalDateTime.now());
salary = new Salary(-1L, FALSE, senior, 10000, LocalDate.now(), LocalDateTime.now(), null);
account = new Account(-1L, "1", "은행", "μœ μ €", senior);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.postgraduate.domain.senior.domain.entity.Profile;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.senior.domain.service.SeniorUpdateService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage;
import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage;
Expand Down Expand Up @@ -65,6 +66,8 @@ class MentoringManageUseTypeTest {
@Mock
private SeniorGetService seniorGetService;
@Mock
private SeniorUpdateService seniorUpdateService;
@Mock
private SalaryGetService salaryGetService;
@Mock
private SalaryUpdateService salaryUpdateService;
Expand Down Expand Up @@ -103,7 +106,7 @@ void setting() {
"a", "123", "a",
0, USER, TRUE, LocalDateTime.now(), LocalDateTime.now(), TRUE);
senior = new Senior(-1L, user, "a",
APPROVE, 1, info, profile,
APPROVE, 1, 1, info, profile,
LocalDateTime.now(), LocalDateTime.now());
salary = new Salary(-1L, FALSE, senior, 10000, LocalDate.now(), LocalDateTime.now(), null);
account = new Account(-1L, "1", "은행", "μœ μ €", senior);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void setting() {
"a", "123", "a",
0, USER, TRUE, LocalDateTime.now(), LocalDateTime.now(), TRUE);
senior = new Senior(-1L, user, "a",
APPROVE, 1, info, profile,
APPROVE, 1, 1, info, profile,
LocalDateTime.now(), LocalDateTime.now());
salary = new Salary(-1L, FALSE, senior, 10000, LocalDate.now(), LocalDateTime.now(), null);
payment = new Payment(-1L, mentoringUser, senior, 20000, "a", "a", "a", LocalDateTime.now(), null, Status.DONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void setting() {
"a", "123", "a",
0, USER, TRUE, LocalDateTime.now(), LocalDateTime.now(), TRUE);
senior = new Senior(-1L, user, "a",
APPROVE, 1, info, profile,
APPROVE, 1,1, info, profile,
LocalDateTime.now(), LocalDateTime.now());
salary = new Salary(-1L, FALSE, senior, 10000, LocalDate.now(), LocalDateTime.now(), null);
payment = new Payment(-1L, mentoringUser, senior, 20000, "a", "a", "a", LocalDateTime.now(), null, Status.DONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void setting() {
"a", "123", "a",
0, USER, TRUE, LocalDateTime.now(), LocalDateTime.now(), TRUE);
senior = new Senior(-1L, user, "a",
APPROVE, 1, info, profile,
APPROVE, 1,1, info, profile,
LocalDateTime.now(), LocalDateTime.now());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void setting() {
"a", "12345", "a",
1, USER, TRUE, LocalDateTime.now(), LocalDateTime.now(), TRUE);
senior = new Senior(1L, user, "a",
APPROVE, 1, info, profile,
APPROVE, 1, 1, info, profile,
LocalDateTime.now(), LocalDateTime.now());
}

Expand Down Expand Up @@ -92,7 +92,7 @@ void getSeniorDetail() {
@DisplayName("검색어 κΈ°λ³Έ νŽ˜μ΄μ§€ 쑰회")
void getSearchSeniorWithNull() {
Senior otherSenior = new Senior(-2L, user, "a",
APPROVE, 1, info, profile,
APPROVE, 1, 1, info, profile,
LocalDateTime.now(), LocalDateTime.now());
List<Senior> seniors = List.of(senior, otherSenior);
Page<Senior> seniorPage = new PageImpl<>(seniors);
Expand All @@ -110,7 +110,7 @@ void getSearchSeniorWithNull() {
@DisplayName("검색어 νŽ˜μ΄μ§€ 쑰회")
void getSearchSeniorWithPage() {
Senior senior1 = new Senior(1L, user, "a",
APPROVE, 1, info, profile,
APPROVE, 1, 1, info, profile,
LocalDateTime.now(), LocalDateTime.now());
List<Senior> seniors = List.of(senior, senior1);
Page<Senior> seniorPage = new PageImpl<>(seniors);
Expand All @@ -128,7 +128,7 @@ void getSearchSeniorWithPage() {
@DisplayName("ν•„ν„° κΈ°λ³Έ νŽ˜μ΄μ§€ 쑰회")
void getFieldSeniorWithNull() {
Senior senior1 = new Senior(1L, user, "a",
APPROVE, 1, info, profile,
APPROVE, 1, 1,info, profile,
LocalDateTime.now(), LocalDateTime.now());
List<Senior> seniors = List.of(senior, senior1);
Page<Senior> seniorPage = new PageImpl<>(seniors);
Expand All @@ -146,7 +146,7 @@ void getFieldSeniorWithNull() {
@DisplayName("ν•„ν„° νŽ˜μ΄μ§€ 쑰회")
void getFieldSeniorWithPage() {
Senior senior1 = new Senior(1L, user, "a",
APPROVE, 1, info, profile,
APPROVE, 1, 1, info, profile,
LocalDateTime.now(), LocalDateTime.now());
List<Senior> seniors = List.of(senior, senior1);
Page<Senior> seniorPage = new PageImpl<>(seniors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void setting() {
"a", "123", "a",
1, SENIOR, TRUE, LocalDateTime.now(), LocalDateTime.now(), TRUE);
senior = new Senior(1L, user, "a",
APPROVE, 1, info, profile,
APPROVE, 1, 1, info, profile,
LocalDateTime.now(), LocalDateTime.now());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ void setting() {
"a", "123", "a",
1, USER, TRUE, LocalDateTime.now(), LocalDateTime.now(), TRUE);
senior = new Senior(1L, user, "a",
APPROVE, 1, info, profile,
APPROVE, 1, 1, info, profile,
LocalDateTime.now(), LocalDateTime.now());
}

@Test
@DisplayName("Profile Null μ„ λ°° μžμ‹ μ˜ 정보 쑰회")
void getSeniorInfoWithNullProfile() {
senior = new Senior(1L, user, "a", WAITING, 1, info, null, LocalDateTime.now(), LocalDateTime.now());
senior = new Senior(1L, user, "a", WAITING, 1, 1, info, null, LocalDateTime.now(), LocalDateTime.now());

given(seniorGetService.byUser(user))
.willReturn(senior);
Expand Down Expand Up @@ -121,7 +121,7 @@ void getSeniorMyPageProfile() {
@Test
@DisplayName("μ„ λ°° μžμ‹ μ˜ λ§ˆμ΄νŽ˜μ΄μ§€ ν”„λ‘œν•„ μž‘μ„± 이전 Info쑰회 ν…ŒμŠ€νŠΈ")
void getSeniorMyPageProfileWithNull() {
Senior nullSenior = new Senior(-2L, user, "asd", APPROVE, 1, info, null, LocalDateTime.now(), null);
Senior nullSenior = new Senior(-2L, user, "asd", APPROVE, 1, 1, info, null, LocalDateTime.now(), null);
given(seniorGetService.byUser(user))
.willReturn(nullSenior);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SeniorUpdateServiceTest {
private Senior senior;
@BeforeEach
void setting() {
senior = new Senior(1L, user, "a", Status.WAITING, 100, new Info(), new Profile(), now(), now());
senior = new Senior(1L, user, "a", Status.WAITING, 1, 100, new Info(), new Profile(), now(), now());
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/postgraduate/support/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class Resource {
private User userOfSenior = new User(-2L, -2L, "mail", "μ„ λ°°", "012", "profile", 0, SENIOR, true, now(), now(), false);
private Info info = new Info("major", "μ„œμšΈλŒ€ν•™κ΅", "κ΅μˆ˜λ‹˜", "ν‚€μ›Œλ“œ1,ν‚€μ›Œλ“œ2", "λž©μ‹€", "인곡지λŠ₯", false, false, "인곡지λŠ₯,ν‚€μ›Œλ“œ1,ν‚€μ›Œλ“œ2", "chatLink", 30);
private Profile profile = new Profile("μ €λŠ”μš”", "ν•œμ€„μ†Œκ°œ", "λŒ€μƒ");
private Senior senior = new Senior(-1L, userOfSenior, "certification", com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING, 0, info, profile, now(), now());
private Senior otherSenior = new Senior(-3L, otherUser, "certification", com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING, 0, info, null, now(), now());
private Senior senior = new Senior(-1L, userOfSenior, "certification", com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING, 0, 0, info, profile, now(), now());
private Senior otherSenior = new Senior(-3L, otherUser, "certification", com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING, 0, 0, info, null, now(), now());
private SalaryAccount salaryAccount = new SalaryAccount("bank", "1234", "holder");
private Salary salary = new Salary(-1L, false, senior, 20000, getSalaryDate(), LocalDateTime.now(), salaryAccount);
private Payment payment = new Payment(-1L, user, senior, 20000, "1", "123", "123", LocalDateTime.now(), LocalDateTime.now(), DONE);
Expand Down

0 comments on commit ae9608c

Please sign in to comment.