Skip to content

Commit

Permalink
Merge branch 'develop' into fix/member_profile_coffeechat
Browse files Browse the repository at this point in the history
  • Loading branch information
jun02160 authored Nov 9, 2024
2 parents 4a7dbf0 + 2ca4af5 commit beabac3
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ out/

### config yml ###
application-**.yml

### Mac OS .DS_Store ###
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
import org.sopt.makers.internal.community.domain.AnonymousProfileImage;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface AnonymousProfileImageRepository extends JpaRepository<AnonymousProfileImage, Long> {

List<AnonymousProfileImage> findAllByIdNot(Long id);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package org.sopt.makers.internal.community.service;

import lombok.RequiredArgsConstructor;
import org.sopt.makers.internal.community.domain.AnonymousProfileImage;
import org.sopt.makers.internal.community.repository.AnonymousProfileImageRepository;
import org.sopt.makers.internal.domain.community.AnonymousProfileImg;
import org.sopt.makers.internal.exception.NotFoundDBEntityException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -16,6 +13,7 @@
public class AnonymousProfileImageService {

private final AnonymousProfileImageRepository anonymousProfileImageRepository;
private final static Long MAKERS_LOGO_IMAGE_ID = 6L;

public AnonymousProfileImageService(AnonymousProfileImageRepository anonymousProfileImageRepository) {
this.anonymousProfileImageRepository = anonymousProfileImageRepository;
Expand All @@ -27,7 +25,7 @@ public AnonymousProfileImageService(AnonymousProfileImageRepository anonymousPro
@Transactional(readOnly = true)
public AnonymousProfileImage getRandomProfileImage(List<Long> excludes) {
if (excludes.isEmpty() || excludes.size() >= profileImageMap.size()) {
return shuffle((long)(Math.random() * 5));
return shuffle((long) (Math.random() * 5));
}
return filtered(excludes);
}
Expand All @@ -37,15 +35,15 @@ private AnonymousProfileImage filtered(List<Long> excludes) {
.filter(i -> !excludes.contains(i))
.findFirst()
.map(profileImageMap::get)
.orElseGet(() -> shuffle((long)(Math.random() * 5)));
.orElseGet(() -> shuffle((long) (Math.random() * 5)));
}

private AnonymousProfileImage shuffle(Long index) {
return profileImageMap.get(index);
}

private void initializeProfileImageMap() {
List<AnonymousProfileImage> anonymousProfileImages = anonymousProfileImageRepository.findAll();
List<AnonymousProfileImage> anonymousProfileImages = anonymousProfileImageRepository.findAllByIdNot(MAKERS_LOGO_IMAGE_ID);
for (AnonymousProfileImage image : anonymousProfileImages) {
profileImageMap.put(image.getId(), image);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.sopt.makers.internal.member.service.MemberRetriever;
import org.springframework.stereotype.Service;

import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class SmsChatSender implements MessageSender {
Expand All @@ -20,7 +22,7 @@ public void sendMessage(Member sender, Member receiver, String content, String r
"연결을 원하신다면 멤버의 전화번호로 직접 연락해 주세요.\n\n" +
"- 이름: " + sender.getName() + "\n" +
"- 연락처: " + replyInfo + "\n" +
"- 파트: " + memberRetriever.concatPartAndGeneration(sender.getId()) + "\n" +
"- 파트: " + String.join(", ", memberRetriever.concatPartAndGeneration(sender.getId())) + "\n" +
"- 멤버 프로필 링크: https://playground.sopt.org/members/" + sender.getId() + "\n\n" +
"- 이런 내용이 궁금해요\n" +
content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.sopt.makers.internal.exception.ClientBadRequestException;
import org.sopt.makers.internal.external.MakersCrewClient;
import org.sopt.makers.internal.mapper.MemberMapper;
import org.sopt.makers.internal.member.controller.dto.response.MemberInfoResponse;
import org.sopt.makers.internal.member.mapper.MemberResponseMapper;
import org.sopt.makers.internal.member.service.coffeechat.CoffeeChatService;
import org.sopt.makers.internal.service.MemberService;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -60,6 +62,7 @@ public class MemberController {
private final MemberService memberService;
private final CoffeeChatService coffeeChatService;
private final MemberMapper memberMapper;
private final MemberResponseMapper memberResponseMapper;
private final InfiniteScrollUtil infiniteScrollUtil;
private final MakersCrewClient makersCrewClient;
@Operation(summary = "유저 id로 조회 API")
Expand All @@ -72,11 +75,12 @@ public ResponseEntity<MemberResponse> getMember (@PathVariable Long id) {

@Operation(summary = "자신의 토큰으로 조회 API")
@GetMapping("/me")
public ResponseEntity<MemberResponse> getMyInformation (
public ResponseEntity<MemberInfoResponse> getMyInformation (
@Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails
) {
val member = memberService.getMemberById(memberDetails.getId());
val response = memberMapper.toResponse(member);
val isCoffeeChatActivate = coffeeChatService.isCoffeeChatExist(member.getId());
val response = memberResponseMapper.toMemberInfoResponse(member, isCoffeeChatActivate);
return ResponseEntity.status(HttpStatus.OK).body(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public record CoffeeChatInfo(

@Schema(required = true)
@NotBlank(message = "커피챗 주제는 필수 입력 값입니다.")
@Size(max = 200, message = "커피챗 주제는 200자를 초과할 수 없습니다.")
@Size(max = 1000, message = "커피챗 주제는 1000자를 초과할 수 없습니다.")
String topic,

@Schema(required = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.sopt.makers.internal.member.controller.dto.response;

public record MemberInfoResponse(

Long id,

String name,

Integer generation,

String profileImage,

Boolean hasProfile,

Boolean editActivitiesAble,

Boolean hasCoffeeChat
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.sopt.makers.internal.member.mapper;

import lombok.RequiredArgsConstructor;
import org.sopt.makers.internal.domain.Member;
import org.sopt.makers.internal.member.controller.dto.response.MemberInfoResponse;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class MemberResponseMapper {

public MemberInfoResponse toMemberInfoResponse(Member member, Boolean isCoffeeChatActive) {

return new MemberInfoResponse(
member.getId(),
member.getName(),
member.getGeneration(),
member.getProfileImage(),
member.getHasProfile(),
member.getEditActivitiesAble(),
isCoffeeChatActive
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public List<RecentCoffeeChatInfoDto> findRecentCoffeeChatInfo() {
return queryFactory
.select(Projections.constructor(
RecentCoffeeChatInfoDto.class,
coffeeChat.member.id,
member.id,
coffeeChat.coffeeChatBio,
coffeeChat.coffeeChatTopicType,
member.profileImage,
Expand All @@ -41,9 +41,20 @@ public List<RecentCoffeeChatInfoDto> findRecentCoffeeChatInfo() {
member.university,
coffeeChatHistory.createdAt
))
.from(coffeeChat)
.leftJoin(member).on(coffeeChat.member.id.eq(member.id))
.join(coffeeChatHistory).on(coffeeChat.member.id.eq(coffeeChatHistory.receiver.id))
.from(coffeeChatHistory)
.join(coffeeChat).on(
coffeeChatHistory.receiver.id.eq(coffeeChat.member.id)
.and(coffeeChat.isCoffeeChatActivate.eq(true))
)
.join(member).on(coffeeChat.member.id.eq(member.id))
.where(
coffeeChatHistory.createdAt.eq(
JPAExpressions
.select(coffeeChatHistory.createdAt.max())
.from(coffeeChatHistory)
.where(coffeeChatHistory.receiver.id.eq(member.id))
)
)
.orderBy(coffeeChatHistory.createdAt.desc())
.limit(6)
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.RequiredArgsConstructor;
import org.sopt.makers.internal.domain.Member;
import org.sopt.makers.internal.exception.NotFoundDBEntityException;
import org.sopt.makers.internal.member.repository.soptactivity.dto.SoptActivityInfoDto;
import org.sopt.makers.internal.repository.MemberRepository;
import org.sopt.makers.internal.member.repository.soptactivity.MemberSoptActivityRepository;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public boolean existsCoffeeChat(Member member) {
return coffeeChatRepository.existsCoffeeChatByMember(member);
}

public CoffeeChat findCoffeeChatAndCheckIsActivated(Member member) {
public CoffeeChat findCoffeeChatAndCheckIsActivated(Member member, Boolean isMine) {
return coffeeChatRepository.findCoffeeChatByMember(member)
.filter(coffeeChat -> coffeeChat.getIsCoffeeChatActivate() || coffeeChat.getMember().equals(member))
.filter(coffeeChat -> coffeeChat.getIsCoffeeChatActivate() || isMine)
.orElseThrow(() -> new NotFoundDBEntityException("커피챗 정보를 확인할 수 없는 유저입니다. member id: " + member.getId()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public CoffeeChatDetailResponse getCoffeeChatDetail (Long memberId, Long detailM
memberRetriever.checkExistsMemberById(memberId);

Member member = memberRetriever.findMemberById(detailMemberId);
CoffeeChat coffeeChat = coffeeChatRetriever.findCoffeeChatAndCheckIsActivated(member);
CoffeeChat coffeeChat = coffeeChatRetriever.findCoffeeChatAndCheckIsActivated(member, memberId.equals(detailMemberId));
MemberCareer memberCareer = memberCareerRetriever.findMemberLastCareerByMemberId(detailMemberId);
Boolean isMine = Objects.equals(memberId, detailMemberId);
return coffeeChatResponseMapper.toCoffeeChatDetailResponse(coffeeChat, member, memberCareer, isMine);
Expand All @@ -89,6 +89,12 @@ public Boolean getCoffeeChatActivate (Long memberId) {
}
}

@Transactional(readOnly = true)
public Boolean isCoffeeChatExist (Long memberId) {
Member member = memberRetriever.findMemberById(memberId);
return coffeeChatRetriever.existsCoffeeChat(member);
}

@Transactional
public void updateCoffeeChatOpen(Long memberId, CoffeeChatOpenRequest request) {
Member member = memberRetriever.findMemberById(memberId);
Expand Down

0 comments on commit beabac3

Please sign in to comment.