Skip to content

Commit

Permalink
refactor: 이름 변경 및 인가 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
HyungHoKim00 committed Jan 4, 2025
1 parent 7a244ab commit e861f69
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.cruru.email.controller;

import com.cruru.applicant.domain.Applicant;
import com.cruru.auth.annotation.RequireAuth;
import com.cruru.auth.annotation.ValidAuth;
import com.cruru.club.domain.Club;
import com.cruru.email.controller.request.EmailRequest;
import com.cruru.email.controller.request.SendVerificationCodeRequest;
import com.cruru.email.controller.request.VerifyCodeRequest;
import com.cruru.email.controller.response.EmailResponses;
import com.cruru.email.controller.response.EmailHistoryResponses;
import com.cruru.email.facade.EmailFacade;
import com.cruru.global.LoginProfile;
import jakarta.validation.Valid;
Expand Down Expand Up @@ -53,12 +54,12 @@ public ResponseEntity<Void> verifyCode(@Valid @RequestBody VerifyCodeRequest req

@GetMapping("/{clubId}/{applicantId}")
@ValidAuth
public ResponseEntity<EmailResponses> read(
public ResponseEntity<EmailHistoryResponses> read(
@RequireAuth(targetDomain = Club.class) @PathVariable Long clubId,
@PathVariable Long applicantId,
@RequireAuth(targetDomain = Applicant.class) @PathVariable Long applicantId,
LoginProfile loginProfile
) {
EmailResponses emailResponses = emailFacade.read(clubId, applicantId);
return ResponseEntity.ok(emailResponses);
EmailHistoryResponses emailHistoryResponses = emailFacade.read(clubId, applicantId);
return ResponseEntity.ok(emailHistoryResponses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.time.LocalDateTime;

public record EmailResponse(
public record EmailHistoryResponse(
String subject,
String content,
LocalDateTime createdDate,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.cruru.email.controller.response;

import java.util.List;

public record EmailHistoryResponses(
List<EmailHistoryResponse> emailHistoryResponses
) {
}

This file was deleted.

12 changes: 6 additions & 6 deletions backend/src/main/java/com/cruru/email/facade/EmailFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.cruru.email.controller.request.EmailRequest;
import com.cruru.email.controller.request.SendVerificationCodeRequest;
import com.cruru.email.controller.request.VerifyCodeRequest;
import com.cruru.email.controller.response.EmailResponse;
import com.cruru.email.controller.response.EmailResponses;
import com.cruru.email.controller.response.EmailHistoryResponse;
import com.cruru.email.controller.response.EmailHistoryResponses;
import com.cruru.email.domain.Email;
import com.cruru.email.exception.EmailAttachmentsException;
import com.cruru.email.exception.EmailConflictException;
Expand Down Expand Up @@ -84,17 +84,17 @@ public void verifyCode(VerifyCodeRequest request) {
emailRedisClient.saveVerifiedEmail(email);
}

public EmailResponses read(long clubId, long applicantId) {
public EmailHistoryResponses read(long clubId, long applicantId) {
Club club = clubService.findById(clubId);
Applicant applicant = applicantService.findById(applicantId);
List<Email> emails = emailService.findAllByFromAndTo(club, applicant);
return new EmailResponses(emails.stream()
return new EmailHistoryResponses(emails.stream()
.map(this::toEmailResponse)
.toList());
}

private EmailResponse toEmailResponse(Email email) {
return new EmailResponse(
private EmailHistoryResponse toEmailResponse(Email email) {
return new EmailHistoryResponse(
email.getSubject(),
email.getContent(),
email.getCreatedDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ void read() {
parameterWithName("clubId").description("발송 동아리 id"),
parameterWithName("applicantId").description("수신 지원자 id")
),
responseFields(fieldWithPath("emailResponses").description("이메일 응답들"))
.andWithPrefix("emailResponses[].",
responseFields(fieldWithPath("emailHistoryResponses").description("이메일 응답들"))
.andWithPrefix("emailHistoryResponses[].",
fieldWithPath("subject").description("이메일 제목"),
fieldWithPath("content").description("이메일 본문"),
fieldWithPath("createdDate").description("전송 날짜"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import com.cruru.email.controller.request.EmailRequest;
import com.cruru.email.controller.request.SendVerificationCodeRequest;
import com.cruru.email.controller.request.VerifyCodeRequest;
import com.cruru.email.controller.response.EmailResponse;
import com.cruru.email.controller.response.EmailResponses;
import com.cruru.email.controller.response.EmailHistoryResponse;
import com.cruru.email.controller.response.EmailHistoryResponses;
import com.cruru.email.domain.Email;
import com.cruru.email.domain.repository.EmailRepository;
import com.cruru.email.exception.EmailConflictException;
Expand Down Expand Up @@ -159,15 +159,15 @@ void read() {
Email email = emailRepository.save(EmailFixture.rejectEmail(defaultClub, applicant));

// when
EmailResponses emailResponses = emailFacade.read(defaultClub.getId(), applicant.getId());
EmailHistoryResponses emailHistoryResponses = emailFacade.read(defaultClub.getId(), applicant.getId());

// then
assertThat(emailResponses.emailResponses()).hasSize(1);
EmailResponse emailResponse = emailResponses.emailResponses().get(0);
assertThat(emailHistoryResponses.emailHistoryResponses()).hasSize(1);
EmailHistoryResponse emailHistoryResponse = emailHistoryResponses.emailHistoryResponses().get(0);
assertAll(
() -> assertThat(emailResponse.subject()).isEqualTo(email.getSubject()),
() -> assertThat(emailResponse.content()).isEqualTo(email.getContent()),
() -> assertThat(emailResponse.isSucceed()).isEqualTo(email.getIsSucceed())
() -> assertThat(emailHistoryResponse.subject()).isEqualTo(email.getSubject()),
() -> assertThat(emailHistoryResponse.content()).isEqualTo(email.getContent()),
() -> assertThat(emailHistoryResponse.isSucceed()).isEqualTo(email.getIsSucceed())
);
}
}

0 comments on commit e861f69

Please sign in to comment.