Skip to content

Commit

Permalink
Merge pull request #41 from Capstone-Richam/feature/39-mail
Browse files Browse the repository at this point in the history
[feat]: Main 메일 목록 불러오기 type별로 수정"Feature/39 mail
  • Loading branch information
qogustj authored Dec 8, 2023
2 parents 2cf9ed5 + 9a7208f commit 25eeffd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum PlatformType {
NAVER("NAVER"),
GOOGLE("GOOGLE");


private final String stringPlatformType;
public static PlatformType getEnumPlatformTypeFromStringPlatformType(String stringPlatformType) {
return Arrays.stream(values())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class MailListResponseDto {
private String title;
private String fromPerson;
private String date;
private PlatformType type;
private String type;

public static MailListResponseDto of(MailHeader mailHeader){
return MailListResponseDto.builder()
.mailId(mailHeader.getId())
.title(mailHeader.getTitle())
.fromPerson(mailHeader.getFromPerson())
.date(mailHeader.getDate())
.type(mailHeader.getPlatformType())
.type(mailHeader.getPlatformType().toString())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.Nunbody.domain.Mail.repository;

import com.Nunbody.domain.Mail.domain.MailHeader;
import com.Nunbody.domain.Mail.domain.PlatformType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -10,4 +11,5 @@
public interface MailRepository extends JpaRepository<MailHeader,Long> {
Page<MailHeader> findAllByMemberId(Long id, Pageable pageable);
List<MailHeader> findAllByMemberId(Long id);
Page<MailHeader> findAllByMemberIdAndPlatformType(Long memberId, PlatformType platformType, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public ResponseEntity<SuccessResponse<?>> getMail(@RequestParam Long memberId, @
return SuccessResponse.ok(mailList);
}
@GetMapping("/header")
public ResponseEntity<SuccessResponse<?>> getHeader(@RequestParam Long memberId, @PageableDefault Pageable pageable){
final Page<MailListResponseDto> mailListResponseDtoList = mailManageService.getMailList(memberId, pageable);
public ResponseEntity<SuccessResponse<?>> getHeader(@RequestParam Long memberId, @RequestParam String type, @PageableDefault Pageable pageable){
final Page<MailListResponseDto> mailListResponseDtoList = mailManageService.getMailList(memberId,type, pageable);
return SuccessResponse.ok(mailListResponseDtoList);
}
@PostMapping("/validate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@


import com.Nunbody.domain.Mail.domain.MailHeader;
import com.Nunbody.domain.Mail.domain.PlatformType;
import com.Nunbody.domain.Mail.dto.response.MailListResponseDto;
import com.Nunbody.domain.Mail.dto.resquest.ValidateRequestDto;
import com.Nunbody.domain.Mail.repository.MailRepository;

import com.Nunbody.domain.member.domain.Member;
import com.Nunbody.domain.member.repository.MemberRepository;
import com.Nunbody.global.error.exception.InvalidValueException;
import com.Nunbody.global.error.exception.LoginException;
import lombok.RequiredArgsConstructor;
Expand All @@ -29,19 +32,28 @@
@Service
public class MailManageService {
private final MailRepository mailRepository;
public Page<MailListResponseDto> getMailList(Long id, Pageable pageable){

Page<MailListResponseDto> mailListResponseDtoList = createMailListResponseDtoList(id,pageable);
private final MemberRepository memberRepository;
public Page<MailListResponseDto> getMailList(Long memberId, String type, Pageable pageable){
Member member =getMember(memberId);
Page<MailListResponseDto> mailListResponseDtoList = createMailListResponseDtoList(memberId,type,pageable);
return mailListResponseDtoList;
}
private Page<MailListResponseDto> createMailListResponseDtoList(Long memberId, Pageable pageable){
Page<MailHeader> mailHeaderPage = mailRepository.findAllByMemberId(memberId, pageable);
private Page<MailListResponseDto> createMailListResponseDtoList(Long memberId, String type,Pageable pageable){
if(type.isEmpty()){
Page<MailHeader> mailHeaderPage = mailRepository.findAllByMemberId(memberId, pageable);
return mailHeaderPage.map(mailHeader -> MailListResponseDto.of(mailHeader));

}
Page<MailHeader> mailHeaderPage = mailRepository.findAllByMemberIdAndPlatformType(memberId, PlatformType.getEnumPlatformTypeFromStringPlatformType(type),pageable);
return mailHeaderPage.map(mailHeader -> MailListResponseDto.of(mailHeader));
}
public String validateConnect(ValidateRequestDto validateRequestDto) throws MessagingException {
String validate = validateImap(validateRequestDto);
return validate;
}
private Member getMember(Long memberId){
return memberRepository.findById(memberId).orElse(null);
}
private String validateImap(ValidateRequestDto validateRequestDto) throws MessagingException {
try {
String id = validateRequestDto.getId();
Expand Down

0 comments on commit 25eeffd

Please sign in to comment.