From 9a351cdad9aa13701dfe994a1b9873a2cbf23bf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:30:05 +0900 Subject: [PATCH 001/215] =?UTF-8?q?refactor:=20properties=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20global=20=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/{uploader => global/config}/AWSConfig.java | 3 ++- .../{uploader => global/property}/S3UploadProperties.java | 2 +- src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java | 1 + src/test/java/com/aliens/backend/uploader/AwsS3MockConfig.java | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) rename src/main/java/com/aliens/backend/{uploader => global/config}/AWSConfig.java (90%) rename src/main/java/com/aliens/backend/{uploader => global/property}/S3UploadProperties.java (94%) diff --git a/src/main/java/com/aliens/backend/uploader/AWSConfig.java b/src/main/java/com/aliens/backend/global/config/AWSConfig.java similarity index 90% rename from src/main/java/com/aliens/backend/uploader/AWSConfig.java rename to src/main/java/com/aliens/backend/global/config/AWSConfig.java index 1a2d5a6c..97966e07 100644 --- a/src/main/java/com/aliens/backend/uploader/AWSConfig.java +++ b/src/main/java/com/aliens/backend/global/config/AWSConfig.java @@ -1,5 +1,6 @@ -package com.aliens.backend.uploader; +package com.aliens.backend.global.config; +import com.aliens.backend.global.property.S3UploadProperties; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.services.s3.AmazonS3Client; diff --git a/src/main/java/com/aliens/backend/uploader/S3UploadProperties.java b/src/main/java/com/aliens/backend/global/property/S3UploadProperties.java similarity index 94% rename from src/main/java/com/aliens/backend/uploader/S3UploadProperties.java rename to src/main/java/com/aliens/backend/global/property/S3UploadProperties.java index 1329fd30..1584a64b 100644 --- a/src/main/java/com/aliens/backend/uploader/S3UploadProperties.java +++ b/src/main/java/com/aliens/backend/global/property/S3UploadProperties.java @@ -1,4 +1,4 @@ -package com.aliens.backend.uploader; +package com.aliens.backend.global.property; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java b/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java index 3149da73..09257be1 100644 --- a/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java +++ b/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java @@ -1,5 +1,6 @@ package com.aliens.backend.uploader; +import com.aliens.backend.global.property.S3UploadProperties; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.ObjectMetadata; import org.springframework.http.MediaType; diff --git a/src/test/java/com/aliens/backend/uploader/AwsS3MockConfig.java b/src/test/java/com/aliens/backend/uploader/AwsS3MockConfig.java index 53db67e0..17f9842b 100644 --- a/src/test/java/com/aliens/backend/uploader/AwsS3MockConfig.java +++ b/src/test/java/com/aliens/backend/uploader/AwsS3MockConfig.java @@ -1,5 +1,6 @@ package com.aliens.backend.uploader; +import com.aliens.backend.global.property.S3UploadProperties; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.AnonymousAWSCredentials; import com.amazonaws.client.builder.AwsClientBuilder; From e362731a7947f7299ddf5277361137e1df69ebb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:30:30 +0900 Subject: [PATCH 002/215] =?UTF-8?q?refactor(EmailServiceTest):=20javaMailS?= =?UTF-8?q?ender=20Mock=EC=9C=BC=EB=A1=9C=20=EB=8C=80=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/email/service/EmailServiceTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java b/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java index b47d90ca..03b8958f 100644 --- a/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java +++ b/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java @@ -7,6 +7,8 @@ import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.mail.javamail.JavaMailSender; @SpringBootTest class EmailServiceTest { @@ -17,6 +19,8 @@ class EmailServiceTest { SymmetricKeyEncoder symmetricKeyEncoder; @Autowired EmailAuthenticationRepository emailAuthenticationRepository; + @MockBean + JavaMailSender javaMailSender; String givenEmail; EmailAuthentication emailEntity; From 6caa753752168f6c1700ca2a97d9ea814810855d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:45:04 +0900 Subject: [PATCH 003/215] =?UTF-8?q?refactor(TokenProviderTest):=20provider?= =?UTF-8?q?=20=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC=EC=98=A4=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/auth/{service => provider}/TokenProviderTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename src/test/java/com/aliens/backend/auth/{service => provider}/TokenProviderTest.java (97%) diff --git a/src/test/java/com/aliens/backend/auth/service/TokenProviderTest.java b/src/test/java/com/aliens/backend/auth/provider/TokenProviderTest.java similarity index 97% rename from src/test/java/com/aliens/backend/auth/service/TokenProviderTest.java rename to src/test/java/com/aliens/backend/auth/provider/TokenProviderTest.java index 07b94f05..9be805e1 100644 --- a/src/test/java/com/aliens/backend/auth/service/TokenProviderTest.java +++ b/src/test/java/com/aliens/backend/auth/provider/TokenProviderTest.java @@ -1,7 +1,8 @@ -package com.aliens.backend.auth.service; +package com.aliens.backend.auth.provider; import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.auth.domain.MemberRole; +import com.aliens.backend.auth.service.TokenProvider; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.JWTProperties; import org.junit.jupiter.api.Assertions; From 5b51306ec89a64824fbea7bc8391ed59699ea325 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Fri, 26 Jan 2024 18:05:40 +0900 Subject: [PATCH 004/215] =?UTF-8?q?chore=20:=20PR=EC=A0=84,=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=8B=A4=ED=8C=A8=20=EC=97=AC=EB=B6=80?= =?UTF-8?q?=EB=A5=BC=20=ED=99=95=EC=9D=B8=ED=95=A0=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=ED=8C=8C=EC=9D=B4=ED=94=84=EB=9D=BC?= =?UTF-8?q?=EC=9D=B8=20=EA=B5=AC=EC=B6=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-pipeline.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/test-pipeline.yml diff --git a/.github/workflows/test-pipeline.yml b/.github/workflows/test-pipeline.yml new file mode 100644 index 00000000..f68d66dc --- /dev/null +++ b/.github/workflows/test-pipeline.yml @@ -0,0 +1,25 @@ +name: test + +on: + push: + branches: [ develop ] + pull_request: + branches: [ develop ] + + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: JDK 17 설치 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Gradle 권한 허용 + run: chmod +x gradlew + - name: PR 및 PUSH 전, 테스트 확인 + run: ./gradlew test \ No newline at end of file From 9958455026777ac5b2bd95380d79cdb3c60a2666 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Fri, 26 Jan 2024 18:13:02 +0900 Subject: [PATCH 005/215] =?UTF-8?q?chore=20:=20secret=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC(yml)=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-pipeline.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test-pipeline.yml b/.github/workflows/test-pipeline.yml index f68d66dc..bf72b761 100644 --- a/.github/workflows/test-pipeline.yml +++ b/.github/workflows/test-pipeline.yml @@ -19,6 +19,12 @@ jobs: java-version: '17' distribution: 'temurin' + - name: secret 설정 파일(yml) 추가 + run: | + cd ./src/main/resources + touch ./application-secret.yml + echo "${{ secrets.APPLICATION_SECRET }}" > ./application-secret.yml + - name: Gradle 권한 허용 run: chmod +x gradlew - name: PR 및 PUSH 전, 테스트 확인 From f735088d58058270d0db6ab6f3a660cb5f34e7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 15:55:01 +0900 Subject: [PATCH 006/215] =?UTF-8?q?refactor(TokenProviderTest):=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=9C=A0=ED=9A=A8=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EC=9D=B4=20=EB=8B=A4=EB=A5=B8=20=EC=8A=A4=EB=A0=88=EB=93=9C?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=A7=A7=EA=B2=8C=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EB=90=98=EA=B3=A0=20=EC=9B=90=EB=9E=98=EB=8C=80=EB=A1=9C=20?= =?UTF-8?q?=EB=8F=8C=EC=95=84=EC=98=A4=EC=A7=80=20=EC=95=8A=EB=8A=94=20?= =?UTF-8?q?=ED=98=84=EC=83=81=20=EB=B0=9C=EC=83=9D=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/auth/provider/TokenProviderTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/aliens/backend/auth/provider/TokenProviderTest.java b/src/test/java/com/aliens/backend/auth/provider/TokenProviderTest.java index 9be805e1..6c892df8 100644 --- a/src/test/java/com/aliens/backend/auth/provider/TokenProviderTest.java +++ b/src/test/java/com/aliens/backend/auth/provider/TokenProviderTest.java @@ -93,6 +93,7 @@ void expiredTokenTest() { @DisplayName("기간이 유효한 토큰 검증") void notExpiredTokenTest() { //Given + jwtProperties.setAccessTokenValidTime(86400000L); //AccessToken 유효기한 원상복구 String accessToken = tokenProvider.generateAccessToken(givenLoginMember); //When @@ -131,9 +132,11 @@ void getTokenIdFromExpiredTokenFailTest() { //Given jwtProperties.setRefreshTokenValidTime(1L); //RefreshToken 유효기한 짧게변경 String expiredRefreshToken = tokenProvider.generateRefreshToken(givenLoginMember, givenTokenId); - jwtProperties.setRefreshTokenValidTime(2592000000L); //RefreshToken 유효기한 원상복구 //When & Then Assertions.assertThrows(RestApiException.class, () -> tokenProvider.getTokenIdFromToken(expiredRefreshToken)); + + //CleanUp + jwtProperties.setRefreshTokenValidTime(2592000000L); //RefreshToken 유효기한 원상복구 } } From b01af9515e56d96496bd1913fcf74d99a7d65471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 15:55:48 +0900 Subject: [PATCH 007/215] =?UTF-8?q?refactor(AuthService):=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=ED=95=9C=20=ED=9A=8C=EC=9B=90=EC=9D=BC=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=ED=86=A0=ED=81=B0=20=EB=B0=9C=EA=B8=89=20=EB=AA=BB?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/aliens/backend/auth/service/AuthService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/auth/service/AuthService.java b/src/main/java/com/aliens/backend/auth/service/AuthService.java index 137f00b7..2bfaa408 100644 --- a/src/main/java/com/aliens/backend/auth/service/AuthService.java +++ b/src/main/java/com/aliens/backend/auth/service/AuthService.java @@ -40,7 +40,11 @@ public AuthToken login(LoginRequest loginRequest) { } private Member getMemberEntityFromEmail(final String email) { - return memberRepository.findByEmail(email).orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER)); + Member member = memberRepository.findByEmail(email).orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER)); + if (member.isWithdraw()) { + throw new RestApiException(MemberError.WITHDRAW_MEMBER); + } + return member; } private void passwordCheck(final String password, final Member member) { From f06870945d0b6bd15056e9afb9974d747c206e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 15:56:34 +0900 Subject: [PATCH 008/215] =?UTF-8?q?refactor(AwsS3Uploader):=20=EB=8B=A8?= =?UTF-8?q?=EC=9D=BC,=20=EB=B3=B5=EC=88=98=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=EA=B0=80=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=98=A4=EB=B2=84=EB=A1=9C?= =?UTF-8?q?=EB=94=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/aliens/backend/uploader/AwsS3Uploader.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java b/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java index 09257be1..eb9b010f 100644 --- a/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java +++ b/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java @@ -25,8 +25,12 @@ public AwsS3Uploader(final AmazonS3Client amazonS3Client, final S3UploadProperti this.s3UploadProperties = s3UploadProperties; } - public List upload(UploadFileRequest request) { - return request.files().parallelStream().map(this::uploadToS3).toList(); + public List upload(List files) { + return files.stream().map(this::uploadToS3).toList(); + } + + public S3File upload(MultipartFile file) { + return uploadToS3(file); } private S3File uploadToS3(MultipartFile multipartFile) { From dd8730c035e3686a2d33d1c7d8e90198d19eca16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 15:58:54 +0900 Subject: [PATCH 009/215] =?UTF-8?q?refactor(AwsS3UploaderTest):=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/aliens/backend/uploader/AwsS3UploaderTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java b/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java index bf1ad5be..fc8b93a0 100644 --- a/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java +++ b/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java @@ -9,6 +9,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; import org.springframework.mock.web.MockMultipartFile; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -35,7 +36,7 @@ void uploadTest() { String contentType = "image/png"; MockMultipartFile file = new MockMultipartFile("test", path, contentType, "test".getBytes()); - UploadFileRequest request = new UploadFileRequest(List.of(file,file,file)); + List request = List.of(file,file,file); // When List S3Files = awsS3Uploader.upload(request); From 79f9af9963fcdb873644cf5e9638aa882afb1877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 15:59:20 +0900 Subject: [PATCH 010/215] =?UTF-8?q?feat(CommonError):=20=EC=9D=B8=EC=BD=94?= =?UTF-8?q?=EB=94=A9=20=EC=97=90=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/aliens/backend/global/error/CommonError.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/global/error/CommonError.java b/src/main/java/com/aliens/backend/global/error/CommonError.java index fd278ed6..d710d59a 100644 --- a/src/main/java/com/aliens/backend/global/error/CommonError.java +++ b/src/main/java/com/aliens/backend/global/error/CommonError.java @@ -4,7 +4,8 @@ public enum CommonError implements ErrorCode { - INTERNAL_SERVER_ERROR(HttpStatus.NOT_FOUND, "S1", "에러"); + INTERNAL_SERVER_ERROR(HttpStatus.NOT_FOUND, "S1", "에러"), + ENCODE_ERROR(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,"S2" ,"암-복호화 실패" ); private final HttpStatus httpStatusCode; private final String developCode; From 0b2696af29d3b8b8fbe091c1310f4196cc660c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:01:02 +0900 Subject: [PATCH 011/215] =?UTF-8?q?refactor(EmailAuthentication):=20?= =?UTF-8?q?=EC=8A=A4=ED=82=A4=EB=A7=88=EC=97=90=EC=84=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/email/domain/EmailAuthentication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/email/domain/EmailAuthentication.java b/src/main/java/com/aliens/backend/email/domain/EmailAuthentication.java index 4e18f23e..187fbe06 100644 --- a/src/main/java/com/aliens/backend/email/domain/EmailAuthentication.java +++ b/src/main/java/com/aliens/backend/email/domain/EmailAuthentication.java @@ -3,7 +3,7 @@ import jakarta.persistence.*; @Entity -@Table(schema = "EMAIL_AUTHENTICATION") +@Table(name = "EMAIL_AUTHENTICATION") public class EmailAuthentication { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) From 70a6fa0e0b48c6ad51b7c7c8e9fab0b5f3cb136a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:02:15 +0900 Subject: [PATCH 012/215] =?UTF-8?q?feat(EmailError):=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EC=9D=80=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/aliens/backend/global/error/EmailError.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/aliens/backend/global/error/EmailError.java b/src/main/java/com/aliens/backend/global/error/EmailError.java index 6d344b8f..2d0ff139 100644 --- a/src/main/java/com/aliens/backend/global/error/EmailError.java +++ b/src/main/java/com/aliens/backend/global/error/EmailError.java @@ -5,6 +5,7 @@ public enum EmailError implements ErrorCode { NULL_EMAIL(HttpStatus.UNPROCESSABLE_ENTITY, "E1", "해당 EmailAuthentication 엔티티 조회 불가"), + NOT_AUTHENTICATED_EMAIL(HttpStatus.UNPROCESSABLE_ENTITY, "E2", "인증되지 않은 이메일"), ; private final HttpStatus httpStatusCode; From 7c3a907573cac647acdba60acf884a4668ea9285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:05:38 +0900 Subject: [PATCH 013/215] =?UTF-8?q?feat(SymmetricEncoderProperties):=20chi?= =?UTF-8?q?pper=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/encode/SymmetricKeyEncoder.java | 32 ++++++++++++------- .../property/SymmetricEncoderProperties.java | 7 ++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/aliens/backend/global/encode/SymmetricKeyEncoder.java b/src/main/java/com/aliens/backend/global/encode/SymmetricKeyEncoder.java index f8ddeb27..050c0b35 100644 --- a/src/main/java/com/aliens/backend/global/encode/SymmetricKeyEncoder.java +++ b/src/main/java/com/aliens/backend/global/encode/SymmetricKeyEncoder.java @@ -1,5 +1,7 @@ package com.aliens.backend.global.encode; +import com.aliens.backend.global.error.CommonError; +import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.SymmetricEncoderProperties; import org.springframework.stereotype.Component; @@ -16,18 +18,26 @@ public SymmetricKeyEncoder(final SymmetricEncoderProperties symmetricEncoderProp this.symmetricEncoderProperties = symmetricEncoderProperties; } - public String encrypt(String plaintext) throws Exception { - Cipher cipher = Cipher.getInstance("AES"); - cipher.init(Cipher.ENCRYPT_MODE, symmetricEncoderProperties.getEncodeKey()); - byte[] encryptedBytes = cipher.doFinal(plaintext.getBytes(StandardCharsets.UTF_8)); - return Base64.getEncoder().encodeToString(encryptedBytes); + public String encrypt(String plaintext) { + try { + Cipher cipher = Cipher.getInstance(symmetricEncoderProperties.getChipper()); + cipher.init(Cipher.ENCRYPT_MODE, symmetricEncoderProperties.getEncodeKey()); + byte[] encryptedBytes = cipher.doFinal(plaintext.getBytes(StandardCharsets.UTF_8)); + return Base64.getEncoder().encodeToString(encryptedBytes); + } catch (Exception e) { + throw new RestApiException(CommonError.ENCODE_ERROR); + } } - public String decrypt(String ciphertext) throws Exception { - Cipher cipher = Cipher.getInstance("AES"); - cipher.init(Cipher.DECRYPT_MODE, symmetricEncoderProperties.getEncodeKey()); - byte[] decodedBytes = Base64.getDecoder().decode(ciphertext); - byte[] decryptedBytes = cipher.doFinal(decodedBytes); - return new String(decryptedBytes, StandardCharsets.UTF_8); + public String decrypt(String ciphertext) { + try { + Cipher cipher = Cipher.getInstance(symmetricEncoderProperties.getChipper()); + cipher.init(Cipher.DECRYPT_MODE, symmetricEncoderProperties.getEncodeKey()); + byte[] decodedBytes = Base64.getDecoder().decode(ciphertext); + byte[] decryptedBytes = cipher.doFinal(decodedBytes); + return new String(decryptedBytes, StandardCharsets.UTF_8); + } catch (Exception e) { + throw new RestApiException(CommonError.ENCODE_ERROR); + } } } diff --git a/src/main/java/com/aliens/backend/global/property/SymmetricEncoderProperties.java b/src/main/java/com/aliens/backend/global/property/SymmetricEncoderProperties.java index 1ac075ea..d3b62394 100644 --- a/src/main/java/com/aliens/backend/global/property/SymmetricEncoderProperties.java +++ b/src/main/java/com/aliens/backend/global/property/SymmetricEncoderProperties.java @@ -13,6 +13,9 @@ public class SymmetricEncoderProperties { @Value("${encode.symmetric.key}") private String secretKey; + @Value("${encode.symmetric.chipper}") + private String chipper; + private SecretKeySpec encodeKey; @PostConstruct @@ -24,4 +27,8 @@ public void init() { public SecretKeySpec getEncodeKey() { return encodeKey; } + + public String getChipper() { + return chipper; + } } From c3a1c0b5285a7c58e85fb9962d29ca57d97fce74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:06:17 +0900 Subject: [PATCH 014/215] =?UTF-8?q?style(SymmetricKeyEncoderTest):=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20throws=20Exception=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/encode/SymmetricKeyEncoderTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/aliens/backend/encode/SymmetricKeyEncoderTest.java b/src/test/java/com/aliens/backend/encode/SymmetricKeyEncoderTest.java index fc62098c..85d6386f 100644 --- a/src/test/java/com/aliens/backend/encode/SymmetricKeyEncoderTest.java +++ b/src/test/java/com/aliens/backend/encode/SymmetricKeyEncoderTest.java @@ -15,7 +15,7 @@ class SymmetricKeyEncoderTest { @Test @DisplayName("문자열 암호화 성공") - void encryptTest() throws Exception { + void encryptTest() { //Given String givenInput = "testText"; @@ -28,7 +28,7 @@ void encryptTest() throws Exception { @Test @DisplayName("문자열 복호화 성공") - void decryptTest() throws Exception { + void decryptTest() { //Given String givenInput = "testText"; String code = symmetricKeyEncoder.encrypt(givenInput); From 77ee83b3bc9e4ca7915f9bc2973f2bc82a7b2c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:07:22 +0900 Subject: [PATCH 015/215] =?UTF-8?q?feat(S3UploadProperties):=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=93=B1=EB=A1=9D?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20=ED=8C=8C=EC=9D=BC=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=EA=B3=BC=20URL=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/property/S3UploadProperties.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/aliens/backend/global/property/S3UploadProperties.java b/src/main/java/com/aliens/backend/global/property/S3UploadProperties.java index 1584a64b..43845eb5 100644 --- a/src/main/java/com/aliens/backend/global/property/S3UploadProperties.java +++ b/src/main/java/com/aliens/backend/global/property/S3UploadProperties.java @@ -18,6 +18,12 @@ public class S3UploadProperties { @Value("${cloud.aws.region.static}") private String region; + @Value("${cloud.aws.default.file-name}") + private String fileName; + + @Value("${cloud.aws.default.file-url}") + private String fileUrl; + public String getBucket() { return bucket; } @@ -33,4 +39,12 @@ public String getSecretKey() { public String getRegion() { return region; } + + public String getDefaultFileName() { + return fileName; + } + + public String getDefaultFileURL() { + return fileUrl; + } } \ No newline at end of file From 5f654f1379e976bf49abd08d7e8a874fd215599f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:08:01 +0900 Subject: [PATCH 016/215] =?UTF-8?q?feat(MemberError):=20=ED=83=88=ED=87=B4?= =?UTF-8?q?=ED=95=9C=20=ED=9A=8C=EC=9B=90=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC=20=EC=97=90=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/aliens/backend/global/error/MemberError.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/global/error/MemberError.java b/src/main/java/com/aliens/backend/global/error/MemberError.java index 6999d5f6..d8ef8ac4 100644 --- a/src/main/java/com/aliens/backend/global/error/MemberError.java +++ b/src/main/java/com/aliens/backend/global/error/MemberError.java @@ -8,7 +8,7 @@ public enum MemberError implements ErrorCode { INVALID_EMAIL(HttpStatus.BAD_REQUEST, "M2", "올바르지 않은 형식의 이메일"), NULL_MEMBER(HttpStatus.UNPROCESSABLE_ENTITY, "M3", "해당 Member 엔티티 조회 불가"), INCORRECT_PASSWORD(HttpStatus.SERVICE_UNAVAILABLE, "M4", "비밀번호 틀림"), - ; + WITHDRAW_MEMBER(HttpStatus.BAD_REQUEST,"M5" ,"탈퇴한 회원에 대한 접근" ); private final HttpStatus httpStatusCode; private final String developCode; From 0d3a4e0e32a53d9c0e9242877309068dfd58adfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:10:14 +0900 Subject: [PATCH 017/215] =?UTF-8?q?feat(Member):=20=EC=9D=B4=EB=A6=84,=20?= =?UTF-8?q?=ED=83=88=ED=87=B4=EC=97=AC=EB=B6=80,=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80,=20=EA=B0=9C=EC=9D=B8?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EA=B7=9C?= =?UTF-8?q?=EC=B9=99=20=EA=B8=B0=EB=B3=B8=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/auth/domain/Member.java | 73 +++++++++++++++++-- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/aliens/backend/auth/domain/Member.java b/src/main/java/com/aliens/backend/auth/domain/Member.java index 3ec76785..ff2bcbf2 100644 --- a/src/main/java/com/aliens/backend/auth/domain/Member.java +++ b/src/main/java/com/aliens/backend/auth/domain/Member.java @@ -1,6 +1,12 @@ package com.aliens.backend.auth.domain; import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.member.controller.dto.MemberPage; +import com.aliens.backend.member.domain.Image; +import com.aliens.backend.member.domain.MemberInfo; +import com.aliens.backend.member.domain.MemberStatus; +import com.aliens.backend.member.controller.dto.EncodedSignUp; +import com.aliens.backend.uploader.S3File; import jakarta.persistence.*; import java.util.ArrayList; @@ -14,6 +20,9 @@ public class Member { @Column private Long id; + @Column + private String name; + @Column private String email; @@ -21,30 +30,80 @@ public class Member { private String password; @Column - private MemberRole role; + private MemberRole role = MemberRole.MEMBER; + + @Column + private MemberStatus status = MemberStatus.NOT_APPLIED_NOT_MATCHED; + + @Column + private Boolean withdraw = false; - @OneToMany(mappedBy = "member", cascade = CascadeType.REMOVE) + @OneToMany(mappedBy = "member", + cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}) private List tokens = new ArrayList<>(); + @OneToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}) + @JoinColumn(name = "image_id") + private Image image; + + @OneToOne(mappedBy = "member", + cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}) + private MemberInfo memberInfo; + protected Member() { } - public Member(final String email, final String password, final MemberRole role) { - this.email = email; + public static Member of(final EncodedSignUp request, final Image image) { + Member member = new Member(); + member.name = request.name(); + member.email = request.email(); + member.password = request.password(); + member.image = image; + return member; + } + + public void changePassword(final String password) { this.password = password; - this.role = role; + } + + public void putMemberInfo(final MemberInfo memberInfo) { + this.memberInfo = memberInfo; } public boolean isCorrectPassword(String password) { return this.password.equals(password); } + public void withdraw() { + withdraw = true; + } + public LoginMember getLoginMember() { - return new LoginMember(id,role); + return new LoginMember(id, role); + } + + public MemberPage getMemberPage() { + return new MemberPage(name, image.getURL()); + } + + public boolean isWithdraw() { + return withdraw; + } + + public String getStatus() { + return status.getMessage(); + } + + public String getProfileName() { + return image.getName(); + } + + public void changeProfileImage(final S3File newFile) { + image.change(newFile); } @Override public String toString() { - return String.format("email: %s, password : %s, role : %s", this.email, this.password, this.role); + return String.format("email: %s, role : %s", this.email, this.role); } } \ No newline at end of file From c4f448d77112a6c9603ffe5acd9f7a4cd744ecf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:10:38 +0900 Subject: [PATCH 018/215] =?UTF-8?q?feat(MemberRepository):=20=EC=9D=B4?= =?UTF-8?q?=EB=A9=94=EC=9D=BC=EA=B3=BC=20=EC=9D=B4=EB=A6=84=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=B0=BE=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/auth/domain/repository/MemberRepository.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/aliens/backend/auth/domain/repository/MemberRepository.java b/src/main/java/com/aliens/backend/auth/domain/repository/MemberRepository.java index 960c9431..674370a6 100644 --- a/src/main/java/com/aliens/backend/auth/domain/repository/MemberRepository.java +++ b/src/main/java/com/aliens/backend/auth/domain/repository/MemberRepository.java @@ -9,4 +9,5 @@ @Repository public interface MemberRepository extends JpaRepository { Optional findByEmail(String email); + Optional findByEmailAndName(String email, String name); } From 59ac8fc79cda4f874fe31d8b6695ac1e4f62f0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:11:58 +0900 Subject: [PATCH 019/215] =?UTF-8?q?refactor(AuthServiceTest):=20member=20?= =?UTF-8?q?=EB=82=B4=EB=B6=80=EB=B3=80=EC=88=98=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=B2=BC=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/auth/service/AuthServiceTest.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java b/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java index 986f20fd..332a3eb5 100644 --- a/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java +++ b/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java @@ -4,9 +4,12 @@ import com.aliens.backend.auth.controller.dto.LoginRequest; import com.aliens.backend.auth.domain.Member; import com.aliens.backend.auth.domain.repository.MemberRepository; -import com.aliens.backend.auth.domain.MemberRole; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.JWTProperties; +import com.aliens.backend.member.controller.dto.EncodedSignUp; +import com.aliens.backend.member.domain.Image; +import com.aliens.backend.member.domain.repository.ImageRepository; +import com.aliens.backend.uploader.S3File; import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -23,25 +26,32 @@ class AuthServiceTest { @Autowired MemberRepository memberRepository; @Autowired + ImageRepository imageRepository; + @Autowired PasswordEncoder passwordEncoder; Member member; + String name; String email; String password; LoginRequest loginRequest; @BeforeEach void setUp() { + name = "김명준"; email = "tmp@example.com"; password = "tmpPassword"; - member = new Member(email, passwordEncoder.encrypt(password), MemberRole.MEMBER); - loginRequest = new LoginRequest(email, password); + EncodedSignUp encodedSignUp = new EncodedSignUp(name, email, passwordEncoder.encrypt(password)); + Image image = Image.from(new S3File("tmpFileName", "tmpFileURL")); + member = Member.of(encodedSignUp, image); memberRepository.save(member); + loginRequest = new LoginRequest(email, password); } @AfterEach void afterDown() { memberRepository.deleteAll(); + imageRepository.deleteAll(); } @Test From 912368bd946dcf47b79b5b14d85b7940c2cecff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:24:27 +0900 Subject: [PATCH 020/215] =?UTF-8?q?test(EmailContentTest):=20=EC=9E=84?= =?UTF-8?q?=EC=8B=9C=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=20=EC=9D=B4?= =?UTF-8?q?=EB=A9=94=EC=9D=BC=20=EB=82=B4=EC=9A=A9=20=EB=B0=8F=20=EC=A0=9C?= =?UTF-8?q?=EB=AA=A9=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../email/sender/EmailContentTest.java | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/aliens/backend/email/sender/EmailContentTest.java b/src/test/java/com/aliens/backend/email/sender/EmailContentTest.java index defae0b3..4ef4f257 100644 --- a/src/test/java/com/aliens/backend/email/sender/EmailContentTest.java +++ b/src/test/java/com/aliens/backend/email/sender/EmailContentTest.java @@ -14,24 +14,47 @@ class EmailContentTest { EmailContent emailContent; @Test - @DisplayName("메일 내용 가져오기") - void getContentTest() { + @DisplayName("이메일 인증 내용 가져오기") + void getAuthenticationEmailContentTest() { //Given String token = "tmpToken"; String domainURL = "tmp.com"; //When - String result = emailContent.getContent(token, domainURL); + String result = emailContent.getAuthenticationMailContent(token, domainURL); //Then Assertions.assertNotNull(result); } @Test - @DisplayName("메일 제목 가져오기") - void getTitleTest() { + @DisplayName("이메일 인증 제목 가져오기") + void getAuthenticationEmailTitleTest() { //When - String result = emailContent.getTitle(); + String result = emailContent.getAuthenticationMailTitle(); + + //Then + Assertions.assertNotNull(result); + } + + @Test + @DisplayName("임시 비밀번호 발급 내용 가져오기") + void getTemporaryPasswordContent() { + //Given + String tmpPassword = "tmpPassword"; + + //When + String result = emailContent.getTemporaryMailContent(tmpPassword); + + //Then + Assertions.assertNotNull(result); + } + + @Test + @DisplayName("임시 비밀번호 발급 제목 가져오기") + void getTemporaryPasswordTitle() { + //When + String result = emailContent.getTemporaryMailTitle(); //Then Assertions.assertNotNull(result); From a98ed11272bf21b0c4bfc65f20eef28a95029772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:25:29 +0900 Subject: [PATCH 021/215] =?UTF-8?q?feat(EmailContent):=20=EC=9E=84?= =?UTF-8?q?=EC=8B=9C=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=20=EC=9D=B4?= =?UTF-8?q?=EB=A9=94=EC=9D=BC=20=EB=82=B4=EC=9A=A9=20=EB=B0=8F=20=EC=A0=9C?= =?UTF-8?q?=EB=AA=A9=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/email/service/EmailContent.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/aliens/backend/email/service/EmailContent.java b/src/main/java/com/aliens/backend/email/service/EmailContent.java index 3cde1922..33bc29ef 100644 --- a/src/main/java/com/aliens/backend/email/service/EmailContent.java +++ b/src/main/java/com/aliens/backend/email/service/EmailContent.java @@ -5,11 +5,11 @@ @Component public class EmailContent { - public String getTitle() { + public String getAuthenticationMailTitle() { return "[FriendShip] Account Verification 회원가입 이메일 인증"; } - public String getContent(String token, String domainUrl) { + public String getAuthenticationMailContent(String token, String domainUrl) { String englishContent = "Thank you for registering with FriendShip App.\n" + "To ensure the security of your account, we need to verify your email address.\n\n" + "Please click the link below to verify your email and activate your account:\n" @@ -38,4 +38,16 @@ public String getContent(String token, String domainUrl) { return englishContent + koreanContent; } + + public String getTemporaryMailTitle() { + return "[FriendShip] 임시 비밀번호 발급"; + } + + public String getTemporaryMailContent(final String tmpPassword) { + String englishContent = "The temporary password has been issued. Your temporary password is: " + tmpPassword; + + String koreanContent = "임시 비밀번호가 발급되었습니다. 임시 비밀번호는 다음과 같습니다: " + tmpPassword; + + return englishContent + "\n\n" + koreanContent; + } } From ca4174949ea57467c92c9e24d36355486255ea97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:26:28 +0900 Subject: [PATCH 022/215] =?UTF-8?q?feat(EmailService):=20=EC=9E=84?= =?UTF-8?q?=EC=8B=9C=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=20=EB=B0=9C?= =?UTF-8?q?=EC=86=A1=ED=95=98=EB=8A=94=20Listener=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/email/service/EmailService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/aliens/backend/email/service/EmailService.java b/src/main/java/com/aliens/backend/email/service/EmailService.java index e4c20697..770e7052 100644 --- a/src/main/java/com/aliens/backend/email/service/EmailService.java +++ b/src/main/java/com/aliens/backend/email/service/EmailService.java @@ -6,6 +6,8 @@ import com.aliens.backend.global.encode.SymmetricKeyEncoder; import com.aliens.backend.global.error.EmailError; import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.member.controller.dto.event.TemporaryPasswordEvent; +import org.springframework.context.event.EventListener; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -58,4 +60,9 @@ public String authenticateEmail(final String token) throws Exception { private EmailAuthentication getEmailAuthentication(final Long emailEntityId) { return emailAuthenticationRepository.findById(emailEntityId).orElseThrow(() -> new RestApiException(EmailError.NULL_EMAIL)); } + + @EventListener + public void listen(TemporaryPasswordEvent event) { + emailSender.sendTemporaryPassword(event); + } } From 624ae39c2be5a89828ae9948f0a08c3dfa70e4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:26:53 +0900 Subject: [PATCH 023/215] =?UTF-8?q?test(EmailSenderTest):=20=EC=9E=84?= =?UTF-8?q?=EC=8B=9C=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=20=EB=B0=9C?= =?UTF-8?q?=EC=86=A1=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/email/sender/EmailSenderTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java b/src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java index b97cd4e4..7c5b4dc3 100644 --- a/src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java +++ b/src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java @@ -1,6 +1,7 @@ package com.aliens.backend.email.sender; import com.aliens.backend.email.service.EmailSender; +import com.aliens.backend.member.controller.dto.event.TemporaryPasswordEvent; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; @@ -10,7 +11,6 @@ import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @SpringBootTest @@ -35,4 +35,17 @@ void sendAuthenticationEmailTest() { // Then verify(javaMailSender).send(ArgumentMatchers.any(SimpleMailMessage.class)); } + + @Test + @DisplayName("임시 비밀반호 발급 이메일 전송 테스트") + void sendTemporaryPasswordEmailTest() { + // Given + TemporaryPasswordEvent event = new TemporaryPasswordEvent("tmp@example.com","tmpPassword"); + + // When + emailSender.sendTemporaryPassword(event); + + // Then + verify(javaMailSender).send(ArgumentMatchers.any(SimpleMailMessage.class)); + } } From 915c5f4941e9a6744c8297bda7c3bf263700ca23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:27:07 +0900 Subject: [PATCH 024/215] =?UTF-8?q?feat(EmailSender):=20=EC=9E=84=EC=8B=9C?= =?UTF-8?q?=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=20=EB=B0=9C=EC=86=A1=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/email/service/EmailSender.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/aliens/backend/email/service/EmailSender.java b/src/main/java/com/aliens/backend/email/service/EmailSender.java index 66565afb..059b4ace 100644 --- a/src/main/java/com/aliens/backend/email/service/EmailSender.java +++ b/src/main/java/com/aliens/backend/email/service/EmailSender.java @@ -1,6 +1,7 @@ package com.aliens.backend.email.service; import com.aliens.backend.global.property.EmailProperties; +import com.aliens.backend.member.controller.dto.event.TemporaryPasswordEvent; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Component; @@ -28,10 +29,25 @@ public void sendAuthenticationEmail(final String email, final String emailToken) private SimpleMailMessage createAuthenticationMail(final String email, final String emailToken) { SimpleMailMessage authenticationEmail = new SimpleMailMessage(); authenticationEmail.setTo(email); - authenticationEmail.setSubject(emailContent.getTitle()); + authenticationEmail.setSubject(emailContent.getAuthenticationMailTitle()); - String content = emailContent.getContent(emailToken, emailProperties.getDomainUrl()); + String content = emailContent.getAuthenticationMailContent(emailToken, emailProperties.getDomainUrl()); authenticationEmail.setText(content); return authenticationEmail; } + + public void sendTemporaryPassword(final TemporaryPasswordEvent event) { + SimpleMailMessage mailMessage = createTemporaryPassword(event); + javaMailSender.send(mailMessage); + } + + private SimpleMailMessage createTemporaryPassword(final TemporaryPasswordEvent event) { + SimpleMailMessage temporaryPasswordEmail = new SimpleMailMessage(); + temporaryPasswordEmail.setTo(event.email()); + temporaryPasswordEmail.setSubject(emailContent.getTemporaryMailTitle()); + + String content = emailContent.getTemporaryMailContent(event.tmpPassword()); + temporaryPasswordEmail.setText(content); + return temporaryPasswordEmail; + } } From 24d8e33501156c2b2714ee03a8cf70e73cae52d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:27:37 +0900 Subject: [PATCH 025/215] =?UTF-8?q?feat(TemporaryPasswordEvent):=20?= =?UTF-8?q?=EC=9E=84=EC=8B=9C=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EB=B0=9C=EC=86=A1=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/dto/event/TemporaryPasswordEvent.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/controller/dto/event/TemporaryPasswordEvent.java diff --git a/src/main/java/com/aliens/backend/member/controller/dto/event/TemporaryPasswordEvent.java b/src/main/java/com/aliens/backend/member/controller/dto/event/TemporaryPasswordEvent.java new file mode 100644 index 00000000..23482065 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/controller/dto/event/TemporaryPasswordEvent.java @@ -0,0 +1,4 @@ +package com.aliens.backend.member.controller.dto.event; + +public record TemporaryPasswordEvent(String email, String tmpPassword){ +} From 32cbf586c1930044ecba5412ef4147b53e988c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:07:53 +0900 Subject: [PATCH 026/215] =?UTF-8?q?feat(SignUpRequest):=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=EA=B0=80=EC=9E=85=20=EC=9A=94=EC=B2=AD=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/dto/request/SignUpRequest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/controller/dto/request/SignUpRequest.java diff --git a/src/main/java/com/aliens/backend/member/controller/dto/request/SignUpRequest.java b/src/main/java/com/aliens/backend/member/controller/dto/request/SignUpRequest.java new file mode 100644 index 00000000..75fc3462 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/controller/dto/request/SignUpRequest.java @@ -0,0 +1,11 @@ +package com.aliens.backend.member.controller.dto.request; + +public record SignUpRequest(String email, + String password, + String name, + String mbti, + String gender, + String nationality, + String birthday, + String aboutMe) { +} \ No newline at end of file From 331d3ce4f9651d59f637dcec19a72276aa4574ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:08:31 +0900 Subject: [PATCH 027/215] =?UTF-8?q?feat(TemporaryPasswordRequest):=20?= =?UTF-8?q?=EC=9E=84=EC=8B=9C=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EA=B0=9D=EC=B2=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dto/request/TemporaryPasswordRequest.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/controller/dto/request/TemporaryPasswordRequest.java diff --git a/src/main/java/com/aliens/backend/member/controller/dto/request/TemporaryPasswordRequest.java b/src/main/java/com/aliens/backend/member/controller/dto/request/TemporaryPasswordRequest.java new file mode 100644 index 00000000..374502e0 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/controller/dto/request/TemporaryPasswordRequest.java @@ -0,0 +1,4 @@ +package com.aliens.backend.member.controller.dto.request; + +public record TemporaryPasswordRequest(String email, String name) { +} From c931b24af09073c5ef327e502d2612f14f2e7561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:09:17 +0900 Subject: [PATCH 028/215] =?UTF-8?q?feat(MemberStatus):=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20=EC=A0=95=EB=B3=B4=20enum=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/member/domain/MemberStatus.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/domain/MemberStatus.java diff --git a/src/main/java/com/aliens/backend/member/domain/MemberStatus.java b/src/main/java/com/aliens/backend/member/domain/MemberStatus.java new file mode 100644 index 00000000..a1389901 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/domain/MemberStatus.java @@ -0,0 +1,19 @@ +package com.aliens.backend.member.domain; + +public enum MemberStatus { + + APPLIED_MATCHED("AppliedAndMatched"), + NOT_APPLIED_MATCHED("NotAppliedAndMatched"), + APPLIED_NOT_MATCHED("AppliedAndNotMatched"), + NOT_APPLIED_NOT_MATCHED("NotAppliedAndNotMatched"); + + private final String message; + + MemberStatus(final String message) { + this.message = message; + } + + public String getMessage() { + return message; + } +} \ No newline at end of file From 55f4cba7d31ce2220f23f60456f11cb64cf7a005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:09:50 +0900 Subject: [PATCH 029/215] =?UTF-8?q?feat(MemberResponse):=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EA=B2=B0=EA=B3=BC=20?= =?UTF-8?q?enum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/MemberResponse.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/controller/dto/response/MemberResponse.java diff --git a/src/main/java/com/aliens/backend/member/controller/dto/response/MemberResponse.java b/src/main/java/com/aliens/backend/member/controller/dto/response/MemberResponse.java new file mode 100644 index 00000000..c94b8483 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/controller/dto/response/MemberResponse.java @@ -0,0 +1,22 @@ +package com.aliens.backend.member.controller.dto.response; + +public enum MemberResponse { + + SIGN_UP_SUCCESS("회원가입이 완료되었습니다."), + WITHDRAW_SUCCESS("회원 탈퇴되었습니다."), + TEMPORARY_PASSWORD_GENERATED_SUCCESS("임시 비밀번호가 발급되었습니다. 이메일을 확인해주세요."), + PASSWORD_CHANGE_SUCCESS("비밀번호 변경이 완료되었습니다."), + PROFILE_IMAGE_CHANGE_SUCCESS("프로필 이미지 변경이 완료되었습니다."), + ABOUT_ME_CHANGE_SUCCESS("자기소개 변경이 완료되었습니다."), + MBTI_CHANGE_SUCCESS("MBTI 변경이 완료되었습니다."); + + private final String message; + + MemberResponse(final String message) { + this.message = message; + } + + public String getMessage() { + return message; + } +} \ No newline at end of file From d5d402714bdbf58c1b4aa53ffa2478d670668172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:11:01 +0900 Subject: [PATCH 030/215] =?UTF-8?q?feat(MemberPage):=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4(=EC=9D=B4=EB=A6=84,=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84URL)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/member/controller/dto/MemberPage.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/controller/dto/MemberPage.java diff --git a/src/main/java/com/aliens/backend/member/controller/dto/MemberPage.java b/src/main/java/com/aliens/backend/member/controller/dto/MemberPage.java new file mode 100644 index 00000000..436fbde0 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/controller/dto/MemberPage.java @@ -0,0 +1,5 @@ +package com.aliens.backend.member.controller.dto; + +public record MemberPage(String name, + String profileImageURL) { +} From 8a27070237fdb681b45f5a8c6e95b7f29601b19e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:17:21 +0900 Subject: [PATCH 031/215] =?UTF-8?q?feat(EncodedMemberPage,=20EncodedSignUp?= =?UTF-8?q?,=20EncodedMember):=20=EC=95=94=ED=98=B8=ED=99=94=EB=90=9C=20?= =?UTF-8?q?=ED=9A=8C=EC=9B=90=EC=A0=95=EB=B3=B4=20=EA=B0=9D=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/member/controller/dto/EncodedMember.java | 8 ++++++++ .../backend/member/controller/dto/EncodedMemberPage.java | 8 ++++++++ .../backend/member/controller/dto/EncodedSignUp.java | 6 ++++++ 3 files changed, 22 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/controller/dto/EncodedMember.java create mode 100644 src/main/java/com/aliens/backend/member/controller/dto/EncodedMemberPage.java create mode 100644 src/main/java/com/aliens/backend/member/controller/dto/EncodedSignUp.java diff --git a/src/main/java/com/aliens/backend/member/controller/dto/EncodedMember.java b/src/main/java/com/aliens/backend/member/controller/dto/EncodedMember.java new file mode 100644 index 00000000..8fbd9e33 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/controller/dto/EncodedMember.java @@ -0,0 +1,8 @@ +package com.aliens.backend.member.controller.dto; + +public record EncodedMember(String gender, + String mbti, + String birthday, + String nationality, + String aboutMe){ +} diff --git a/src/main/java/com/aliens/backend/member/controller/dto/EncodedMemberPage.java b/src/main/java/com/aliens/backend/member/controller/dto/EncodedMemberPage.java new file mode 100644 index 00000000..7ac29ba3 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/controller/dto/EncodedMemberPage.java @@ -0,0 +1,8 @@ +package com.aliens.backend.member.controller.dto; + +public record EncodedMemberPage(String mbti, + String gender, + String nationality, + String birthday, + String aboutMe) { +} diff --git a/src/main/java/com/aliens/backend/member/controller/dto/EncodedSignUp.java b/src/main/java/com/aliens/backend/member/controller/dto/EncodedSignUp.java new file mode 100644 index 00000000..b52435c5 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/controller/dto/EncodedSignUp.java @@ -0,0 +1,6 @@ +package com.aliens.backend.member.controller.dto; + +public record EncodedSignUp(String name, + String email, + String password) { +} From 616b753dc4ef6b0e3479210bfc2c5c9a357c7f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:21:38 +0900 Subject: [PATCH 032/215] =?UTF-8?q?feat(Image):=20=EC=82=AC=EC=A7=84=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EA=B0=80=EC=A7=80=EB=8A=94=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/member/domain/Image.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/domain/Image.java diff --git a/src/main/java/com/aliens/backend/member/domain/Image.java b/src/main/java/com/aliens/backend/member/domain/Image.java new file mode 100644 index 00000000..25ea0fc6 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/domain/Image.java @@ -0,0 +1,41 @@ +package com.aliens.backend.member.domain; + +import com.aliens.backend.uploader.S3File; +import jakarta.persistence.*; + +@Entity +public class Image { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column + private Long id; + + @Column + String name; + + @Column + String url; + + protected Image() { + } + + public static Image from(final S3File imageFile) { + Image image = new Image(); + image.name = imageFile.fileName(); + image.url = imageFile.fileURL(); + return image; + } + + public void change(final S3File newFile) { + name = newFile.fileName(); + url = newFile.fileURL(); + } + + public String getName() { + return name; + } + + public String getURL() { + return url; + } +} From 61ac9ea8397a1101346b51613323e6cda182a895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:23:59 +0900 Subject: [PATCH 033/215] =?UTF-8?q?feat(ImageRepository):=20Image=20Entity?= =?UTF-8?q?=20=EC=A0=91=EA=B7=BC=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EB=A0=88?= =?UTF-8?q?=ED=8C=8C=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/domain/repository/ImageRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/domain/repository/ImageRepository.java diff --git a/src/main/java/com/aliens/backend/member/domain/repository/ImageRepository.java b/src/main/java/com/aliens/backend/member/domain/repository/ImageRepository.java new file mode 100644 index 00000000..4416b3de --- /dev/null +++ b/src/main/java/com/aliens/backend/member/domain/repository/ImageRepository.java @@ -0,0 +1,9 @@ +package com.aliens.backend.member.domain.repository; + +import com.aliens.backend.member.domain.Image; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ImageRepository extends JpaRepository { +} From 3d7d48854526d765117642fc17eee7af6a962c1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:24:23 +0900 Subject: [PATCH 034/215] =?UTF-8?q?feat(MemberPageResponse):=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EB=8B=B4=EC=9D=80=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20=EA=B0=9D=EC=B2=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dto/response/MemberPageResponse.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/controller/dto/response/MemberPageResponse.java diff --git a/src/main/java/com/aliens/backend/member/controller/dto/response/MemberPageResponse.java b/src/main/java/com/aliens/backend/member/controller/dto/response/MemberPageResponse.java new file mode 100644 index 00000000..5d5f2bfc --- /dev/null +++ b/src/main/java/com/aliens/backend/member/controller/dto/response/MemberPageResponse.java @@ -0,0 +1,11 @@ +package com.aliens.backend.member.controller.dto.response; + + +public record MemberPageResponse(String name, + String mbti, + String gender, + String nationality, + String birthday, + String selfIntroduction, + String profileImageURL) { +} From bfc67a7173001dedca8087e8a28290e264ae3e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:26:21 +0900 Subject: [PATCH 035/215] =?UTF-8?q?feat(MemberController):=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20=EB=8F=84=EB=A9=94=EC=9D=B8=EC=97=90=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8A=94=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/controller/MemberController.java diff --git a/src/main/java/com/aliens/backend/member/controller/MemberController.java b/src/main/java/com/aliens/backend/member/controller/MemberController.java new file mode 100644 index 00000000..83b30708 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/controller/MemberController.java @@ -0,0 +1,92 @@ +package com.aliens.backend.member.controller; + +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.global.config.resolver.Login; +import com.aliens.backend.member.controller.dto.request.SignUpRequest; +import com.aliens.backend.member.controller.dto.request.TemporaryPasswordRequest; +import com.aliens.backend.member.controller.dto.response.MemberPageResponse; +import com.aliens.backend.member.sevice.MemberInfoService; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.util.Collections; +import java.util.Map; + +@RequestMapping("/members") +@RestController +public class MemberController { + + private final MemberInfoService memberInfoService; + + public MemberController(final MemberInfoService memberInfoService) { + this.memberInfoService = memberInfoService; + } + + @PostMapping() + public ResponseEntity> signUp(@RequestPart SignUpRequest signUpRequest, + @RequestPart MultipartFile profileImage) { + String result = memberInfoService.signUp(signUpRequest, profileImage); + Map response = Collections.singletonMap("response", result); + return ResponseEntity.ok(response); + } + + @PostMapping("/temporary-password") + public ResponseEntity> temporaryPassword(@RequestBody TemporaryPasswordRequest request) { + String result = memberInfoService.generateTemporaryPassword(request); + Map response = Collections.singletonMap("response", result); + return ResponseEntity.ok(response); + } + + @PatchMapping("/password") + public ResponseEntity> changePassword(@Login LoginMember loginMember, + @RequestBody String newPassword ) { + String result = memberInfoService.changePassword(loginMember, newPassword); + Map response = Collections.singletonMap("response", result); + return ResponseEntity.ok(response); + } + + @PostMapping("/profile-image") + public ResponseEntity> changeProfileImage(@Login LoginMember loginMember, + @RequestPart MultipartFile newProfileImage) { + String result = memberInfoService.changeProfileImage(loginMember, newProfileImage); + Map response = Collections.singletonMap("response", result); + return ResponseEntity.ok(response); + } + + @PatchMapping("/about-me") + public ResponseEntity> changeAboutMe(@Login LoginMember loginMember, + @RequestBody String newAboutMe) { + String result = memberInfoService.changeAboutMe(loginMember, newAboutMe); + Map response = Collections.singletonMap("response", result); + return ResponseEntity.ok(response); + } + + @PatchMapping("/mbti") + public ResponseEntity> changeMBTI(@Login LoginMember loginMember, + @RequestBody String newMBTI) { + String result = memberInfoService.changeMBTI(loginMember, newMBTI); + Map response = Collections.singletonMap("response", result); + return ResponseEntity.ok(response); + } + + @PatchMapping("/withdraw") + public ResponseEntity> withdraw(@Login LoginMember loginMember) { + String result = memberInfoService.withdraw(loginMember); + Map response = Collections.singletonMap("response", result); + return ResponseEntity.ok(response); + } + + @GetMapping("/status") + public ResponseEntity> getStatus(@Login LoginMember loginMember) { + String result = memberInfoService.getStatus(loginMember); + Map response = Collections.singletonMap("response", result); + return ResponseEntity.ok(response); + } + + @GetMapping() + public ResponseEntity getMemberPage(@Login LoginMember loginMember) { + MemberPageResponse result = memberInfoService.getMemberPage(loginMember); + return ResponseEntity.ok(result); + } +} From 90a4c4bda2b4bdbf8ce77fbe728e0e6274bc5b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:26:44 +0900 Subject: [PATCH 036/215] =?UTF-8?q?feat(MemberInfo):=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EC=A0=80=EC=9E=A5=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/member/domain/MemberInfo.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/domain/MemberInfo.java diff --git a/src/main/java/com/aliens/backend/member/domain/MemberInfo.java b/src/main/java/com/aliens/backend/member/domain/MemberInfo.java new file mode 100644 index 00000000..9768957c --- /dev/null +++ b/src/main/java/com/aliens/backend/member/domain/MemberInfo.java @@ -0,0 +1,59 @@ +package com.aliens.backend.member.domain; + +import com.aliens.backend.auth.domain.Member; +import com.aliens.backend.member.controller.dto.EncodedMember; +import com.aliens.backend.member.controller.dto.EncodedMemberPage; +import jakarta.persistence.*; + +@Entity +public class MemberInfo { + + @Id + private Long id; + + @MapsId + @OneToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE}) + @JoinColumn(name = "id") + private Member member; + + @Column + private String mbti; + + @Column + private String gender; + + @Column + private String nationality; + + @Column + private String birthday; + + @Column(name = "about_me") + private String aboutMe; + + protected MemberInfo() { + } + + public static MemberInfo of(EncodedMember request, Member member) { + MemberInfo memberInfo = new MemberInfo(); + memberInfo.member =member; + memberInfo.gender = request.gender(); + memberInfo.mbti = request.mbti(); + memberInfo.nationality = request.nationality(); + memberInfo.birthday = request.birthday(); + memberInfo.aboutMe = request.aboutMe(); + return memberInfo; + } + + public void changeAboutMe(final String newAboutMe) { + aboutMe = newAboutMe; + } + + public void changeMBTI(final String newMBTI) { + mbti = newMBTI; + } + + public EncodedMemberPage getMemberPage() { + return new EncodedMemberPage(mbti,gender,nationality,birthday,aboutMe); + } +} From 863fada5792da58a480ea18590b81cb84635ca70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:27:02 +0900 Subject: [PATCH 037/215] =?UTF-8?q?feat(MemberInfoRepository):=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EC=A0=91=EA=B7=BC?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20=EB=A0=88=ED=8C=8C?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/domain/repository/MemberInfoRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/domain/repository/MemberInfoRepository.java diff --git a/src/main/java/com/aliens/backend/member/domain/repository/MemberInfoRepository.java b/src/main/java/com/aliens/backend/member/domain/repository/MemberInfoRepository.java new file mode 100644 index 00000000..38008a41 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/domain/repository/MemberInfoRepository.java @@ -0,0 +1,9 @@ +package com.aliens.backend.member.domain.repository; + +import com.aliens.backend.member.domain.MemberInfo; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface MemberInfoRepository extends JpaRepository { +} From 96350ec43f8d3b7c5e4901eeb9040d57cd51a002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:28:58 +0900 Subject: [PATCH 038/215] =?UTF-8?q?test(MemberDocTest):=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20=EB=8F=84=EB=A9=94=EC=9D=B8=20API=20=EB=AC=B8?= =?UTF-8?q?=EC=84=9C=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/member.adoc | 158 ++++++++++ .../aliens/backend/docs/MemberDocTest.java | 287 ++++++++++++++++++ 2 files changed, 445 insertions(+) create mode 100644 src/docs/asciidoc/member.adoc create mode 100644 src/test/java/com/aliens/backend/docs/MemberDocTest.java diff --git a/src/docs/asciidoc/member.adoc b/src/docs/asciidoc/member.adoc new file mode 100644 index 00000000..9390883c --- /dev/null +++ b/src/docs/asciidoc/member.adoc @@ -0,0 +1,158 @@ += Spring REST Docs +:toc: left +:toclevels: 2 +:sectlinks: + +[[resources-post]] +== 회원 + +[[resources-post-create]] +=== 회원 가입 + +==== HTTP request +include::{snippets}/member-signup/http-request.adoc[] + + +==== HTTP response +include::{snippets}/member-signup/http-response.adoc[] + +==== response-body 설명 +include::{snippets}/member-signup/response-fields.adoc[] + + + +=== 프로필 이미지 변경 + +==== HTTP request +include::{snippets}/member-change-profile-image/http-request.adoc[] + +==== HTTP response +include::{snippets}/member-change-profile-image/http-response.adoc[] + +==== response-body 설명 +include::{snippets}/member-change-profile-image/response-fields.adoc[] + + +=== 임시 비밀번호 발급 + +==== HTTP request +include::{snippets}/member-temporary-password/http-request.adoc[] + +==== request-body 설명 +include::{snippets}/member-temporary-password/request-fields.adoc[] + +==== HTTP response +include::{snippets}/member-temporary-password/http-response.adoc[] + +==== response-body 설명 +include::{snippets}/email-verification-send/response-fields.adoc[] + + +=== 비밀번호 변경 + +==== HTTP request + +include::{snippets}/member-change-password/http-request.adoc[] + +==== request-body 설명 +include::{snippets}/member-change-password/request-fields.adoc[] + +==== HTTP response + +include::{snippets}/member-change-password/http-response.adoc[] + +==== response-body 설명 +include::{snippets}/member-change-password/response-fields.adoc[] + + + + +=== 회원 탈퇴 + +==== HTTP request + +include::{snippets}/member-withdraw/http-request.adoc[] + + +==== HTTP response + +include::{snippets}/member-withdraw/http-response.adoc[] + +==== response-body 설명 +include::{snippets}/member-withdraw/response-fields.adoc[] + + + + + +=== 회원 상태 + +==== HTTP request + +include::{snippets}/member-get-status/http-request.adoc[] + + +==== HTTP response + +include::{snippets}/member-get-status/http-response.adoc[] + +==== response-body 설명 +include::{snippets}/member-get-status/response-fields.adoc[] + + + + +=== 개인 정보 조회 + +==== HTTP request + +include::{snippets}/member-get-member-page/http-request.adoc[] + + +==== HTTP response + +include::{snippets}/member-get-member-page/http-response.adoc[] + +==== response-body 설명 +include::{snippets}/member-get-member-page/response-fields.adoc[] + + + + +=== 자기소개 변경 + +==== HTTP request + +include::{snippets}/member-change-about-me/http-request.adoc[] + +==== request-body 설명 +include::{snippets}/member-change-about-me/request-fields.adoc[] + + + +==== HTTP response + +include::{snippets}/member-change-about-me/http-response.adoc[] + +==== response-body 설명 +include::{snippets}/member-change-about-me/response-fields.adoc[] + + + +=== MBTI 변경 + +==== HTTP request + +include::{snippets}/member-change-mbti/http-request.adoc[] + +==== request-body 설명 +include::{snippets}/member-change-mbti/request-fields.adoc[] + + + +==== HTTP response + +include::{snippets}/member-change-mbti/http-response.adoc[] + +==== response-body 설명 +include::{snippets}/member-change-mbti/response-fields.adoc[] \ No newline at end of file diff --git a/src/test/java/com/aliens/backend/docs/MemberDocTest.java b/src/test/java/com/aliens/backend/docs/MemberDocTest.java new file mode 100644 index 00000000..e9d1e5dc --- /dev/null +++ b/src/test/java/com/aliens/backend/docs/MemberDocTest.java @@ -0,0 +1,287 @@ +package com.aliens.backend.docs; + +import com.aliens.backend.auth.service.TokenProvider; +import com.aliens.backend.member.controller.dto.request.SignUpRequest; +import com.aliens.backend.member.controller.dto.request.TemporaryPasswordRequest; +import com.aliens.backend.member.controller.dto.response.MemberPageResponse; +import com.aliens.backend.member.controller.dto.response.MemberResponse; +import com.aliens.backend.member.domain.MemberStatus; +import com.aliens.backend.member.sevice.MemberInfoService; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.test.web.servlet.MockMvc; + +import java.nio.charset.StandardCharsets; +import java.util.Collections; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; +import static org.springframework.restdocs.payload.PayloadDocumentation.*; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.request.RequestDocumentation.partWithName; +import static org.springframework.restdocs.request.RequestDocumentation.requestParts; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@AutoConfigureMockMvc +@AutoConfigureRestDocs +@SpringBootTest +class MemberDocTest { + + @Autowired + private MockMvc mockMvc; + @MockBean + private MemberInfoService memberInfoService; + @MockBean + private TokenProvider tokenProvider; + + ObjectMapper objectMapper; + MockMultipartFile multipartFile; + String accessToken; + + @BeforeEach + void setUp() { + multipartFile = new MockMultipartFile("profile-data", + "profile-data", + "image/png", + "test data".getBytes()); + accessToken= "accessToken"; + objectMapper = new ObjectMapper(); + } + + @Test + @DisplayName("회원가입 API 테스트") + void signUp() throws Exception { + final SignUpRequest request = createSignUpRequest(); + final String response = MemberResponse.SIGN_UP_SUCCESS.getMessage(); + when(memberInfoService.signUp(any(),any())).thenReturn(response); + + MockMultipartFile signUpRequestFile = getSignUpRequestFile(request); + + // When and Then + mockMvc.perform(multipart("/members") + .file(signUpRequestFile) + .file("profileImage", multipartFile.getBytes()) + .contentType(MediaType.MULTIPART_FORM_DATA) + .accept(MediaType.APPLICATION_JSON) + .characterEncoding("UTF-8") + ) + .andExpect(status().isOk()) + .andDo(document("member-signup", + requestParts( + partWithName("signUpRequest").description("회원가입 요청 데이터"), + partWithName("profileImage").description("프로필 이미지 파일") + ), + responseFields( + fieldWithPath("response").description("회원가입 결과") + ) + )); + } + + @Test + @DisplayName("프로필 이미지 변경 API 테스트") + void changeProfileImage() throws Exception { + String response = MemberResponse.PROFILE_IMAGE_CHANGE_SUCCESS.getMessage(); + when(memberInfoService.changeProfileImage(any(),any())).thenReturn(response); + + mockMvc.perform(multipart("/members/profile-image") + .file("newProfileImage", multipartFile.getBytes()) + .header("Authorization", accessToken) + .contentType(MediaType.MULTIPART_FORM_DATA)) + .andExpect(status().isOk()) + .andDo(document("member-change-profile-image", + requestParts( + partWithName("newProfileImage").description("새로운 프로필 이미지 파일") + ), + responseFields( + fieldWithPath("response").description("프로필 이미지 변경 결과") + ) + )); + } + + @Test + @DisplayName("임시 비밀번호 발급 API 테스트") + void generateTemporaryPassword() throws Exception { + final TemporaryPasswordRequest request = new TemporaryPasswordRequest("tmp@example.com", "tmpName"); + final String response = MemberResponse.TEMPORARY_PASSWORD_GENERATED_SUCCESS.getMessage(); + when(memberInfoService.generateTemporaryPassword(any())).thenReturn(response); + + this.mockMvc.perform(post("/members/temporary-password") + .content(objectMapper.writeValueAsString(request)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andDo(document("member-temporary-password", + requestFields( + fieldWithPath("email").description("이메일"), + fieldWithPath("name").description("이름") + ), + responseFields( + fieldWithPath("response").description("임시 비밀번호 발급 결과") + ) + )); + } + + @Test + @DisplayName("비밀번호 변경 API 테스트") + void changePassword() throws Exception { + String newPassword = "newPassword"; + String response = MemberResponse.PASSWORD_CHANGE_SUCCESS.getMessage(); + when(memberInfoService.changePassword(any(), any())).thenReturn(response); + + this.mockMvc.perform(patch("/members/password") + .header("Authorization", accessToken) + .content(objectMapper.writeValueAsString(Collections.singletonMap("newPassword", newPassword))) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andDo(document("member-change-password", + requestFields( + fieldWithPath("newPassword").description("새로운 비밀번호") + ), + responseFields( + fieldWithPath("response").description("비밀번호 변경 결과") + ) + )); + } + + @Test + @DisplayName("회원 탈퇴 API 테스트") + void withdraw() throws Exception { + String response = MemberResponse.WITHDRAW_SUCCESS.getMessage(); + when(memberInfoService.withdraw(any())).thenReturn(response); + + mockMvc.perform(patch("/members/withdraw") + .header("Authorization", accessToken) + ) + .andExpect(status().isOk()) + .andDo(document("member-withdraw", + responseFields( + fieldWithPath("response").description("회원 탈퇴 결과") + ) + )); + } + + @Test + @DisplayName("상태 요청 API 테스트") + void getStatus() throws Exception { + String response = MemberStatus.NOT_APPLIED_NOT_MATCHED.getMessage(); + when(memberInfoService.getStatus(any())).thenReturn(response); + + mockMvc.perform(get("/members/status") + .header("Authorization", accessToken) + ) + .andExpect(status().isOk()) + .andDo(document("member-get-status", + responseFields( + fieldWithPath("response").description("상태 요청 결과") + ) + )); + } + + @Test + @DisplayName("회원 개인정보 요청 API 테스트") + void getMemberPage() throws Exception { + MemberPageResponse response = getMemberPageResponse(); + when(memberInfoService.getMemberPage(any())).thenReturn(response); + + mockMvc.perform(get("/members") + .header("Authorization", accessToken) + ) + .andExpect(status().isOk()) + .andDo(document("member-get-member-page", + responseFields( + fieldWithPath("name").description("이름"), + fieldWithPath("mbti").description("MBTI"), + fieldWithPath("gender").description("성별"), + fieldWithPath("nationality").description("국적"), + fieldWithPath("birthday").description("생년월일"), + fieldWithPath("selfIntroduction").description("자기 소개"), + fieldWithPath("profileImageURL").description("프로필 이미지 주소") + ) + )); + } + + + @Test + @DisplayName("자기소개 변경 API 테스트") + void changeAboutMe() throws Exception { + String newAboutMe = "새로운 자기소개"; + String response = MemberResponse.PASSWORD_CHANGE_SUCCESS.getMessage(); + when(memberInfoService.changeAboutMe(any(),any())).thenReturn(response); + + mockMvc.perform(patch("/members/about-me") + .header("Authorization", accessToken) + .content(objectMapper.writeValueAsString(Collections.singletonMap("newAboutMe", newAboutMe))) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andDo(document("member-change-about-me", + requestFields( + fieldWithPath("newAboutMe").description("새로운 자기소개") + ), + responseFields( + fieldWithPath("response").description("자기소개 변경 결과") + ) + )); + } + + @Test + @DisplayName("MBTI 변경 API 테스트") + void changeMBTI() throws Exception { + String newMBTI = "ENFP"; + String response = MemberResponse.MBTI_CHANGE_SUCCESS.getMessage(); + when(memberInfoService.changeMBTI(any(),any())).thenReturn(response); + + mockMvc.perform(patch("/members/mbti") + .header("Authorization", accessToken) + .content(objectMapper.writeValueAsString(Collections.singletonMap("newMBTI", newMBTI))) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andDo(document("member-change-mbti", + requestFields( + fieldWithPath("newMBTI").description("새로운 MBTI") + ), + responseFields( + fieldWithPath("response").description("MBTI 변경 결과") + ) + )); + } + + public SignUpRequest createSignUpRequest() { + SignUpRequest signUpRequest = new SignUpRequest("tmp@example.com", + "password", + "tmpName", + "INTJ", + "MALE", + "KOREA", + "1998-11-25", + "반갑습니다" + ); + return signUpRequest; + } + + public MockMultipartFile getSignUpRequestFile(final SignUpRequest request) throws JsonProcessingException { + String signupRequestJson = objectMapper.writeValueAsString(request); + MockMultipartFile signUpRequestFile = new MockMultipartFile( + "signUpRequest", + "signupRequest.json", + MediaType.APPLICATION_JSON_VALUE, + signupRequestJson.getBytes(StandardCharsets.UTF_8) + ); + return signUpRequestFile; + } + + public MemberPageResponse getMemberPageResponse() { + MemberPageResponse response = new MemberPageResponse("name","MBTI","MALE","KOREA","1998-11-25","반갑습니다","tmpImage.com"); + return response; + } +} \ No newline at end of file From c50687c8b77c1035c80a9b3716a6c086338a5a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:30:47 +0900 Subject: [PATCH 039/215] =?UTF-8?q?test(MemberInfoServiceTest):=20?= =?UTF-8?q?=ED=9A=8C=EC=9B=90=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/member/MemberInfoServiceTest.java | 260 ++++++++++++++++++ 1 file changed, 260 insertions(+) create mode 100644 src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java diff --git a/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java b/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java new file mode 100644 index 00000000..13f06680 --- /dev/null +++ b/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java @@ -0,0 +1,260 @@ +package com.aliens.backend.member; + +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.domain.Member; +import com.aliens.backend.auth.domain.repository.MemberRepository; +import com.aliens.backend.auth.service.PasswordEncoder; +import com.aliens.backend.email.domain.EmailAuthentication; +import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; +import com.aliens.backend.global.encode.SymmetricKeyEncoder; +import com.aliens.backend.member.controller.dto.*; +import com.aliens.backend.member.controller.dto.request.SignUpRequest; +import com.aliens.backend.member.controller.dto.request.TemporaryPasswordRequest; +import com.aliens.backend.member.controller.dto.response.MemberPageResponse; +import com.aliens.backend.member.controller.dto.response.MemberResponse; +import com.aliens.backend.member.domain.Image; +import com.aliens.backend.member.domain.MemberInfo; +import com.aliens.backend.member.domain.repository.ImageRepository; +import com.aliens.backend.member.domain.repository.MemberInfoRepository; +import com.aliens.backend.member.domain.MemberStatus; +import com.aliens.backend.member.sevice.MemberInfoService; +import com.aliens.backend.uploader.AwsS3Uploader; +import com.aliens.backend.uploader.S3File; +import org.junit.jupiter.api.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.web.multipart.MultipartFile; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@SpringBootTest +class MemberInfoServiceTest { + + @Autowired + MemberInfoRepository memberInfoRepository; + @Autowired + MemberInfoService memberInfoService; + @Autowired + EmailAuthenticationRepository emailAuthenticationRepository; + @Autowired + ImageRepository imageRepository; + @Autowired + MemberRepository memberRepository; + @Autowired + SymmetricKeyEncoder symmetricKeyEncoder; + @Autowired + PasswordEncoder passwordEncoder; + + @MockBean + AwsS3Uploader awsS3Uploader; + @MockBean + JavaMailSender javaMailSender; + + MockMultipartFile file; + LoginMember loginMember; + String givenName = "김명준"; + String givenEmail = "tmp@example"; + String givenPassword = "tmpPassword"; + String givenGender = "MALE"; + String givenMbti = "INTJ"; + String givenBirthday = "1998-11-25"; + String givenNationality = "KOREA"; + String givenAboutMe = "반갑습니다."; + String givenFileName = "tmpFile"; + String givenFileURL = "example.com"; + + @BeforeEach + void setUp() { + setUpEmailEntity(givenEmail); + Image image = setUpImage(); + Member member = setUpMember(image); + setUpMemberInfo(member); + setUpLoginMember(member); + setUpMockMultipartFile(); + } + + @AfterEach + void setDown() { + emailAuthenticationRepository.deleteAll(); + memberInfoRepository.deleteAll(); + memberRepository.deleteAll(); + imageRepository.deleteAll(); + } + + @Test + @DisplayName("회원가입") + void signUpTest() { + //Given + S3File tmpFile = new S3File(givenFileName, givenFileURL); + when(awsS3Uploader.upload((MultipartFile) any())).thenReturn(tmpFile); + SignUpRequest signUpRequest = createSignUpRequest(); + + //When + String result = memberInfoService.signUp(signUpRequest, file); + + //Then + Assertions.assertEquals(MemberResponse.SIGN_UP_SUCCESS.getMessage(),result); + } + + @Test + @DisplayName("회원 탈퇴") + void withdrawTest() { + //When + String result = memberInfoService.withdraw(loginMember); + + //Then + Assertions.assertEquals(MemberResponse.WITHDRAW_SUCCESS.getMessage(),result); + } + + @Test + @DisplayName("임시 비밀번호 발급") + void temporaryPassword() { + //Given + TemporaryPasswordRequest temporaryPasswordRequest = new TemporaryPasswordRequest(givenEmail,givenName); + + //When + String result = memberInfoService.generateTemporaryPassword(temporaryPasswordRequest); + + //Then + Assertions.assertEquals(MemberResponse.TEMPORARY_PASSWORD_GENERATED_SUCCESS.getMessage(),result); + } + + @Test + @DisplayName("비밀번호 변경") + void changePassword() { + //Given + String newPassword = "newPassword"; + + //When + String result = memberInfoService.changePassword(loginMember, newPassword); + + //Then + Assertions.assertEquals(MemberResponse.PASSWORD_CHANGE_SUCCESS.getMessage(),result); + } + + @Test + @DisplayName("프로필 이미지 변경") + void changeProfileImage() { + //Given + S3File tmpFile = new S3File(givenFileName, givenFileURL); + when(awsS3Uploader.upload((MultipartFile) any())).thenReturn(tmpFile); + + //When + String result = memberInfoService.changeProfileImage(loginMember, file); + + //Then + Assertions.assertEquals(MemberResponse.PROFILE_IMAGE_CHANGE_SUCCESS.getMessage(),result); + } + + @Test + @DisplayName("자기소개 변경") + void changeAboutMe() { + //Given + String newAboutMe = "newAboutMe"; + + //When + String result = memberInfoService.changeAboutMe(loginMember, newAboutMe); + + //Then + Assertions.assertEquals(MemberResponse.ABOUT_ME_CHANGE_SUCCESS.getMessage(),result); + } + + @Test + @DisplayName("MBTI 변경") + void changeMBTI() { + //Given + String newMBTI = "ESTJ"; + + //When + String result = memberInfoService.changeMBTI(loginMember, newMBTI); + + //Then + Assertions.assertEquals(MemberResponse.MBTI_CHANGE_SUCCESS.getMessage(),result); + } + + @Test + @DisplayName("상태 요청") + void getStatus() { + //When + String result = memberInfoService.getStatus(loginMember); + + //Then + Assertions.assertEquals(MemberStatus.NOT_APPLIED_NOT_MATCHED.getMessage(),result); + } + + @Test + @DisplayName("회원 개인정보 요청") + void getMemberInfo() { + //Given + MemberPageResponse expectedResponse = new MemberPageResponse(givenName, + givenMbti, + givenGender, + givenNationality, + givenBirthday, + givenAboutMe, + givenFileURL); + + //When + MemberPageResponse result = memberInfoService.getMemberPage(loginMember); + + //Then + Assertions.assertEquals(expectedResponse,result); + } + + public void setUpLoginMember(final Member member) { + loginMember = member.getLoginMember(); + } + + public void setUpMemberInfo(final Member member) { + EncodedMember encodedRequest = new EncodedMember(symmetricKeyEncoder.encrypt(givenGender), + symmetricKeyEncoder.encrypt(givenMbti), + symmetricKeyEncoder.encrypt(givenBirthday), + symmetricKeyEncoder.encrypt(givenNationality), + symmetricKeyEncoder.encrypt(givenAboutMe)); + + MemberInfo memberInfo = MemberInfo.of(encodedRequest, member); + memberInfoRepository.save(memberInfo); + } + + public Member setUpMember(final Image image) { + EncodedSignUp signUp = new EncodedSignUp(givenName, givenEmail, passwordEncoder.encrypt(givenPassword)); + Member member = Member.of(signUp, image); + return member; + } + + public Image setUpImage() { + Image image = Image.from(new S3File(givenFileName, givenFileURL)); + return image; + } + + public void setUpMockMultipartFile() { + String fileName = "test"; + String path = "/test"; + String contentType = "image/png"; + byte[] content = fileName.getBytes(); + file = new MockMultipartFile(fileName, path, contentType, content); + } + + public void setUpEmailEntity(final String givenEmail) { + EmailAuthentication emailEntity = new EmailAuthentication(givenEmail); + emailEntity.authenticate(); + emailAuthenticationRepository.save(emailEntity); + } + + public SignUpRequest createSignUpRequest() { + SignUpRequest signUpRequest = new SignUpRequest(givenEmail, + "password", + "tmpName", + "INTJ", + "MALE", + "KOREA", + "1998-11-25", + "반갑습니다" + ); + return signUpRequest; + } +} From f5afcb00b1f1d9cbea4169ebda0b64d3fd575094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:31:17 +0900 Subject: [PATCH 040/215] =?UTF-8?q?feat(MemberInfoService):=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EC=BD=94=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/sevice/MemberInfoService.java | 226 ++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java diff --git a/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java b/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java new file mode 100644 index 00000000..61a3e966 --- /dev/null +++ b/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java @@ -0,0 +1,226 @@ +package com.aliens.backend.member.sevice; + +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.domain.Member; +import com.aliens.backend.auth.domain.repository.MemberRepository; +import com.aliens.backend.auth.service.PasswordEncoder; +import com.aliens.backend.email.domain.EmailAuthentication; +import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; +import com.aliens.backend.global.encode.SymmetricKeyEncoder; +import com.aliens.backend.global.error.EmailError; +import com.aliens.backend.global.error.MemberError; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.property.S3UploadProperties; +import com.aliens.backend.member.controller.dto.*; +import com.aliens.backend.member.controller.dto.event.TemporaryPasswordEvent; +import com.aliens.backend.member.controller.dto.request.TemporaryPasswordRequest; +import com.aliens.backend.member.controller.dto.response.MemberPageResponse; +import com.aliens.backend.member.controller.dto.response.MemberResponse; +import com.aliens.backend.member.controller.dto.request.SignUpRequest; +import com.aliens.backend.member.domain.*; +import com.aliens.backend.member.domain.repository.MemberInfoRepository; +import com.aliens.backend.uploader.AwsS3Uploader; +import com.aliens.backend.uploader.S3File; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import java.util.*; + +@Service +public class MemberInfoService { + private final AwsS3Uploader uploader; + private final SymmetricKeyEncoder symmetricKeyEncoder; + private final PasswordEncoder passwordEncoder; + private final ApplicationEventPublisher publisher; + + private final S3UploadProperties s3UploadProperties; + private final MemberRepository memberRepository; + private final MemberInfoRepository memberInfoRepository; + private final EmailAuthenticationRepository emailAuthenticationRepository; + + public MemberInfoService(final AwsS3Uploader uploader, + final SymmetricKeyEncoder symmetricKeyEncoder, + final PasswordEncoder passwordEncoder, + final ApplicationEventPublisher publisher, + final S3UploadProperties s3UploadProperties, final MemberRepository memberRepository, + final MemberInfoRepository memberInfoRepository, + final EmailAuthenticationRepository emailAuthenticationRepository) + { + this.uploader = uploader; + this.symmetricKeyEncoder = symmetricKeyEncoder; + this.passwordEncoder = passwordEncoder; + this.s3UploadProperties = s3UploadProperties; + this.memberRepository = memberRepository; + this.memberInfoRepository = memberInfoRepository; + this.emailAuthenticationRepository = emailAuthenticationRepository; + this.publisher = publisher; + } + + @Transactional + public String signUp(final SignUpRequest request, final MultipartFile profileImage) { + checkEmail(request.email()); + + Image image = saveImage(profileImage); + + Member member = getMemberEntity(request, image); + + MemberInfo memberInfo = getMemberInfoEntity(request, member); + member.putMemberInfo(memberInfo); + + memberInfoRepository.save(memberInfo); + + return MemberResponse.SIGN_UP_SUCCESS.getMessage(); + } + + private void checkEmail(final String email) { + Optional emailEntity = emailAuthenticationRepository.findByEmail(email); + if (emailEntity.isEmpty()) { + throw new RestApiException(EmailError.NULL_EMAIL); + } + if (!emailEntity.get().isAuthenticated()) { + throw new RestApiException(EmailError.NOT_AUTHENTICATED_EMAIL); + } + } + + private Image saveImage(final MultipartFile profileImage) { + if (profileImage == null || profileImage.isEmpty()) { + return Image.from(new S3File(s3UploadProperties.getDefaultFileName(), + s3UploadProperties.getDefaultFileURL())); + } + + S3File uploadedFile = uploader.upload(profileImage); + return Image.from(uploadedFile); + } + + private Member getMemberEntity(final SignUpRequest request, final Image image) { + EncodedSignUp encodedSignUp = encodeForMember(request); + return Member.of(encodedSignUp, image); + } + + private EncodedSignUp encodeForMember(final SignUpRequest request) { + return new EncodedSignUp(request.name(), request.email(), passwordEncoder.encrypt(request.password())); + } + + private MemberInfo getMemberInfoEntity(final SignUpRequest request, final Member member) { + EncodedMember encodedInfo = encodeForMemberInfo(request); + return MemberInfo.of(encodedInfo, member); + } + + private EncodedMember encodeForMemberInfo(final SignUpRequest request) { + return new EncodedMember( + symmetricKeyEncoder.encrypt(request.gender()), + symmetricKeyEncoder.encrypt(request.mbti()), + symmetricKeyEncoder.encrypt(request.birthday()), + symmetricKeyEncoder.encrypt(request.nationality()), + symmetricKeyEncoder.encrypt(request.aboutMe())); + } + + @Transactional + public String withdraw(final LoginMember loginMember) { + Member member = getMember(loginMember); + member.withdraw(); + return MemberResponse.WITHDRAW_SUCCESS.getMessage(); + } + + private Member getMember(final LoginMember loginMember) { + return memberRepository.findById(loginMember.memberId()).orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER)); + } + + @Transactional + public String changePassword(final LoginMember loginMember, final String newPassword) { + Member member = getMember(loginMember); + member.changePassword(passwordEncoder.encrypt(newPassword)); + return MemberResponse.PASSWORD_CHANGE_SUCCESS.getMessage(); + } + + @Transactional + public String changeProfileImage(final LoginMember loginMember, final MultipartFile newProfileImage) { + Member member = getMember(loginMember); + changeImageInDB(newProfileImage, member); + return MemberResponse.PROFILE_IMAGE_CHANGE_SUCCESS.getMessage(); + } + + private void changeImageInDB(final MultipartFile newProfileImage, final Member member) { + String savedProfileName = member.getProfileName(); + + if (!savedProfileName.equals(s3UploadProperties.getDefaultFileName())) { + uploader.delete(savedProfileName); + } + + S3File newFile = uploader.upload(newProfileImage); + member.changeProfileImage(newFile); + } + + @Transactional + public String changeAboutMe(final LoginMember loginMember, final String newAboutMe) { + MemberInfo memberInfo = getMemberInfo(loginMember); + memberInfo.changeAboutMe(symmetricKeyEncoder.encrypt(newAboutMe)); + return MemberResponse.ABOUT_ME_CHANGE_SUCCESS.getMessage(); + } + + @Transactional + public String changeMBTI(final LoginMember loginMember, final String newMBTI) { + MemberInfo memberInfo = getMemberInfo(loginMember); + memberInfo.changeMBTI(symmetricKeyEncoder.encrypt(newMBTI)); + return MemberResponse.MBTI_CHANGE_SUCCESS.getMessage(); + } + + private MemberInfo getMemberInfo(final LoginMember loginMember) { + return memberInfoRepository.findById(loginMember.memberId()).orElseThrow(()-> new RestApiException(MemberError.NULL_MEMBER)); + } + + @Transactional(readOnly = true) + public String getStatus(final LoginMember loginMember) { + Member member = getMember(loginMember); + return member.getStatus(); + } + + @Transactional(readOnly = true) + public MemberPageResponse getMemberPage(final LoginMember loginMember) { + MemberInfo memberInfo = getMemberInfo(loginMember); + EncodedMemberPage encodedMemberPage = memberInfo.getMemberPage(); + + Member member = getMember(loginMember); + MemberPage memberPage = member.getMemberPage(); + + return new MemberPageResponse(memberPage.name(), + symmetricKeyEncoder.decrypt(encodedMemberPage.mbti()), + symmetricKeyEncoder.decrypt(encodedMemberPage.gender()), + symmetricKeyEncoder.decrypt(encodedMemberPage.nationality()), + symmetricKeyEncoder.decrypt(encodedMemberPage.birthday()), + symmetricKeyEncoder.decrypt(encodedMemberPage.aboutMe()), + memberPage.profileImageURL()); + } + + @Transactional + public String generateTemporaryPassword(final TemporaryPasswordRequest request) { + Member member = memberRepository.findByEmailAndName(request.email(), request.name()).orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER)); + + String tmpPassword = getRandomPassword(); + member.changePassword(passwordEncoder.encrypt(tmpPassword)); + + TemporaryPasswordEvent event = new TemporaryPasswordEvent(request.email(),tmpPassword); + publisher.publishEvent(event); + + return MemberResponse.TEMPORARY_PASSWORD_GENERATED_SUCCESS.getMessage(); + } + + private String getRandomPassword() { + Random random = new Random(); + List password = new ArrayList<>(); + + for (int i = 0; i < 6; i++) { + int ranNum = random.nextInt(45) + 1; + password.add(ranNum); + } + + StringBuilder passwordBuilder = new StringBuilder(); + for (Integer num : password) { + passwordBuilder.append(num); + } + + return passwordBuilder.toString(); + } +} From ab2f31cf40cc4c1e361341586bce91e339984c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 21:03:19 +0900 Subject: [PATCH 041/215] =?UTF-8?q?refactor:=20=EB=94=94=EB=A0=89=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/aliens/backend/auth/domain/Member.java | 2 +- .../java/com/aliens/backend/email/service/EmailService.java | 2 +- src/main/java/com/aliens/backend/member/domain/Image.java | 2 +- .../com/aliens/backend/member/sevice/MemberInfoService.java | 3 +-- .../{global/encode => member/sevice}/SymmetricKeyEncoder.java | 2 +- src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java | 1 + .../java/com/aliens/backend/uploader/{ => dto}/S3File.java | 2 +- .../aliens/backend/uploader/{ => dto}/UploadFileRequest.java | 2 +- .../java/com/aliens/backend/auth/service/AuthServiceTest.java | 2 +- .../com/aliens/backend/email/service/EmailServiceTest.java | 2 +- .../com/aliens/backend/encode/SymmetricKeyEncoderTest.java | 2 +- .../java/com/aliens/backend/member/MemberInfoServiceTest.java | 4 ++-- .../java/com/aliens/backend/uploader/AwsS3UploaderTest.java | 1 + 13 files changed, 14 insertions(+), 13 deletions(-) rename src/main/java/com/aliens/backend/{global/encode => member/sevice}/SymmetricKeyEncoder.java (97%) rename src/main/java/com/aliens/backend/uploader/{ => dto}/S3File.java (59%) rename src/main/java/com/aliens/backend/uploader/{ => dto}/UploadFileRequest.java (77%) diff --git a/src/main/java/com/aliens/backend/auth/domain/Member.java b/src/main/java/com/aliens/backend/auth/domain/Member.java index ff2bcbf2..e38e040d 100644 --- a/src/main/java/com/aliens/backend/auth/domain/Member.java +++ b/src/main/java/com/aliens/backend/auth/domain/Member.java @@ -6,7 +6,7 @@ import com.aliens.backend.member.domain.MemberInfo; import com.aliens.backend.member.domain.MemberStatus; import com.aliens.backend.member.controller.dto.EncodedSignUp; -import com.aliens.backend.uploader.S3File; +import com.aliens.backend.uploader.dto.S3File; import jakarta.persistence.*; import java.util.ArrayList; diff --git a/src/main/java/com/aliens/backend/email/service/EmailService.java b/src/main/java/com/aliens/backend/email/service/EmailService.java index 770e7052..776c5973 100644 --- a/src/main/java/com/aliens/backend/email/service/EmailService.java +++ b/src/main/java/com/aliens/backend/email/service/EmailService.java @@ -3,7 +3,7 @@ import com.aliens.backend.email.controller.response.EmailResponse; import com.aliens.backend.email.domain.EmailAuthentication; import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; -import com.aliens.backend.global.encode.SymmetricKeyEncoder; +import com.aliens.backend.member.sevice.SymmetricKeyEncoder; import com.aliens.backend.global.error.EmailError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.member.controller.dto.event.TemporaryPasswordEvent; diff --git a/src/main/java/com/aliens/backend/member/domain/Image.java b/src/main/java/com/aliens/backend/member/domain/Image.java index 25ea0fc6..5269853c 100644 --- a/src/main/java/com/aliens/backend/member/domain/Image.java +++ b/src/main/java/com/aliens/backend/member/domain/Image.java @@ -1,6 +1,6 @@ package com.aliens.backend.member.domain; -import com.aliens.backend.uploader.S3File; +import com.aliens.backend.uploader.dto.S3File; import jakarta.persistence.*; @Entity diff --git a/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java b/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java index 61a3e966..18a90e14 100644 --- a/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java +++ b/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java @@ -6,7 +6,6 @@ import com.aliens.backend.auth.service.PasswordEncoder; import com.aliens.backend.email.domain.EmailAuthentication; import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; -import com.aliens.backend.global.encode.SymmetricKeyEncoder; import com.aliens.backend.global.error.EmailError; import com.aliens.backend.global.error.MemberError; import com.aliens.backend.global.exception.RestApiException; @@ -20,7 +19,7 @@ import com.aliens.backend.member.domain.*; import com.aliens.backend.member.domain.repository.MemberInfoRepository; import com.aliens.backend.uploader.AwsS3Uploader; -import com.aliens.backend.uploader.S3File; +import com.aliens.backend.uploader.dto.S3File; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/aliens/backend/global/encode/SymmetricKeyEncoder.java b/src/main/java/com/aliens/backend/member/sevice/SymmetricKeyEncoder.java similarity index 97% rename from src/main/java/com/aliens/backend/global/encode/SymmetricKeyEncoder.java rename to src/main/java/com/aliens/backend/member/sevice/SymmetricKeyEncoder.java index 050c0b35..e82e9863 100644 --- a/src/main/java/com/aliens/backend/global/encode/SymmetricKeyEncoder.java +++ b/src/main/java/com/aliens/backend/member/sevice/SymmetricKeyEncoder.java @@ -1,4 +1,4 @@ -package com.aliens.backend.global.encode; +package com.aliens.backend.member.sevice; import com.aliens.backend.global.error.CommonError; import com.aliens.backend.global.exception.RestApiException; diff --git a/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java b/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java index eb9b010f..5d2af253 100644 --- a/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java +++ b/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java @@ -1,6 +1,7 @@ package com.aliens.backend.uploader; import com.aliens.backend.global.property.S3UploadProperties; +import com.aliens.backend.uploader.dto.S3File; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.ObjectMetadata; import org.springframework.http.MediaType; diff --git a/src/main/java/com/aliens/backend/uploader/S3File.java b/src/main/java/com/aliens/backend/uploader/dto/S3File.java similarity index 59% rename from src/main/java/com/aliens/backend/uploader/S3File.java rename to src/main/java/com/aliens/backend/uploader/dto/S3File.java index 01da091a..f83e5c08 100644 --- a/src/main/java/com/aliens/backend/uploader/S3File.java +++ b/src/main/java/com/aliens/backend/uploader/dto/S3File.java @@ -1,4 +1,4 @@ -package com.aliens.backend.uploader; +package com.aliens.backend.uploader.dto; public record S3File(String fileName, String fileURL) { } diff --git a/src/main/java/com/aliens/backend/uploader/UploadFileRequest.java b/src/main/java/com/aliens/backend/uploader/dto/UploadFileRequest.java similarity index 77% rename from src/main/java/com/aliens/backend/uploader/UploadFileRequest.java rename to src/main/java/com/aliens/backend/uploader/dto/UploadFileRequest.java index cc449d7e..9d38c509 100644 --- a/src/main/java/com/aliens/backend/uploader/UploadFileRequest.java +++ b/src/main/java/com/aliens/backend/uploader/dto/UploadFileRequest.java @@ -1,4 +1,4 @@ -package com.aliens.backend.uploader; +package com.aliens.backend.uploader.dto; import org.springframework.web.multipart.MultipartFile; diff --git a/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java b/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java index 332a3eb5..4974c72f 100644 --- a/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java +++ b/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java @@ -9,7 +9,7 @@ import com.aliens.backend.member.controller.dto.EncodedSignUp; import com.aliens.backend.member.domain.Image; import com.aliens.backend.member.domain.repository.ImageRepository; -import com.aliens.backend.uploader.S3File; +import com.aliens.backend.uploader.dto.S3File; import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; diff --git a/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java b/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java index 03b8958f..6efee77c 100644 --- a/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java +++ b/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java @@ -3,7 +3,7 @@ import com.aliens.backend.email.controller.response.EmailResponse; import com.aliens.backend.email.domain.EmailAuthentication; import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; -import com.aliens.backend.global.encode.SymmetricKeyEncoder; +import com.aliens.backend.member.sevice.SymmetricKeyEncoder; import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; diff --git a/src/test/java/com/aliens/backend/encode/SymmetricKeyEncoderTest.java b/src/test/java/com/aliens/backend/encode/SymmetricKeyEncoderTest.java index 85d6386f..c98d61aa 100644 --- a/src/test/java/com/aliens/backend/encode/SymmetricKeyEncoderTest.java +++ b/src/test/java/com/aliens/backend/encode/SymmetricKeyEncoderTest.java @@ -1,6 +1,6 @@ package com.aliens.backend.encode; -import com.aliens.backend.global.encode.SymmetricKeyEncoder; +import com.aliens.backend.member.sevice.SymmetricKeyEncoder; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java b/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java index 13f06680..11d7a82e 100644 --- a/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java +++ b/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java @@ -6,7 +6,7 @@ import com.aliens.backend.auth.service.PasswordEncoder; import com.aliens.backend.email.domain.EmailAuthentication; import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; -import com.aliens.backend.global.encode.SymmetricKeyEncoder; +import com.aliens.backend.member.sevice.SymmetricKeyEncoder; import com.aliens.backend.member.controller.dto.*; import com.aliens.backend.member.controller.dto.request.SignUpRequest; import com.aliens.backend.member.controller.dto.request.TemporaryPasswordRequest; @@ -19,7 +19,7 @@ import com.aliens.backend.member.domain.MemberStatus; import com.aliens.backend.member.sevice.MemberInfoService; import com.aliens.backend.uploader.AwsS3Uploader; -import com.aliens.backend.uploader.S3File; +import com.aliens.backend.uploader.dto.S3File; import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; diff --git a/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java b/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java index fc8b93a0..91766f73 100644 --- a/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java +++ b/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java @@ -1,5 +1,6 @@ package com.aliens.backend.uploader; +import com.aliens.backend.uploader.dto.S3File; import io.findify.s3mock.S3Mock; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; From ba61083a1b58c374665bec14a879e6bf0ae8efda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sun, 28 Jan 2024 21:03:47 +0900 Subject: [PATCH 042/215] =?UTF-8?q?chore(build.gradle):=20FCM=20=EC=9D=84?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index 7348fc68..15e8bbdb 100644 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,9 @@ dependencies { //SMTP implementation 'org.springframework.boot:spring-boot-starter-mail' + + //FCM + implementation 'com.google.firebase:firebase-admin:9.1.1' } ext { From 149d147eede9b9622c3c08dd84122a3ddbfd9e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 29 Jan 2024 00:49:18 +0900 Subject: [PATCH 043/215] =?UTF-8?q?feat(CommonError):=20FCM=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EB=B0=8F=20=EC=A0=84=EC=86=A1=20=EC=8B=A4=ED=8C=A8?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/aliens/backend/global/error/CommonError.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/global/error/CommonError.java b/src/main/java/com/aliens/backend/global/error/CommonError.java index d710d59a..d35b30df 100644 --- a/src/main/java/com/aliens/backend/global/error/CommonError.java +++ b/src/main/java/com/aliens/backend/global/error/CommonError.java @@ -5,7 +5,9 @@ public enum CommonError implements ErrorCode { INTERNAL_SERVER_ERROR(HttpStatus.NOT_FOUND, "S1", "에러"), - ENCODE_ERROR(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,"S2" ,"암-복호화 실패" ); + ENCODE_ERROR(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,"S2" ,"암-복호화 실패" ), + FCM_MESSAGING_ERROR(HttpStatus.NOT_FOUND, "S3" ,"FCM 전송 실패" ), + FCM_CONFIGURATION_ERROR(HttpStatus.NOT_FOUND, "S4" ,"FCM 설정 에러" ); private final HttpStatus httpStatusCode; private final String developCode; From 8b39aaa1a3f03f0e93ac70505e37310871896510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 29 Jan 2024 00:49:48 +0900 Subject: [PATCH 044/215] =?UTF-8?q?feat(FCMConfig):=20FCM=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/config/FCMConfig.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/config/FCMConfig.java diff --git a/src/main/java/com/aliens/backend/global/config/FCMConfig.java b/src/main/java/com/aliens/backend/global/config/FCMConfig.java new file mode 100644 index 00000000..0201390a --- /dev/null +++ b/src/main/java/com/aliens/backend/global/config/FCMConfig.java @@ -0,0 +1,34 @@ +package com.aliens.backend.global.config; + +import com.aliens.backend.global.error.CommonError; +import com.aliens.backend.global.exception.RestApiException; +import com.google.auth.oauth2.GoogleCredentials; +import com.google.firebase.FirebaseApp; +import com.google.firebase.FirebaseOptions; +import jakarta.annotation.PostConstruct; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; + +import java.io.IOException; + +@Configuration +public class FCMConfig{ + + private static final String path = "firebase/firebase_service_key.json"; + + @PostConstruct + public void init() { + try {FirebaseOptions options = FirebaseOptions.builder() + .setCredentials(GoogleCredentials. + fromStream( + new ClassPathResource(path).getInputStream() + ) + ) + .build(); + if (FirebaseApp.getApps().isEmpty()) FirebaseApp.initializeApp(options); + } catch (IOException e) { + e.printStackTrace(); + throw new RestApiException(CommonError.FCM_CONFIGURATION_ERROR); + } + } +} From d8c37b10f7ecfdc7119609694ea30c9adb8b256d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 29 Jan 2024 00:50:08 +0900 Subject: [PATCH 045/215] =?UTF-8?q?test(EventPublisherTest):=20FCM=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=A6=AC=EC=8A=A4=EB=84=88=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/event/EventPublisherTest.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/test/java/com/aliens/backend/event/EventPublisherTest.java diff --git a/src/test/java/com/aliens/backend/event/EventPublisherTest.java b/src/test/java/com/aliens/backend/event/EventPublisherTest.java new file mode 100644 index 00000000..9c18d059 --- /dev/null +++ b/src/test/java/com/aliens/backend/event/EventPublisherTest.java @@ -0,0 +1,56 @@ +package com.aliens.backend.event; + +import com.aliens.backend.notification.FcmSender; +import com.google.firebase.messaging.Message; +import com.google.firebase.messaging.MulticastMessage; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.ApplicationEventPublisher; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.internal.verification.VerificationModeFactory.times; + +@SpringBootTest +class EventPublisherTest { + + @Autowired + ApplicationEventPublisher publisher; + + @MockBean + FcmSender fcmSender; + + String givenType = "normal"; + String giveContent = "content"; + String givenToken = "token"; + + @Test + void listenSingleMessageRequestTest() { + Message givenSingleMessage = Message.builder() + .putData("type", givenType) + .putData("comment", giveContent) + .setToken(givenToken) + .build(); + + publisher.publishEvent(givenSingleMessage); + + verify(fcmSender, times(1)).listenSingleMessageRequest(any()); + } + + @Test + void listenMultiMessageRequestTest() { + MulticastMessage givenSingleMessage = MulticastMessage.builder() + .putData("type", givenType) + .putData("comment", giveContent) + .addAllTokens(List.of(givenToken, givenToken)) + .build(); + + publisher.publishEvent(givenSingleMessage); + + verify(fcmSender, times(1)).listenMultiMessageRequest(any()); + } +} From cc968bb4e65d3511ec1be4374642d7900f197751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 29 Jan 2024 00:50:51 +0900 Subject: [PATCH 046/215] =?UTF-8?q?feat(FcmSender):=20=EB=91=90=20?= =?UTF-8?q?=EA=B0=80=EC=A7=80=20=ED=83=80=EC=9E=85=EC=9D=98=20=ED=8C=8C?= =?UTF-8?q?=EB=9D=BC=EB=AF=B8=ED=84=B0=EB=A5=BC=20=EB=B0=9B=EC=95=84=20FCM?= =?UTF-8?q?=EB=A5=BC=20=EB=B9=84=EB=8F=99=EA=B8=B0=EC=A0=81=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=A0=84=EC=86=A1=ED=95=98=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/notification/FcmSender.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/com/aliens/backend/notification/FcmSender.java diff --git a/src/main/java/com/aliens/backend/notification/FcmSender.java b/src/main/java/com/aliens/backend/notification/FcmSender.java new file mode 100644 index 00000000..3d9d1b67 --- /dev/null +++ b/src/main/java/com/aliens/backend/notification/FcmSender.java @@ -0,0 +1,35 @@ +package com.aliens.backend.notification; + +import com.aliens.backend.global.error.CommonError; +import com.aliens.backend.global.exception.RestApiException; +import com.google.firebase.messaging.FirebaseMessaging; +import com.google.firebase.messaging.Message; +import com.google.firebase.messaging.MulticastMessage; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +@Component +public class FcmSender { + + @EventListener + public void listenSingleMessageRequest(Message message) { + sendSingleMessage(message); + } + + @EventListener + public void listenMultiMessageRequest(MulticastMessage message) { + sendMultiMessage(message); + } + + private void sendSingleMessage(Message message) { + FirebaseMessaging.getInstance().sendAsync(message); + } + + private void sendMultiMessage(MulticastMessage message) { + try { + FirebaseMessaging.getInstance().sendMulticastAsync(message); + } catch (Exception e) { + throw new RestApiException(CommonError.FCM_MESSAGING_ERROR); + } + } +} From b3d7f65a887b07174ce2d472aad1cb5400661374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 29 Jan 2024 00:58:58 +0900 Subject: [PATCH 047/215] =?UTF-8?q?refactor(FCMConfig):=20firebase=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC=EC=9D=84=20=EC=9C=84=ED=95=9C=20key=20Json?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EA=B2=BD=EB=A1=9C=EB=A5=BC=20properties?= =?UTF-8?q?=20=EA=B0=9D=EC=B2=B4=EB=A1=9C=20=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/global/config/FCMConfig.java | 9 +++++++-- .../backend/global/property/FCMProperties.java | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/aliens/backend/global/property/FCMProperties.java diff --git a/src/main/java/com/aliens/backend/global/config/FCMConfig.java b/src/main/java/com/aliens/backend/global/config/FCMConfig.java index 0201390a..5a8ca532 100644 --- a/src/main/java/com/aliens/backend/global/config/FCMConfig.java +++ b/src/main/java/com/aliens/backend/global/config/FCMConfig.java @@ -2,6 +2,7 @@ import com.aliens.backend.global.error.CommonError; import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.property.FCMProperties; import com.google.auth.oauth2.GoogleCredentials; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; @@ -14,14 +15,18 @@ @Configuration public class FCMConfig{ - private static final String path = "firebase/firebase_service_key.json"; + private final FCMProperties fcmProperties; + + public FCMConfig(final FCMProperties fcmProperties) { + this.fcmProperties = fcmProperties; + } @PostConstruct public void init() { try {FirebaseOptions options = FirebaseOptions.builder() .setCredentials(GoogleCredentials. fromStream( - new ClassPathResource(path).getInputStream() + new ClassPathResource(fcmProperties.getLocationOfFcmJson()).getInputStream() ) ) .build(); diff --git a/src/main/java/com/aliens/backend/global/property/FCMProperties.java b/src/main/java/com/aliens/backend/global/property/FCMProperties.java new file mode 100644 index 00000000..fe0b4153 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/property/FCMProperties.java @@ -0,0 +1,15 @@ +package com.aliens.backend.global.property; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class FCMProperties { + + @Value("${fcm.certification}") + String locationOfFcmJson; + + public String getLocationOfFcmJson() { + return locationOfFcmJson; + } +} From 2bbb2f988ea071d88070fc49f160b1571d6ed632 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Mon, 29 Jan 2024 21:20:04 +0900 Subject: [PATCH 048/215] =?UTF-8?q?chore=20:=20firebase=5Fservice=5Fkey.js?= =?UTF-8?q?on=20=EC=9D=84=20=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/friendship-pipeline.yml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/friendship-pipeline.yml b/.github/workflows/friendship-pipeline.yml index b2dad45b..f6d1b4bf 100644 --- a/.github/workflows/friendship-pipeline.yml +++ b/.github/workflows/friendship-pipeline.yml @@ -18,33 +18,39 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: JDK 17 설치 uses: actions/setup-java@v3 with: java-version: '17' distribution: 'temurin' # 설정 파일 추가 - - name: make application-secret.yml + - name: application-secret.yml 구성 run: | cd ./src/main/resources touch ./application-secret.yml echo "${{ secrets.APPLICATION_SECRET }}" > ./application-secret.yml - - name: Grant execute permission for gradlew + - name: firebase_service_key.json 구성 + run: | + cd ./src/main/resources + touch ./firebase_service_key.json + echo "${{ secrets.FCM_KEY }}" > ./firebase_service_key.json + + - name: gradlew 실행 권한 부여 run: chmod +x gradlew - - name: Build with Gradle - run: ./gradlew build + - name: Gradle 빌드 + run: ./gradlew build -x test - - name: Docker build + - name: Docker 이미지 파일 PUSH run: | docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} docker build --platform linux/arm64/v8 -t app . docker tag app ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}:latest docker push ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}:latest - - name: Deploy + - name: AWS 배포 uses: appleboy/ssh-action@master with: host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS From cca982254da4b37cf2f8396bcc454dff18d2e5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:21:18 +0900 Subject: [PATCH 049/215] =?UTF-8?q?refactor(EventPublisherTest):=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=84=A4=EB=AA=85=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/aliens/backend/event/EventPublisherTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/aliens/backend/event/EventPublisherTest.java b/src/test/java/com/aliens/backend/event/EventPublisherTest.java index 9c18d059..9b8bee44 100644 --- a/src/test/java/com/aliens/backend/event/EventPublisherTest.java +++ b/src/test/java/com/aliens/backend/event/EventPublisherTest.java @@ -3,6 +3,7 @@ import com.aliens.backend.notification.FcmSender; import com.google.firebase.messaging.Message; import com.google.firebase.messaging.MulticastMessage; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -29,6 +30,7 @@ class EventPublisherTest { String givenToken = "token"; @Test + @DisplayName("단일 메시지 이벤트 발행 및 전송 ") void listenSingleMessageRequestTest() { Message givenSingleMessage = Message.builder() .putData("type", givenType) @@ -42,6 +44,7 @@ void listenSingleMessageRequestTest() { } @Test + @DisplayName("다수 메시지 이벤트 발행 및 전송 ") void listenMultiMessageRequestTest() { MulticastMessage givenSingleMessage = MulticastMessage.builder() .putData("type", givenType) From 9ba075311178138958a05a5ebfeb0dcbde5ea05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:22:04 +0900 Subject: [PATCH 050/215] =?UTF-8?q?docs(gitginore):=20firebase=5Fservice?= =?UTF-8?q?=5Fkey.json=20=ED=8C=8C=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 46149dbc..84f99451 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ build/ !**/src/main/**/build/ !**/src/test/**/build/ src/main/resources/application-secret.yml +src/main/resources/firebase_service_key.json ### STS ### .apt_generated From b15a0c1c56718a11298347591dba6f1303f9ae13 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Tue, 30 Jan 2024 13:26:55 +0900 Subject: [PATCH 051/215] =?UTF-8?q?feat(SuccessCode)=20:=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=BD=94=EB=93=9C,=20=EB=A9=94=EC=8B=9C=EC=A7=80?= =?UTF-8?q?=EB=A5=BC=20=EB=8B=B4=EC=9D=84=20=EC=88=98=20=EC=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=BB=A4=EC=8A=A4=ED=85=80=20ResponseEntity=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/success/SuccessCode.java | 9 +++++++ .../global/success/SuccessResponse.java | 21 +++++++++++++++ .../success/SuccessResponseWithoutResult.java | 26 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/success/SuccessCode.java create mode 100644 src/main/java/com/aliens/backend/global/success/SuccessResponse.java create mode 100644 src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java diff --git a/src/main/java/com/aliens/backend/global/success/SuccessCode.java b/src/main/java/com/aliens/backend/global/success/SuccessCode.java new file mode 100644 index 00000000..517468fe --- /dev/null +++ b/src/main/java/com/aliens/backend/global/success/SuccessCode.java @@ -0,0 +1,9 @@ +package com.aliens.backend.global.success; + +import org.springframework.http.HttpStatus; + +public interface SuccessCode { + HttpStatus getHttpStatus(); + String getCode(); + String getMessage(); +} diff --git a/src/main/java/com/aliens/backend/global/success/SuccessResponse.java b/src/main/java/com/aliens/backend/global/success/SuccessResponse.java new file mode 100644 index 00000000..43164c45 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/success/SuccessResponse.java @@ -0,0 +1,21 @@ +package com.aliens.backend.global.success; + +import org.springframework.http.ResponseEntity; + +public class SuccessResponse { + + private String code; + private String message; + private T result; + + public SuccessResponse(final String code, final String message, final T result) { + this.code = code; + this.message = message; + this.result = result; + } + + public static ResponseEntity toResponseEntity(SuccessCode successCode, Object result) { + SuccessResponse res = new SuccessResponse(successCode.getCode(), successCode.getMessage(), result); + return new ResponseEntity<>(res, successCode.getHttpStatus()); + } +} diff --git a/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java b/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java new file mode 100644 index 00000000..0e95ce51 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java @@ -0,0 +1,26 @@ +package com.aliens.backend.global.success; + +import org.springframework.http.ResponseEntity; + +public class SuccessResponseWithoutResult { + private String code; + private String message; + + public SuccessResponseWithoutResult(final String code, final String message) { + this.code = code; + this.message = message; + } + + public static ResponseEntity toResponseEntity(SuccessCode successCode) { + SuccessResponseWithoutResult res = new SuccessResponseWithoutResult(successCode.getCode(), successCode.getMessage()); + return new ResponseEntity<>(res, successCode.getHttpStatus()); + } + + public String getCode() { + return code; + } + + public String getMessage() { + return message; + } +} From 52ecce47b8e9da11eec4766f812ff07f45821103 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Tue, 30 Jan 2024 13:35:17 +0900 Subject: [PATCH 052/215] =?UTF-8?q?build=20:=20matching=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20=EB=B3=80=EC=88=98=20=ED=8C=8C=EC=9D=BC=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-matching.yml | 16 ++++++++++++++++ src/main/resources/application.yml | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/application-matching.yml diff --git a/src/main/resources/application-matching.yml b/src/main/resources/application-matching.yml new file mode 100644 index 00000000..10e7b596 --- /dev/null +++ b/src/main/resources/application-matching.yml @@ -0,0 +1,16 @@ +matching: + round: + update-date: 0 0 0 * * MON,THU + start: 0 0 18 ? * MON,THU" + request: + time: + hours: 18 + valid: + time: + hours: 20 + day-of-week: + if: + monday: + hours: 52 + thursday: + hours: 76 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f266cd1d..ccaebcd4 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,4 +10,4 @@ spring: defer-datasource-initialization: true profiles: - include: secret + include: secret, matching From f5e37aabf0ff3b458ad9be9907eeceed4550d13e Mon Sep 17 00:00:00 2001 From: Oniqued Date: Tue, 30 Jan 2024 14:05:53 +0900 Subject: [PATCH 053/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20properties=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../property/MatchingTimeProperties.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java diff --git a/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java b/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java new file mode 100644 index 00000000..d9a4e367 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java @@ -0,0 +1,44 @@ +package com.aliens.backend.global.property; + +import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.exception.RestApiException; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.time.DayOfWeek; + +@Component +public class MatchingTimeProperties { + @Value("${matching.request.time.hours}") + private String matchingRequestAvailableTime; + + @Value("${matching.valid.time.hours}") + private String matchingValidBeginHours; + + @Value("${matching.valid.day-of-week.if.monday.hours}") + private String mondayMatchingValidHours; + + @Value("${matching.valid.day-of-week.if.thursday.hours}") + private String thursdayMatchingValidHours; + + @Value("${matching.valid.day-of-week.if.default.hours}") + private String defaultMatchingValidHours; + + public Long getMatchingRequestAvailableTime() { + return Long.parseLong(matchingRequestAvailableTime); + } + + public Integer getMatchingValidBeginHours() { + return Integer.parseInt(matchingValidBeginHours); + } + + public Long getMatchingValidHours(DayOfWeek dayOfWeek) { + if (dayOfWeek.equals(DayOfWeek.MONDAY)) { + return Long.parseLong(mondayMatchingValidHours); + } + if (dayOfWeek.equals(DayOfWeek.THURSDAY)) { + return Long.parseLong(thursdayMatchingValidHours); + } + return Long.parseLong(defaultMatchingValidHours); + } +} From 868ca9d4c2a3dece0787cd6aa547e1f38b7dc3c3 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Tue, 30 Jan 2024 14:06:03 +0900 Subject: [PATCH 054/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20properties=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-matching.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/application-matching.yml b/src/main/resources/application-matching.yml index 10e7b596..85f83cc3 100644 --- a/src/main/resources/application-matching.yml +++ b/src/main/resources/application-matching.yml @@ -10,6 +10,8 @@ matching: hours: 20 day-of-week: if: + default: + hours: 48 monday: hours: 52 thursday: From 1dc5da4e54e3bdaed571420f96325bff55094f7f Mon Sep 17 00:00:00 2001 From: Oniqued Date: Tue, 30 Jan 2024 14:36:27 +0900 Subject: [PATCH 055/215] =?UTF-8?q?feat=20:=20=EC=9B=94,=20=EB=AA=A9?= =?UTF-8?q?=EC=9A=94=EC=9D=BC=EC=97=90=20=EB=A7=A4=EC=B9=AD=20=ED=9A=8C?= =?UTF-8?q?=EC=B0=A8=EB=A5=BC=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/MatchingRoundRepository.java | 14 ++++++++++ .../service/MatchingRoundService.java | 28 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingRoundRepository.java create mode 100644 src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java diff --git a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingRoundRepository.java b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingRoundRepository.java new file mode 100644 index 00000000..af5f1431 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingRoundRepository.java @@ -0,0 +1,14 @@ +package com.aliens.backend.mathcing.domain.repository; + +import com.aliens.backend.mathcing.domain.MatchingRound; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface MatchingRoundRepository extends JpaRepository { + @Query("SELECT mr FROM MatchingRound mr ORDER BY mr.round DESC") + Optional findCurrentRound(); +} diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java new file mode 100644 index 00000000..dfaa0d35 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java @@ -0,0 +1,28 @@ +package com.aliens.backend.mathcing.service; + +import com.aliens.backend.global.property.MatchingTimeProperties; +import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; + +@Service +public class MatchingRoundService { + private MatchingRoundRepository matchingRoundRepository; + private MatchingTimeProperties matchingTimeProperties; + + @Autowired + public MatchingRoundService(final MatchingRoundRepository matchingRoundRepository, + final MatchingTimeProperties matchingTimeProperties) { + this.matchingRoundRepository = matchingRoundRepository; + this.matchingTimeProperties = matchingTimeProperties; + } + + @Scheduled(cron = "${matching.round.update-date}") + private void saveMatchRound() { + matchingRoundRepository.save(MatchingRound.of(LocalDateTime.now(), matchingTimeProperties)); + } +} From ef300971ae04b67a747b268138cd0edd2b564781 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 31 Jan 2024 16:23:49 +0900 Subject: [PATCH 056/215] =?UTF-8?q?feat=20:=20=EC=9B=94,=20=EB=AA=A9?= =?UTF-8?q?=EC=9A=94=EC=9D=BC=EC=97=90=20=EB=A7=A4=EC=B9=AD=20=ED=9A=8C?= =?UTF-8?q?=EC=B0=A8=EB=A5=BC=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B0=9C=EB=B0=9C=20?= =?UTF-8?q?=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/error/MatchingError.java | 34 +++++++++ .../mathcing/domain/MatchingRound.java | 70 +++++++++++++++++++ .../service/MatchingRoundServiceTest.java | 51 ++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/error/MatchingError.java create mode 100644 src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java create mode 100644 src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java diff --git a/src/main/java/com/aliens/backend/global/error/MatchingError.java b/src/main/java/com/aliens/backend/global/error/MatchingError.java new file mode 100644 index 00000000..eedf9f0d --- /dev/null +++ b/src/main/java/com/aliens/backend/global/error/MatchingError.java @@ -0,0 +1,34 @@ +package com.aliens.backend.global.error; + +import org.springframework.http.HttpStatus; + +public enum MatchingError implements ErrorCode { + NOT_FOUND_MATCHING_ROUND(HttpStatus.NOT_FOUND, "MA1", "매칭 회차를 찾을 수 없음"), + INVALID_MATCHING_TIME(HttpStatus.BAD_REQUEST, "MA2", "올바르지 않은 매칭 시간") + ; + + private final HttpStatus httpStatusCode; + private final String developCode; + private final String message; + + MatchingError(final HttpStatus httpStatusCode, final String developCode, final String message) { + this.httpStatusCode = httpStatusCode; + this.developCode = developCode; + this.message = message; + } + + @Override + public HttpStatus getHttpStatus() { + return httpStatusCode; + } + + @Override + public String getDevelopCode() { + return developCode; + } + + @Override + public String getMessage() { + return message; + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java new file mode 100644 index 00000000..68078c9e --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java @@ -0,0 +1,70 @@ +package com.aliens.backend.mathcing.domain; + +import com.aliens.backend.global.property.MatchingTimeProperties; +import jakarta.persistence.*; + +import java.time.DayOfWeek; +import java.time.LocalDateTime; + +@Entity +public class MatchingRound { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long round; + + @Column(name = "matching_request_start_time") + private LocalDateTime matchingRequestStartTime; + + @Column(name = "matching_request_end_time") + private LocalDateTime matchingRequestEndTime; + + @Column(name = "matching_valid_start_time") + private LocalDateTime matchingValidStartTime; + + @Column(name = "matching_valid_end_time") + private LocalDateTime matchingValidEndTime; + + protected MatchingRound() { + } + + public Long getRound() { + return round; + } + + public LocalDateTime getMatchingRequestStartTime() { + return matchingRequestStartTime; + } + + public LocalDateTime getMatchingRequestEndTime() { + return matchingRequestEndTime; + } + + public LocalDateTime getMatchingValidStartTime() { + return matchingValidStartTime; + } + + public LocalDateTime getMatchingValidEndTime() { + return matchingValidEndTime; + } + + public MatchingRound(final LocalDateTime matchingRequestStartTime, + final LocalDateTime matchingRequestEndTime, + final LocalDateTime matchingValidStartTime, + final LocalDateTime matchingValidEndTime) { + this.matchingRequestStartTime = matchingRequestStartTime; + this.matchingRequestEndTime = matchingRequestEndTime; + this.matchingValidStartTime = matchingValidStartTime; + this.matchingValidEndTime = matchingValidEndTime; + } + + public static MatchingRound of(LocalDateTime today, MatchingTimeProperties matchingTimeProperties) { + DayOfWeek dayOfWeek = today.getDayOfWeek(); + + LocalDateTime matchingRequestStartTime = today.withHour(0).withMinute(0).withSecond(0).withNano(0); + LocalDateTime matchingRequestEndTime = matchingRequestStartTime.plusHours(matchingTimeProperties.getMatchingRequestAvailableTime()); + LocalDateTime matchingValidStartTime = today.withHour(matchingTimeProperties.getMatchingValidBeginHours()).withMinute(0).withSecond(0).withNano(0); + LocalDateTime matchingValidEndTime = matchingValidStartTime.plusHours(matchingTimeProperties.getMatchingValidHours(dayOfWeek)); + + return new MatchingRound(matchingRequestStartTime, matchingRequestEndTime, matchingValidStartTime, matchingValidEndTime); + } +} diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java b/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java new file mode 100644 index 00000000..15cf15ea --- /dev/null +++ b/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java @@ -0,0 +1,51 @@ +package com.aliens.backend.matching.service; + +import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.property.MatchingTimeProperties; +import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.*; + +@SpringBootTest +public class MatchingRoundServiceTest { + @Autowired + MatchingRoundRepository matchingRoundRepository; + + @Autowired + MatchingTimeProperties matchingTimeProperties; + + @Test + @DisplayName("매주 월, 목 매칭 회차 업데이트") + @Transactional + void saveMatchRoundTest() { + MatchingRound result = saveMatchRound(); + + assertThat(result.getRound()).isNotNull(); + } + + @Test + @DisplayName("현재 매칭 회차 조회") + @Transactional + void getCurrentRound() { + saveMatchRound(); + + MatchingRound result = matchingRoundRepository.findCurrentRound() + .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + + assertThat(result.getRound()).isNotNull(); + } + + private MatchingRound saveMatchRound() { + LocalDateTime monday = LocalDateTime.of(2024, 1, 29, 0, 0); + return matchingRoundRepository.save(MatchingRound.of(monday, matchingTimeProperties)); + } +} From f86312cc02fc4ebbb2da70da0b27c81b7e0494f2 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 31 Jan 2024 16:31:09 +0900 Subject: [PATCH 057/215] =?UTF-8?q?fix=20:=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=EC=97=90=20final=20=ED=82=A4=EC=9B=8C=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/global/property/MatchingTimeProperties.java | 2 +- .../java/com/aliens/backend/global/success/SuccessResponse.java | 2 +- .../backend/global/success/SuccessResponseWithoutResult.java | 2 +- .../java/com/aliens/backend/mathcing/domain/MatchingRound.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java b/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java index d9a4e367..7be71410 100644 --- a/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java +++ b/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java @@ -32,7 +32,7 @@ public Integer getMatchingValidBeginHours() { return Integer.parseInt(matchingValidBeginHours); } - public Long getMatchingValidHours(DayOfWeek dayOfWeek) { + public Long getMatchingValidHours(final DayOfWeek dayOfWeek) { if (dayOfWeek.equals(DayOfWeek.MONDAY)) { return Long.parseLong(mondayMatchingValidHours); } diff --git a/src/main/java/com/aliens/backend/global/success/SuccessResponse.java b/src/main/java/com/aliens/backend/global/success/SuccessResponse.java index 43164c45..3d5aed23 100644 --- a/src/main/java/com/aliens/backend/global/success/SuccessResponse.java +++ b/src/main/java/com/aliens/backend/global/success/SuccessResponse.java @@ -14,7 +14,7 @@ public SuccessResponse(final String code, final String message, final T result) this.result = result; } - public static ResponseEntity toResponseEntity(SuccessCode successCode, Object result) { + public static ResponseEntity toResponseEntity(final SuccessCode successCode, final Object result) { SuccessResponse res = new SuccessResponse(successCode.getCode(), successCode.getMessage(), result); return new ResponseEntity<>(res, successCode.getHttpStatus()); } diff --git a/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java b/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java index 0e95ce51..f35282a1 100644 --- a/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java +++ b/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java @@ -11,7 +11,7 @@ public SuccessResponseWithoutResult(final String code, final String message) { this.message = message; } - public static ResponseEntity toResponseEntity(SuccessCode successCode) { + public static ResponseEntity toResponseEntity(final SuccessCode successCode) { SuccessResponseWithoutResult res = new SuccessResponseWithoutResult(successCode.getCode(), successCode.getMessage()); return new ResponseEntity<>(res, successCode.getHttpStatus()); } diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java index 68078c9e..6f040518 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java @@ -57,7 +57,7 @@ public MatchingRound(final LocalDateTime matchingRequestStartTime, this.matchingValidEndTime = matchingValidEndTime; } - public static MatchingRound of(LocalDateTime today, MatchingTimeProperties matchingTimeProperties) { + public static MatchingRound of(final LocalDateTime today, final MatchingTimeProperties matchingTimeProperties) { DayOfWeek dayOfWeek = today.getDayOfWeek(); LocalDateTime matchingRequestStartTime = today.withHour(0).withMinute(0).withSecond(0).withNano(0); From 8c62b6259072282e7a4498a79cf17139f43c0f2f Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 31 Jan 2024 18:38:14 +0900 Subject: [PATCH 058/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/success/MatchingSuccessCode.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java diff --git a/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java b/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java new file mode 100644 index 00000000..2dafd4fa --- /dev/null +++ b/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java @@ -0,0 +1,35 @@ +package com.aliens.backend.global.success; + +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.*; + +public enum MatchingSuccessCode implements SuccessCode { + APPLY_MATCHING_SUCCESS(CREATED, "MA001", "매칭 신청 성공"), + ; + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + MatchingSuccessCode(final HttpStatus httpStatus, final String code, final String message) { + this.httpStatus = httpStatus; + this.code = code; + this.message = message; + } + + @Override + public HttpStatus getHttpStatus() { + return httpStatus; + } + + @Override + public String getCode() { + return code; + } + + @Override + public String getMessage() { + return message; + } +} From ebeef9932f8e9333b5b84303f34bcca2534d584c Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 31 Jan 2024 20:04:28 +0900 Subject: [PATCH 059/215] =?UTF-8?q?feat=20:=20Input,=20Request=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dto/input/MatchingInput.java | 22 +++++++++++ .../dto/request/MatchingRequest.java | 37 +++++++++++++++++++ .../mathcing/service/model/Language.java | 9 +++++ 3 files changed, 68 insertions(+) create mode 100644 src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java create mode 100644 src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java create mode 100644 src/main/java/com/aliens/backend/mathcing/service/model/Language.java diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java new file mode 100644 index 00000000..5d003f58 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java @@ -0,0 +1,22 @@ +package com.aliens.backend.mathcing.controller.dto.input; + +import com.aliens.backend.mathcing.service.model.Language; + +import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; + +public class MatchingInput { + + public static class MatchingApplicationInput { + private Language firstPreferLanguage; + private Language secondPreferLanguage; + + public MatchingApplicationInput(final Language firstPreferLanguage, final Language secondPreferLanguage) { + this.firstPreferLanguage = firstPreferLanguage; + this.secondPreferLanguage = secondPreferLanguage; + } + + public MatchingApplicationRequest toRequest(final Long memberId){ + return new MatchingApplicationRequest(memberId, firstPreferLanguage, secondPreferLanguage); + } + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java new file mode 100644 index 00000000..fa905785 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java @@ -0,0 +1,37 @@ +package com.aliens.backend.mathcing.controller.dto.request; + +import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.service.model.Language; + +public class MatchingRequest { + public static class MatchingApplicationRequest { + private Long memberId; + private Language firstPreferLanguage; + private Language secondPreferLanguage; + + public MatchingApplicationRequest(final Long memberId, + final Language firstPreferLanguage, + final Language secondPreferLanguage) { + this.memberId = memberId; + this.firstPreferLanguage = firstPreferLanguage; + this.secondPreferLanguage = secondPreferLanguage; + } + + public MatchingApplication toEntity(MatchingRound matchingRound) { + return MatchingApplication.of(matchingRound, memberId, firstPreferLanguage, secondPreferLanguage); + } + + public Long getMemberId() { + return memberId; + } + + public Language getFirstPreferLanguage() { + return firstPreferLanguage; + } + + public Language getSecondPreferLanguage() { + return secondPreferLanguage; + } + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Language.java b/src/main/java/com/aliens/backend/mathcing/service/model/Language.java new file mode 100644 index 00000000..528408d7 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/service/model/Language.java @@ -0,0 +1,9 @@ +package com.aliens.backend.mathcing.service.model; + +public enum Language { + KOREAN, + ENGLISH, + JAPANESE, + CHINESE + ; +} From 50ee4a6e431f5e16518afbeda3fc63094e4e5c9c Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 31 Jan 2024 20:08:31 +0900 Subject: [PATCH 060/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20controller=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MatchingController.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java diff --git a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java new file mode 100644 index 00000000..87407ed4 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java @@ -0,0 +1,33 @@ +package com.aliens.backend.mathcing.controller; + +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.global.config.resolver.Login; +import com.aliens.backend.global.success.MatchingSuccessCode; +import com.aliens.backend.global.success.SuccessResponseWithoutResult; +import com.aliens.backend.mathcing.service.MatchingApplicationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static com.aliens.backend.mathcing.controller.dto.input.MatchingInput.*; + +@RestController +@RequestMapping("/matchings") +public class MatchingController { + private final MatchingApplicationService matchingApplicationService; + + @Autowired + public MatchingController(final MatchingApplicationService matchingApplicationService) { + this.matchingApplicationService = matchingApplicationService; + } + + @PostMapping("/applications") + public ResponseEntity applyMatch(@Login LoginMember loginMember, + @RequestBody MatchingApplicationInput matchingApplicationInput) { + matchingApplicationService.saveParticipant(matchingApplicationInput.toRequest(loginMember.memberId())); + return SuccessResponseWithoutResult.toResponseEntity(MatchingSuccessCode.APPLY_MATCHING_SUCCESS); + } +} From 2c6423aaf782afdd039770a93e6b042ba0db123d Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 31 Jan 2024 20:08:52 +0900 Subject: [PATCH 061/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/domain/MatchingApplication.java | 64 +++++++++++++++++++ .../domain/id/MatchingApplicationId.java | 40 ++++++++++++ .../MatchingApplicationRepository.java | 10 +++ .../service/MatchingApplicationService.java | 32 ++++++++++ .../MatchingApplicationServiceTest.java | 4 ++ 5 files changed, 150 insertions(+) create mode 100644 src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java create mode 100644 src/main/java/com/aliens/backend/mathcing/domain/id/MatchingApplicationId.java create mode 100644 src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingApplicationRepository.java create mode 100644 src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java create mode 100644 src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java new file mode 100644 index 00000000..67d50cc0 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java @@ -0,0 +1,64 @@ +package com.aliens.backend.mathcing.domain; + +import com.aliens.backend.mathcing.controller.dto.request.MatchingRequest; +import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; +import com.aliens.backend.mathcing.service.model.Language; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; + +import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; + +@Entity +public class MatchingApplication { + @EmbeddedId + private MatchingApplicationId matchingApplicationId; + + @Enumerated(EnumType.STRING) + private Language firstPreferLanguage; + + @Enumerated(EnumType.STRING) + private Language secondPreferLanguage; + + protected MatchingApplication() { + } + + public MatchingApplication(final MatchingApplicationId matchingApplicationId, + final Language firstPreferLanguage, + final Language secondPreferLanguage) { + this.matchingApplicationId = matchingApplicationId; + this.firstPreferLanguage = firstPreferLanguage; + this.secondPreferLanguage = secondPreferLanguage; + } + + public MatchingApplicationId getMatchingApplicationId() { + return matchingApplicationId; + } + + public Language getFirstPreferLanguage() { + return firstPreferLanguage; + } + + public Language getSecondPreferLanguage() { + return secondPreferLanguage; + } + + public static MatchingApplication of(final MatchingRound matchingRound, + final Long memberId, + final Language firstPreferLanguage, final Language secondPreferLanguage) { + return new MatchingApplication( + new MatchingApplicationId(matchingRound, memberId), + firstPreferLanguage, secondPreferLanguage); + } + + @Override + public String toString() { + return "MatchingApplication{" + + "matchingApplicationId=" + matchingApplicationId + + ", firstLanguage=" + firstPreferLanguage + + ", secondLanguage=" + secondPreferLanguage + + '}'; + } +} + diff --git a/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingApplicationId.java b/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingApplicationId.java new file mode 100644 index 00000000..14732ee0 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingApplicationId.java @@ -0,0 +1,40 @@ +package com.aliens.backend.mathcing.domain.id; + +import com.aliens.backend.mathcing.domain.MatchingRound; +import jakarta.persistence.*; + +import java.io.Serializable; + +@Embeddable +public class MatchingApplicationId implements Serializable { + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "matching_round") + private MatchingRound matchingRound; + + @Column(name = "member_id") + private Long memberId; + + protected MatchingApplicationId() { + } + + public MatchingApplicationId(final MatchingRound matchingRound, final Long memberId) { + this.matchingRound = matchingRound; + this.memberId = memberId; + } + + public MatchingRound getMatchingRound() { + return matchingRound; + } + + public Long getMemberId() { + return memberId; + } + + @Override + public String toString() { + return "MatchingApplicationId{" + + "matchingRound=" + matchingRound + + ", memberId=" + memberId + + '}'; + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingApplicationRepository.java b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingApplicationRepository.java new file mode 100644 index 00000000..d87c0df0 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingApplicationRepository.java @@ -0,0 +1,10 @@ +package com.aliens.backend.mathcing.domain.repository; + +import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface MatchingApplicationRepository extends JpaRepository { +} diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java new file mode 100644 index 00000000..17e82399 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -0,0 +1,32 @@ +package com.aliens.backend.mathcing.service; + +import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; +import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; + +@Service +public class MatchingApplicationService { + private MatchingApplicationRepository matchingApplicationRepository; + private MatchingRoundRepository matchingRoundRepository; + + @Autowired + public MatchingApplicationService(final MatchingApplicationRepository matchingApplicationRepository, + final MatchingRoundRepository matchingRoundRepository) { + this.matchingApplicationRepository = matchingApplicationRepository; + this.matchingRoundRepository = matchingRoundRepository; + } + + @Transactional + public void saveParticipant(final MatchingApplicationRequest matchingApplicationRequest) { + MatchingRound currentRound = matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + matchingApplicationRepository.save(matchingApplicationRequest.toEntity(currentRound)); + } +} diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java new file mode 100644 index 00000000..fe1d8296 --- /dev/null +++ b/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java @@ -0,0 +1,4 @@ +package com.aliens.backend.matching.service; + +public class MatchingApplicationServiceTest { +} From 90daefc1108d8c862c2ce84049386f303475d653 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 31 Jan 2024 20:38:04 +0900 Subject: [PATCH 062/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EA=B0=80=EB=8A=A5=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EB=8C=80=20=ED=99=95=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/error/MatchingError.java | 3 ++- .../controller/MatchingController.java | 4 ++-- .../service/MatchingApplicationService.java | 14 +++++++++---- .../MatchingApplicationValidator.java | 20 +++++++++++++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java diff --git a/src/main/java/com/aliens/backend/global/error/MatchingError.java b/src/main/java/com/aliens/backend/global/error/MatchingError.java index eedf9f0d..3713e201 100644 --- a/src/main/java/com/aliens/backend/global/error/MatchingError.java +++ b/src/main/java/com/aliens/backend/global/error/MatchingError.java @@ -4,7 +4,8 @@ public enum MatchingError implements ErrorCode { NOT_FOUND_MATCHING_ROUND(HttpStatus.NOT_FOUND, "MA1", "매칭 회차를 찾을 수 없음"), - INVALID_MATCHING_TIME(HttpStatus.BAD_REQUEST, "MA2", "올바르지 않은 매칭 시간") + NOT_VALID_MATCHING_TIME(HttpStatus.BAD_REQUEST, "MA2", "매칭 시간이 아님"), + ; private final HttpStatus httpStatusCode; diff --git a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java index 87407ed4..8c0aaf6d 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java @@ -25,8 +25,8 @@ public MatchingController(final MatchingApplicationService matchingApplicationSe } @PostMapping("/applications") - public ResponseEntity applyMatch(@Login LoginMember loginMember, - @RequestBody MatchingApplicationInput matchingApplicationInput) { + public ResponseEntity applyMatch(final @Login LoginMember loginMember, + final @RequestBody MatchingApplicationInput matchingApplicationInput) { matchingApplicationService.saveParticipant(matchingApplicationInput.toRequest(loginMember.memberId())); return SuccessResponseWithoutResult.toResponseEntity(MatchingSuccessCode.APPLY_MATCHING_SUCCESS); } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index 17e82399..71a1bf56 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -5,6 +5,7 @@ import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; +import com.aliens.backend.mathcing.validator.MatchingApplicationValidator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -13,20 +14,25 @@ @Service public class MatchingApplicationService { - private MatchingApplicationRepository matchingApplicationRepository; - private MatchingRoundRepository matchingRoundRepository; + private final MatchingApplicationRepository matchingApplicationRepository; + private final MatchingRoundRepository matchingRoundRepository; + private final MatchingApplicationValidator matchingApplicationValidator; @Autowired public MatchingApplicationService(final MatchingApplicationRepository matchingApplicationRepository, - final MatchingRoundRepository matchingRoundRepository) { + final MatchingRoundRepository matchingRoundRepository, + final MatchingApplicationValidator matchingApplicationValidator) { this.matchingApplicationRepository = matchingApplicationRepository; this.matchingRoundRepository = matchingRoundRepository; + this.matchingApplicationValidator = matchingApplicationValidator; } @Transactional public void saveParticipant(final MatchingApplicationRequest matchingApplicationRequest) { MatchingRound currentRound = matchingRoundRepository.findCurrentRound() .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); - matchingApplicationRepository.save(matchingApplicationRequest.toEntity(currentRound)); + if (matchingApplicationValidator.canApplyMatching(currentRound)) { + matchingApplicationRepository.save(matchingApplicationRequest.toEntity(currentRound)); + } } } diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java new file mode 100644 index 00000000..8b51798b --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java @@ -0,0 +1,20 @@ +package com.aliens.backend.mathcing.validator; + +import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.mathcing.domain.MatchingRound; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; + +@Component +public class MatchingApplicationValidator { + public boolean canApplyMatching(MatchingRound matchingRound) { + LocalDateTime now = LocalDateTime.now(); + if (matchingRound.getMatchingRequestStartTime().isAfter(now) && + matchingRound.getMatchingRequestEndTime().isBefore(now)) { + return true; + } + throw new RestApiException(MatchingError.NOT_VALID_MATCHING_TIME); + } +} From c9d758fd945154d7b5471be07a82e5add0fbc3ce Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 31 Jan 2024 21:15:58 +0900 Subject: [PATCH 063/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MatchingApplicationServiceTest.java | 4 -- .../MatchingApplicationServiceTest.java | 69 +++++++++++++++++++ .../service/MatchingRoundServiceTest.java | 13 ++-- 3 files changed, 74 insertions(+), 12 deletions(-) delete mode 100644 src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java create mode 100644 src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java rename src/test/java/com/aliens/backend/matching/{ => unit}/service/MatchingRoundServiceTest.java (82%) diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java deleted file mode 100644 index fe1d8296..00000000 --- a/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.aliens.backend.matching.service; - -public class MatchingApplicationServiceTest { -} diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java new file mode 100644 index 00000000..44926f8b --- /dev/null +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -0,0 +1,69 @@ +package com.aliens.backend.matching.unit.service; + +import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.property.MatchingTimeProperties; +import com.aliens.backend.mathcing.controller.dto.request.MatchingRequest; +import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; +import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; +import com.aliens.backend.mathcing.service.MatchingApplicationService; +import com.aliens.backend.mathcing.service.model.Language; +import com.aliens.backend.mathcing.validator.MatchingApplicationValidator; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mockito.BDDMockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; + +import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; +import static org.mockito.BDDMockito.*; + + +@SpringBootTest +public class MatchingApplicationServiceTest { + @Autowired + MatchingApplicationService matchingApplicationService; + + @Autowired + MatchingApplicationRepository matchingApplicationRepository; + + @Autowired + MatchingRoundRepository matchingRoundRepository; + + @Autowired + MatchingTimeProperties matchingTimeProperties; + + @MockBean + MatchingApplicationValidator matchingApplicationValidator; + + MatchingApplicationRequest matchingApplicationRequest; + MatchingRound currentRound; + + @BeforeEach + @Transactional + void setUp() { + LocalDateTime monday = LocalDateTime.of(2024, 1, 29, 0, 0); + matchingRoundRepository.save(MatchingRound.of(monday, matchingTimeProperties)); + + matchingApplicationRequest = new MatchingApplicationRequest(1L, Language.KOREAN, Language.ENGLISH); + currentRound = matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } + + @Test + @DisplayName("매칭 신청 단위 테스트") + void applyMatchTest() { + given(matchingApplicationValidator.canApplyMatching(currentRound)).willReturn(true); + + matchingApplicationService.saveParticipant(matchingApplicationRequest); + + + } +} diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java similarity index 82% rename from src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java rename to src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java index 15cf15ea..eda9c872 100644 --- a/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java @@ -1,4 +1,4 @@ -package com.aliens.backend.matching.service; +package com.aliens.backend.matching.unit.service; import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; @@ -27,7 +27,8 @@ public class MatchingRoundServiceTest { @DisplayName("매주 월, 목 매칭 회차 업데이트") @Transactional void saveMatchRoundTest() { - MatchingRound result = saveMatchRound(); + LocalDateTime monday = LocalDateTime.of(2024, 1, 29, 0, 0); + MatchingRound result = matchingRoundRepository.save(MatchingRound.of(monday, matchingTimeProperties)); assertThat(result.getRound()).isNotNull(); } @@ -36,16 +37,12 @@ void saveMatchRoundTest() { @DisplayName("현재 매칭 회차 조회") @Transactional void getCurrentRound() { - saveMatchRound(); + LocalDateTime monday = LocalDateTime.of(2024, 1, 29, 0, 0); + matchingRoundRepository.save(MatchingRound.of(monday, matchingTimeProperties)); MatchingRound result = matchingRoundRepository.findCurrentRound() .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); assertThat(result.getRound()).isNotNull(); } - - private MatchingRound saveMatchRound() { - LocalDateTime monday = LocalDateTime.of(2024, 1, 29, 0, 0); - return matchingRoundRepository.save(MatchingRound.of(monday, matchingTimeProperties)); - } } From 1409d96a6f22a2b3dedb030f4baddc8939e842f0 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 31 Jan 2024 21:28:19 +0900 Subject: [PATCH 064/215] =?UTF-8?q?fix=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/global/error/MatchingError.java | 1 + .../unit/service/MatchingApplicationServiceTest.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/aliens/backend/global/error/MatchingError.java b/src/main/java/com/aliens/backend/global/error/MatchingError.java index 3713e201..c80144f4 100644 --- a/src/main/java/com/aliens/backend/global/error/MatchingError.java +++ b/src/main/java/com/aliens/backend/global/error/MatchingError.java @@ -5,6 +5,7 @@ public enum MatchingError implements ErrorCode { NOT_FOUND_MATCHING_ROUND(HttpStatus.NOT_FOUND, "MA1", "매칭 회차를 찾을 수 없음"), NOT_VALID_MATCHING_TIME(HttpStatus.BAD_REQUEST, "MA2", "매칭 시간이 아님"), + NOT_FOUND_MATCHING_APPLICATION_INFO(HttpStatus.NOT_FOUND, "MA3", "매칭 신청 정보 찾을 수 없음"), ; diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index 44926f8b..7ac974ef 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -6,11 +6,13 @@ import com.aliens.backend.mathcing.controller.dto.request.MatchingRequest; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.MatchingApplicationService; import com.aliens.backend.mathcing.service.model.Language; import com.aliens.backend.mathcing.validator.MatchingApplicationValidator; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -23,6 +25,7 @@ import java.time.LocalDateTime; import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; +import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; @@ -47,7 +50,6 @@ public class MatchingApplicationServiceTest { MatchingRound currentRound; @BeforeEach - @Transactional void setUp() { LocalDateTime monday = LocalDateTime.of(2024, 1, 29, 0, 0); matchingRoundRepository.save(MatchingRound.of(monday, matchingTimeProperties)); @@ -59,11 +61,17 @@ void setUp() { @Test @DisplayName("매칭 신청 단위 테스트") + @Transactional void applyMatchTest() { given(matchingApplicationValidator.canApplyMatching(currentRound)).willReturn(true); matchingApplicationService.saveParticipant(matchingApplicationRequest); - + MatchingApplication result = + matchingApplicationRepository.findById( + new MatchingApplicationId(currentRound, matchingApplicationRequest.getMemberId())) + .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); + assertThat(result.getMatchingApplicationId().getMemberId()) + .isEqualTo(matchingApplicationRequest.getMemberId()); } } From 4be9e4848633a0ac75d6051c9f06a17f45fed3eb Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 1 Feb 2024 12:42:03 +0900 Subject: [PATCH 065/215] =?UTF-8?q?fix=20:=20input,=20request=20dto=20clas?= =?UTF-8?q?s=EB=A5=BC=20record=20=ED=83=80=EC=9E=85=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dto/input/MatchingInput.java | 13 ++------ .../dto/request/MatchingRequest.java | 30 ++++--------------- .../MatchingApplicationServiceTest.java | 15 +++++++--- 3 files changed, 19 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java index 5d003f58..2114cbb4 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java @@ -5,16 +5,9 @@ import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; public class MatchingInput { - - public static class MatchingApplicationInput { - private Language firstPreferLanguage; - private Language secondPreferLanguage; - - public MatchingApplicationInput(final Language firstPreferLanguage, final Language secondPreferLanguage) { - this.firstPreferLanguage = firstPreferLanguage; - this.secondPreferLanguage = secondPreferLanguage; - } - + public record MatchingApplicationInput( + Language firstPreferLanguage, + Language secondPreferLanguage) { public MatchingApplicationRequest toRequest(final Long memberId){ return new MatchingApplicationRequest(memberId, firstPreferLanguage, secondPreferLanguage); } diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java index fa905785..dbd8943c 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java @@ -5,33 +5,13 @@ import com.aliens.backend.mathcing.service.model.Language; public class MatchingRequest { - public static class MatchingApplicationRequest { - private Long memberId; - private Language firstPreferLanguage; - private Language secondPreferLanguage; - - public MatchingApplicationRequest(final Long memberId, - final Language firstPreferLanguage, - final Language secondPreferLanguage) { - this.memberId = memberId; - this.firstPreferLanguage = firstPreferLanguage; - this.secondPreferLanguage = secondPreferLanguage; - } - + public record MatchingApplicationRequest( + Long memberId, + Language firstPreferLanguage, + Language secondPreferLanguage + ) { public MatchingApplication toEntity(MatchingRound matchingRound) { return MatchingApplication.of(matchingRound, memberId, firstPreferLanguage, secondPreferLanguage); } - - public Long getMemberId() { - return memberId; - } - - public Language getFirstPreferLanguage() { - return firstPreferLanguage; - } - - public Language getSecondPreferLanguage() { - return secondPreferLanguage; - } } } diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index 7ac974ef..49bd3cf6 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -56,7 +56,7 @@ void setUp() { matchingApplicationRequest = new MatchingApplicationRequest(1L, Language.KOREAN, Language.ENGLISH); currentRound = matchingRoundRepository.findCurrentRound() - .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); } @Test @@ -69,9 +69,16 @@ void applyMatchTest() { MatchingApplication result = matchingApplicationRepository.findById( - new MatchingApplicationId(currentRound, matchingApplicationRequest.getMemberId())) - .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); + new MatchingApplicationId(currentRound, matchingApplicationRequest.memberId())) + .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); assertThat(result.getMatchingApplicationId().getMemberId()) - .isEqualTo(matchingApplicationRequest.getMemberId()); + .isEqualTo(matchingApplicationRequest.memberId()); + } + + @Test + @DisplayName("매칭 신청 조회 테스트") + @Transactional(readOnly = true) + void getMatchingApplicationTest() { + } } From 4bcf356e7047194fc14dda9baf236db6b1b218d0 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 1 Feb 2024 13:15:44 +0900 Subject: [PATCH 066/215] =?UTF-8?q?fix=20:=20=EC=83=9D=EC=84=B1=EC=9E=90?= =?UTF-8?q?=EB=A5=BC=20=EC=A7=81=EC=A0=91=20=ED=98=B8=EC=B6=9C=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EB=AA=BB=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=EC=9D=98=20=EC=A0=91=EA=B7=BC=EC=A0=9C?= =?UTF-8?q?=ED=95=9C=EC=9E=90=EB=A5=BC=20private=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=ED=9B=84,=20of=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=9D=EC=B2=B4=EB=A5=BC=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=9C=A0=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/mathcing/domain/MatchingApplication.java | 4 ++-- .../com/aliens/backend/mathcing/domain/MatchingRound.java | 2 +- .../backend/mathcing/domain/id/MatchingApplicationId.java | 6 +++++- .../unit/service/MatchingApplicationServiceTest.java | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java index 67d50cc0..713e50e3 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java @@ -24,7 +24,7 @@ public class MatchingApplication { protected MatchingApplication() { } - public MatchingApplication(final MatchingApplicationId matchingApplicationId, + private MatchingApplication(final MatchingApplicationId matchingApplicationId, final Language firstPreferLanguage, final Language secondPreferLanguage) { this.matchingApplicationId = matchingApplicationId; @@ -48,7 +48,7 @@ public static MatchingApplication of(final MatchingRound matchingRound, final Long memberId, final Language firstPreferLanguage, final Language secondPreferLanguage) { return new MatchingApplication( - new MatchingApplicationId(matchingRound, memberId), + MatchingApplicationId.of(matchingRound, memberId), firstPreferLanguage, secondPreferLanguage); } diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java index 6f040518..c9e811a3 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java @@ -47,7 +47,7 @@ public LocalDateTime getMatchingValidEndTime() { return matchingValidEndTime; } - public MatchingRound(final LocalDateTime matchingRequestStartTime, + private MatchingRound(final LocalDateTime matchingRequestStartTime, final LocalDateTime matchingRequestEndTime, final LocalDateTime matchingValidStartTime, final LocalDateTime matchingValidEndTime) { diff --git a/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingApplicationId.java b/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingApplicationId.java index 14732ee0..cd166501 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingApplicationId.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingApplicationId.java @@ -17,7 +17,7 @@ public class MatchingApplicationId implements Serializable { protected MatchingApplicationId() { } - public MatchingApplicationId(final MatchingRound matchingRound, final Long memberId) { + private MatchingApplicationId(final MatchingRound matchingRound, final Long memberId) { this.matchingRound = matchingRound; this.memberId = memberId; } @@ -30,6 +30,10 @@ public Long getMemberId() { return memberId; } + public static MatchingApplicationId of(final MatchingRound matchingRound, final Long memberId) { + return new MatchingApplicationId(matchingRound, memberId); + } + @Override public String toString() { return "MatchingApplicationId{" + diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index 49bd3cf6..b69964be 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -69,7 +69,7 @@ void applyMatchTest() { MatchingApplication result = matchingApplicationRepository.findById( - new MatchingApplicationId(currentRound, matchingApplicationRequest.memberId())) + MatchingApplicationId.of(currentRound, matchingApplicationRequest.memberId())) .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); assertThat(result.getMatchingApplicationId().getMemberId()) .isEqualTo(matchingApplicationRequest.memberId()); From 5521c49f744f487b2f97c49679d9688e0b5eaa55 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 1 Feb 2024 14:13:11 +0900 Subject: [PATCH 067/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD,=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/success/MatchingSuccessCode.java | 6 +++--- .../controller/MatchingController.java | 12 +++++++---- .../dto/response/MatchingResponse.java | 20 ++++++++++++++++++ .../service/MatchingApplicationService.java | 21 +++++++++++++++++-- .../MatchingApplicationServiceTest.java | 18 +++++++++++----- 5 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java diff --git a/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java b/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java index 2dafd4fa..6567f298 100644 --- a/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java +++ b/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java @@ -2,10 +2,10 @@ import org.springframework.http.HttpStatus; -import static org.springframework.http.HttpStatus.*; - public enum MatchingSuccessCode implements SuccessCode { - APPLY_MATCHING_SUCCESS(CREATED, "MA001", "매칭 신청 성공"), + APPLY_MATCHING_SUCCESS(HttpStatus.CREATED, "MA001", "매칭 신청 성공"), + GET_MATCHING_APPLICATION_STATUS_SUCCESS(HttpStatus.OK, "MA002", "매칭 신청 정보 조회 성공"), + ; private final HttpStatus httpStatus; diff --git a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java index 8c0aaf6d..fe58a0f5 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java @@ -3,14 +3,12 @@ import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.global.config.resolver.Login; import com.aliens.backend.global.success.MatchingSuccessCode; +import com.aliens.backend.global.success.SuccessResponse; import com.aliens.backend.global.success.SuccessResponseWithoutResult; import com.aliens.backend.mathcing.service.MatchingApplicationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import static com.aliens.backend.mathcing.controller.dto.input.MatchingInput.*; @@ -30,4 +28,10 @@ public ResponseEntity applyMatch(final @Login LoginMember loginMember, matchingApplicationService.saveParticipant(matchingApplicationInput.toRequest(loginMember.memberId())); return SuccessResponseWithoutResult.toResponseEntity(MatchingSuccessCode.APPLY_MATCHING_SUCCESS); } + + @GetMapping("/applications") + public ResponseEntity getMatchingApplication(final @Login LoginMember loginMember) { + return SuccessResponse.toResponseEntity(MatchingSuccessCode.GET_MATCHING_APPLICATION_STATUS_SUCCESS, + matchingApplicationService.findMatchingApplication(loginMember.memberId())); + } } diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java new file mode 100644 index 00000000..ee736800 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java @@ -0,0 +1,20 @@ +package com.aliens.backend.mathcing.controller.dto.response; + +import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.service.model.Language; + +public class MatchingResponse { + public record MatchingApplicationResponse( + Long matchingRound, + Long memberId, + Language firstPreferLanguage, + Language secondPreferLanguage) { + public static MatchingApplicationResponse of(MatchingApplication matchingApplication) { + return new MatchingApplicationResponse( + matchingApplication.getMatchingApplicationId().getMatchingRound().getRound(), + matchingApplication.getMatchingApplicationId().getMemberId(), + matchingApplication.getFirstPreferLanguage(), + matchingApplication.getSecondPreferLanguage()); + } + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index 71a1bf56..831e1010 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -2,7 +2,10 @@ import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.mathcing.controller.dto.response.MatchingResponse; +import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.validator.MatchingApplicationValidator; @@ -11,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional; import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; +import static com.aliens.backend.mathcing.controller.dto.response.MatchingResponse.*; @Service public class MatchingApplicationService { @@ -29,10 +33,23 @@ public MatchingApplicationService(final MatchingApplicationRepository matchingAp @Transactional public void saveParticipant(final MatchingApplicationRequest matchingApplicationRequest) { - MatchingRound currentRound = matchingRoundRepository.findCurrentRound() - .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + MatchingRound currentRound = getCurrentRound(); if (matchingApplicationValidator.canApplyMatching(currentRound)) { matchingApplicationRepository.save(matchingApplicationRequest.toEntity(currentRound)); } } + + @Transactional(readOnly = true) + public MatchingApplicationResponse findMatchingApplication(final Long memberId) { + MatchingRound currentRound = getCurrentRound(); + MatchingApplication matchingApplication = + matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, memberId)) + .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); + return MatchingApplicationResponse.of(matchingApplication); + } + + private MatchingRound getCurrentRound() { + return matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } } diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index b69964be..2d301199 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -3,7 +3,6 @@ import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; -import com.aliens.backend.mathcing.controller.dto.request.MatchingRequest; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; @@ -12,11 +11,9 @@ import com.aliens.backend.mathcing.service.MatchingApplicationService; import com.aliens.backend.mathcing.service.model.Language; import com.aliens.backend.mathcing.validator.MatchingApplicationValidator; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.mockito.BDDMockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -25,6 +22,7 @@ import java.time.LocalDateTime; import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; +import static com.aliens.backend.mathcing.controller.dto.response.MatchingResponse.*; import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; @@ -63,7 +61,7 @@ void setUp() { @DisplayName("매칭 신청 단위 테스트") @Transactional void applyMatchTest() { - given(matchingApplicationValidator.canApplyMatching(currentRound)).willReturn(true); + given(matchingApplicationValidator.canApplyMatching(any())).willReturn(true); matchingApplicationService.saveParticipant(matchingApplicationRequest); @@ -77,8 +75,18 @@ void applyMatchTest() { @Test @DisplayName("매칭 신청 조회 테스트") - @Transactional(readOnly = true) + @Transactional void getMatchingApplicationTest() { + applyToMatch(); + + MatchingApplicationResponse result = matchingApplicationService + .findMatchingApplication(matchingApplicationRequest.memberId()); + assertThat(result.memberId()).isEqualTo(matchingApplicationRequest.memberId()); + } + + private void applyToMatch() { + given(matchingApplicationValidator.canApplyMatching(any())).willReturn(true); + matchingApplicationService.saveParticipant(matchingApplicationRequest); } } From 307fa35e0bdd668a2050d74ab665666cd226736b Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 1 Feb 2024 18:03:26 +0900 Subject: [PATCH 068/215] =?UTF-8?q?fix=20:=20LocalDateTime.now()=EA=B0=80?= =?UTF-8?q?=20Mocking=EC=9D=B4=20=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94?= =?UTF-8?q?=20=EB=AC=B8=EC=A0=9C=EC=A0=90=EC=9D=84=20=EB=B0=9C=EA=B2=AC?= =?UTF-8?q?=ED=95=98=EA=B3=A0=20Clock=EC=9D=84=20=EC=A3=BC=EC=9E=85?= =?UTF-8?q?=EB=B0=9B=EC=95=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=EC=9E=88=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/config/ClockConfig.java | 15 ++++++ .../service/MatchingApplicationService.java | 14 +++-- .../service/MatchingRoundService.java | 13 +++-- .../MatchingApplicationValidator.java | 9 ++-- .../MatchingApplicationServiceTest.java | 54 +++++++++++++++---- 5 files changed, 81 insertions(+), 24 deletions(-) create mode 100644 src/main/java/com/aliens/backend/global/config/ClockConfig.java diff --git a/src/main/java/com/aliens/backend/global/config/ClockConfig.java b/src/main/java/com/aliens/backend/global/config/ClockConfig.java new file mode 100644 index 00000000..752bd818 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/config/ClockConfig.java @@ -0,0 +1,15 @@ +package com.aliens.backend.global.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.time.Clock; + +@Configuration +public class ClockConfig { + + @Bean + public Clock clock() { + return Clock.systemDefaultZone(); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index 831e1010..2ebb28da 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -2,17 +2,21 @@ import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; -import com.aliens.backend.mathcing.controller.dto.response.MatchingResponse; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.validator.MatchingApplicationValidator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.Clock; +import java.time.LocalDateTime; + import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; import static com.aliens.backend.mathcing.controller.dto.response.MatchingResponse.*; @@ -21,20 +25,22 @@ public class MatchingApplicationService { private final MatchingApplicationRepository matchingApplicationRepository; private final MatchingRoundRepository matchingRoundRepository; private final MatchingApplicationValidator matchingApplicationValidator; + private final Clock clock; - @Autowired public MatchingApplicationService(final MatchingApplicationRepository matchingApplicationRepository, final MatchingRoundRepository matchingRoundRepository, - final MatchingApplicationValidator matchingApplicationValidator) { + final MatchingApplicationValidator matchingApplicationValidator, + final Clock clock) { this.matchingApplicationRepository = matchingApplicationRepository; this.matchingRoundRepository = matchingRoundRepository; this.matchingApplicationValidator = matchingApplicationValidator; + this.clock = clock; } @Transactional public void saveParticipant(final MatchingApplicationRequest matchingApplicationRequest) { MatchingRound currentRound = getCurrentRound(); - if (matchingApplicationValidator.canApplyMatching(currentRound)) { + if (matchingApplicationValidator.canApplyMatch(currentRound, LocalDateTime.now(clock))) { matchingApplicationRepository.save(matchingApplicationRequest.toEntity(currentRound)); } } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java index dfaa0d35..c2ba2929 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java @@ -7,22 +7,25 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import java.time.Clock; import java.time.LocalDateTime; @Service public class MatchingRoundService { - private MatchingRoundRepository matchingRoundRepository; - private MatchingTimeProperties matchingTimeProperties; + private final MatchingRoundRepository matchingRoundRepository; + private final MatchingTimeProperties matchingTimeProperties; + private final Clock clock; - @Autowired public MatchingRoundService(final MatchingRoundRepository matchingRoundRepository, - final MatchingTimeProperties matchingTimeProperties) { + final MatchingTimeProperties matchingTimeProperties, + final Clock clock) { this.matchingRoundRepository = matchingRoundRepository; this.matchingTimeProperties = matchingTimeProperties; + this.clock = clock; } @Scheduled(cron = "${matching.round.update-date}") private void saveMatchRound() { - matchingRoundRepository.save(MatchingRound.of(LocalDateTime.now(), matchingTimeProperties)); + matchingRoundRepository.save(MatchingRound.of(LocalDateTime.now(clock), matchingTimeProperties)); } } diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java index 8b51798b..c20e8416 100644 --- a/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java +++ b/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java @@ -3,16 +3,17 @@ import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.domain.MatchingRound; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import java.time.LocalDateTime; @Component public class MatchingApplicationValidator { - public boolean canApplyMatching(MatchingRound matchingRound) { - LocalDateTime now = LocalDateTime.now(); - if (matchingRound.getMatchingRequestStartTime().isAfter(now) && - matchingRound.getMatchingRequestEndTime().isBefore(now)) { + public boolean canApplyMatch(MatchingRound matchingRound, LocalDateTime now) { + if (now.isAfter(matchingRound.getMatchingRequestStartTime()) && + now.isBefore(matchingRound.getMatchingRequestEndTime())) { return true; } throw new RestApiException(MatchingError.NOT_VALID_MATCHING_TIME); diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index 2d301199..0cac8323 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -19,7 +19,9 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.transaction.annotation.Transactional; +import java.time.Clock; import java.time.LocalDateTime; +import java.time.ZoneId; import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; import static com.aliens.backend.mathcing.controller.dto.response.MatchingResponse.*; @@ -44,13 +46,17 @@ public class MatchingApplicationServiceTest { @MockBean MatchingApplicationValidator matchingApplicationValidator; + @MockBean + Clock clock; + MatchingApplicationRequest matchingApplicationRequest; MatchingRound currentRound; @BeforeEach void setUp() { - LocalDateTime monday = LocalDateTime.of(2024, 1, 29, 0, 0); - matchingRoundRepository.save(MatchingRound.of(monday, matchingTimeProperties)); + LocalDateTime testTime = LocalDateTime.of(2024, 1, 29, 0, 0); + + matchingRoundRepository.save(MatchingRound.of(testTime, matchingTimeProperties)); matchingApplicationRequest = new MatchingApplicationRequest(1L, Language.KOREAN, Language.ENGLISH); currentRound = matchingRoundRepository.findCurrentRound() @@ -61,20 +67,38 @@ void setUp() { @DisplayName("매칭 신청 단위 테스트") @Transactional void applyMatchTest() { - given(matchingApplicationValidator.canApplyMatching(any())).willReturn(true); + // given + LocalDateTime validTime = LocalDateTime.of(2024, 1, 29, 10, 0); + mockTime(validTime); + given(matchingApplicationValidator.canApplyMatch(currentRound, validTime)).willCallRealMethod(); + // when matchingApplicationService.saveParticipant(matchingApplicationRequest); - MatchingApplication result = - matchingApplicationRepository.findById( - MatchingApplicationId.of(currentRound, matchingApplicationRequest.memberId())) - .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); - assertThat(result.getMatchingApplicationId().getMemberId()) - .isEqualTo(matchingApplicationRequest.memberId()); + // then + MatchingApplication result = matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, matchingApplicationRequest.memberId())) + .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); + assertThat(result.getMatchingApplicationId().getMemberId()).isEqualTo(matchingApplicationRequest.memberId()); + } + + @Test + @DisplayName("지정 시간 외 매칭 신청시, 에러 발생") + @Transactional + void applyMatchIfNotValidTime() { + // given + LocalDateTime invalidTime = LocalDateTime.of(2024, 1, 29, 19, 0); + mockTime(invalidTime); + given(matchingApplicationValidator.canApplyMatch(currentRound, invalidTime)).willCallRealMethod(); + + // when & then + assertThatThrownBy(() -> matchingApplicationService.saveParticipant(matchingApplicationRequest)) + .isInstanceOf(RestApiException.class) + .hasMessage(MatchingError.NOT_VALID_MATCHING_TIME.getMessage()); } + @Test - @DisplayName("매칭 신청 조회 테스트") + @DisplayName("매칭 신청 조회 단위 테스트") @Transactional void getMatchingApplicationTest() { applyToMatch(); @@ -86,7 +110,15 @@ void getMatchingApplicationTest() { } private void applyToMatch() { - given(matchingApplicationValidator.canApplyMatching(any())).willReturn(true); + LocalDateTime validTime = LocalDateTime.of(2024, 1, 29, 10, 0); + mockTime(validTime); + given(matchingApplicationValidator.canApplyMatch(currentRound, validTime)).willReturn(true); matchingApplicationService.saveParticipant(matchingApplicationRequest); } + + private void mockTime(LocalDateTime time) { + Clock fixedClock = Clock.fixed(time.atZone(ZoneId.systemDefault()).toInstant(), ZoneId.systemDefault()); + when(clock.instant()).thenReturn(fixedClock.instant()); + when(clock.getZone()).thenReturn(fixedClock.getZone()); + } } From dbcdbf2291f22d8049ae780c917b63940614ae15 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 1 Feb 2024 19:33:01 +0900 Subject: [PATCH 069/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EC=B7=A8=EC=86=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B0=9C=EB=B0=9C=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/error/MatchingError.java | 3 +- .../global/success/MatchingSuccessCode.java | 1 + .../controller/MatchingController.java | 6 ++ .../service/MatchingApplicationService.java | 19 ++++-- .../MatchingApplicationValidator.java | 15 ++-- .../MatchingApplicationServiceTest.java | 68 +++++++++++++++---- 6 files changed, 84 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/aliens/backend/global/error/MatchingError.java b/src/main/java/com/aliens/backend/global/error/MatchingError.java index c80144f4..5b63949b 100644 --- a/src/main/java/com/aliens/backend/global/error/MatchingError.java +++ b/src/main/java/com/aliens/backend/global/error/MatchingError.java @@ -4,9 +4,10 @@ public enum MatchingError implements ErrorCode { NOT_FOUND_MATCHING_ROUND(HttpStatus.NOT_FOUND, "MA1", "매칭 회차를 찾을 수 없음"), - NOT_VALID_MATCHING_TIME(HttpStatus.BAD_REQUEST, "MA2", "매칭 시간이 아님"), + NOT_VALID_MATCHING_RECEPTION_TIME(HttpStatus.BAD_REQUEST, "MA2", "매칭 접수 시간이 아님"), NOT_FOUND_MATCHING_APPLICATION_INFO(HttpStatus.NOT_FOUND, "MA3", "매칭 신청 정보 찾을 수 없음"), + ; private final HttpStatus httpStatusCode; diff --git a/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java b/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java index 6567f298..6c3eea68 100644 --- a/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java +++ b/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java @@ -5,6 +5,7 @@ public enum MatchingSuccessCode implements SuccessCode { APPLY_MATCHING_SUCCESS(HttpStatus.CREATED, "MA001", "매칭 신청 성공"), GET_MATCHING_APPLICATION_STATUS_SUCCESS(HttpStatus.OK, "MA002", "매칭 신청 정보 조회 성공"), + CANCEL_MATCHING_APPLICATION_SUCCESS(HttpStatus.OK, "MA003", "매칭 신청 취소 성공") ; diff --git a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java index fe58a0f5..9a732773 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java @@ -34,4 +34,10 @@ public ResponseEntity getMatchingApplication(final @Login LoginMember loginMe return SuccessResponse.toResponseEntity(MatchingSuccessCode.GET_MATCHING_APPLICATION_STATUS_SUCCESS, matchingApplicationService.findMatchingApplication(loginMember.memberId())); } + + @DeleteMapping("/applications") + public ResponseEntity cancelMatchingApplication(final @Login LoginMember loginMember) { + matchingApplicationService.deleteMatchingApplication(loginMember.memberId()); + return SuccessResponseWithoutResult.toResponseEntity(MatchingSuccessCode.CANCEL_MATCHING_APPLICATION_SUCCESS); + } } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index 2ebb28da..0979da63 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -8,9 +8,6 @@ import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.validator.MatchingApplicationValidator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -40,20 +37,30 @@ public MatchingApplicationService(final MatchingApplicationRepository matchingAp @Transactional public void saveParticipant(final MatchingApplicationRequest matchingApplicationRequest) { MatchingRound currentRound = getCurrentRound(); - if (matchingApplicationValidator.canApplyMatch(currentRound, LocalDateTime.now(clock))) { - matchingApplicationRepository.save(matchingApplicationRequest.toEntity(currentRound)); - } + matchingApplicationValidator.checkReceptionTime(currentRound, LocalDateTime.now(clock)); + matchingApplicationRepository.save(matchingApplicationRequest.toEntity(currentRound)); } @Transactional(readOnly = true) public MatchingApplicationResponse findMatchingApplication(final Long memberId) { MatchingRound currentRound = getCurrentRound(); + matchingApplicationValidator.checkReceptionTime(currentRound, LocalDateTime.now(clock)); MatchingApplication matchingApplication = matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, memberId)) .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); return MatchingApplicationResponse.of(matchingApplication); } + @Transactional + public void deleteMatchingApplication(final Long memberId) { + MatchingRound currentRound = getCurrentRound(); + matchingApplicationValidator.checkReceptionTime(currentRound, LocalDateTime.now(clock)); + MatchingApplication matchingApplication = + matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, memberId)) + .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); + matchingApplicationRepository.delete(matchingApplication); + } + private MatchingRound getCurrentRound() { return matchingRoundRepository.findCurrentRound() .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java index c20e8416..78fc7857 100644 --- a/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java +++ b/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java @@ -3,19 +3,20 @@ import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.domain.MatchingRound; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import java.time.LocalDateTime; @Component public class MatchingApplicationValidator { - public boolean canApplyMatch(MatchingRound matchingRound, LocalDateTime now) { - if (now.isAfter(matchingRound.getMatchingRequestStartTime()) && - now.isBefore(matchingRound.getMatchingRequestEndTime())) { - return true; + public void checkReceptionTime(MatchingRound matchingRound, LocalDateTime now) { + if (!isMatchingReceptionTime(matchingRound, now)) { + throw new RestApiException(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME); } - throw new RestApiException(MatchingError.NOT_VALID_MATCHING_TIME); + } + + private boolean isMatchingReceptionTime(MatchingRound matchingRound, LocalDateTime now) { + return now.isAfter(matchingRound.getMatchingRequestStartTime()) && + now.isBefore(matchingRound.getMatchingRequestEndTime()); } } diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index 0cac8323..c21d33ee 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -52,12 +52,13 @@ public class MatchingApplicationServiceTest { MatchingApplicationRequest matchingApplicationRequest; MatchingRound currentRound; + final LocalDateTime VALID_TIME = LocalDateTime.of(2024, 1, 29, 10, 0); + final LocalDateTime INVALID_TIME = LocalDateTime.of(2024, 1, 29, 19, 0); + @BeforeEach void setUp() { - LocalDateTime testTime = LocalDateTime.of(2024, 1, 29, 0, 0); - - matchingRoundRepository.save(MatchingRound.of(testTime, matchingTimeProperties)); - + LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); + matchingRoundRepository.save(MatchingRound.of(roundBeginTime, matchingTimeProperties)); matchingApplicationRequest = new MatchingApplicationRequest(1L, Language.KOREAN, Language.ENGLISH); currentRound = matchingRoundRepository.findCurrentRound() .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); @@ -68,9 +69,7 @@ void setUp() { @Transactional void applyMatchTest() { // given - LocalDateTime validTime = LocalDateTime.of(2024, 1, 29, 10, 0); - mockTime(validTime); - given(matchingApplicationValidator.canApplyMatch(currentRound, validTime)).willCallRealMethod(); + mockTime(VALID_TIME); // when matchingApplicationService.saveParticipant(matchingApplicationRequest); @@ -86,14 +85,12 @@ void applyMatchTest() { @Transactional void applyMatchIfNotValidTime() { // given - LocalDateTime invalidTime = LocalDateTime.of(2024, 1, 29, 19, 0); - mockTime(invalidTime); - given(matchingApplicationValidator.canApplyMatch(currentRound, invalidTime)).willCallRealMethod(); + mockTime(INVALID_TIME); // when & then assertThatThrownBy(() -> matchingApplicationService.saveParticipant(matchingApplicationRequest)) .isInstanceOf(RestApiException.class) - .hasMessage(MatchingError.NOT_VALID_MATCHING_TIME.getMessage()); + .hasMessage(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME.getMessage()); } @@ -101,18 +98,59 @@ void applyMatchIfNotValidTime() { @DisplayName("매칭 신청 조회 단위 테스트") @Transactional void getMatchingApplicationTest() { + // given applyToMatch(); + //when MatchingApplicationResponse result = matchingApplicationService .findMatchingApplication(matchingApplicationRequest.memberId()); + // then assertThat(result.memberId()).isEqualTo(matchingApplicationRequest.memberId()); } + @Test + @DisplayName("매칭 신청 취소 단위 테스트") + @Transactional + void deleteMatchingApplicationTest() { + // given + applyToMatch(); + mockTime(VALID_TIME); + + // when + matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId()); + + // then + assertThatThrownBy(() -> matchingApplicationService.findMatchingApplication(matchingApplicationRequest.memberId())) + .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getMessage()); + } + + @Test + @DisplayName("지정 시간 외 매칭 취소 신청시, 에러 발생") + @Transactional + void deleteMatchIfNotValidTime() { + // given + applyToMatch(); + mockTime(INVALID_TIME); + + // when & then + assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId())) + .hasMessage(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME.getMessage()); + } + + @Test + @DisplayName("매칭을 신청하지 않은 사용자 매칭 삭제 요청 테스트") + @Transactional + void deleteMatchIfNotApplied() { + // given + mockTime(VALID_TIME); + + assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId())) + .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getMessage()); + } + private void applyToMatch() { - LocalDateTime validTime = LocalDateTime.of(2024, 1, 29, 10, 0); - mockTime(validTime); - given(matchingApplicationValidator.canApplyMatch(currentRound, validTime)).willReturn(true); + mockTime(VALID_TIME); matchingApplicationService.saveParticipant(matchingApplicationRequest); } @@ -120,5 +158,7 @@ private void mockTime(LocalDateTime time) { Clock fixedClock = Clock.fixed(time.atZone(ZoneId.systemDefault()).toInstant(), ZoneId.systemDefault()); when(clock.instant()).thenReturn(fixedClock.instant()); when(clock.getZone()).thenReturn(fixedClock.getZone()); + + doCallRealMethod().when(matchingApplicationValidator).checkReceptionTime(currentRound, time); } } From a577353ee0f47bcb0b6f90e1e6b147d8a537d00c Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 1 Feb 2024 19:42:31 +0900 Subject: [PATCH 070/215] =?UTF-8?q?fix=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=EC=9E=90=20=EC=A1=B0=ED=9A=8C=EC=97=90=20?= =?UTF-8?q?=EB=A7=A4=EC=B9=AD=20=EC=A0=91=EC=88=98=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EC=BD=94=EB=93=9C=EA=B0=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EB=90=98=EC=96=B4=EC=9E=88=EB=8D=98=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/mathcing/service/MatchingApplicationService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index 0979da63..57bbe164 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -44,7 +44,6 @@ public void saveParticipant(final MatchingApplicationRequest matchingApplication @Transactional(readOnly = true) public MatchingApplicationResponse findMatchingApplication(final Long memberId) { MatchingRound currentRound = getCurrentRound(); - matchingApplicationValidator.checkReceptionTime(currentRound, LocalDateTime.now(clock)); MatchingApplication matchingApplication = matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, memberId)) .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); From 8af34f6dfc346d1b17c5f5922fa1c1bc169e778f Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 1 Feb 2024 19:42:58 +0900 Subject: [PATCH 071/215] =?UTF-8?q?test=20:=20=EB=A7=A4=EC=B9=AD=EC=97=90?= =?UTF-8?q?=20=EC=8B=A0=EC=B2=AD=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9D=80=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=EB=A5=BC=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BC=80?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unit/service/MatchingApplicationServiceTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index c21d33ee..c022758d 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -109,6 +109,15 @@ void getMatchingApplicationTest() { assertThat(result.memberId()).isEqualTo(matchingApplicationRequest.memberId()); } + @Test + @DisplayName("매칭 신청하지 않은 사용자 조회 테스트") + @Transactional + void getMatchingApplicationIfNotApplied() { + // when & then + assertThatThrownBy(() -> matchingApplicationService.findMatchingApplication(matchingApplicationRequest.memberId())) + .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getMessage()); + } + @Test @DisplayName("매칭 신청 취소 단위 테스트") @Transactional From 033127065f279956db2bc33962c60661ae6e8fd2 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sat, 3 Feb 2024 16:29:59 +0900 Subject: [PATCH 072/215] =?UTF-8?q?fix(MatchingApplication)=20:=20?= =?UTF-8?q?=EB=B3=B5=ED=95=A9=ED=82=A4=20=EB=B3=80=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/MatchingResponse.java | 4 +- .../mathcing/domain/MatchingApplication.java | 15 +++---- .../mathcing/service/model/Participant.java | 43 +++++++++++++++++++ .../service/model/PreferLanguage.java | 7 +++ .../MatchingApplicationServiceTest.java | 2 +- 5 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/aliens/backend/mathcing/service/model/Participant.java create mode 100644 src/main/java/com/aliens/backend/mathcing/service/model/PreferLanguage.java diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java index ee736800..8cbd7d1b 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java @@ -11,8 +11,8 @@ public record MatchingApplicationResponse( Language secondPreferLanguage) { public static MatchingApplicationResponse of(MatchingApplication matchingApplication) { return new MatchingApplicationResponse( - matchingApplication.getMatchingApplicationId().getMatchingRound().getRound(), - matchingApplication.getMatchingApplicationId().getMemberId(), + matchingApplication.getId().getMatchingRound().getRound(), + matchingApplication.getId().getMemberId(), matchingApplication.getFirstPreferLanguage(), matchingApplication.getSecondPreferLanguage()); } diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java index 713e50e3..b040d96b 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java @@ -1,6 +1,5 @@ package com.aliens.backend.mathcing.domain; -import com.aliens.backend.mathcing.controller.dto.request.MatchingRequest; import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; import com.aliens.backend.mathcing.service.model.Language; import jakarta.persistence.EmbeddedId; @@ -8,12 +7,10 @@ import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; -import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; - @Entity public class MatchingApplication { @EmbeddedId - private MatchingApplicationId matchingApplicationId; + private MatchingApplicationId id; @Enumerated(EnumType.STRING) private Language firstPreferLanguage; @@ -24,16 +21,16 @@ public class MatchingApplication { protected MatchingApplication() { } - private MatchingApplication(final MatchingApplicationId matchingApplicationId, + private MatchingApplication(final MatchingApplicationId id, final Language firstPreferLanguage, final Language secondPreferLanguage) { - this.matchingApplicationId = matchingApplicationId; + this.id = id; this.firstPreferLanguage = firstPreferLanguage; this.secondPreferLanguage = secondPreferLanguage; } - public MatchingApplicationId getMatchingApplicationId() { - return matchingApplicationId; + public MatchingApplicationId getId() { + return id; } public Language getFirstPreferLanguage() { @@ -55,7 +52,7 @@ public static MatchingApplication of(final MatchingRound matchingRound, @Override public String toString() { return "MatchingApplication{" + - "matchingApplicationId=" + matchingApplicationId + + "matchingApplicationId=" + id + ", firstLanguage=" + firstPreferLanguage + ", secondLanguage=" + secondPreferLanguage + '}'; diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java b/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java new file mode 100644 index 00000000..fa5aaa59 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java @@ -0,0 +1,43 @@ +package com.aliens.backend.mathcing.service.model; + +import java.util.List; + +public class Participant { + private Long memberId; + private Language firstPreferLanguage; + private Language secondPreferLanguage; + private List partners; + + public Participant(final Long memberId, final Language firstPreferLanguage, final Language secondPreferLanguage, final List partners) { + this.memberId = memberId; + this.firstPreferLanguage = firstPreferLanguage; + this.secondPreferLanguage = secondPreferLanguage; + this.partners = partners; + } + + public Long getMemberId() { + return memberId; + } + + public Language getPreferLanguage(PreferLanguage preferLanguage) { + if (preferLanguage.equals(PreferLanguage.FIRST)) { + return firstPreferLanguage; + } + if (preferLanguage.equals(PreferLanguage.SECOND)) { + return secondPreferLanguage; + } + return Language.KOREAN; + } + + public List getPartners() { + return partners; + } + + public int getNumberOfPartners() { + return partners.size(); + } + + public void addPartner(Participant participant) { + partners.add(participant); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/PreferLanguage.java b/src/main/java/com/aliens/backend/mathcing/service/model/PreferLanguage.java new file mode 100644 index 00000000..98ef9c6c --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/service/model/PreferLanguage.java @@ -0,0 +1,7 @@ +package com.aliens.backend.mathcing.service.model; + +public enum PreferLanguage { + FIRST, + SECOND + ; +} diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index c022758d..8b76d1c9 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -77,7 +77,7 @@ void applyMatchTest() { // then MatchingApplication result = matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, matchingApplicationRequest.memberId())) .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); - assertThat(result.getMatchingApplicationId().getMemberId()).isEqualTo(matchingApplicationRequest.memberId()); + assertThat(result.getId().getMemberId()).isEqualTo(matchingApplicationRequest.memberId()); } @Test From 9670141950e94953bd2811327973e88f634857c0 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sat, 3 Feb 2024 20:44:13 +0900 Subject: [PATCH 073/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EC=9E=85=EB=A0=A5=EA=B0=92=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/global/error/MatchingError.java | 3 ++- .../mathcing/controller/dto/input/MatchingInput.java | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/global/error/MatchingError.java b/src/main/java/com/aliens/backend/global/error/MatchingError.java index 5b63949b..96bc0678 100644 --- a/src/main/java/com/aliens/backend/global/error/MatchingError.java +++ b/src/main/java/com/aliens/backend/global/error/MatchingError.java @@ -6,7 +6,8 @@ public enum MatchingError implements ErrorCode { NOT_FOUND_MATCHING_ROUND(HttpStatus.NOT_FOUND, "MA1", "매칭 회차를 찾을 수 없음"), NOT_VALID_MATCHING_RECEPTION_TIME(HttpStatus.BAD_REQUEST, "MA2", "매칭 접수 시간이 아님"), NOT_FOUND_MATCHING_APPLICATION_INFO(HttpStatus.NOT_FOUND, "MA3", "매칭 신청 정보 찾을 수 없음"), - + NOT_FOUND_PREFER_LANGUAGE(HttpStatus.NOT_FOUND, "MA4", "선호 언어를 찾을 수 없음"), + INVALID_LANGUAGE_INPUT(HttpStatus.BAD_REQUEST, "MA5", "두 선호 언어가 같을 수 없음"), ; diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java index 2114cbb4..f5317b6b 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java @@ -1,5 +1,7 @@ package com.aliens.backend.mathcing.controller.dto.input; +import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.service.model.Language; import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; @@ -9,7 +11,14 @@ public record MatchingApplicationInput( Language firstPreferLanguage, Language secondPreferLanguage) { public MatchingApplicationRequest toRequest(final Long memberId){ + validateInput(); return new MatchingApplicationRequest(memberId, firstPreferLanguage, secondPreferLanguage); } + + private void validateInput() { + if (firstPreferLanguage.equals(secondPreferLanguage)) { + throw new RestApiException(MatchingError.INVALID_LANGUAGE_INPUT); + } + } } } From 72ba06c02e4d5072459b0c6a7e3b812fe5bcaf95 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sat, 3 Feb 2024 21:03:43 +0900 Subject: [PATCH 074/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A3=B0=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EB=B3=80=EC=88=98=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../property/MatchingRuleProperties.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/property/MatchingRuleProperties.java diff --git a/src/main/java/com/aliens/backend/global/property/MatchingRuleProperties.java b/src/main/java/com/aliens/backend/global/property/MatchingRuleProperties.java new file mode 100644 index 00000000..1f678d9b --- /dev/null +++ b/src/main/java/com/aliens/backend/global/property/MatchingRuleProperties.java @@ -0,0 +1,28 @@ +package com.aliens.backend.global.property; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class MatchingRuleProperties { + @Value("${matching.rule.max-matches.partner}") + private String maxPartners; + + @Value("${matching.rule.max-matches.normal-partner}") + private String maxNormalPartners; + + @Value("${matching.rule.max-tries}") + private String maxTries; + + public Integer getMaxNormalPartners() { + return Integer.parseInt(maxNormalPartners); + } + + public Integer getMaxTries() { + return Integer.parseInt(maxTries); + } + + public Integer getMaxPartners() { + return Integer.parseInt(maxPartners); + } +} From 646f18d7efcf38d6220a456c538dd1ad3faf31b1 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sat, 3 Feb 2024 21:04:04 +0900 Subject: [PATCH 075/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A3=B0=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EB=B3=80=EC=88=98=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-matching.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/application-matching.yml b/src/main/resources/application-matching.yml index 85f83cc3..3bfabc50 100644 --- a/src/main/resources/application-matching.yml +++ b/src/main/resources/application-matching.yml @@ -1,4 +1,9 @@ matching: + rule: + max-matches: + partner : 5 + normal-partner: 4 + max-tries: 200 round: update-date: 0 0 0 * * MON,THU start: 0 0 18 ? * MON,THU" From e94c1c9565b10ddd2480cded87dc8cf660a663b7 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sat, 3 Feb 2024 21:05:00 +0900 Subject: [PATCH 076/215] =?UTF-8?q?feat=20:=201=EC=88=9C=EC=9C=84=20?= =?UTF-8?q?=EC=84=A0=ED=98=B8=20=EC=96=B8=EC=96=B4=20=EB=A7=A4=EC=B9=AD,?= =?UTF-8?q?=202=EC=88=9C=EC=9C=84=20=EC=84=A0=ED=98=B8=20=EC=96=B8?= =?UTF-8?q?=EC=96=B4=20=EB=A7=A4=EC=B9=AD=20=EB=A1=9C=EC=A7=81=20=EA=B0=9C?= =?UTF-8?q?=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/business/MatchingBusiness.java | 112 ++++++++++++++++++ .../business/util/MatchingConverter.java | 27 +++++ .../business/util/MatchingQueueBuilder.java | 29 +++++ .../MatchingApplicationRepository.java | 6 + .../mathcing/service/model/Participant.java | 41 +++---- .../mathcing/service/model/Partner.java | 10 ++ .../mathcing/service/model/Relationship.java | 7 ++ .../validator/MatchingBusinessValidator.java | 30 +++++ 8 files changed, 238 insertions(+), 24 deletions(-) create mode 100644 src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java create mode 100644 src/main/java/com/aliens/backend/mathcing/business/util/MatchingConverter.java create mode 100644 src/main/java/com/aliens/backend/mathcing/business/util/MatchingQueueBuilder.java create mode 100644 src/main/java/com/aliens/backend/mathcing/service/model/Partner.java create mode 100644 src/main/java/com/aliens/backend/mathcing/service/model/Relationship.java create mode 100644 src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java new file mode 100644 index 00000000..7ab9b819 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -0,0 +1,112 @@ +package com.aliens.backend.mathcing.business; + +import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.property.MatchingRuleProperties; +import com.aliens.backend.mathcing.business.util.MatchingConverter; +import com.aliens.backend.mathcing.business.util.MatchingQueueBuilder; +import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; +import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; +import com.aliens.backend.mathcing.service.model.Language; +import com.aliens.backend.mathcing.service.model.Participant; +import com.aliens.backend.mathcing.service.model.PreferLanguage; +import com.aliens.backend.mathcing.service.model.Relationship; +import com.aliens.backend.mathcing.validator.MatchingBusinessValidator; +import jakarta.annotation.PostConstruct; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.*; +import java.util.stream.Collectors; + +@Component +public class MatchingBusiness { + private final MatchingApplicationRepository matchingApplicationRepository; + private final MatchingRoundRepository matchingRoundRepository; + private final MatchingConverter matchingConverter; + private final MatchingQueueBuilder matchingQueueBuilder; + private final MatchingBusinessValidator matchingBusinessValidator; + private final MatchingRuleProperties matchingRuleProperties; + + private List participants = new ArrayList<>(); + private Map> languageQueueWithParticipants = new HashMap<>(); + private Relationship relationship; + + public MatchingBusiness(final MatchingApplicationRepository matchingApplicationRepository, + final MatchingRoundRepository matchingRoundRepository, + final MatchingConverter matchingConverter, + final MatchingQueueBuilder matchingQueueBuilder, + final MatchingBusinessValidator matchingBusinessValidator, + final MatchingRuleProperties matchingRuleProperties) { + this.matchingApplicationRepository = matchingApplicationRepository; + this.matchingRoundRepository = matchingRoundRepository; + this.matchingConverter = matchingConverter; + this.matchingQueueBuilder = matchingQueueBuilder; + this.matchingBusinessValidator = matchingBusinessValidator; + this.matchingRuleProperties = matchingRuleProperties; + } + + @PostConstruct + private void initialize() { + MatchingRound currentRound = matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + participants = matchingConverter.toParticipantList( + matchingApplicationRepository.findAllByMatchingRound(currentRound)); + languageQueueWithParticipants = matchingQueueBuilder.buildLanguageQueues(participants); + relationship = Relationship.NORMAL; + } + + @Scheduled(cron = "${matching.round.start}") + public void operateMatching() { + matchParticipantsWith(PreferLanguage.FIRST); + matchParticipantsWith(PreferLanguage.SECOND); + + } + + private void matchParticipantsWith(PreferLanguage preferLanguage) { + if (preferLanguage.equals(PreferLanguage.FIRST)) { + matchWith(preferLanguage, participants); + } + if (preferLanguage.equals(PreferLanguage.SECOND)) { + List lessMatchedParticipants = getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); + languageQueueWithParticipants = matchingQueueBuilder.buildLanguageQueues(participants); + matchWith(preferLanguage, lessMatchedParticipants); + } + } + + private void matchWith(PreferLanguage preferLanguage, List participants) { + for (Participant participant : participants) { + Queue candidates = languageQueueWithParticipants.get(participant.getPreferLanguage(preferLanguage)); + tryMatchBetween(participant, candidates); + } + } + + private void tryMatchBetween(Participant participant, Queue candidates) { + int tries = 0; + while (matchingBusinessValidator.isExceededMaxNormalPartners(participant) && + matchingBusinessValidator.isExceedMaxTries(tries) && !candidates.isEmpty()) { + Participant partner = candidates.poll(); + tries++; + if (matchingBusinessValidator.isValidMatching(participant, partner)) { + addMatching(participant, partner); + if (!matchingBusinessValidator.isExceededMaxNormalPartners(partner)) { + candidates.add(partner); + } + } else { + candidates.add(partner); + } + } + } + + private void addMatching(Participant participant, Participant partner) { + participant.addPartner(relationship, partner); + partner.addPartner(relationship, participant); + } + + private List getParticipantsLessThan(int numberOfPartner) { + return participants.stream() + .filter(participant -> participant.getNumberOfPartners() < numberOfPartner) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/util/MatchingConverter.java b/src/main/java/com/aliens/backend/mathcing/business/util/MatchingConverter.java new file mode 100644 index 00000000..357c83ab --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/util/MatchingConverter.java @@ -0,0 +1,27 @@ +package com.aliens.backend.mathcing.business.util; + +import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.service.model.Participant; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@Component +public class MatchingConverter { + public List toParticipantList(List matchingApplications) { + return matchingApplications.stream() + .map(this::toParticipantList) + .collect(Collectors.toList()); + } + + private Participant toParticipantList(MatchingApplication matchingApplication) { + return new Participant( + matchingApplication.getId().getMemberId(), + matchingApplication.getFirstPreferLanguage(), + matchingApplication.getSecondPreferLanguage(), + new ArrayList<>() + ); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/util/MatchingQueueBuilder.java b/src/main/java/com/aliens/backend/mathcing/business/util/MatchingQueueBuilder.java new file mode 100644 index 00000000..af94e1c0 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/util/MatchingQueueBuilder.java @@ -0,0 +1,29 @@ +package com.aliens.backend.mathcing.business.util; + +import com.aliens.backend.mathcing.service.model.Language; +import com.aliens.backend.mathcing.service.model.Participant; +import com.aliens.backend.mathcing.service.model.PreferLanguage; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component +public class MatchingQueueBuilder { + public Map> buildLanguageQueues(List participants) { + Map> languageQueue = createQueuesByLanguage(); + + for (Participant participant : participants) { + languageQueue.get(participant.getPreferLanguage(PreferLanguage.FIRST)).add(participant); + } + + return languageQueue; + } + + private Map> createQueuesByLanguage() { + Map> languageQueue = new HashMap<>(); + for (Language language : Language.values()) { + languageQueue.put(language, new LinkedList<>()); + } + return languageQueue; + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingApplicationRepository.java b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingApplicationRepository.java index d87c0df0..eb6aef6c 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingApplicationRepository.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingApplicationRepository.java @@ -1,10 +1,16 @@ package com.aliens.backend.mathcing.domain.repository; import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface MatchingApplicationRepository extends JpaRepository { + @Query("SELECT ma FROM MatchingApplication ma WHERE ma.id.matchingRound = :matchingRound") + List findAllByMatchingRound(MatchingRound matchingRound); } diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java b/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java index fa5aaa59..97bccba3 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java +++ b/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java @@ -1,24 +1,16 @@ package com.aliens.backend.mathcing.service.model; -import java.util.List; - -public class Participant { - private Long memberId; - private Language firstPreferLanguage; - private Language secondPreferLanguage; - private List partners; +import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.exception.RestApiException; - public Participant(final Long memberId, final Language firstPreferLanguage, final Language secondPreferLanguage, final List partners) { - this.memberId = memberId; - this.firstPreferLanguage = firstPreferLanguage; - this.secondPreferLanguage = secondPreferLanguage; - this.partners = partners; - } - - public Long getMemberId() { - return memberId; - } +import java.util.List; +public record Participant( + Long memberId, + Language firstPreferLanguage, + Language secondPreferLanguage, + List partners +) { public Language getPreferLanguage(PreferLanguage preferLanguage) { if (preferLanguage.equals(PreferLanguage.FIRST)) { return firstPreferLanguage; @@ -26,18 +18,19 @@ public Language getPreferLanguage(PreferLanguage preferLanguage) { if (preferLanguage.equals(PreferLanguage.SECOND)) { return secondPreferLanguage; } - return Language.KOREAN; - } - - public List getPartners() { - return partners; + throw new RestApiException(MatchingError.NOT_FOUND_PREFER_LANGUAGE); } public int getNumberOfPartners() { return partners.size(); } - public void addPartner(Participant participant) { - partners.add(participant); + public void addPartner(Relationship relationship, Participant participant) { + partners.add(Partner.of(relationship, participant)); + } + + public boolean isPartnerWith(Participant participant) { + return partners.stream() + .anyMatch(partner -> partner.participant().equals(participant)); } } diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Partner.java b/src/main/java/com/aliens/backend/mathcing/service/model/Partner.java new file mode 100644 index 00000000..a85a9813 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/service/model/Partner.java @@ -0,0 +1,10 @@ +package com.aliens.backend.mathcing.service.model; + +public record Partner( + Relationship relationship, + Participant participant +) { + public static Partner of(Relationship relationship, Participant participant) { + return new Partner(relationship, participant); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Relationship.java b/src/main/java/com/aliens/backend/mathcing/service/model/Relationship.java new file mode 100644 index 00000000..04b97fbd --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/service/model/Relationship.java @@ -0,0 +1,7 @@ +package com.aliens.backend.mathcing.service.model; + +public enum Relationship { + NORMAL, + SPECIAL, + ; +} diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java new file mode 100644 index 00000000..a54fd198 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java @@ -0,0 +1,30 @@ +package com.aliens.backend.mathcing.validator; + +import com.aliens.backend.global.property.MatchingRuleProperties; +import com.aliens.backend.mathcing.service.model.Participant; +import org.springframework.stereotype.Component; + +@Component +public class MatchingBusinessValidator { + private final MatchingRuleProperties matchingRuleProperties; + + public MatchingBusinessValidator(final MatchingRuleProperties matchingRuleProperties) { + this.matchingRuleProperties = matchingRuleProperties; + } + + public boolean isValidMatching(Participant participant, Participant partner) { + return participant != partner && + !participant.isPartnerWith(partner) && + !partner.isPartnerWith(participant) && + isExceededMaxNormalPartners(partner); + } + + public boolean isExceededMaxNormalPartners(Participant participant) { + return participant.getNumberOfPartners() > matchingRuleProperties.getMaxNormalPartners(); + } + + public boolean isExceedMaxTries(int tries) { + return tries > matchingRuleProperties.getMaxTries(); + } + +} From 61ffab3e7781dafa39cfc05cc973402bef917990 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Tue, 30 Jan 2024 13:26:55 +0900 Subject: [PATCH 077/215] =?UTF-8?q?feat(SuccessCode)=20:=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=BD=94=EB=93=9C,=20=EB=A9=94=EC=8B=9C=EC=A7=80?= =?UTF-8?q?=EB=A5=BC=20=EB=8B=B4=EC=9D=84=20=EC=88=98=20=EC=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=BB=A4=EC=8A=A4=ED=85=80=20ResponseEntity=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/success/SuccessCode.java | 9 +++++++ .../global/success/SuccessResponse.java | 21 +++++++++++++++ .../success/SuccessResponseWithoutResult.java | 26 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/success/SuccessCode.java create mode 100644 src/main/java/com/aliens/backend/global/success/SuccessResponse.java create mode 100644 src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java diff --git a/src/main/java/com/aliens/backend/global/success/SuccessCode.java b/src/main/java/com/aliens/backend/global/success/SuccessCode.java new file mode 100644 index 00000000..517468fe --- /dev/null +++ b/src/main/java/com/aliens/backend/global/success/SuccessCode.java @@ -0,0 +1,9 @@ +package com.aliens.backend.global.success; + +import org.springframework.http.HttpStatus; + +public interface SuccessCode { + HttpStatus getHttpStatus(); + String getCode(); + String getMessage(); +} diff --git a/src/main/java/com/aliens/backend/global/success/SuccessResponse.java b/src/main/java/com/aliens/backend/global/success/SuccessResponse.java new file mode 100644 index 00000000..43164c45 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/success/SuccessResponse.java @@ -0,0 +1,21 @@ +package com.aliens.backend.global.success; + +import org.springframework.http.ResponseEntity; + +public class SuccessResponse { + + private String code; + private String message; + private T result; + + public SuccessResponse(final String code, final String message, final T result) { + this.code = code; + this.message = message; + this.result = result; + } + + public static ResponseEntity toResponseEntity(SuccessCode successCode, Object result) { + SuccessResponse res = new SuccessResponse(successCode.getCode(), successCode.getMessage(), result); + return new ResponseEntity<>(res, successCode.getHttpStatus()); + } +} diff --git a/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java b/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java new file mode 100644 index 00000000..0e95ce51 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java @@ -0,0 +1,26 @@ +package com.aliens.backend.global.success; + +import org.springframework.http.ResponseEntity; + +public class SuccessResponseWithoutResult { + private String code; + private String message; + + public SuccessResponseWithoutResult(final String code, final String message) { + this.code = code; + this.message = message; + } + + public static ResponseEntity toResponseEntity(SuccessCode successCode) { + SuccessResponseWithoutResult res = new SuccessResponseWithoutResult(successCode.getCode(), successCode.getMessage()); + return new ResponseEntity<>(res, successCode.getHttpStatus()); + } + + public String getCode() { + return code; + } + + public String getMessage() { + return message; + } +} From efc2ea9635f1bffad0e081ad82780a7958548c41 Mon Sep 17 00:00:00 2001 From: coke98 Date: Fri, 2 Feb 2024 16:47:37 +0900 Subject: [PATCH 078/215] =?UTF-8?q?chore(build.gradle):=20=EC=9B=B9?= =?UTF-8?q?=EC=86=8C=EC=BC=93=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7348fc68..d15b9f69 100644 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,9 @@ dependencies { //SMTP implementation 'org.springframework.boot:spring-boot-starter-mail' + + //WEBSOCKET + implementation 'org.springframework.boot:spring-boot-starter-websocket' } ext { @@ -71,4 +74,4 @@ bootJar { tasks.named('test') { useJUnitPlatform() -} +} \ No newline at end of file From 532ada4f0425191db9b64886a9fe0da2480ec4b1 Mon Sep 17 00:00:00 2001 From: coke98 Date: Fri, 2 Feb 2024 17:04:36 +0900 Subject: [PATCH 079/215] =?UTF-8?q?feat(WebSocketProperties):=20=EC=9B=B9?= =?UTF-8?q?=EC=86=8C=EC=BC=93=20Properties=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/property/WebSocketProperties.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/property/WebSocketProperties.java diff --git a/src/main/java/com/aliens/backend/global/property/WebSocketProperties.java b/src/main/java/com/aliens/backend/global/property/WebSocketProperties.java new file mode 100644 index 00000000..bbf059dc --- /dev/null +++ b/src/main/java/com/aliens/backend/global/property/WebSocketProperties.java @@ -0,0 +1,36 @@ +package com.aliens.backend.global.property; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class WebSocketProperties { + + @Value("${websocket.port}") + private String port; + + @Value("${websocket.request}") + private String request; + + @Value("${websocket.topic}") + private String topic; + + @Value("${websocket.endpoint}") + private String endpoint; + + public String getPort() { + return port; + } + + public String getRequest() { + return request; + } + + public String getTopic() { + return topic; + } + + public String getEndpoint() { + return endpoint; + } +} From 4d9fd70ebdcd6de40844edf52fed6d3cb7513552 Mon Sep 17 00:00:00 2001 From: coke98 Date: Fri, 2 Feb 2024 17:13:54 +0900 Subject: [PATCH 080/215] =?UTF-8?q?feat(ChatClient):=20STOMP=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=ED=81=B4=EB=9D=BC=EC=9D=B4=EC=96=B8=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/chatting/util/ChatClient.java | 33 +++++++++++++++++++ .../chatting/util/ChatClientHandler.java | 18 ++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/test/java/com/aliens/backend/chatting/util/ChatClient.java create mode 100644 src/test/java/com/aliens/backend/chatting/util/ChatClientHandler.java diff --git a/src/test/java/com/aliens/backend/chatting/util/ChatClient.java b/src/test/java/com/aliens/backend/chatting/util/ChatClient.java new file mode 100644 index 00000000..d2c95c30 --- /dev/null +++ b/src/test/java/com/aliens/backend/chatting/util/ChatClient.java @@ -0,0 +1,33 @@ +package com.aliens.backend.chatting.util; + +import com.aliens.backend.global.property.WebSocketProperties; +import org.springframework.messaging.simp.stomp.StompSession; +import org.springframework.web.socket.client.WebSocketClient; +import org.springframework.web.socket.client.standard.StandardWebSocketClient; +import org.springframework.web.socket.messaging.WebSocketStompClient; + +public class ChatClient { + private final String endPoint; + private final String port; + private final WebSocketStompClient stompClient; + private final ChatClientHandler chatClientHandler; + + public ChatClient(WebSocketProperties properties) { + this.endPoint = properties.getEndpoint(); + this.port = properties.getPort(); + this.stompClient = createStompClient(); + this.chatClientHandler = new ChatClientHandler(); + } + + public StompSession connect() throws Exception { + String url = "ws://localhost:" + port + endPoint; + StompSession session = stompClient.connect(url, chatClientHandler).get(); + return session; + } + + private WebSocketStompClient createStompClient() { + WebSocketClient webSocketClient = new StandardWebSocketClient(); + WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient); + return stompClient; + } +} diff --git a/src/test/java/com/aliens/backend/chatting/util/ChatClientHandler.java b/src/test/java/com/aliens/backend/chatting/util/ChatClientHandler.java new file mode 100644 index 00000000..590e0d7c --- /dev/null +++ b/src/test/java/com/aliens/backend/chatting/util/ChatClientHandler.java @@ -0,0 +1,18 @@ +package com.aliens.backend.chatting.util; + +import org.springframework.messaging.simp.stomp.StompHeaders; +import org.springframework.messaging.simp.stomp.StompSession; +import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter; + +public class ChatClientHandler extends StompSessionHandlerAdapter { + public ChatClientHandler() { + } + + @Override + public void afterConnected(StompSession session, StompHeaders connectedHeaders) { + } + + @Override + public void handleFrame(StompHeaders headers, Object payload) { + } + } \ No newline at end of file From 0b84acdb52ffab66015b44e36cba04d943498d60 Mon Sep 17 00:00:00 2001 From: coke98 Date: Fri, 2 Feb 2024 17:43:55 +0900 Subject: [PATCH 081/215] =?UTF-8?q?test(WebSocketTest):=20=EC=9B=B9?= =?UTF-8?q?=EC=86=8C=EC=BC=93=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/chatting/WebSocketTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/test/java/com/aliens/backend/chatting/WebSocketTest.java diff --git a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java new file mode 100644 index 00000000..bfd20fbe --- /dev/null +++ b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java @@ -0,0 +1,35 @@ +package com.aliens.backend.chatting; + +import com.aliens.backend.chatting.util.ChatClient; +import com.aliens.backend.global.property.WebSocketProperties; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.messaging.simp.stomp.StompSession; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class WebSocketTest { + + @Autowired + private WebSocketProperties properties; + private ChatClient chatClient; + + @BeforeEach + public void setup() { + chatClient = new ChatClient(properties); + } + + @Test + @DisplayName("웹소켓 연결 테스트") + public void WebSocketConnection() throws Exception { + //given + //when + StompSession session = chatClient.connect(); + //then + assert session.isConnected(); + } +} \ No newline at end of file From f90f12859686e7bee8e8603337bcb8c30bb88be7 Mon Sep 17 00:00:00 2001 From: coke98 Date: Fri, 2 Feb 2024 17:45:07 +0900 Subject: [PATCH 082/215] =?UTF-8?q?feat(WebSocketConfig):=20=EC=9B=B9?= =?UTF-8?q?=EC=86=8C=EC=BC=93=20=EC=84=A4=EC=A0=95=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/WebSocketConfig.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/config/WebSocketConfig.java diff --git a/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java b/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java new file mode 100644 index 00000000..fe5cfd06 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java @@ -0,0 +1,49 @@ +package com.aliens.backend.global.config; + +import com.aliens.backend.global.property.WebSocketProperties; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.context.annotation.Configuration; +import org.springframework.messaging.converter.DefaultContentTypeResolver; +import org.springframework.messaging.converter.MappingJackson2MessageConverter; +import org.springframework.messaging.converter.MessageConverter; +import org.springframework.messaging.simp.config.MessageBrokerRegistry; +import org.springframework.util.MimeTypeUtils; +import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; +import org.springframework.web.socket.config.annotation.StompEndpointRegistry; +import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; + +import java.util.List; + +@Configuration +@EnableWebSocketMessageBroker +public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { + + private final WebSocketProperties properties; + + public WebSocketConfig(WebSocketProperties properties) { + this.properties = properties; + } + + @Override + public void configureMessageBroker(MessageBrokerRegistry registry) { + registry.setApplicationDestinationPrefixes(properties.getRequest()); + registry.setUserDestinationPrefix(properties.getTopic()); + } + + @Override + public void registerStompEndpoints(StompEndpointRegistry registry) { + registry.addEndpoint(properties.getEndpoint()) + .setAllowedOrigins("*"); + } + + @Override + public boolean configureMessageConverters(List messageConverters) { + DefaultContentTypeResolver resolver = new DefaultContentTypeResolver(); + resolver.setDefaultMimeType(MimeTypeUtils.APPLICATION_JSON); + MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); + converter.setObjectMapper(new ObjectMapper()); + converter.setContentTypeResolver(resolver); + messageConverters.add(converter); + return false; + } +} From a405a6dd88b23ecadf8b31f01837c50bbc4a9c84 Mon Sep 17 00:00:00 2001 From: coke98 Date: Sat, 3 Feb 2024 18:38:29 +0900 Subject: [PATCH 083/215] =?UTF-8?q?test(WebSocketTest):=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=A0=84=EC=86=A1,=20=EC=9D=BD=EC=9D=8C?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC,=20=EC=B1=84=ED=8C=85=20=EC=9A=94?= =?UTF-8?q?=EC=95=BD=EC=A0=95=EB=B3=B4=20=EC=9A=94=EC=B2=AD=20=EC=BC=80?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/chatting/WebSocketTest.java | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java index bfd20fbe..7f7868ee 100644 --- a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java +++ b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java @@ -1,21 +1,27 @@ package com.aliens.backend.chatting; +import com.aliens.backend.chat.controller.ChatController; +import com.aliens.backend.chat.service.ChatService; import com.aliens.backend.chatting.util.ChatClient; import com.aliens.backend.global.property.WebSocketProperties; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.messaging.simp.stomp.StompSession; -import org.springframework.test.context.junit.jupiter.SpringExtension; + +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) public class WebSocketTest { @Autowired private WebSocketProperties properties; + @MockBean + private ChatController chatController; private ChatClient chatClient; @BeforeEach @@ -24,12 +30,44 @@ public void setup() { } @Test - @DisplayName("웹소켓 연결 테스트") + @DisplayName("웹소켓 - 연결") public void WebSocketConnection() throws Exception { - //given //when StompSession session = chatClient.connect(); //then assert session.isConnected(); } + + @Test + @DisplayName("웹소켓 - 메시지 전송 요청시 sendMessage() 호출") + public void WebSocketSendMessage() throws Exception { + //given + StompSession session = chatClient.connect(); + //when + session.send(properties.getRequest()+"/send",""); + //then + verify(chatController, timeout(100).times(1)).sendMessage(); + } + + @Test + @DisplayName("웹소켓 - 읽음 처리 요청 시 readMessage() 호출") + public void WebSocketReadMessage() throws Exception { + //given + StompSession session = chatClient.connect(); + //when + session.send(properties.getRequest()+"/read",""); + //then + verify(chatController, timeout(100).times(1)).readMessage(); + } + + @Test + @DisplayName("웹소켓 - 채팅 요약 정보 요청 시 getChatSummary() 호출") + public void WebSocketGetChatSummary() throws Exception { + //given + StompSession session = chatClient.connect(); + //when + session.send(properties.getRequest()+"/summary",""); + //then + verify(chatController, timeout(100).times(1)).getChatSummary(); + } } \ No newline at end of file From 04749c10e52b635f0266aadf86c7830b9b2826a5 Mon Sep 17 00:00:00 2001 From: coke98 Date: Sat, 3 Feb 2024 18:40:22 +0900 Subject: [PATCH 084/215] =?UTF-8?q?feat(ChatController):=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC,=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/controller/ChatController.java | 32 +++++++++++++++++++ .../backend/chat/service/ChatService.java | 15 +++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/controller/ChatController.java create mode 100644 src/main/java/com/aliens/backend/chat/service/ChatService.java diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatController.java b/src/main/java/com/aliens/backend/chat/controller/ChatController.java new file mode 100644 index 00000000..83a9c351 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/controller/ChatController.java @@ -0,0 +1,32 @@ +package com.aliens.backend.chat.controller; + +import com.aliens.backend.chat.service.ChatService; +import org.springframework.messaging.handler.annotation.MessageMapping; +import org.springframework.stereotype.Controller; + + +@Controller +public class ChatController { + + private final ChatService chatService; + + public ChatController(ChatService chatService) { + this.chatService = chatService; + } + + @MessageMapping("/send") + public void sendMessage() { + chatService.sendMessage(); + } + + @MessageMapping("/read") + public void readMessage() { + chatService.readMessage(); + } + + @MessageMapping("/summary") + public void getChatSummary() { + chatService.getChatSummary(); + } + +} diff --git a/src/main/java/com/aliens/backend/chat/service/ChatService.java b/src/main/java/com/aliens/backend/chat/service/ChatService.java new file mode 100644 index 00000000..6c56bb01 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/service/ChatService.java @@ -0,0 +1,15 @@ +package com.aliens.backend.chat.service; + +import org.springframework.stereotype.Service; + +@Service +public class ChatService { + public void sendMessage() { + } + + public void readMessage() { + } + + public void getChatSummary() { + } +} From 7fa7c6c8e6c9d5e8e361a0664fcd80c9b1d6ae65 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sat, 3 Feb 2024 23:02:17 +0900 Subject: [PATCH 085/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/business/MatchingBusiness.java | 51 +++++++++++++------ .../business/util/MatchingQueueBuilder.java | 4 +- .../mathcing/service/model/MatchingMode.java | 9 ++++ .../mathcing/service/model/Participant.java | 6 +-- .../service/model/PreferLanguage.java | 7 --- .../validator/MatchingBusinessValidator.java | 12 +++-- 6 files changed, 57 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/aliens/backend/mathcing/service/model/MatchingMode.java delete mode 100644 src/main/java/com/aliens/backend/mathcing/service/model/PreferLanguage.java diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index 7ab9b819..df98b6ec 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -10,7 +10,7 @@ import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.model.Language; import com.aliens.backend.mathcing.service.model.Participant; -import com.aliens.backend.mathcing.service.model.PreferLanguage; +import com.aliens.backend.mathcing.service.model.MatchingMode; import com.aliens.backend.mathcing.service.model.Relationship; import com.aliens.backend.mathcing.validator.MatchingBusinessValidator; import jakarta.annotation.PostConstruct; @@ -59,38 +59,57 @@ private void initialize() { @Scheduled(cron = "${matching.round.start}") public void operateMatching() { - matchParticipantsWith(PreferLanguage.FIRST); - matchParticipantsWith(PreferLanguage.SECOND); - + matchParticipantsWith(MatchingMode.FIRST_PREFER_LANGUAGE); + matchParticipantsWith(MatchingMode.SECOND_PREFER_LANGUAGE); + matchParticipantsWith(MatchingMode.RANDOM); + matchParticipantsWith(MatchingMode.SPECIAL); } - private void matchParticipantsWith(PreferLanguage preferLanguage) { - if (preferLanguage.equals(PreferLanguage.FIRST)) { - matchWith(preferLanguage, participants); + private void matchParticipantsWith(MatchingMode matchingMode) { + List participants = null; + if (matchingMode.equals(MatchingMode.FIRST_PREFER_LANGUAGE)) { + participants = this.participants; + } + if (matchingMode.equals(MatchingMode.SECOND_PREFER_LANGUAGE)) { + participants = getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); + languageQueueWithParticipants = matchingQueueBuilder.buildLanguageQueues(this.participants); + } + if (matchingMode.equals(MatchingMode.RANDOM)) { + relationship = Relationship.SPECIAL; + participants = getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); } - if (preferLanguage.equals(PreferLanguage.SECOND)) { - List lessMatchedParticipants = getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); - languageQueueWithParticipants = matchingQueueBuilder.buildLanguageQueues(participants); - matchWith(preferLanguage, lessMatchedParticipants); + if (matchingMode.equals(MatchingMode.SPECIAL)) { + participants = getParticipantsLessThan(matchingRuleProperties.getMaxPartners()); } + matchWith(matchingMode, participants); } - private void matchWith(PreferLanguage preferLanguage, List participants) { + private void matchWith(MatchingMode matchingMode, List participants) { + Queue candidates = null; + if (matchingMode.equals(MatchingMode.RANDOM)) { + candidates = new LinkedList<>(getParticipantsLessThan(matchingRuleProperties.getMaxPartners())); + } + if (matchingMode.equals(MatchingMode.SPECIAL)) { + candidates = new LinkedList<>(participants); + } for (Participant participant : participants) { - Queue candidates = languageQueueWithParticipants.get(participant.getPreferLanguage(preferLanguage)); + if (matchingMode.equals(MatchingMode.FIRST_PREFER_LANGUAGE) || + matchingMode.equals(MatchingMode.SECOND_PREFER_LANGUAGE)) { + candidates = languageQueueWithParticipants.get(participant.getPreferLanguage(matchingMode)); + } tryMatchBetween(participant, candidates); } } private void tryMatchBetween(Participant participant, Queue candidates) { int tries = 0; - while (matchingBusinessValidator.isExceededMaxNormalPartners(participant) && + while (matchingBusinessValidator.isExceededMaxPartners(relationship, participant) && matchingBusinessValidator.isExceedMaxTries(tries) && !candidates.isEmpty()) { Participant partner = candidates.poll(); tries++; - if (matchingBusinessValidator.isValidMatching(participant, partner)) { + if (matchingBusinessValidator.isValidMatching(relationship, participant, partner)) { addMatching(participant, partner); - if (!matchingBusinessValidator.isExceededMaxNormalPartners(partner)) { + if (!matchingBusinessValidator.isExceededMaxPartners(relationship, partner)) { candidates.add(partner); } } else { diff --git a/src/main/java/com/aliens/backend/mathcing/business/util/MatchingQueueBuilder.java b/src/main/java/com/aliens/backend/mathcing/business/util/MatchingQueueBuilder.java index af94e1c0..45b5121d 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/util/MatchingQueueBuilder.java +++ b/src/main/java/com/aliens/backend/mathcing/business/util/MatchingQueueBuilder.java @@ -2,7 +2,7 @@ import com.aliens.backend.mathcing.service.model.Language; import com.aliens.backend.mathcing.service.model.Participant; -import com.aliens.backend.mathcing.service.model.PreferLanguage; +import com.aliens.backend.mathcing.service.model.MatchingMode; import org.springframework.stereotype.Component; import java.util.*; @@ -13,7 +13,7 @@ public Map> buildLanguageQueues(List p Map> languageQueue = createQueuesByLanguage(); for (Participant participant : participants) { - languageQueue.get(participant.getPreferLanguage(PreferLanguage.FIRST)).add(participant); + languageQueue.get(participant.getPreferLanguage(MatchingMode.FIRST_PREFER_LANGUAGE)).add(participant); } return languageQueue; diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/MatchingMode.java b/src/main/java/com/aliens/backend/mathcing/service/model/MatchingMode.java new file mode 100644 index 00000000..82909c58 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/service/model/MatchingMode.java @@ -0,0 +1,9 @@ +package com.aliens.backend.mathcing.service.model; + +public enum MatchingMode { + FIRST_PREFER_LANGUAGE, + SECOND_PREFER_LANGUAGE, + RANDOM, + SPECIAL, + ; +} diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java b/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java index 97bccba3..a5e3fa1b 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java +++ b/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java @@ -11,11 +11,11 @@ public record Participant( Language secondPreferLanguage, List partners ) { - public Language getPreferLanguage(PreferLanguage preferLanguage) { - if (preferLanguage.equals(PreferLanguage.FIRST)) { + public Language getPreferLanguage(MatchingMode matchingMode) { + if (matchingMode.equals(MatchingMode.FIRST_PREFER_LANGUAGE)) { return firstPreferLanguage; } - if (preferLanguage.equals(PreferLanguage.SECOND)) { + if (matchingMode.equals(MatchingMode.SECOND_PREFER_LANGUAGE)) { return secondPreferLanguage; } throw new RestApiException(MatchingError.NOT_FOUND_PREFER_LANGUAGE); diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/PreferLanguage.java b/src/main/java/com/aliens/backend/mathcing/service/model/PreferLanguage.java deleted file mode 100644 index 98ef9c6c..00000000 --- a/src/main/java/com/aliens/backend/mathcing/service/model/PreferLanguage.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.aliens.backend.mathcing.service.model; - -public enum PreferLanguage { - FIRST, - SECOND - ; -} diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java index a54fd198..00b52b96 100644 --- a/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java +++ b/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java @@ -2,6 +2,7 @@ import com.aliens.backend.global.property.MatchingRuleProperties; import com.aliens.backend.mathcing.service.model.Participant; +import com.aliens.backend.mathcing.service.model.Relationship; import org.springframework.stereotype.Component; @Component @@ -12,15 +13,18 @@ public MatchingBusinessValidator(final MatchingRuleProperties matchingRuleProper this.matchingRuleProperties = matchingRuleProperties; } - public boolean isValidMatching(Participant participant, Participant partner) { + public boolean isValidMatching(Relationship relationship, Participant participant, Participant partner) { return participant != partner && !participant.isPartnerWith(partner) && !partner.isPartnerWith(participant) && - isExceededMaxNormalPartners(partner); + isExceededMaxPartners(relationship, partner); } - public boolean isExceededMaxNormalPartners(Participant participant) { - return participant.getNumberOfPartners() > matchingRuleProperties.getMaxNormalPartners(); + public boolean isExceededMaxPartners(Relationship relationship, Participant participant) { + if (relationship.equals(Relationship.NORMAL)) { + return participant.getNumberOfPartners() > matchingRuleProperties.getMaxNormalPartners(); + } + return participant.getNumberOfPartners() > matchingRuleProperties.getMaxPartners(); } public boolean isExceedMaxTries(int tries) { From 5d5f10014cbc7e91a3489935aded37f28a414d28 Mon Sep 17 00:00:00 2001 From: coke98 Date: Sun, 4 Feb 2024 11:35:28 +0900 Subject: [PATCH 086/215] =?UTF-8?q?chore(build.gradle):=20mongo=20db?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index d15b9f69..9b038d6b 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,9 @@ dependencies { //WEBSOCKET implementation 'org.springframework.boot:spring-boot-starter-websocket' + + //MONGO_DB + implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' } ext { From 8d3122208f10e458709763e6bfdb0e1f0d2b0e15 Mon Sep 17 00:00:00 2001 From: coke98 Date: Sun, 4 Feb 2024 14:10:18 +0900 Subject: [PATCH 087/215] =?UTF-8?q?feat(Message,MessageRepository):=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20Document=EC=99=80=20=EB=A0=88?= =?UTF-8?q?=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ChatRepository/MessageRepository.java | 10 +++ .../aliens/backend/chat/domain/Message.java | 81 +++++++++++++++++++ .../backend/chat/domain/MessageType.java | 5 ++ 3 files changed, 96 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/domain/ChatRepository/MessageRepository.java create mode 100644 src/main/java/com/aliens/backend/chat/domain/Message.java create mode 100644 src/main/java/com/aliens/backend/chat/domain/MessageType.java diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/MessageRepository.java b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/MessageRepository.java new file mode 100644 index 00000000..d593de10 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/MessageRepository.java @@ -0,0 +1,10 @@ +package com.aliens.backend.chat.domain.ChatRepository; + +import com.aliens.backend.chat.domain.Message; +import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.stereotype.Repository; + + +@Repository +public interface MessageRepository extends MongoRepository { +} diff --git a/src/main/java/com/aliens/backend/chat/domain/Message.java b/src/main/java/com/aliens/backend/chat/domain/Message.java new file mode 100644 index 00000000..bb505568 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/Message.java @@ -0,0 +1,81 @@ +package com.aliens.backend.chat.domain; + +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.util.Date; + + +@Document(collection = "message") +public class Message { + @Id + private String id; + private MessageType type; + private String content; + private Long roomId; + private Long senderId; + private Long receiverId; + private Date sendTime; + private Boolean isRead; + + public static class MessageBuilder { + private MessageType type; + private String content; + private Long roomId; + private Long senderId; + private Long receiverId; + + public MessageBuilder type(MessageType type) { + this.type = type; + return this; + } + + public MessageBuilder content(String content) { + this.content = content; + return this; + } + + public MessageBuilder roomId(Long roomId) { + this.roomId = roomId; + return this; + } + + public MessageBuilder senderId(Long senderId) { + this.senderId = senderId; + return this; + } + + public MessageBuilder receiverId(Long receiverId) { + this.receiverId = receiverId; + return this; + } + + public Message build() { + return new Message(this); + } + } + + private Message(MessageBuilder builder) { + this.type = builder.type; + this.content = builder.content; + this.roomId = builder.roomId; + this.senderId = builder.senderId; + this.receiverId = builder.receiverId; + this.sendTime = new Date(); + this.isRead = false; + } + + @Override + public String toString() { + return "Message{" + + "id=" + id + + ", type=" + type + + ", content='" + content + '\'' + + ", roomId=" + roomId + + ", senderId=" + senderId + + ", receiverId=" + receiverId + + ", sendTime=" + sendTime + + ", isRead=" + isRead + + '}'; + } +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/domain/MessageType.java b/src/main/java/com/aliens/backend/chat/domain/MessageType.java new file mode 100644 index 00000000..4704d4a8 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/MessageType.java @@ -0,0 +1,5 @@ +package com.aliens.backend.chat.domain; + +public enum MessageType { + NORMAL, BALANCE_GAME +} From 0529e3a31e922348de2c4fef228fd7e47c00d156 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sun, 4 Feb 2024 14:18:56 +0900 Subject: [PATCH 088/215] =?UTF-8?q?test=20:=20LocalDateTime=20=EA=B0=80?= =?UTF-8?q?=EC=A7=9C=20=EC=8B=9C=EA=B0=84=20=EC=83=9D=EC=84=B1=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/matching/MockClock.java | 33 +++++++++++++++++ .../com/aliens/backend/matching/MockTime.java | 14 ++++++++ .../MatchingApplicationServiceTest.java | 36 +++++++------------ 3 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 src/test/java/com/aliens/backend/matching/MockClock.java create mode 100644 src/test/java/com/aliens/backend/matching/MockTime.java diff --git a/src/test/java/com/aliens/backend/matching/MockClock.java b/src/test/java/com/aliens/backend/matching/MockClock.java new file mode 100644 index 00000000..c1159643 --- /dev/null +++ b/src/test/java/com/aliens/backend/matching/MockClock.java @@ -0,0 +1,33 @@ +package com.aliens.backend.matching; + +import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.validator.MatchingApplicationValidator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.stereotype.Component; + +import java.time.Clock; +import java.time.LocalDateTime; +import java.time.ZoneId; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doCallRealMethod; +import static org.mockito.Mockito.when; + +@Component +public class MockClock { + @MockBean + MatchingApplicationValidator matchingApplicationValidator; + + @MockBean + private Clock clock; + + public void mockTime(MatchingRound matchingRound, MockTime mockTime) { + LocalDateTime time = mockTime.time; + Clock fixedClock = Clock.fixed(time.atZone(ZoneId.systemDefault()).toInstant(), ZoneId.systemDefault()); + when(clock.instant()).thenReturn(fixedClock.instant()); + when(clock.getZone()).thenReturn(fixedClock.getZone()); + + doCallRealMethod().when(matchingApplicationValidator).checkReceptionTime(matchingRound, time); + } +} diff --git a/src/test/java/com/aliens/backend/matching/MockTime.java b/src/test/java/com/aliens/backend/matching/MockTime.java new file mode 100644 index 00000000..7d601541 --- /dev/null +++ b/src/test/java/com/aliens/backend/matching/MockTime.java @@ -0,0 +1,14 @@ +package com.aliens.backend.matching; + +import java.time.LocalDateTime; + +public enum MockTime { + INVALID_TIME(LocalDateTime.of(2024, 1, 29, 19, 0)), + VALID_TIME(LocalDateTime.of(2024, 1, 29, 10, 0)); + + public LocalDateTime time; + + private MockTime(LocalDateTime time) { + this.time = time; + } +} diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index 8b76d1c9..dd1d8827 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -3,6 +3,8 @@ import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; +import com.aliens.backend.matching.MockClock; +import com.aliens.backend.matching.MockTime; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; @@ -21,12 +23,12 @@ import java.time.Clock; import java.time.LocalDateTime; -import java.time.ZoneId; +import static com.aliens.backend.matching.MockTime.INVALID_TIME; +import static com.aliens.backend.matching.MockTime.VALID_TIME; import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; import static com.aliens.backend.mathcing.controller.dto.response.MatchingResponse.*; import static org.assertj.core.api.Assertions.*; -import static org.mockito.BDDMockito.*; @SpringBootTest @@ -43,18 +45,12 @@ public class MatchingApplicationServiceTest { @Autowired MatchingTimeProperties matchingTimeProperties; - @MockBean - MatchingApplicationValidator matchingApplicationValidator; - - @MockBean - Clock clock; + @Autowired + MockClock mockClock; MatchingApplicationRequest matchingApplicationRequest; MatchingRound currentRound; - final LocalDateTime VALID_TIME = LocalDateTime.of(2024, 1, 29, 10, 0); - final LocalDateTime INVALID_TIME = LocalDateTime.of(2024, 1, 29, 19, 0); - @BeforeEach void setUp() { LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); @@ -69,7 +65,7 @@ void setUp() { @Transactional void applyMatchTest() { // given - mockTime(VALID_TIME); + mockClock.mockTime(currentRound, VALID_TIME); // when matchingApplicationService.saveParticipant(matchingApplicationRequest); @@ -85,7 +81,7 @@ void applyMatchTest() { @Transactional void applyMatchIfNotValidTime() { // given - mockTime(INVALID_TIME); + mockClock.mockTime(currentRound, INVALID_TIME); // when & then assertThatThrownBy(() -> matchingApplicationService.saveParticipant(matchingApplicationRequest)) @@ -124,7 +120,7 @@ void getMatchingApplicationIfNotApplied() { void deleteMatchingApplicationTest() { // given applyToMatch(); - mockTime(VALID_TIME); + mockClock.mockTime(currentRound, VALID_TIME); // when matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId()); @@ -140,7 +136,7 @@ void deleteMatchingApplicationTest() { void deleteMatchIfNotValidTime() { // given applyToMatch(); - mockTime(INVALID_TIME); + mockClock.mockTime(currentRound, INVALID_TIME); // when & then assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId())) @@ -152,22 +148,14 @@ void deleteMatchIfNotValidTime() { @Transactional void deleteMatchIfNotApplied() { // given - mockTime(VALID_TIME); + mockClock.mockTime(currentRound, VALID_TIME); assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId())) .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getMessage()); } private void applyToMatch() { - mockTime(VALID_TIME); + mockClock.mockTime(currentRound, VALID_TIME); matchingApplicationService.saveParticipant(matchingApplicationRequest); } - - private void mockTime(LocalDateTime time) { - Clock fixedClock = Clock.fixed(time.atZone(ZoneId.systemDefault()).toInstant(), ZoneId.systemDefault()); - when(clock.instant()).thenReturn(fixedClock.instant()); - when(clock.getZone()).thenReturn(fixedClock.getZone()); - - doCallRealMethod().when(matchingApplicationValidator).checkReceptionTime(currentRound, time); - } } From ee3892054039fd276df55889fe53dbb38f74e02d Mon Sep 17 00:00:00 2001 From: coke98 Date: Sun, 4 Feb 2024 14:23:53 +0900 Subject: [PATCH 089/215] =?UTF-8?q?feat(ChatSummary):=20=EC=B1=84=ED=8C=85?= =?UTF-8?q?=20=EC=9A=94=EC=95=BD=20=EC=A0=95=EB=B3=B4=20DTO=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/chat/controller/dto/ChatSummary.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/controller/dto/ChatSummary.java diff --git a/src/main/java/com/aliens/backend/chat/controller/dto/ChatSummary.java b/src/main/java/com/aliens/backend/chat/controller/dto/ChatSummary.java new file mode 100644 index 00000000..20ce7336 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/controller/dto/ChatSummary.java @@ -0,0 +1,6 @@ +package com.aliens.backend.chat.controller.dto; + +import com.aliens.backend.chat.domain.Message; + +public record ChatSummary(Long roomId, Long partnerId, Message lastMessage, Long numberOfUnreadMessages) { +} From e679c0dc4d245613f60b80963781e10d78eaff42 Mon Sep 17 00:00:00 2001 From: coke98 Date: Sun, 4 Feb 2024 14:25:20 +0900 Subject: [PATCH 090/215] =?UTF-8?q?test(ChatServiceTest):=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chatting/service/ChatServiceTest.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java diff --git a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java new file mode 100644 index 00000000..16236e93 --- /dev/null +++ b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java @@ -0,0 +1,65 @@ +package com.aliens.backend.chatting.service; + +import com.aliens.backend.chat.controller.dto.ChatSummary; +import com.aliens.backend.chat.domain.Message; +import com.aliens.backend.chat.service.ChatService; +import com.aliens.backend.global.success.ChatSuccessCode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.List; + +@SpringBootTest +public class ChatServiceTest { + @Autowired + ChatService chatService; + + @Test + @DisplayName("메시지 전송") + void sendMessage() { + //given + Message message = new Message.MessageBuilder() + .content("test message") + .roomId(1L) + .senderId(1L) + .receiverId(2L) + .build(); + //when + String result = chatService.sendMessage(message); + //then + Assertions.assertEquals(ChatSuccessCode.SEND_MESSAGE_SUCCESS.getMessage(), result); + } + + @Test + @DisplayName("메시지 읽음 처리") + void readMessages() { + //given + //when + String result = chatService.readMessages(); + //then + Assertions.assertEquals(ChatSuccessCode.READ_MESSAGES_SUCCESS.getMessage(), result); + } + + @Test + @DisplayName("채팅 요약 정보 조회") + void getChatSummary() { + //given + //when + List result = chatService.getChatSummary(); + //then + Assertions.assertNotNull(result); + } + + @Test + @DisplayName("메시지 조회") + void getMessages() { + //given + //when + List result = chatService.getMessages(); + //then + Assertions.assertNotNull(result); + } +} From 4d97f4dd6a738a6faddc15f54dc045148c91c551 Mon Sep 17 00:00:00 2001 From: coke98 Date: Sun, 4 Feb 2024 14:26:46 +0900 Subject: [PATCH 091/215] =?UTF-8?q?feat(ChatSuccessCode):=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=84=B1=EA=B3=B5=20=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/success/ChatSuccessCode.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java diff --git a/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java b/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java new file mode 100644 index 00000000..79c90653 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java @@ -0,0 +1,34 @@ +package com.aliens.backend.global.success; + +import org.springframework.http.HttpStatus; + +public enum ChatSuccessCode implements SuccessCode { + SEND_MESSAGE_SUCCESS(HttpStatus.CREATED, "CH001", "메시지 전송 성공"), + READ_MESSAGES_SUCCESS(HttpStatus.OK, "CH002", "메시지 읽음 처리 성공"), + ; + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + ChatSuccessCode(final HttpStatus httpStatus, final String code, final String message) { + this.httpStatus = httpStatus; + this.code = code; + this.message = message; + } + + @Override + public HttpStatus getHttpStatus() { + return httpStatus; + } + + @Override + public String getCode() { + return code; + } + + @Override + public String getMessage() { + return message; + } +} \ No newline at end of file From a0c50a7c5aca2228c34b4442d8ed102bb03acf05 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sun, 4 Feb 2024 15:56:55 +0900 Subject: [PATCH 092/215] =?UTF-8?q?fix=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20=EB=94=94=EB=B2=84=EA=B9=85=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/business/MatchingBusiness.java | 23 ++++++++++++------- .../mathcing/domain/MatchingRound.java | 11 +++++++++ .../mathcing/service/model/Participant.java | 12 ++++++---- .../mathcing/service/model/Partner.java | 6 ++--- .../validator/MatchingBusinessValidator.java | 6 ++--- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index df98b6ec..f8b78e2e 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -8,6 +8,7 @@ import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; +import com.aliens.backend.mathcing.service.MatchingRoundService; import com.aliens.backend.mathcing.service.model.Language; import com.aliens.backend.mathcing.service.model.Participant; import com.aliens.backend.mathcing.service.model.MatchingMode; @@ -17,6 +18,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -49,16 +51,17 @@ public MatchingBusiness(final MatchingApplicationRepository matchingApplicationR @PostConstruct private void initialize() { + relationship = Relationship.NORMAL; + } + + @Scheduled(cron = "${matching.round.start}") + public void operateMatching() { MatchingRound currentRound = matchingRoundRepository.findCurrentRound() .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); participants = matchingConverter.toParticipantList( matchingApplicationRepository.findAllByMatchingRound(currentRound)); languageQueueWithParticipants = matchingQueueBuilder.buildLanguageQueues(participants); - relationship = Relationship.NORMAL; - } - @Scheduled(cron = "${matching.round.start}") - public void operateMatching() { matchParticipantsWith(MatchingMode.FIRST_PREFER_LANGUAGE); matchParticipantsWith(MatchingMode.SECOND_PREFER_LANGUAGE); matchParticipantsWith(MatchingMode.RANDOM); @@ -103,8 +106,8 @@ private void matchWith(MatchingMode matchingMode, List participants private void tryMatchBetween(Participant participant, Queue candidates) { int tries = 0; - while (matchingBusinessValidator.isExceededMaxPartners(relationship, participant) && - matchingBusinessValidator.isExceedMaxTries(tries) && !candidates.isEmpty()) { + while (!matchingBusinessValidator.isExceededMaxPartners(relationship, participant) && + !matchingBusinessValidator.isExceedMaxTries(tries) && !candidates.isEmpty()) { Participant partner = candidates.poll(); tries++; if (matchingBusinessValidator.isValidMatching(relationship, participant, partner)) { @@ -119,8 +122,8 @@ private void tryMatchBetween(Participant participant, Queue candida } private void addMatching(Participant participant, Participant partner) { - participant.addPartner(relationship, partner); - partner.addPartner(relationship, participant); + participant.addPartner(relationship, partner.memberId()); + partner.addPartner(relationship, participant.memberId()); } private List getParticipantsLessThan(int numberOfPartner) { @@ -128,4 +131,8 @@ private List getParticipantsLessThan(int numberOfPartner) { .filter(participant -> participant.getNumberOfPartners() < numberOfPartner) .collect(Collectors.toList()); } + + public List getMatchedParticipants() { + return participants; + } } diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java index c9e811a3..fdf9d9e9 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java @@ -67,4 +67,15 @@ public static MatchingRound of(final LocalDateTime today, final MatchingTimeProp return new MatchingRound(matchingRequestStartTime, matchingRequestEndTime, matchingValidStartTime, matchingValidEndTime); } + + @Override + public String toString() { + return "MatchingRound{" + + "round=" + round + + ", matchingRequestStartTime=" + matchingRequestStartTime + + ", matchingRequestEndTime=" + matchingRequestEndTime + + ", matchingValidStartTime=" + matchingValidStartTime + + ", matchingValidEndTime=" + matchingValidEndTime + + '}'; + } } diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java b/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java index a5e3fa1b..727f2f66 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java +++ b/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java @@ -25,12 +25,16 @@ public int getNumberOfPartners() { return partners.size(); } - public void addPartner(Relationship relationship, Participant participant) { - partners.add(Partner.of(relationship, participant)); + public void addPartner(Relationship relationship, Long memberId) { + partners.add(Partner.of(relationship, memberId)); } public boolean isPartnerWith(Participant participant) { - return partners.stream() - .anyMatch(partner -> partner.participant().equals(participant)); + for (Partner partner : partners) { + if (partner.memberId().equals(participant.memberId())) { + return true; + } + } + return false; } } diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Partner.java b/src/main/java/com/aliens/backend/mathcing/service/model/Partner.java index a85a9813..288f1f0c 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/Partner.java +++ b/src/main/java/com/aliens/backend/mathcing/service/model/Partner.java @@ -2,9 +2,9 @@ public record Partner( Relationship relationship, - Participant participant + Long memberId ) { - public static Partner of(Relationship relationship, Participant participant) { - return new Partner(relationship, participant); + public static Partner of(Relationship relationship, Long memberId) { + return new Partner(relationship, memberId); } } diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java index 00b52b96..a4f2ab6b 100644 --- a/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java +++ b/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java @@ -17,14 +17,14 @@ public boolean isValidMatching(Relationship relationship, Participant participan return participant != partner && !participant.isPartnerWith(partner) && !partner.isPartnerWith(participant) && - isExceededMaxPartners(relationship, partner); + !isExceededMaxPartners(relationship, partner); } public boolean isExceededMaxPartners(Relationship relationship, Participant participant) { if (relationship.equals(Relationship.NORMAL)) { - return participant.getNumberOfPartners() > matchingRuleProperties.getMaxNormalPartners(); + return participant.getNumberOfPartners() >= matchingRuleProperties.getMaxNormalPartners(); // 4 } - return participant.getNumberOfPartners() > matchingRuleProperties.getMaxPartners(); + return participant.getNumberOfPartners() >= matchingRuleProperties.getMaxPartners(); // 5 } public boolean isExceedMaxTries(int tries) { From b3765858fcc7d5d44d8d3e6a9bba2efff5880517 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sun, 4 Feb 2024 16:05:00 +0900 Subject: [PATCH 093/215] =?UTF-8?q?fix=20:=20initialize()=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/business/MatchingBusiness.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index f8b78e2e..9dbe702e 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -49,18 +49,9 @@ public MatchingBusiness(final MatchingApplicationRepository matchingApplicationR this.matchingRuleProperties = matchingRuleProperties; } - @PostConstruct - private void initialize() { - relationship = Relationship.NORMAL; - } - @Scheduled(cron = "${matching.round.start}") public void operateMatching() { - MatchingRound currentRound = matchingRoundRepository.findCurrentRound() - .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); - participants = matchingConverter.toParticipantList( - matchingApplicationRepository.findAllByMatchingRound(currentRound)); - languageQueueWithParticipants = matchingQueueBuilder.buildLanguageQueues(participants); + initialize(); matchParticipantsWith(MatchingMode.FIRST_PREFER_LANGUAGE); matchParticipantsWith(MatchingMode.SECOND_PREFER_LANGUAGE); @@ -132,6 +123,15 @@ private List getParticipantsLessThan(int numberOfPartner) { .collect(Collectors.toList()); } + private void initialize() { + MatchingRound currentRound = matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + participants = matchingConverter.toParticipantList( + matchingApplicationRepository.findAllByMatchingRound(currentRound)); + languageQueueWithParticipants = matchingQueueBuilder.buildLanguageQueues(participants); + relationship = Relationship.NORMAL; + } + public List getMatchedParticipants() { return participants; } From 62bc6e8894680f616ac3ce5cd4e8f9b3d35afead Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sun, 4 Feb 2024 16:10:16 +0900 Subject: [PATCH 094/215] =?UTF-8?q?test=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MatchingApplicationGenerator.java | 39 +++++++++++ .../unit/business/MatchingBusinessTest.java | 67 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/test/java/com/aliens/backend/matching/unit/business/MatchingApplicationGenerator.java create mode 100644 src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingApplicationGenerator.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingApplicationGenerator.java new file mode 100644 index 00000000..51b0d47c --- /dev/null +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingApplicationGenerator.java @@ -0,0 +1,39 @@ +package com.aliens.backend.matching.unit.business; + +import com.aliens.backend.mathcing.service.MatchingApplicationService; +import com.aliens.backend.mathcing.service.model.Language; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Random; + +import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; + +@Component +public class MatchingApplicationGenerator { + @Autowired + MatchingApplicationService matchingApplicationService; + + + + public void applyToMatch(Long numberOfMember) { + Random random = new Random(); + + for (long i = 1L; i <= numberOfMember; i++) { + Language firstPreferLanguage = getRandomLanguage(random); + Language secondPreferLanguage; + + do { + secondPreferLanguage = getRandomLanguage(random); + } while (firstPreferLanguage == secondPreferLanguage); + + MatchingApplicationRequest request = new MatchingApplicationRequest(i, firstPreferLanguage, secondPreferLanguage); + matchingApplicationService.saveParticipant(request); + } + } + + private Language getRandomLanguage(Random random) { + Language[] languages = Language.values(); + return languages[random.nextInt(languages.length)]; + } +} diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java new file mode 100644 index 00000000..6ce709cf --- /dev/null +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -0,0 +1,67 @@ +package com.aliens.backend.matching.unit.business; + +import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.property.MatchingTimeProperties; +import com.aliens.backend.matching.MockClock; +import com.aliens.backend.matching.MockTime; +import com.aliens.backend.mathcing.business.MatchingBusiness; +import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; +import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; +import com.aliens.backend.mathcing.service.MatchingApplicationService; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@SpringBootTest +public class MatchingBusinessTest { + @Autowired + MatchingApplicationService matchingApplicationService; + + @Autowired + MatchingApplicationRepository matchingApplicationRepository; + + @Autowired + MatchingRoundRepository matchingRoundRepository; + + @Autowired + MatchingBusiness matchingBusiness; + + @Autowired + MatchingApplicationGenerator matchingApplicationGenerator; + + @Autowired + MatchingTimeProperties matchingTimeProperties; + + @Autowired + MockClock mockClock; + + MatchingRound currentRound; + + @BeforeEach + void setUp() { + LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); + matchingRoundRepository.save(MatchingRound.of(roundBeginTime, matchingTimeProperties)); + currentRound = matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } + + @Test + @Transactional + void matchingLogicTest() { + mockClock.mockTime(currentRound, MockTime.VALID_TIME); + matchingApplicationGenerator.applyToMatch(15L); + + matchingBusiness.operateMatching(); + + matchingBusiness.getMatchedParticipants().forEach(participant -> assertThat(participant.partners()).isNotNull()); + } +} From 8a9b69241e691dc193d867a07924b42180062783 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sun, 4 Feb 2024 16:11:55 +0900 Subject: [PATCH 095/215] =?UTF-8?q?fix=20:=20MockClock,=20MockTime=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../matching/unit/business/MatchingBusinessTest.java | 5 ++--- .../unit/service/MatchingApplicationServiceTest.java | 10 +++------- .../aliens/backend/matching/{ => util}/MockClock.java | 3 +-- .../aliens/backend/matching/{ => util}/MockTime.java | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) rename src/test/java/com/aliens/backend/matching/{ => util}/MockClock.java (91%) rename src/test/java/com/aliens/backend/matching/{ => util}/MockTime.java (86%) diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index 6ce709cf..226e57f2 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -3,14 +3,13 @@ import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; -import com.aliens.backend.matching.MockClock; -import com.aliens.backend.matching.MockTime; +import com.aliens.backend.matching.util.MockClock; +import com.aliens.backend.matching.util.MockTime; import com.aliens.backend.mathcing.business.MatchingBusiness; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.MatchingApplicationService; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index dd1d8827..01bf4da2 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -3,8 +3,7 @@ import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; -import com.aliens.backend.matching.MockClock; -import com.aliens.backend.matching.MockTime; +import com.aliens.backend.matching.util.MockClock; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; @@ -12,20 +11,17 @@ import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.MatchingApplicationService; import com.aliens.backend.mathcing.service.model.Language; -import com.aliens.backend.mathcing.validator.MatchingApplicationValidator; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.transaction.annotation.Transactional; -import java.time.Clock; import java.time.LocalDateTime; -import static com.aliens.backend.matching.MockTime.INVALID_TIME; -import static com.aliens.backend.matching.MockTime.VALID_TIME; +import static com.aliens.backend.matching.util.MockTime.INVALID_TIME; +import static com.aliens.backend.matching.util.MockTime.VALID_TIME; import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; import static com.aliens.backend.mathcing.controller.dto.response.MatchingResponse.*; import static org.assertj.core.api.Assertions.*; diff --git a/src/test/java/com/aliens/backend/matching/MockClock.java b/src/test/java/com/aliens/backend/matching/util/MockClock.java similarity index 91% rename from src/test/java/com/aliens/backend/matching/MockClock.java rename to src/test/java/com/aliens/backend/matching/util/MockClock.java index c1159643..291781c5 100644 --- a/src/test/java/com/aliens/backend/matching/MockClock.java +++ b/src/test/java/com/aliens/backend/matching/util/MockClock.java @@ -1,8 +1,7 @@ -package com.aliens.backend.matching; +package com.aliens.backend.matching.util; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.validator.MatchingApplicationValidator; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.stereotype.Component; diff --git a/src/test/java/com/aliens/backend/matching/MockTime.java b/src/test/java/com/aliens/backend/matching/util/MockTime.java similarity index 86% rename from src/test/java/com/aliens/backend/matching/MockTime.java rename to src/test/java/com/aliens/backend/matching/util/MockTime.java index 7d601541..235bcbab 100644 --- a/src/test/java/com/aliens/backend/matching/MockTime.java +++ b/src/test/java/com/aliens/backend/matching/util/MockTime.java @@ -1,4 +1,4 @@ -package com.aliens.backend.matching; +package com.aliens.backend.matching.util; import java.time.LocalDateTime; From db7fc32c99c79067f66ffeec734b291a4a5190f4 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sun, 4 Feb 2024 19:04:29 +0900 Subject: [PATCH 096/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EC=A0=80=EC=9E=A5=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94,=20=EB=A6=AC=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/domain/MatchingResult.java | 30 ++++++++++++++++ .../mathcing/domain/id/MatchingResultId.java | 36 +++++++++++++++++++ .../repository/MatchingResultRepository.java | 10 ++++++ 3 files changed, 76 insertions(+) create mode 100644 src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java create mode 100644 src/main/java/com/aliens/backend/mathcing/domain/id/MatchingResultId.java create mode 100644 src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingResultRepository.java diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java new file mode 100644 index 00000000..571c311d --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java @@ -0,0 +1,30 @@ +package com.aliens.backend.mathcing.domain; + +import com.aliens.backend.mathcing.domain.id.MatchingResultId; +import jakarta.persistence.Column; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; + +@Entity +public class MatchingResult { + @EmbeddedId + private MatchingResultId id; + + @Column + private Long matchingMemberId; + + @Column + private Long matchedMemberId; + + public MatchingResultId getId() { + return id; + } + + public Long getMatchingMemberId() { + return matchingMemberId; + } + + public Long getMatchedMemberId() { + return matchedMemberId; + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingResultId.java b/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingResultId.java new file mode 100644 index 00000000..b3bf49d5 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingResultId.java @@ -0,0 +1,36 @@ +package com.aliens.backend.mathcing.domain.id; + +import com.aliens.backend.mathcing.domain.MatchingRound; +import jakarta.persistence.*; + +import java.io.Serializable; + +@Embeddable +public class MatchingResultId implements Serializable { + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "matching_round") + private MatchingRound matchingRound; + + @Column(name = "member_id") + private Long memberId; + + protected MatchingResultId() { + } + + private MatchingResultId(final MatchingRound matchingRound, final Long memberId) { + this.matchingRound = matchingRound; + this.memberId = memberId; + } + + public MatchingResultId of(MatchingRound matchingRound, Long memberId) { + return new MatchingResultId(matchingRound, memberId); + } + + public MatchingRound getMatchingRound() { + return matchingRound; + } + + public Long getMemberId() { + return memberId; + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingResultRepository.java b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingResultRepository.java new file mode 100644 index 00000000..fec9a8de --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingResultRepository.java @@ -0,0 +1,10 @@ +package com.aliens.backend.mathcing.domain.repository; + +import com.aliens.backend.mathcing.domain.MatchingResult; +import com.aliens.backend.mathcing.domain.id.MatchingResultId; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface MatchingResultRepository extends JpaRepository { +} From 9dcf2e82dee658697271c05728a6efce696138e3 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sun, 4 Feb 2024 19:04:38 +0900 Subject: [PATCH 097/215] =?UTF-8?q?fix=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EC=9D=98=20=EB=A6=AC=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/business/MatchingBusiness.java | 31 +++++-------- .../mathcing/service/MatchingService.java | 45 +++++++++++++++++++ 2 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/aliens/backend/mathcing/service/MatchingService.java diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index 9dbe702e..4489e568 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -5,6 +5,7 @@ import com.aliens.backend.global.property.MatchingRuleProperties; import com.aliens.backend.mathcing.business.util.MatchingConverter; import com.aliens.backend.mathcing.business.util.MatchingQueueBuilder; +import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; @@ -24,8 +25,6 @@ @Component public class MatchingBusiness { - private final MatchingApplicationRepository matchingApplicationRepository; - private final MatchingRoundRepository matchingRoundRepository; private final MatchingConverter matchingConverter; private final MatchingQueueBuilder matchingQueueBuilder; private final MatchingBusinessValidator matchingBusinessValidator; @@ -35,28 +34,31 @@ public class MatchingBusiness { private Map> languageQueueWithParticipants = new HashMap<>(); private Relationship relationship; - public MatchingBusiness(final MatchingApplicationRepository matchingApplicationRepository, - final MatchingRoundRepository matchingRoundRepository, - final MatchingConverter matchingConverter, + public MatchingBusiness(final MatchingConverter matchingConverter, final MatchingQueueBuilder matchingQueueBuilder, final MatchingBusinessValidator matchingBusinessValidator, final MatchingRuleProperties matchingRuleProperties) { - this.matchingApplicationRepository = matchingApplicationRepository; - this.matchingRoundRepository = matchingRoundRepository; this.matchingConverter = matchingConverter; this.matchingQueueBuilder = matchingQueueBuilder; this.matchingBusinessValidator = matchingBusinessValidator; this.matchingRuleProperties = matchingRuleProperties; } - @Scheduled(cron = "${matching.round.start}") - public void operateMatching() { - initialize(); + private void initialize(List matchingApplications) { + participants = matchingConverter.toParticipantList(matchingApplications); + languageQueueWithParticipants = matchingQueueBuilder.buildLanguageQueues(participants); + relationship = Relationship.NORMAL; + } + + public List operateMatching(List matchingApplications) { + initialize(matchingApplications); matchParticipantsWith(MatchingMode.FIRST_PREFER_LANGUAGE); matchParticipantsWith(MatchingMode.SECOND_PREFER_LANGUAGE); matchParticipantsWith(MatchingMode.RANDOM); matchParticipantsWith(MatchingMode.SPECIAL); + + return participants; } private void matchParticipantsWith(MatchingMode matchingMode) { @@ -123,15 +125,6 @@ private List getParticipantsLessThan(int numberOfPartner) { .collect(Collectors.toList()); } - private void initialize() { - MatchingRound currentRound = matchingRoundRepository.findCurrentRound() - .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); - participants = matchingConverter.toParticipantList( - matchingApplicationRepository.findAllByMatchingRound(currentRound)); - languageQueueWithParticipants = matchingQueueBuilder.buildLanguageQueues(participants); - relationship = Relationship.NORMAL; - } - public List getMatchedParticipants() { return participants; } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java new file mode 100644 index 00000000..76f14c91 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -0,0 +1,45 @@ +package com.aliens.backend.mathcing.service; + +import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.mathcing.business.MatchingBusiness; +import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; +import com.aliens.backend.mathcing.domain.repository.MatchingResultRepository; +import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; +import com.aliens.backend.mathcing.service.model.Participant; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class MatchingService { + private final MatchingRoundRepository matchingRoundRepository; + private final MatchingApplicationRepository matchingApplicationRepository; + private final MatchingResultRepository matchingResultRepository; + private final MatchingBusiness matchingBusiness; + + @Autowired + public MatchingService(final MatchingRoundRepository matchingRoundRepository, + final MatchingApplicationRepository matchingApplicationRepository, + final MatchingResultRepository matchingResultRepository, + final MatchingBusiness matchingBusiness) { + this.matchingRoundRepository = matchingRoundRepository; + this.matchingApplicationRepository = matchingApplicationRepository; + this.matchingResultRepository = matchingResultRepository; + this.matchingBusiness = matchingBusiness; + } + + @Scheduled(cron = "${matching.round.start}") + public void someMethod() { + MatchingRound currentRound = matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + + List participants = matchingBusiness.operateMatching( + matchingApplicationRepository.findAllByMatchingRound(currentRound)); + + } +} From c48427cc174183a9d2b5c4de0fbe5b2dc54cf1dc Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sun, 4 Feb 2024 21:24:45 +0900 Subject: [PATCH 098/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EC=A0=80=EC=9E=A5=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B0=9C=EB=B0=9C=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/domain/MatchingResult.java | 34 ++++++++++++------- .../mathcing/domain/id/MatchingResultId.java | 24 ++++++++----- .../repository/MatchingResultRepository.java | 6 ++++ .../mathcing/service/MatchingService.java | 23 ++++++++++--- .../unit/business/MatchingBusinessTest.java | 31 ++++++++++++++++- 5 files changed, 92 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java index 571c311d..7c347059 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java @@ -1,30 +1,38 @@ package com.aliens.backend.mathcing.domain; import com.aliens.backend.mathcing.domain.id.MatchingResultId; -import jakarta.persistence.Column; -import jakarta.persistence.EmbeddedId; -import jakarta.persistence.Entity; +import com.aliens.backend.mathcing.service.model.Relationship; +import jakarta.persistence.*; @Entity public class MatchingResult { @EmbeddedId private MatchingResultId id; - @Column - private Long matchingMemberId; + @Enumerated(EnumType.STRING) + private Relationship relationship; - @Column - private Long matchedMemberId; + protected MatchingResult() { + } - public MatchingResultId getId() { - return id; + private MatchingResult(final MatchingResultId id, final Relationship relationship) { + this.id = id; + this.relationship = relationship; } - public Long getMatchingMemberId() { - return matchingMemberId; + public static MatchingResult of(MatchingRound matchingRound, + Long matchingMemberId, + Long matchedMemberId, + Relationship relationship) { + return new MatchingResult( + MatchingResultId.of(matchingRound, matchingMemberId, matchedMemberId), relationship); + } + + public MatchingResultId getId() { + return id; } - public Long getMatchedMemberId() { - return matchedMemberId; + public Relationship getRelationship() { + return relationship; } } diff --git a/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingResultId.java b/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingResultId.java index b3bf49d5..2184909d 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingResultId.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/id/MatchingResultId.java @@ -11,26 +11,34 @@ public class MatchingResultId implements Serializable { @JoinColumn(name = "matching_round") private MatchingRound matchingRound; - @Column(name = "member_id") - private Long memberId; + @Column(name = "matching_member_id") + private Long matchingMemberId; + + @Column(name = "matched_member_id") + private Long matchedMemberId; protected MatchingResultId() { } - private MatchingResultId(final MatchingRound matchingRound, final Long memberId) { + private MatchingResultId(final MatchingRound matchingRound, final Long matchingMemberId, final Long matchedMemberId) { this.matchingRound = matchingRound; - this.memberId = memberId; + this.matchingMemberId = matchingMemberId; + this.matchedMemberId = matchedMemberId; } - public MatchingResultId of(MatchingRound matchingRound, Long memberId) { - return new MatchingResultId(matchingRound, memberId); + public static MatchingResultId of(MatchingRound matchingRound, Long matchingMemberId, Long matchedMemberId) { + return new MatchingResultId(matchingRound, matchingMemberId, matchedMemberId); } public MatchingRound getMatchingRound() { return matchingRound; } - public Long getMemberId() { - return memberId; + public Long getMatchingMemberId() { + return matchingMemberId; + } + + public Long getMatchedMemberId() { + return matchedMemberId; } } diff --git a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingResultRepository.java b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingResultRepository.java index fec9a8de..d0cebeb1 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingResultRepository.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingResultRepository.java @@ -1,10 +1,16 @@ package com.aliens.backend.mathcing.domain.repository; import com.aliens.backend.mathcing.domain.MatchingResult; +import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.id.MatchingResultId; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface MatchingResultRepository extends JpaRepository { + @Query("SELECT mr FROM MatchingResult mr WHERE mr.id.matchingRound = :matchingRound") + List findAllByMatchingRound(MatchingRound matchingRound); } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java index 76f14c91..c2ea5a1d 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -3,15 +3,17 @@ import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.business.MatchingBusiness; -import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.domain.MatchingResult; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingResultRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.model.Participant; +import com.aliens.backend.mathcing.service.model.Partner; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -22,6 +24,8 @@ public class MatchingService { private final MatchingResultRepository matchingResultRepository; private final MatchingBusiness matchingBusiness; + private MatchingRound currentRound; + @Autowired public MatchingService(final MatchingRoundRepository matchingRoundRepository, final MatchingApplicationRepository matchingApplicationRepository, @@ -34,12 +38,23 @@ public MatchingService(final MatchingRoundRepository matchingRoundRepository, } @Scheduled(cron = "${matching.round.start}") - public void someMethod() { - MatchingRound currentRound = matchingRoundRepository.findCurrentRound() + @Transactional + public void operateMatching() { + currentRound = matchingRoundRepository.findCurrentRound() .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); - List participants = matchingBusiness.operateMatching( matchingApplicationRepository.findAllByMatchingRound(currentRound)); + saveMatchingResult(participants); + } + private void saveMatchingResult(List participants) { + for (Participant participant : participants) { + Long memberId = participant.memberId(); + for (Partner partner : participant.partners()) { + matchingResultRepository.save( + MatchingResult.of(currentRound, memberId, partner.memberId(), partner.relationship())); + } + // TODO : 매칭 완료 알림 이벤트 발송 & 채팅방 개설 이벤트 발송 + } } } diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index 226e57f2..2f1c203f 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -6,17 +6,23 @@ import com.aliens.backend.matching.util.MockClock; import com.aliens.backend.matching.util.MockTime; import com.aliens.backend.mathcing.business.MatchingBusiness; +import com.aliens.backend.mathcing.domain.MatchingResult; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; +import com.aliens.backend.mathcing.domain.repository.MatchingResultRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.MatchingApplicationService; +import com.aliens.backend.mathcing.service.MatchingService; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; +import java.util.List; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -25,12 +31,18 @@ public class MatchingBusinessTest { @Autowired MatchingApplicationService matchingApplicationService; + @Autowired + MatchingService matchingService; + @Autowired MatchingApplicationRepository matchingApplicationRepository; @Autowired MatchingRoundRepository matchingRoundRepository; + @Autowired + MatchingResultRepository matchingResultRepository; + @Autowired MatchingBusiness matchingBusiness; @@ -55,12 +67,29 @@ void setUp() { @Test @Transactional + @DisplayName("매칭 로직 실행 테스트") void matchingLogicTest() { mockClock.mockTime(currentRound, MockTime.VALID_TIME); matchingApplicationGenerator.applyToMatch(15L); - matchingBusiness.operateMatching(); + matchingBusiness.operateMatching(matchingApplicationRepository.findAllByMatchingRound(currentRound)); matchingBusiness.getMatchedParticipants().forEach(participant -> assertThat(participant.partners()).isNotNull()); } + + @Test + @DisplayName("매칭 결과 조회") + @Transactional + void operateMatchingTest() { + // given + mockClock.mockTime(currentRound, MockTime.VALID_TIME); + matchingApplicationGenerator.applyToMatch(100L); + + // when + matchingService.operateMatching(); + + // then + List result = matchingResultRepository.findAllByMatchingRound(currentRound); + Assertions.assertThat(result).isNotNull(); + } } From 8fd5b464e94516b14a0ce71deb2ca9f4df0becde Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sun, 4 Feb 2024 21:43:11 +0900 Subject: [PATCH 099/215] =?UTF-8?q?feat=20:=20@Scheduler=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/aliens/backend/BackendApplication.java | 2 ++ src/main/resources/application-matching.yml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/BackendApplication.java b/src/main/java/com/aliens/backend/BackendApplication.java index e4a66a86..0a214b2e 100644 --- a/src/main/java/com/aliens/backend/BackendApplication.java +++ b/src/main/java/com/aliens/backend/BackendApplication.java @@ -2,7 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; +@EnableScheduling @SpringBootApplication public class BackendApplication { diff --git a/src/main/resources/application-matching.yml b/src/main/resources/application-matching.yml index 3bfabc50..ea6baca4 100644 --- a/src/main/resources/application-matching.yml +++ b/src/main/resources/application-matching.yml @@ -6,7 +6,7 @@ matching: max-tries: 200 round: update-date: 0 0 0 * * MON,THU - start: 0 0 18 ? * MON,THU" + start: 0 0 18 * * MON,THU request: time: hours: 18 From 57d7e6f5ec25fb5ac328a408a07f53f79d2aaf95 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sun, 4 Feb 2024 22:09:59 +0900 Subject: [PATCH 100/215] =?UTF-8?q?fix=20:=20util=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EB=94=94=EB=A0=89=ED=84=B0=EB=A6=AC=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/mathcing/business/MatchingBusiness.java | 13 ++----------- .../{business => }/util/MatchingConverter.java | 2 +- .../{business => }/util/MatchingQueueBuilder.java | 2 +- 3 files changed, 4 insertions(+), 13 deletions(-) rename src/main/java/com/aliens/backend/mathcing/{business => }/util/MatchingConverter.java (94%) rename src/main/java/com/aliens/backend/mathcing/{business => }/util/MatchingQueueBuilder.java (95%) diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index 4489e568..9a9b9029 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -1,25 +1,16 @@ package com.aliens.backend.mathcing.business; -import com.aliens.backend.global.error.MatchingError; -import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingRuleProperties; -import com.aliens.backend.mathcing.business.util.MatchingConverter; -import com.aliens.backend.mathcing.business.util.MatchingQueueBuilder; +import com.aliens.backend.mathcing.util.MatchingConverter; +import com.aliens.backend.mathcing.util.MatchingQueueBuilder; import com.aliens.backend.mathcing.domain.MatchingApplication; -import com.aliens.backend.mathcing.domain.MatchingRound; -import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; -import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; -import com.aliens.backend.mathcing.service.MatchingRoundService; import com.aliens.backend.mathcing.service.model.Language; import com.aliens.backend.mathcing.service.model.Participant; import com.aliens.backend.mathcing.service.model.MatchingMode; import com.aliens.backend.mathcing.service.model.Relationship; import com.aliens.backend.mathcing.validator.MatchingBusinessValidator; -import jakarta.annotation.PostConstruct; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; diff --git a/src/main/java/com/aliens/backend/mathcing/business/util/MatchingConverter.java b/src/main/java/com/aliens/backend/mathcing/util/MatchingConverter.java similarity index 94% rename from src/main/java/com/aliens/backend/mathcing/business/util/MatchingConverter.java rename to src/main/java/com/aliens/backend/mathcing/util/MatchingConverter.java index 357c83ab..1b38c1d2 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/util/MatchingConverter.java +++ b/src/main/java/com/aliens/backend/mathcing/util/MatchingConverter.java @@ -1,4 +1,4 @@ -package com.aliens.backend.mathcing.business.util; +package com.aliens.backend.mathcing.util; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.service.model.Participant; diff --git a/src/main/java/com/aliens/backend/mathcing/business/util/MatchingQueueBuilder.java b/src/main/java/com/aliens/backend/mathcing/util/MatchingQueueBuilder.java similarity index 95% rename from src/main/java/com/aliens/backend/mathcing/business/util/MatchingQueueBuilder.java rename to src/main/java/com/aliens/backend/mathcing/util/MatchingQueueBuilder.java index 45b5121d..dfc68157 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/util/MatchingQueueBuilder.java +++ b/src/main/java/com/aliens/backend/mathcing/util/MatchingQueueBuilder.java @@ -1,4 +1,4 @@ -package com.aliens.backend.mathcing.business.util; +package com.aliens.backend.mathcing.util; import com.aliens.backend.mathcing.service.model.Language; import com.aliens.backend.mathcing.service.model.Participant; From 3294241cebe3bcd4e9c32050c2b961d3f8ebf64f Mon Sep 17 00:00:00 2001 From: Oniqued Date: Sun, 4 Feb 2024 22:21:17 +0900 Subject: [PATCH 101/215] =?UTF-8?q?fix=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EA=B0=80=EB=8F=85=EC=84=B1=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MatchingApplicationGenerator.java | 3 +- .../unit/business/MatchingBusinessTest.java | 34 +++++-------------- .../MatchingApplicationServiceTest.java | 19 +++-------- .../service/MatchingRoundServiceTest.java | 7 ++-- 4 files changed, 16 insertions(+), 47 deletions(-) diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingApplicationGenerator.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingApplicationGenerator.java index 51b0d47c..0afc342b 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingApplicationGenerator.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingApplicationGenerator.java @@ -11,8 +11,7 @@ @Component public class MatchingApplicationGenerator { - @Autowired - MatchingApplicationService matchingApplicationService; + @Autowired MatchingApplicationService matchingApplicationService; diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index 2f1c203f..fd745e94 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -28,32 +28,14 @@ @SpringBootTest public class MatchingBusinessTest { - @Autowired - MatchingApplicationService matchingApplicationService; - - @Autowired - MatchingService matchingService; - - @Autowired - MatchingApplicationRepository matchingApplicationRepository; - - @Autowired - MatchingRoundRepository matchingRoundRepository; - - @Autowired - MatchingResultRepository matchingResultRepository; - - @Autowired - MatchingBusiness matchingBusiness; - - @Autowired - MatchingApplicationGenerator matchingApplicationGenerator; - - @Autowired - MatchingTimeProperties matchingTimeProperties; - - @Autowired - MockClock mockClock; + @Autowired MatchingService matchingService; + @Autowired MatchingApplicationRepository matchingApplicationRepository; + @Autowired MatchingRoundRepository matchingRoundRepository; + @Autowired MatchingResultRepository matchingResultRepository; + @Autowired MatchingBusiness matchingBusiness; + @Autowired MatchingApplicationGenerator matchingApplicationGenerator; + @Autowired MatchingTimeProperties matchingTimeProperties; + @Autowired MockClock mockClock; MatchingRound currentRound; diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index 01bf4da2..245ab8fd 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -29,20 +29,11 @@ @SpringBootTest public class MatchingApplicationServiceTest { - @Autowired - MatchingApplicationService matchingApplicationService; - - @Autowired - MatchingApplicationRepository matchingApplicationRepository; - - @Autowired - MatchingRoundRepository matchingRoundRepository; - - @Autowired - MatchingTimeProperties matchingTimeProperties; - - @Autowired - MockClock mockClock; + @Autowired MatchingApplicationService matchingApplicationService; + @Autowired MatchingApplicationRepository matchingApplicationRepository; + @Autowired MatchingRoundRepository matchingRoundRepository; + @Autowired MatchingTimeProperties matchingTimeProperties; + @Autowired MockClock mockClock; MatchingApplicationRequest matchingApplicationRequest; MatchingRound currentRound; diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java index eda9c872..50d25c11 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java @@ -17,11 +17,8 @@ @SpringBootTest public class MatchingRoundServiceTest { - @Autowired - MatchingRoundRepository matchingRoundRepository; - - @Autowired - MatchingTimeProperties matchingTimeProperties; + @Autowired MatchingRoundRepository matchingRoundRepository; + @Autowired MatchingTimeProperties matchingTimeProperties; @Test @DisplayName("매주 월, 목 매칭 회차 업데이트") From 5e14f58f5321b6eb3dbf88ee983918a1588b1d38 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Mon, 5 Feb 2024 15:13:46 +0900 Subject: [PATCH 102/215] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC(=ED=8C=8C=ED=8A=B8=EB=84=88)=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B0=9C=EB=B0=9C=20=EB=B0=8F?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/success/MatchingSuccessCode.java | 3 +- .../controller/MatchingController.java | 12 +++++- .../dto/response/MatchingResponse.java | 14 ++++++ .../repository/MatchingResultRepository.java | 4 ++ .../mathcing/service/MatchingService.java | 19 +++++++- .../validator/MatchingServiceValidator.java | 17 ++++++++ .../unit/business/MatchingBusinessTest.java | 2 +- .../unit/service/MatchingServiceTest.java | 43 +++++++++++++++++++ 8 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/aliens/backend/mathcing/validator/MatchingServiceValidator.java create mode 100644 src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java diff --git a/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java b/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java index 6c3eea68..b78b34de 100644 --- a/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java +++ b/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java @@ -5,7 +5,8 @@ public enum MatchingSuccessCode implements SuccessCode { APPLY_MATCHING_SUCCESS(HttpStatus.CREATED, "MA001", "매칭 신청 성공"), GET_MATCHING_APPLICATION_STATUS_SUCCESS(HttpStatus.OK, "MA002", "매칭 신청 정보 조회 성공"), - CANCEL_MATCHING_APPLICATION_SUCCESS(HttpStatus.OK, "MA003", "매칭 신청 취소 성공") + CANCEL_MATCHING_APPLICATION_SUCCESS(HttpStatus.OK, "MA003", "매칭 신청 취소 성공"), + GET_MATCHING_PARTNERS_SUCCESS(HttpStatus.OK, "MA004", "매칭 파트너 조회 성공"), ; diff --git a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java index 9a732773..f6905269 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java @@ -6,6 +6,7 @@ import com.aliens.backend.global.success.SuccessResponse; import com.aliens.backend.global.success.SuccessResponseWithoutResult; import com.aliens.backend.mathcing.service.MatchingApplicationService; +import com.aliens.backend.mathcing.service.MatchingService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -16,10 +17,13 @@ @RequestMapping("/matchings") public class MatchingController { private final MatchingApplicationService matchingApplicationService; + private final MatchingService matchingService; @Autowired - public MatchingController(final MatchingApplicationService matchingApplicationService) { + public MatchingController(final MatchingApplicationService matchingApplicationService, + final MatchingService matchingService) { this.matchingApplicationService = matchingApplicationService; + this.matchingService = matchingService; } @PostMapping("/applications") @@ -40,4 +44,10 @@ public ResponseEntity cancelMatchingApplication(final @Login LoginMember logi matchingApplicationService.deleteMatchingApplication(loginMember.memberId()); return SuccessResponseWithoutResult.toResponseEntity(MatchingSuccessCode.CANCEL_MATCHING_APPLICATION_SUCCESS); } + + @GetMapping("/partners") + public ResponseEntity getMatchingPartners(final @Login LoginMember loginMember) { + return SuccessResponse.toResponseEntity(MatchingSuccessCode.GET_MATCHING_PARTNERS_SUCCESS, + matchingService.findMatchingResult(loginMember.memberId())); + } } diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java index 8cbd7d1b..c2415b8a 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java @@ -1,7 +1,12 @@ package com.aliens.backend.mathcing.controller.dto.response; import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.domain.MatchingResult; import com.aliens.backend.mathcing.service.model.Language; +import com.aliens.backend.mathcing.service.model.Partner; +import com.aliens.backend.mathcing.service.model.Relationship; + +import java.util.List; public class MatchingResponse { public record MatchingApplicationResponse( @@ -17,4 +22,13 @@ public static MatchingApplicationResponse of(MatchingApplication matchingApplica matchingApplication.getSecondPreferLanguage()); } } + + public record MatchingResultResponse( + Long matchedMemberId, + Relationship relationship + ) { + public static MatchingResultResponse of(MatchingResult matchingResult) { + return new MatchingResultResponse(matchingResult.getId().getMatchedMemberId(), matchingResult.getRelationship()); + } + } } diff --git a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingResultRepository.java b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingResultRepository.java index d0cebeb1..166ece39 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingResultRepository.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingResultRepository.java @@ -13,4 +13,8 @@ public interface MatchingResultRepository extends JpaRepository { @Query("SELECT mr FROM MatchingResult mr WHERE mr.id.matchingRound = :matchingRound") List findAllByMatchingRound(MatchingRound matchingRound); + + @Query("SELECT mr FROM MatchingResult mr " + + "WHERE mr.id.matchingRound = :matchingRound AND mr.id.matchingMemberId = :memberId") + List findAllByMatchingRoundAndMemberId(MatchingRound matchingRound, Long memberId); } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java index c2ea5a1d..bcaece58 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -3,6 +3,7 @@ import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.business.MatchingBusiness; +import com.aliens.backend.mathcing.controller.dto.response.MatchingResponse; import com.aliens.backend.mathcing.domain.MatchingResult; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; @@ -10,6 +11,7 @@ import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.model.Participant; import com.aliens.backend.mathcing.service.model.Partner; +import com.aliens.backend.mathcing.validator.MatchingServiceValidator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -17,12 +19,15 @@ import java.util.List; +import static com.aliens.backend.mathcing.controller.dto.response.MatchingResponse.*; + @Service public class MatchingService { private final MatchingRoundRepository matchingRoundRepository; private final MatchingApplicationRepository matchingApplicationRepository; private final MatchingResultRepository matchingResultRepository; private final MatchingBusiness matchingBusiness; + private final MatchingServiceValidator matchingServiceValidator; private MatchingRound currentRound; @@ -30,11 +35,13 @@ public class MatchingService { public MatchingService(final MatchingRoundRepository matchingRoundRepository, final MatchingApplicationRepository matchingApplicationRepository, final MatchingResultRepository matchingResultRepository, - final MatchingBusiness matchingBusiness) { + final MatchingBusiness matchingBusiness, + final MatchingServiceValidator matchingServiceValidator) { this.matchingRoundRepository = matchingRoundRepository; this.matchingApplicationRepository = matchingApplicationRepository; this.matchingResultRepository = matchingResultRepository; this.matchingBusiness = matchingBusiness; + this.matchingServiceValidator = matchingServiceValidator; } @Scheduled(cron = "${matching.round.start}") @@ -47,6 +54,16 @@ public void operateMatching() { saveMatchingResult(participants); } + @Transactional(readOnly = true) + public List findMatchingResult(Long memberId) { + currentRound = matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + List matchingResults = + matchingResultRepository.findAllByMatchingRoundAndMemberId(currentRound, memberId); + matchingServiceValidator.checkHasApplied(matchingResults); + return matchingResults.stream().map(matchingResult -> MatchingResultResponse.of(matchingResult)).toList(); + } + private void saveMatchingResult(List participants) { for (Participant participant : participants) { Long memberId = participant.memberId(); diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingServiceValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingServiceValidator.java new file mode 100644 index 00000000..e66aea6a --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/validator/MatchingServiceValidator.java @@ -0,0 +1,17 @@ +package com.aliens.backend.mathcing.validator; + +import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.mathcing.domain.MatchingResult; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class MatchingServiceValidator { + public void checkHasApplied(List matchingResults) { + if (matchingResults.isEmpty()) { + throw new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO); + } + } +} diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index fd745e94..bec64265 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -65,7 +65,7 @@ void matchingLogicTest() { void operateMatchingTest() { // given mockClock.mockTime(currentRound, MockTime.VALID_TIME); - matchingApplicationGenerator.applyToMatch(100L); + matchingApplicationGenerator.applyToMatch(20L); // when matchingService.operateMatching(); diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java new file mode 100644 index 00000000..c033ab9d --- /dev/null +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java @@ -0,0 +1,43 @@ +package com.aliens.backend.matching.unit.service; + +import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.property.MatchingTimeProperties; +import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; +import com.aliens.backend.mathcing.service.MatchingService; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.*; + +@SpringBootTest +public class MatchingServiceTest { + + @Autowired MatchingService matchingService; + @Autowired MatchingRoundRepository matchingRoundRepository; + @Autowired MatchingTimeProperties matchingTimeProperties; + + MatchingRound currentRound; + + @BeforeEach + void setUp() { + LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); + matchingRoundRepository.save(MatchingRound.of(roundBeginTime, matchingTimeProperties)); + currentRound = matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } + + @Test + @DisplayName("매칭을 신청한 적이 없는 회원이 매칭 조회") + void getMatchingResultTest() { + assertThatThrownBy(() -> matchingService.findMatchingResult(1L)) + .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getMessage()); + } +} From f7a9803af3d41c30834aa4c1a4cdb52cbe11553f Mon Sep 17 00:00:00 2001 From: Oniqued Date: Mon, 5 Feb 2024 15:25:08 +0900 Subject: [PATCH 103/215] =?UTF-8?q?fix=20:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20final=20=ED=82=A4=EC=9B=8C=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/mathcing/business/MatchingBusiness.java | 12 ++++++------ .../backend/mathcing/service/MatchingService.java | 4 ++-- .../backend/mathcing/util/MatchingConverter.java | 4 ++-- .../backend/mathcing/util/MatchingQueueBuilder.java | 2 +- .../validator/MatchingApplicationValidator.java | 4 ++-- .../validator/MatchingBusinessValidator.java | 6 ++++-- .../mathcing/validator/MatchingServiceValidator.java | 2 +- .../integration/MatchingApplicationApiTest.java | 8 ++++++++ 8 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index 9a9b9029..1db7baf0 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -35,13 +35,13 @@ public MatchingBusiness(final MatchingConverter matchingConverter, this.matchingRuleProperties = matchingRuleProperties; } - private void initialize(List matchingApplications) { + private void initialize(final List matchingApplications) { participants = matchingConverter.toParticipantList(matchingApplications); languageQueueWithParticipants = matchingQueueBuilder.buildLanguageQueues(participants); relationship = Relationship.NORMAL; } - public List operateMatching(List matchingApplications) { + public List operateMatching(final List matchingApplications) { initialize(matchingApplications); matchParticipantsWith(MatchingMode.FIRST_PREFER_LANGUAGE); @@ -52,7 +52,7 @@ public List operateMatching(List matchingAppli return participants; } - private void matchParticipantsWith(MatchingMode matchingMode) { + private void matchParticipantsWith(final MatchingMode matchingMode) { List participants = null; if (matchingMode.equals(MatchingMode.FIRST_PREFER_LANGUAGE)) { participants = this.participants; @@ -71,7 +71,7 @@ private void matchParticipantsWith(MatchingMode matchingMode) { matchWith(matchingMode, participants); } - private void matchWith(MatchingMode matchingMode, List participants) { + private void matchWith(final MatchingMode matchingMode, final List participants) { Queue candidates = null; if (matchingMode.equals(MatchingMode.RANDOM)) { candidates = new LinkedList<>(getParticipantsLessThan(matchingRuleProperties.getMaxPartners())); @@ -88,7 +88,7 @@ private void matchWith(MatchingMode matchingMode, List participants } } - private void tryMatchBetween(Participant participant, Queue candidates) { + private void tryMatchBetween(final Participant participant, final Queue candidates) { int tries = 0; while (!matchingBusinessValidator.isExceededMaxPartners(relationship, participant) && !matchingBusinessValidator.isExceedMaxTries(tries) && !candidates.isEmpty()) { @@ -105,7 +105,7 @@ private void tryMatchBetween(Participant participant, Queue candida } } - private void addMatching(Participant participant, Participant partner) { + private void addMatching(final Participant participant, final Participant partner) { participant.addPartner(relationship, partner.memberId()); partner.addPartner(relationship, participant.memberId()); } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java index bcaece58..db21fd1a 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -55,7 +55,7 @@ public void operateMatching() { } @Transactional(readOnly = true) - public List findMatchingResult(Long memberId) { + public List findMatchingResult(final Long memberId) { currentRound = matchingRoundRepository.findCurrentRound() .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); List matchingResults = @@ -64,7 +64,7 @@ public List findMatchingResult(Long memberId) { return matchingResults.stream().map(matchingResult -> MatchingResultResponse.of(matchingResult)).toList(); } - private void saveMatchingResult(List participants) { + private void saveMatchingResult(final List participants) { for (Participant participant : participants) { Long memberId = participant.memberId(); for (Partner partner : participant.partners()) { diff --git a/src/main/java/com/aliens/backend/mathcing/util/MatchingConverter.java b/src/main/java/com/aliens/backend/mathcing/util/MatchingConverter.java index 1b38c1d2..fcf6469c 100644 --- a/src/main/java/com/aliens/backend/mathcing/util/MatchingConverter.java +++ b/src/main/java/com/aliens/backend/mathcing/util/MatchingConverter.java @@ -10,13 +10,13 @@ @Component public class MatchingConverter { - public List toParticipantList(List matchingApplications) { + public List toParticipantList(final List matchingApplications) { return matchingApplications.stream() .map(this::toParticipantList) .collect(Collectors.toList()); } - private Participant toParticipantList(MatchingApplication matchingApplication) { + private Participant toParticipantList(final MatchingApplication matchingApplication) { return new Participant( matchingApplication.getId().getMemberId(), matchingApplication.getFirstPreferLanguage(), diff --git a/src/main/java/com/aliens/backend/mathcing/util/MatchingQueueBuilder.java b/src/main/java/com/aliens/backend/mathcing/util/MatchingQueueBuilder.java index dfc68157..480dbdc0 100644 --- a/src/main/java/com/aliens/backend/mathcing/util/MatchingQueueBuilder.java +++ b/src/main/java/com/aliens/backend/mathcing/util/MatchingQueueBuilder.java @@ -9,7 +9,7 @@ @Component public class MatchingQueueBuilder { - public Map> buildLanguageQueues(List participants) { + public Map> buildLanguageQueues(final List participants) { Map> languageQueue = createQueuesByLanguage(); for (Participant participant : participants) { diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java index 78fc7857..2138775f 100644 --- a/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java +++ b/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java @@ -9,13 +9,13 @@ @Component public class MatchingApplicationValidator { - public void checkReceptionTime(MatchingRound matchingRound, LocalDateTime now) { + public void checkReceptionTime(final MatchingRound matchingRound, final LocalDateTime now) { if (!isMatchingReceptionTime(matchingRound, now)) { throw new RestApiException(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME); } } - private boolean isMatchingReceptionTime(MatchingRound matchingRound, LocalDateTime now) { + private boolean isMatchingReceptionTime(final MatchingRound matchingRound, final LocalDateTime now) { return now.isAfter(matchingRound.getMatchingRequestStartTime()) && now.isBefore(matchingRound.getMatchingRequestEndTime()); } diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java index a4f2ab6b..580686cc 100644 --- a/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java +++ b/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java @@ -13,14 +13,16 @@ public MatchingBusinessValidator(final MatchingRuleProperties matchingRuleProper this.matchingRuleProperties = matchingRuleProperties; } - public boolean isValidMatching(Relationship relationship, Participant participant, Participant partner) { + public boolean isValidMatching(final Relationship relationship, + final Participant participant, + final Participant partner) { return participant != partner && !participant.isPartnerWith(partner) && !partner.isPartnerWith(participant) && !isExceededMaxPartners(relationship, partner); } - public boolean isExceededMaxPartners(Relationship relationship, Participant participant) { + public boolean isExceededMaxPartners(final Relationship relationship, final Participant participant) { if (relationship.equals(Relationship.NORMAL)) { return participant.getNumberOfPartners() >= matchingRuleProperties.getMaxNormalPartners(); // 4 } diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingServiceValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingServiceValidator.java index e66aea6a..a18e3ea9 100644 --- a/src/main/java/com/aliens/backend/mathcing/validator/MatchingServiceValidator.java +++ b/src/main/java/com/aliens/backend/mathcing/validator/MatchingServiceValidator.java @@ -9,7 +9,7 @@ @Component public class MatchingServiceValidator { - public void checkHasApplied(List matchingResults) { + public void checkHasApplied(final List matchingResults) { if (matchingResults.isEmpty()) { throw new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO); } diff --git a/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java b/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java new file mode 100644 index 00000000..ad70d9e8 --- /dev/null +++ b/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java @@ -0,0 +1,8 @@ +package com.aliens.backend.matching.integration; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class MatchingApplicationApiTest { + +} From dfeafd17d13c4fb271b35d152372cd8242adbe42 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Mon, 5 Feb 2024 18:21:45 +0900 Subject: [PATCH 104/215] =?UTF-8?q?fix=20:=20MatchingRound=20=EB=82=B4?= =?UTF-8?q?=EB=B6=80=EC=97=90=EC=84=9C=20=EC=A0=91=EC=88=98=20=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=EC=9D=84=20=EA=B2=80=EC=A6=9D=20=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20MatchingApplicationValidator.j?= =?UTF-8?q?ava=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/domain/MatchingRound.java | 4 +++ .../service/MatchingApplicationService.java | 12 +++---- .../MatchingApplicationValidator.java | 22 ------------- .../MatchingApplicationApiTest.java | 12 +++++++ .../unit/business/MatchingBusinessTest.java | 4 +-- .../MatchingApplicationServiceTest.java | 31 ++++++++++++------- .../backend/matching/util/MockClock.java | 11 +------ 7 files changed, 44 insertions(+), 52 deletions(-) delete mode 100644 src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java index fdf9d9e9..bac8ccb2 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java @@ -68,6 +68,10 @@ public static MatchingRound of(final LocalDateTime today, final MatchingTimeProp return new MatchingRound(matchingRequestStartTime, matchingRequestEndTime, matchingValidStartTime, matchingValidEndTime); } + public boolean isReceptionTime(LocalDateTime now) { + return now.isAfter(this.getMatchingRequestStartTime()) && now.isBefore(this.getMatchingRequestEndTime()); + } + @Override public String toString() { return "MatchingRound{" + diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index 57bbe164..e74daee2 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -7,7 +7,6 @@ import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; -import com.aliens.backend.mathcing.validator.MatchingApplicationValidator; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,23 +20,22 @@ public class MatchingApplicationService { private final MatchingApplicationRepository matchingApplicationRepository; private final MatchingRoundRepository matchingRoundRepository; - private final MatchingApplicationValidator matchingApplicationValidator; private final Clock clock; public MatchingApplicationService(final MatchingApplicationRepository matchingApplicationRepository, final MatchingRoundRepository matchingRoundRepository, - final MatchingApplicationValidator matchingApplicationValidator, final Clock clock) { this.matchingApplicationRepository = matchingApplicationRepository; this.matchingRoundRepository = matchingRoundRepository; - this.matchingApplicationValidator = matchingApplicationValidator; this.clock = clock; } @Transactional public void saveParticipant(final MatchingApplicationRequest matchingApplicationRequest) { MatchingRound currentRound = getCurrentRound(); - matchingApplicationValidator.checkReceptionTime(currentRound, LocalDateTime.now(clock)); + if (!currentRound.isReceptionTime(LocalDateTime.now(clock))) { + throw new RestApiException(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME); + } matchingApplicationRepository.save(matchingApplicationRequest.toEntity(currentRound)); } @@ -53,7 +51,9 @@ public MatchingApplicationResponse findMatchingApplication(final Long memberId) @Transactional public void deleteMatchingApplication(final Long memberId) { MatchingRound currentRound = getCurrentRound(); - matchingApplicationValidator.checkReceptionTime(currentRound, LocalDateTime.now(clock)); + if (!currentRound.isReceptionTime(LocalDateTime.now(clock))) { + throw new RestApiException(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME); + } MatchingApplication matchingApplication = matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, memberId)) .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java deleted file mode 100644 index 2138775f..00000000 --- a/src/main/java/com/aliens/backend/mathcing/validator/MatchingApplicationValidator.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.aliens.backend.mathcing.validator; - -import com.aliens.backend.global.error.MatchingError; -import com.aliens.backend.global.exception.RestApiException; -import com.aliens.backend.mathcing.domain.MatchingRound; -import org.springframework.stereotype.Component; - -import java.time.LocalDateTime; - -@Component -public class MatchingApplicationValidator { - public void checkReceptionTime(final MatchingRound matchingRound, final LocalDateTime now) { - if (!isMatchingReceptionTime(matchingRound, now)) { - throw new RestApiException(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME); - } - } - - private boolean isMatchingReceptionTime(final MatchingRound matchingRound, final LocalDateTime now) { - return now.isAfter(matchingRound.getMatchingRequestStartTime()) && - now.isBefore(matchingRound.getMatchingRequestEndTime()); - } -} diff --git a/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java b/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java index ad70d9e8..5761b458 100644 --- a/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java +++ b/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java @@ -1,8 +1,20 @@ package com.aliens.backend.matching.integration; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest public class MatchingApplicationApiTest { + @BeforeEach + void setUp() { + } + + @Test + @DisplayName("매칭 신청 API 테스트") + void applyMatchApiTest() { + + } } diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index bec64265..5f1447a2 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -51,7 +51,7 @@ void setUp() { @Transactional @DisplayName("매칭 로직 실행 테스트") void matchingLogicTest() { - mockClock.mockTime(currentRound, MockTime.VALID_TIME); + mockClock.mockTime(MockTime.VALID_TIME); matchingApplicationGenerator.applyToMatch(15L); matchingBusiness.operateMatching(matchingApplicationRepository.findAllByMatchingRound(currentRound)); @@ -64,7 +64,7 @@ void matchingLogicTest() { @Transactional void operateMatchingTest() { // given - mockClock.mockTime(currentRound, MockTime.VALID_TIME); + mockClock.mockTime(MockTime.VALID_TIME); matchingApplicationGenerator.applyToMatch(20L); // when diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index 245ab8fd..e2d750fd 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -36,15 +36,11 @@ public class MatchingApplicationServiceTest { @Autowired MockClock mockClock; MatchingApplicationRequest matchingApplicationRequest; - MatchingRound currentRound; @BeforeEach void setUp() { - LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); - matchingRoundRepository.save(MatchingRound.of(roundBeginTime, matchingTimeProperties)); + createNewMatchingRound(); matchingApplicationRequest = new MatchingApplicationRequest(1L, Language.KOREAN, Language.ENGLISH); - currentRound = matchingRoundRepository.findCurrentRound() - .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); } @Test @@ -52,13 +48,14 @@ void setUp() { @Transactional void applyMatchTest() { // given - mockClock.mockTime(currentRound, VALID_TIME); + mockClock.mockTime(VALID_TIME); // when matchingApplicationService.saveParticipant(matchingApplicationRequest); // then - MatchingApplication result = matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, matchingApplicationRequest.memberId())) + MatchingApplication result = matchingApplicationRepository + .findById(MatchingApplicationId.of(getCurrentRound(), matchingApplicationRequest.memberId())) .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); assertThat(result.getId().getMemberId()).isEqualTo(matchingApplicationRequest.memberId()); } @@ -68,7 +65,7 @@ void applyMatchTest() { @Transactional void applyMatchIfNotValidTime() { // given - mockClock.mockTime(currentRound, INVALID_TIME); + mockClock.mockTime(INVALID_TIME); // when & then assertThatThrownBy(() -> matchingApplicationService.saveParticipant(matchingApplicationRequest)) @@ -107,7 +104,7 @@ void getMatchingApplicationIfNotApplied() { void deleteMatchingApplicationTest() { // given applyToMatch(); - mockClock.mockTime(currentRound, VALID_TIME); + mockClock.mockTime(VALID_TIME); // when matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId()); @@ -123,7 +120,7 @@ void deleteMatchingApplicationTest() { void deleteMatchIfNotValidTime() { // given applyToMatch(); - mockClock.mockTime(currentRound, INVALID_TIME); + mockClock.mockTime(INVALID_TIME); // when & then assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId())) @@ -135,14 +132,24 @@ void deleteMatchIfNotValidTime() { @Transactional void deleteMatchIfNotApplied() { // given - mockClock.mockTime(currentRound, VALID_TIME); + mockClock.mockTime(VALID_TIME); assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId())) .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getMessage()); } private void applyToMatch() { - mockClock.mockTime(currentRound, VALID_TIME); + mockClock.mockTime(VALID_TIME); matchingApplicationService.saveParticipant(matchingApplicationRequest); } + + private void createNewMatchingRound() { + LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); + matchingRoundRepository.save(MatchingRound.of(roundBeginTime, matchingTimeProperties)); + } + + private MatchingRound getCurrentRound() { + return matchingRoundRepository.findCurrentRound() + .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } } diff --git a/src/test/java/com/aliens/backend/matching/util/MockClock.java b/src/test/java/com/aliens/backend/matching/util/MockClock.java index 291781c5..a6d23e79 100644 --- a/src/test/java/com/aliens/backend/matching/util/MockClock.java +++ b/src/test/java/com/aliens/backend/matching/util/MockClock.java @@ -1,7 +1,5 @@ package com.aliens.backend.matching.util; -import com.aliens.backend.mathcing.domain.MatchingRound; -import com.aliens.backend.mathcing.validator.MatchingApplicationValidator; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.stereotype.Component; @@ -9,24 +7,17 @@ import java.time.LocalDateTime; import java.time.ZoneId; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.when; @Component public class MockClock { - @MockBean - MatchingApplicationValidator matchingApplicationValidator; - @MockBean private Clock clock; - public void mockTime(MatchingRound matchingRound, MockTime mockTime) { + public void mockTime(MockTime mockTime) { LocalDateTime time = mockTime.time; Clock fixedClock = Clock.fixed(time.atZone(ZoneId.systemDefault()).toInstant(), ZoneId.systemDefault()); when(clock.instant()).thenReturn(fixedClock.instant()); when(clock.getZone()).thenReturn(fixedClock.getZone()); - - doCallRealMethod().when(matchingApplicationValidator).checkReceptionTime(matchingRound, time); } } From a69fc085e761b95ae703b93c27084fab7b538d80 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Mon, 5 Feb 2024 18:26:00 +0900 Subject: [PATCH 105/215] =?UTF-8?q?fix=20:=20MatchingBusiness=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=A7=81=EC=A0=91=20=EB=B9=84=EC=A6=88=EB=8B=88?= =?UTF-8?q?=EC=8A=A4=EB=A3=B0=20=EA=B2=80=EC=A6=9D=20=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20->=20MatchingBusinessValidator?= =?UTF-8?q?.java=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/business/MatchingBusiness.java | 32 ++++++++++++----- .../mathcing/service/MatchingService.java | 2 +- .../validator/MatchingBusinessValidator.java | 36 ------------------- 3 files changed, 25 insertions(+), 45 deletions(-) delete mode 100644 src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index 1db7baf0..de899fc0 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -8,7 +8,6 @@ import com.aliens.backend.mathcing.service.model.Participant; import com.aliens.backend.mathcing.service.model.MatchingMode; import com.aliens.backend.mathcing.service.model.Relationship; -import com.aliens.backend.mathcing.validator.MatchingBusinessValidator; import org.springframework.stereotype.Component; import java.util.*; @@ -18,7 +17,6 @@ public class MatchingBusiness { private final MatchingConverter matchingConverter; private final MatchingQueueBuilder matchingQueueBuilder; - private final MatchingBusinessValidator matchingBusinessValidator; private final MatchingRuleProperties matchingRuleProperties; private List participants = new ArrayList<>(); @@ -27,11 +25,9 @@ public class MatchingBusiness { public MatchingBusiness(final MatchingConverter matchingConverter, final MatchingQueueBuilder matchingQueueBuilder, - final MatchingBusinessValidator matchingBusinessValidator, final MatchingRuleProperties matchingRuleProperties) { this.matchingConverter = matchingConverter; this.matchingQueueBuilder = matchingQueueBuilder; - this.matchingBusinessValidator = matchingBusinessValidator; this.matchingRuleProperties = matchingRuleProperties; } @@ -90,13 +86,12 @@ private void matchWith(final MatchingMode matchingMode, final List private void tryMatchBetween(final Participant participant, final Queue candidates) { int tries = 0; - while (!matchingBusinessValidator.isExceededMaxPartners(relationship, participant) && - !matchingBusinessValidator.isExceedMaxTries(tries) && !candidates.isEmpty()) { + while (!isExceededMaxPartners(relationship, participant) && !isExceedMaxTries(tries) && !candidates.isEmpty()) { Participant partner = candidates.poll(); tries++; - if (matchingBusinessValidator.isValidMatching(relationship, participant, partner)) { + if (isValidMatching(relationship, participant, partner)) { addMatching(participant, partner); - if (!matchingBusinessValidator.isExceededMaxPartners(relationship, partner)) { + if (!isExceededMaxPartners(relationship, partner)) { candidates.add(partner); } } else { @@ -119,4 +114,25 @@ private List getParticipantsLessThan(int numberOfPartner) { public List getMatchedParticipants() { return participants; } + + + private boolean isValidMatching(final Relationship relationship, + final Participant participant, + final Participant partner) { + return participant != partner && + !participant.isPartnerWith(partner) && + !partner.isPartnerWith(participant) && + !isExceededMaxPartners(relationship, partner); + } + + private boolean isExceededMaxPartners(final Relationship relationship, final Participant participant) { + if (relationship.equals(Relationship.NORMAL)) { + return participant.getNumberOfPartners() >= matchingRuleProperties.getMaxNormalPartners(); // 4 + } + return participant.getNumberOfPartners() >= matchingRuleProperties.getMaxPartners(); // 5 + } + + private boolean isExceedMaxTries(int tries) { + return tries > matchingRuleProperties.getMaxTries(); + } } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java index db21fd1a..76405f88 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -61,7 +61,7 @@ public List findMatchingResult(final Long memberId) { List matchingResults = matchingResultRepository.findAllByMatchingRoundAndMemberId(currentRound, memberId); matchingServiceValidator.checkHasApplied(matchingResults); - return matchingResults.stream().map(matchingResult -> MatchingResultResponse.of(matchingResult)).toList(); + return matchingResults.stream().map(MatchingResultResponse::of).toList(); } private void saveMatchingResult(final List participants) { diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java deleted file mode 100644 index 580686cc..00000000 --- a/src/main/java/com/aliens/backend/mathcing/validator/MatchingBusinessValidator.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.aliens.backend.mathcing.validator; - -import com.aliens.backend.global.property.MatchingRuleProperties; -import com.aliens.backend.mathcing.service.model.Participant; -import com.aliens.backend.mathcing.service.model.Relationship; -import org.springframework.stereotype.Component; - -@Component -public class MatchingBusinessValidator { - private final MatchingRuleProperties matchingRuleProperties; - - public MatchingBusinessValidator(final MatchingRuleProperties matchingRuleProperties) { - this.matchingRuleProperties = matchingRuleProperties; - } - - public boolean isValidMatching(final Relationship relationship, - final Participant participant, - final Participant partner) { - return participant != partner && - !participant.isPartnerWith(partner) && - !partner.isPartnerWith(participant) && - !isExceededMaxPartners(relationship, partner); - } - - public boolean isExceededMaxPartners(final Relationship relationship, final Participant participant) { - if (relationship.equals(Relationship.NORMAL)) { - return participant.getNumberOfPartners() >= matchingRuleProperties.getMaxNormalPartners(); // 4 - } - return participant.getNumberOfPartners() >= matchingRuleProperties.getMaxPartners(); // 5 - } - - public boolean isExceedMaxTries(int tries) { - return tries > matchingRuleProperties.getMaxTries(); - } - -} From 08bc880a049ac079a7784e70592ea9d2ff35ba88 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Mon, 5 Feb 2024 18:28:48 +0900 Subject: [PATCH 106/215] =?UTF-8?q?fix=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EA=B2=80=EC=A6=9D=20validator=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/service/MatchingService.java | 11 ++++------- .../validator/MatchingServiceValidator.java | 17 ----------------- 2 files changed, 4 insertions(+), 24 deletions(-) delete mode 100644 src/main/java/com/aliens/backend/mathcing/validator/MatchingServiceValidator.java diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java index 76405f88..be7962d2 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -3,7 +3,6 @@ import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.business.MatchingBusiness; -import com.aliens.backend.mathcing.controller.dto.response.MatchingResponse; import com.aliens.backend.mathcing.domain.MatchingResult; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; @@ -11,7 +10,6 @@ import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.model.Participant; import com.aliens.backend.mathcing.service.model.Partner; -import com.aliens.backend.mathcing.validator.MatchingServiceValidator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -27,7 +25,6 @@ public class MatchingService { private final MatchingApplicationRepository matchingApplicationRepository; private final MatchingResultRepository matchingResultRepository; private final MatchingBusiness matchingBusiness; - private final MatchingServiceValidator matchingServiceValidator; private MatchingRound currentRound; @@ -35,13 +32,11 @@ public class MatchingService { public MatchingService(final MatchingRoundRepository matchingRoundRepository, final MatchingApplicationRepository matchingApplicationRepository, final MatchingResultRepository matchingResultRepository, - final MatchingBusiness matchingBusiness, - final MatchingServiceValidator matchingServiceValidator) { + final MatchingBusiness matchingBusiness) { this.matchingRoundRepository = matchingRoundRepository; this.matchingApplicationRepository = matchingApplicationRepository; this.matchingResultRepository = matchingResultRepository; this.matchingBusiness = matchingBusiness; - this.matchingServiceValidator = matchingServiceValidator; } @Scheduled(cron = "${matching.round.start}") @@ -60,7 +55,9 @@ public List findMatchingResult(final Long memberId) { .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); List matchingResults = matchingResultRepository.findAllByMatchingRoundAndMemberId(currentRound, memberId); - matchingServiceValidator.checkHasApplied(matchingResults); + if (matchingResults.isEmpty()) { + throw new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO); + } return matchingResults.stream().map(MatchingResultResponse::of).toList(); } diff --git a/src/main/java/com/aliens/backend/mathcing/validator/MatchingServiceValidator.java b/src/main/java/com/aliens/backend/mathcing/validator/MatchingServiceValidator.java deleted file mode 100644 index a18e3ea9..00000000 --- a/src/main/java/com/aliens/backend/mathcing/validator/MatchingServiceValidator.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.aliens.backend.mathcing.validator; - -import com.aliens.backend.global.error.MatchingError; -import com.aliens.backend.global.exception.RestApiException; -import com.aliens.backend.mathcing.domain.MatchingResult; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -public class MatchingServiceValidator { - public void checkHasApplied(final List matchingResults) { - if (matchingResults.isEmpty()) { - throw new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO); - } - } -} From a9216c270ef006c4d01476607e91a56064f027da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:47:16 +0900 Subject: [PATCH 107/215] =?UTF-8?q?feat(DatabaseCleanup):=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=EB=B2=A0=EC=9D=B4=EC=8A=A4=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=ED=85=8C=EC=9D=B4=EB=B8=94=EC=97=90=20=EC=BB=AC=EB=9F=BC?= =?UTF-8?q?=ED=95=98=EB=82=98=EC=94=A9=20=EC=82=AD=EC=A0=9C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20deletAll()=20=EC=9D=B4=20=EC=95=84=EB=8B=8C,=20?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=B8=94=20=EC=9E=90=EC=B2=B4=EB=A5=BC=20?= =?UTF-8?q?=EB=B9=84=EC=9A=B0=EB=8F=84=EB=A1=9D=20=ED=95=98=EB=8A=94=20Dat?= =?UTF-8?q?abaseCleanup=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #41 --- .../backend/global/DatabaseCleanup.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/test/java/com/aliens/backend/global/DatabaseCleanup.java diff --git a/src/test/java/com/aliens/backend/global/DatabaseCleanup.java b/src/test/java/com/aliens/backend/global/DatabaseCleanup.java new file mode 100644 index 00000000..3aad2d37 --- /dev/null +++ b/src/test/java/com/aliens/backend/global/DatabaseCleanup.java @@ -0,0 +1,44 @@ +package com.aliens.backend.global; + +import com.google.common.base.CaseFormat; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.stereotype.Component; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.transaction.annotation.Transactional; + +import jakarta.persistence.Entity; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import java.util.List; +import java.util.stream.Collectors; + +@Component +@ActiveProfiles("test") +public class DatabaseCleanup implements InitializingBean { + + @PersistenceContext + private EntityManager entityManager; + + private List tableNames; + + @Override + public void afterPropertiesSet() { + tableNames = entityManager.getMetamodel().getEntities().stream() + .filter(e -> e.getJavaType().getAnnotation(Entity.class) != null) + .map(e -> CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, e.getName())) + .collect(Collectors.toList()); + } + + @Transactional + public void execute() { + entityManager.flush(); + entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 0").executeUpdate(); + + for (String tableName : tableNames) { + entityManager.createNativeQuery("TRUNCATE TABLE " + tableName).executeUpdate(); + entityManager.createNativeQuery("ALTER TABLE " + tableName + " AUTO_INCREMENT = 1").executeUpdate(); + } + + entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 1").executeUpdate(); + } +} \ No newline at end of file From 683b9dd28bf2959ce17ba4dea2a3cd1cdbb22039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:48:01 +0900 Subject: [PATCH 108/215] =?UTF-8?q?feat(BaseTest):=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=B4=88=EA=B8=B0=ED=99=94=EC=99=80=20=EC=99=B8?= =?UTF-8?q?=EB=B6=80=20=EB=A6=AC=EC=86=8C=EC=8A=A4=20=EC=A0=91=EA=B7=BC?= =?UTF-8?q?=EC=8B=9C=20=EB=A7=89=EC=9D=84=20=EC=88=98=20=EC=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=ED=95=98=EB=8A=94=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EC=83=81=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #41 --- .../com/aliens/backend/global/BaseTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/test/java/com/aliens/backend/global/BaseTest.java diff --git a/src/test/java/com/aliens/backend/global/BaseTest.java b/src/test/java/com/aliens/backend/global/BaseTest.java new file mode 100644 index 00000000..7019cccb --- /dev/null +++ b/src/test/java/com/aliens/backend/global/BaseTest.java @@ -0,0 +1,57 @@ +package com.aliens.backend.global; + +import com.aliens.backend.notification.FcmSender; +import com.aliens.backend.uploader.AwsS3Uploader; +import com.aliens.backend.uploader.dto.S3File; +import com.google.firebase.messaging.Message; +import com.google.firebase.messaging.MulticastMessage; +import org.junit.jupiter.api.BeforeEach; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; + +@SpringBootTest +public abstract class BaseTest { + + @SpyBean + protected AwsS3Uploader awsS3Uploader; + + @SpyBean + protected JavaMailSender javaMailSender; + + @SpyBean + protected FcmSender fcmSender; + + @Autowired + private DatabaseCleanup databaseCleanUp; + + private static final String GIVEN_FILE_NAME = "test"; + private static final String GIVEN_FILE_URL = "/test"; + + @BeforeEach + void setUpSpy() { + //Data Initializer + databaseCleanUp.execute(); + + //SMTP + doNothing().when(javaMailSender).send(any(SimpleMailMessage.class)); + + //FCM + doNothing().when(fcmSender).listenMultiMessageRequest(any(MulticastMessage.class)); + doNothing().when(fcmSender).listenSingleMessageRequest(any(Message.class)); + + //AWS + S3File tmpFile = new S3File(GIVEN_FILE_NAME, GIVEN_FILE_URL); + doReturn(tmpFile).when(awsS3Uploader).singleUpload(any(MultipartFile.class)); + doReturn(List.of(tmpFile)).when(awsS3Uploader).multiUpload(any()); + } +} From 27cefef99601f8b1f2ea87204b352f65ea876c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:48:41 +0900 Subject: [PATCH 109/215] =?UTF-8?q?remove(AwsS3MockConfig):=20BaseTest?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=8A=A4=ED=8C=8C=EC=9D=B4=EB=B9=88?= =?UTF-8?q?=EC=9D=84=20=EC=82=AC=EC=9A=A9=ED=95=A8=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=ED=95=84=EC=9A=94=EC=97=86=EC=96=B4=EC=A7=90=EC=97=90=EB=94=B0?= =?UTF-8?q?=EB=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #41 --- .../backend/uploader/AwsS3MockConfig.java | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 src/test/java/com/aliens/backend/uploader/AwsS3MockConfig.java diff --git a/src/test/java/com/aliens/backend/uploader/AwsS3MockConfig.java b/src/test/java/com/aliens/backend/uploader/AwsS3MockConfig.java deleted file mode 100644 index 17f9842b..00000000 --- a/src/test/java/com/aliens/backend/uploader/AwsS3MockConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.aliens.backend.uploader; - -import com.aliens.backend.global.property.S3UploadProperties; -import com.amazonaws.auth.AWSStaticCredentialsProvider; -import com.amazonaws.auth.AnonymousAWSCredentials; -import com.amazonaws.client.builder.AwsClientBuilder; -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.AmazonS3ClientBuilder; -import io.findify.s3mock.S3Mock; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; - -@TestConfiguration -public class AwsS3MockConfig { - - private final S3UploadProperties s3UploadProperties; - - public AwsS3MockConfig(S3UploadProperties s3UploadProperties) { - this.s3UploadProperties = s3UploadProperties; - } - - @Bean - public S3Mock s3Mock() { - return new S3Mock.Builder().withPort(8001).withInMemoryBackend().build(); - } - - @Bean - public AmazonS3 amazonS3(S3Mock s3Mock){ - s3Mock.start(); - AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration("http://localhost:8001", s3UploadProperties.getRegion()); - AmazonS3 client = AmazonS3ClientBuilder - .standard() - .withPathStyleAccessEnabled(true) - .withEndpointConfiguration(endpoint) - .withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())) - .build(); - client.createBucket(s3UploadProperties.getBucket()); - - return client; - } -} From 5fd468a9191490c776a1541b2e5a6f9c7787b666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:49:48 +0900 Subject: [PATCH 110/215] =?UTF-8?q?refactor:=20BaseTest=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=20=EB=B0=8F=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94=20=EB=8F=99=EC=9E=91=20=EC=82=AD=EC=A0=9C,?= =?UTF-8?q?=20Mock=20=EA=B0=9D=EC=B2=B4=20=EB=8F=99=EC=9E=91=EC=A0=95?= =?UTF-8?q?=EC=9D=98=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #41 --- .../aliens/backend/auth/domain/Member.java | 1 + .../member/sevice/MemberInfoService.java | 8 ++- .../backend/uploader/AwsS3Uploader.java | 4 +- .../backend/auth/service/AuthServiceTest.java | 9 +--- .../backend/email/sender/EmailSenderTest.java | 14 ++--- .../email/service/EmailServiceTest.java | 13 ++--- .../backend/event/EventPublisherTest.java | 6 +-- .../backend/member/MemberInfoServiceTest.java | 53 ++++++------------- .../backend/uploader/AwsS3UploaderTest.java | 19 ++----- 9 files changed, 41 insertions(+), 86 deletions(-) diff --git a/src/main/java/com/aliens/backend/auth/domain/Member.java b/src/main/java/com/aliens/backend/auth/domain/Member.java index e38e040d..0f139d69 100644 --- a/src/main/java/com/aliens/backend/auth/domain/Member.java +++ b/src/main/java/com/aliens/backend/auth/domain/Member.java @@ -29,6 +29,7 @@ public class Member { @Column private String password; + @Enumerated(value = EnumType.STRING) @Column private MemberRole role = MemberRole.MEMBER; diff --git a/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java b/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java index 18a90e14..b574c38b 100644 --- a/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java +++ b/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java @@ -89,7 +89,7 @@ private Image saveImage(final MultipartFile profileImage) { s3UploadProperties.getDefaultFileURL())); } - S3File uploadedFile = uploader.upload(profileImage); + S3File uploadedFile = uploader.singleUpload(profileImage); return Image.from(uploadedFile); } @@ -136,6 +136,10 @@ public String changePassword(final LoginMember loginMember, final String newPass @Transactional public String changeProfileImage(final LoginMember loginMember, final MultipartFile newProfileImage) { + if (newProfileImage == null || newProfileImage.isEmpty()) { + throw new RestApiException(MemberError.INVALID_EMAIL); // 예외 처리를 원하는 대로 수정 필요 + } + Member member = getMember(loginMember); changeImageInDB(newProfileImage, member); return MemberResponse.PROFILE_IMAGE_CHANGE_SUCCESS.getMessage(); @@ -148,7 +152,7 @@ private void changeImageInDB(final MultipartFile newProfileImage, final Member m uploader.delete(savedProfileName); } - S3File newFile = uploader.upload(newProfileImage); + S3File newFile = uploader.singleUpload(newProfileImage); member.changeProfileImage(newFile); } diff --git a/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java b/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java index 5d2af253..cbf1a677 100644 --- a/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java +++ b/src/main/java/com/aliens/backend/uploader/AwsS3Uploader.java @@ -26,11 +26,11 @@ public AwsS3Uploader(final AmazonS3Client amazonS3Client, final S3UploadProperti this.s3UploadProperties = s3UploadProperties; } - public List upload(List files) { + public List multiUpload(List files) { return files.stream().map(this::uploadToS3).toList(); } - public S3File upload(MultipartFile file) { + public S3File singleUpload(MultipartFile file) { return uploadToS3(file); } diff --git a/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java b/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java index 4974c72f..019d985b 100644 --- a/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java +++ b/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java @@ -4,6 +4,7 @@ import com.aliens.backend.auth.controller.dto.LoginRequest; import com.aliens.backend.auth.domain.Member; import com.aliens.backend.auth.domain.repository.MemberRepository; +import com.aliens.backend.global.BaseTest; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.JWTProperties; import com.aliens.backend.member.controller.dto.EncodedSignUp; @@ -17,7 +18,7 @@ import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -class AuthServiceTest { +class AuthServiceTest extends BaseTest { @Autowired AuthService authService; @@ -48,12 +49,6 @@ void setUp() { loginRequest = new LoginRequest(email, password); } - @AfterEach - void afterDown() { - memberRepository.deleteAll(); - imageRepository.deleteAll(); - } - @Test @DisplayName("로그인 성공") void loginTest() { diff --git a/src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java b/src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java index 7c5b4dc3..dc981911 100644 --- a/src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java +++ b/src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java @@ -1,27 +1,23 @@ package com.aliens.backend.email.sender; import com.aliens.backend.email.service.EmailSender; +import com.aliens.backend.global.BaseTest; import com.aliens.backend.member.controller.dto.event.TemporaryPasswordEvent; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.mockito.ArgumentMatchers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.mail.SimpleMailMessage; -import org.springframework.mail.javamail.JavaMailSender; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; @SpringBootTest -class EmailSenderTest { +class EmailSenderTest extends BaseTest { @Autowired private EmailSender emailSender; - @MockBean - private JavaMailSender javaMailSender; - @Test @DisplayName("인증 이메일 전송 테스트") void sendAuthenticationEmailTest() { @@ -33,7 +29,7 @@ void sendAuthenticationEmailTest() { emailSender.sendAuthenticationEmail(email, token); // Then - verify(javaMailSender).send(ArgumentMatchers.any(SimpleMailMessage.class)); + verify(javaMailSender).send(any(SimpleMailMessage.class)); } @Test @@ -46,6 +42,6 @@ void sendTemporaryPasswordEmailTest() { emailSender.sendTemporaryPassword(event); // Then - verify(javaMailSender).send(ArgumentMatchers.any(SimpleMailMessage.class)); + verify(javaMailSender).send(any(SimpleMailMessage.class)); } } diff --git a/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java b/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java index 6efee77c..8949424e 100644 --- a/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java +++ b/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java @@ -3,15 +3,14 @@ import com.aliens.backend.email.controller.response.EmailResponse; import com.aliens.backend.email.domain.EmailAuthentication; import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; +import com.aliens.backend.global.BaseTest; import com.aliens.backend.member.sevice.SymmetricKeyEncoder; import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.mail.javamail.JavaMailSender; @SpringBootTest -class EmailServiceTest { +class EmailServiceTest extends BaseTest { @Autowired EmailService emailService; @@ -19,8 +18,7 @@ class EmailServiceTest { SymmetricKeyEncoder symmetricKeyEncoder; @Autowired EmailAuthenticationRepository emailAuthenticationRepository; - @MockBean - JavaMailSender javaMailSender; + String givenEmail; EmailAuthentication emailEntity; @@ -32,11 +30,6 @@ void setUp() { emailAuthenticationRepository.save(emailEntity); } - @AfterEach - void afterDown() { - emailAuthenticationRepository.deleteAll(); - } - @Test @DisplayName("이메일 중복 검사 - 사용 불가한 이메일") void duplicateCheckTestNotAvailable() { diff --git a/src/test/java/com/aliens/backend/event/EventPublisherTest.java b/src/test/java/com/aliens/backend/event/EventPublisherTest.java index 9b8bee44..d8ce7af2 100644 --- a/src/test/java/com/aliens/backend/event/EventPublisherTest.java +++ b/src/test/java/com/aliens/backend/event/EventPublisherTest.java @@ -1,5 +1,6 @@ package com.aliens.backend.event; +import com.aliens.backend.global.BaseTest; import com.aliens.backend.notification.FcmSender; import com.google.firebase.messaging.Message; import com.google.firebase.messaging.MulticastMessage; @@ -7,7 +8,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.ApplicationEventPublisher; import java.util.List; @@ -17,12 +17,12 @@ import static org.mockito.internal.verification.VerificationModeFactory.times; @SpringBootTest -class EventPublisherTest { +class EventPublisherTest extends BaseTest { @Autowired ApplicationEventPublisher publisher; - @MockBean + @Autowired FcmSender fcmSender; String givenType = "normal"; diff --git a/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java b/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java index 11d7a82e..ca96f5bd 100644 --- a/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java +++ b/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java @@ -6,6 +6,7 @@ import com.aliens.backend.auth.service.PasswordEncoder; import com.aliens.backend.email.domain.EmailAuthentication; import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; +import com.aliens.backend.global.BaseTest; import com.aliens.backend.member.sevice.SymmetricKeyEncoder; import com.aliens.backend.member.controller.dto.*; import com.aliens.backend.member.controller.dto.request.SignUpRequest; @@ -18,27 +19,22 @@ import com.aliens.backend.member.domain.repository.MemberInfoRepository; import com.aliens.backend.member.domain.MemberStatus; import com.aliens.backend.member.sevice.MemberInfoService; -import com.aliens.backend.uploader.AwsS3Uploader; import com.aliens.backend.uploader.dto.S3File; import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; @SpringBootTest -class MemberInfoServiceTest { +class MemberInfoServiceTest extends BaseTest { - @Autowired - MemberInfoRepository memberInfoRepository; @Autowired MemberInfoService memberInfoService; @Autowired + MemberInfoRepository memberInfoRepository; + @Autowired EmailAuthenticationRepository emailAuthenticationRepository; @Autowired ImageRepository imageRepository; @@ -49,12 +45,7 @@ class MemberInfoServiceTest { @Autowired PasswordEncoder passwordEncoder; - @MockBean - AwsS3Uploader awsS3Uploader; - @MockBean - JavaMailSender javaMailSender; - - MockMultipartFile file; + MultipartFile file; LoginMember loginMember; String givenName = "김명준"; String givenEmail = "tmp@example"; @@ -74,30 +65,20 @@ void setUp() { Member member = setUpMember(image); setUpMemberInfo(member); setUpLoginMember(member); - setUpMockMultipartFile(); - } - - @AfterEach - void setDown() { - emailAuthenticationRepository.deleteAll(); - memberInfoRepository.deleteAll(); - memberRepository.deleteAll(); - imageRepository.deleteAll(); + file = setUpMockMultipartFile(); } @Test @DisplayName("회원가입") void signUpTest() { //Given - S3File tmpFile = new S3File(givenFileName, givenFileURL); - when(awsS3Uploader.upload((MultipartFile) any())).thenReturn(tmpFile); SignUpRequest signUpRequest = createSignUpRequest(); //When String result = memberInfoService.signUp(signUpRequest, file); //Then - Assertions.assertEquals(MemberResponse.SIGN_UP_SUCCESS.getMessage(),result); + Assertions.assertEquals(MemberResponse.SIGN_UP_SUCCESS.getMessage(), result); } @Test @@ -139,10 +120,6 @@ void changePassword() { @Test @DisplayName("프로필 이미지 변경") void changeProfileImage() { - //Given - S3File tmpFile = new S3File(givenFileName, givenFileURL); - when(awsS3Uploader.upload((MultipartFile) any())).thenReturn(tmpFile); - //When String result = memberInfoService.changeProfileImage(loginMember, file); @@ -205,11 +182,11 @@ void getMemberInfo() { Assertions.assertEquals(expectedResponse,result); } - public void setUpLoginMember(final Member member) { + private void setUpLoginMember(final Member member) { loginMember = member.getLoginMember(); } - public void setUpMemberInfo(final Member member) { + private void setUpMemberInfo(final Member member) { EncodedMember encodedRequest = new EncodedMember(symmetricKeyEncoder.encrypt(givenGender), symmetricKeyEncoder.encrypt(givenMbti), symmetricKeyEncoder.encrypt(givenBirthday), @@ -220,32 +197,32 @@ public void setUpMemberInfo(final Member member) { memberInfoRepository.save(memberInfo); } - public Member setUpMember(final Image image) { + private Member setUpMember(final Image image) { EncodedSignUp signUp = new EncodedSignUp(givenName, givenEmail, passwordEncoder.encrypt(givenPassword)); Member member = Member.of(signUp, image); return member; } - public Image setUpImage() { + private Image setUpImage() { Image image = Image.from(new S3File(givenFileName, givenFileURL)); return image; } - public void setUpMockMultipartFile() { + private MultipartFile setUpMockMultipartFile() { String fileName = "test"; String path = "/test"; String contentType = "image/png"; byte[] content = fileName.getBytes(); - file = new MockMultipartFile(fileName, path, contentType, content); + return new MockMultipartFile(fileName, path, contentType, content); } - public void setUpEmailEntity(final String givenEmail) { + private void setUpEmailEntity(final String givenEmail) { EmailAuthentication emailEntity = new EmailAuthentication(givenEmail); emailEntity.authenticate(); emailAuthenticationRepository.save(emailEntity); } - public SignUpRequest createSignUpRequest() { + private SignUpRequest createSignUpRequest() { SignUpRequest signUpRequest = new SignUpRequest(givenEmail, "password", "tmpName", diff --git a/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java b/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java index 91766f73..550b20ce 100644 --- a/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java +++ b/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java @@ -1,34 +1,23 @@ package com.aliens.backend.uploader; +import com.aliens.backend.global.BaseTest; import com.aliens.backend.uploader.dto.S3File; -import io.findify.s3mock.S3Mock; import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Import; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; import java.util.List; -@Import(AwsS3MockConfig.class) @SpringBootTest -class AwsS3UploaderTest { - - @Autowired - private S3Mock s3Mock; +class AwsS3UploaderTest extends BaseTest { @Autowired private AwsS3Uploader awsS3Uploader; - @AfterEach - public void tearDown() { - s3Mock.stop(); - } - @Test @DisplayName("S3 파일 업로드 테스트") void uploadTest() { @@ -40,10 +29,10 @@ void uploadTest() { List request = List.of(file,file,file); // When - List S3Files = awsS3Uploader.upload(request); + List S3Files = awsS3Uploader.multiUpload(request); // Then - Assertions.assertThat(S3Files).isNotNull(); + Assertions.assertThat(S3Files).isNotEmpty(); } @Test From 079c2473190bfce5bf2d45e4b094f69a9351cb89 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Mon, 5 Feb 2024 18:50:04 +0900 Subject: [PATCH 111/215] =?UTF-8?q?fix=20:=20Business=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EC=9D=98=20Validator=20=ED=81=B4=EB=9E=98=EC=8A=A4,=20Converte?= =?UTF-8?q?r=20=ED=81=B4=EB=9E=98=EC=8A=A4,=20QueueBuilder=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/business/MatchingBusiness.java | 21 ++++--------------- .../mathcing/domain/MatchingApplication.java | 20 ++++++++++++++++++ .../mathcing/service/model/Language.java | 15 +++++++++++++ .../unit/business/MatchingBusinessTest.java | 5 +++-- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index de899fc0..84fed9b5 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -1,8 +1,6 @@ package com.aliens.backend.mathcing.business; import com.aliens.backend.global.property.MatchingRuleProperties; -import com.aliens.backend.mathcing.util.MatchingConverter; -import com.aliens.backend.mathcing.util.MatchingQueueBuilder; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.service.model.Language; import com.aliens.backend.mathcing.service.model.Participant; @@ -15,25 +13,19 @@ @Component public class MatchingBusiness { - private final MatchingConverter matchingConverter; - private final MatchingQueueBuilder matchingQueueBuilder; private final MatchingRuleProperties matchingRuleProperties; private List participants = new ArrayList<>(); private Map> languageQueueWithParticipants = new HashMap<>(); private Relationship relationship; - public MatchingBusiness(final MatchingConverter matchingConverter, - final MatchingQueueBuilder matchingQueueBuilder, - final MatchingRuleProperties matchingRuleProperties) { - this.matchingConverter = matchingConverter; - this.matchingQueueBuilder = matchingQueueBuilder; + public MatchingBusiness(final MatchingRuleProperties matchingRuleProperties) { this.matchingRuleProperties = matchingRuleProperties; } private void initialize(final List matchingApplications) { - participants = matchingConverter.toParticipantList(matchingApplications); - languageQueueWithParticipants = matchingQueueBuilder.buildLanguageQueues(participants); + participants = MatchingApplication.toParticipantList(matchingApplications); + languageQueueWithParticipants = Language.buildLanguageQueues(participants); relationship = Relationship.NORMAL; } @@ -55,7 +47,7 @@ private void matchParticipantsWith(final MatchingMode matchingMode) { } if (matchingMode.equals(MatchingMode.SECOND_PREFER_LANGUAGE)) { participants = getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); - languageQueueWithParticipants = matchingQueueBuilder.buildLanguageQueues(this.participants); + languageQueueWithParticipants = Language.buildLanguageQueues(this.participants); } if (matchingMode.equals(MatchingMode.RANDOM)) { relationship = Relationship.SPECIAL; @@ -111,11 +103,6 @@ private List getParticipantsLessThan(int numberOfPartner) { .collect(Collectors.toList()); } - public List getMatchedParticipants() { - return participants; - } - - private boolean isValidMatching(final Relationship relationship, final Participant participant, final Participant partner) { diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java index b040d96b..074bfc1d 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java @@ -2,11 +2,16 @@ import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; import com.aliens.backend.mathcing.service.model.Language; +import com.aliens.backend.mathcing.service.model.Participant; import jakarta.persistence.EmbeddedId; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + @Entity public class MatchingApplication { @EmbeddedId @@ -49,6 +54,21 @@ public static MatchingApplication of(final MatchingRound matchingRound, firstPreferLanguage, secondPreferLanguage); } + public static List toParticipantList(final List matchingApplications) { + return matchingApplications.stream() + .map(MatchingApplication::of) + .collect(Collectors.toList()); + } + + private static Participant of(final MatchingApplication matchingApplication) { + return new Participant( + matchingApplication.getId().getMemberId(), + matchingApplication.getFirstPreferLanguage(), + matchingApplication.getSecondPreferLanguage(), + new ArrayList<>() + ); + } + @Override public String toString() { return "MatchingApplication{" + diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Language.java b/src/main/java/com/aliens/backend/mathcing/service/model/Language.java index 528408d7..5a8155a9 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/Language.java +++ b/src/main/java/com/aliens/backend/mathcing/service/model/Language.java @@ -1,9 +1,24 @@ package com.aliens.backend.mathcing.service.model; +import java.util.*; + public enum Language { KOREAN, ENGLISH, JAPANESE, CHINESE ; + + public static Map> buildLanguageQueues(final List participants) { + Map> languageQueue = new HashMap<>(); + for (Language language : values()) { + languageQueue.put(language, new LinkedList<>()); + } + + for (Participant participant : participants) { + languageQueue.get(participant.getPreferLanguage(MatchingMode.FIRST_PREFER_LANGUAGE)).add(participant); + } + + return languageQueue; + } } diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index 5f1447a2..8270d79b 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -13,6 +13,7 @@ import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.MatchingApplicationService; import com.aliens.backend.mathcing.service.MatchingService; +import com.aliens.backend.mathcing.service.model.Participant; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -54,9 +55,9 @@ void matchingLogicTest() { mockClock.mockTime(MockTime.VALID_TIME); matchingApplicationGenerator.applyToMatch(15L); - matchingBusiness.operateMatching(matchingApplicationRepository.findAllByMatchingRound(currentRound)); + List result = matchingBusiness.operateMatching(matchingApplicationRepository.findAllByMatchingRound(currentRound)); - matchingBusiness.getMatchedParticipants().forEach(participant -> assertThat(participant.partners()).isNotNull()); + result.forEach(participant -> assertThat(participant.partners()).isNotNull()); } @Test From 40afa78d30138a3bdecad96b87b092243eea7d42 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Mon, 5 Feb 2024 18:53:12 +0900 Subject: [PATCH 112/215] =?UTF-8?q?fix=20:=20LanguageQueue=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/mathcing/business/MatchingBusiness.java | 4 ++-- .../com/aliens/backend/mathcing/service/model/Language.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index 84fed9b5..e000f0e4 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -25,7 +25,7 @@ public MatchingBusiness(final MatchingRuleProperties matchingRuleProperties) { private void initialize(final List matchingApplications) { participants = MatchingApplication.toParticipantList(matchingApplications); - languageQueueWithParticipants = Language.buildLanguageQueues(participants); + languageQueueWithParticipants = Language.createQueueWith(participants); relationship = Relationship.NORMAL; } @@ -47,7 +47,7 @@ private void matchParticipantsWith(final MatchingMode matchingMode) { } if (matchingMode.equals(MatchingMode.SECOND_PREFER_LANGUAGE)) { participants = getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); - languageQueueWithParticipants = Language.buildLanguageQueues(this.participants); + languageQueueWithParticipants = Language.createQueueWith(this.participants); } if (matchingMode.equals(MatchingMode.RANDOM)) { relationship = Relationship.SPECIAL; diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Language.java b/src/main/java/com/aliens/backend/mathcing/service/model/Language.java index 5a8155a9..2c217c7a 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/Language.java +++ b/src/main/java/com/aliens/backend/mathcing/service/model/Language.java @@ -9,7 +9,7 @@ public enum Language { CHINESE ; - public static Map> buildLanguageQueues(final List participants) { + public static Map> createQueueWith(final List participants) { Map> languageQueue = new HashMap<>(); for (Language language : values()) { languageQueue.put(language, new LinkedList<>()); From 5d9962ebce6afe2ef4257b19b2d6c7fd4fc09b95 Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 01:01:19 +0900 Subject: [PATCH 113/215] =?UTF-8?q?feat(MessageSendRequest):=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=A0=84=EC=86=A1=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EB=A0=88=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/controller/dto/request/MessageSendRequest.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/controller/dto/request/MessageSendRequest.java diff --git a/src/main/java/com/aliens/backend/chat/controller/dto/request/MessageSendRequest.java b/src/main/java/com/aliens/backend/chat/controller/dto/request/MessageSendRequest.java new file mode 100644 index 00000000..ca223419 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/controller/dto/request/MessageSendRequest.java @@ -0,0 +1,4 @@ +package com.aliens.backend.chat.controller.dto.request; + +public record MessageSendRequest(String type, String content, Long roomId, Long senderId, Long receiverId) { +} \ No newline at end of file From 7909c3d47645254864884ec45c7fb024fe43bf20 Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 01:03:24 +0900 Subject: [PATCH 114/215] =?UTF-8?q?refactor(ChatSummary):=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/chat/controller/dto/{ => response}/ChatSummary.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/com/aliens/backend/chat/controller/dto/{ => response}/ChatSummary.java (73%) diff --git a/src/main/java/com/aliens/backend/chat/controller/dto/ChatSummary.java b/src/main/java/com/aliens/backend/chat/controller/dto/response/ChatSummary.java similarity index 73% rename from src/main/java/com/aliens/backend/chat/controller/dto/ChatSummary.java rename to src/main/java/com/aliens/backend/chat/controller/dto/response/ChatSummary.java index 20ce7336..711b2118 100644 --- a/src/main/java/com/aliens/backend/chat/controller/dto/ChatSummary.java +++ b/src/main/java/com/aliens/backend/chat/controller/dto/response/ChatSummary.java @@ -1,4 +1,4 @@ -package com.aliens.backend.chat.controller.dto; +package com.aliens.backend.chat.controller.dto.response; import com.aliens.backend.chat.domain.Message; From 298941b509e5394b778a77885bbee2f2b50ccada Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 01:04:15 +0900 Subject: [PATCH 115/215] =?UTF-8?q?test(ChatServiceTest,WebsocketTest):=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=A0=84=EC=86=A1=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20Payload=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/chatting/WebSocketTest.java | 12 ++++++++--- .../chatting/service/ChatServiceTest.java | 21 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java index 7f7868ee..2c95b662 100644 --- a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java +++ b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java @@ -1,7 +1,7 @@ package com.aliens.backend.chatting; import com.aliens.backend.chat.controller.ChatController; -import com.aliens.backend.chat.service.ChatService; +import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; import com.aliens.backend.chatting.util.ChatClient; import com.aliens.backend.global.property.WebSocketProperties; import org.junit.jupiter.api.BeforeEach; @@ -43,10 +43,16 @@ public void WebSocketConnection() throws Exception { public void WebSocketSendMessage() throws Exception { //given StompSession session = chatClient.connect(); + String type = "NORMAL"; + String content = "Hello"; + Long roomId = 1L; + Long senderId = 1L; + Long receiverId = 2L; + MessageSendRequest messageSendRequest = new MessageSendRequest(type, content, roomId, senderId, receiverId); //when - session.send(properties.getRequest()+"/send",""); + session.send(properties.getRequest()+"/send", messageSendRequest); //then - verify(chatController, timeout(100).times(1)).sendMessage(); + verify(chatController, timeout(100).times(1)).sendMessage(messageSendRequest); } @Test diff --git a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java index 16236e93..cc5ef843 100644 --- a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java +++ b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java @@ -1,6 +1,8 @@ package com.aliens.backend.chatting.service; -import com.aliens.backend.chat.controller.dto.ChatSummary; +import com.aliens.backend.chat.controller.dto.response.ChatSummary; +import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; +import com.aliens.backend.chat.domain.ChatRepository.MessageRepository; import com.aliens.backend.chat.domain.Message; import com.aliens.backend.chat.service.ChatService; import com.aliens.backend.global.success.ChatSuccessCode; @@ -9,6 +11,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import java.util.List; @@ -16,19 +19,21 @@ public class ChatServiceTest { @Autowired ChatService chatService; + @MockBean + MessageRepository messageRepository; @Test @DisplayName("메시지 전송") void sendMessage() { //given - Message message = new Message.MessageBuilder() - .content("test message") - .roomId(1L) - .senderId(1L) - .receiverId(2L) - .build(); + String type = "NORMAL"; + String content = "Hello"; + Long roomId = 1L; + Long senderId = 1L; + Long receiverId = 2L; + MessageSendRequest messageSendRequest = new MessageSendRequest(type, content, roomId, senderId, receiverId); //when - String result = chatService.sendMessage(message); + String result = chatService.sendMessage(messageSendRequest); //then Assertions.assertEquals(ChatSuccessCode.SEND_MESSAGE_SUCCESS.getMessage(), result); } From d5cc10d25723584fd8cc3f71ae69cc6939509b87 Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 01:08:08 +0900 Subject: [PATCH 116/215] =?UTF-8?q?feat(Message):=20=EB=B9=8C=EB=8D=94=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C,=20=ED=8C=A9=ED=86=A0=EB=A6=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/chat/domain/Message.java | 58 +++++-------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/aliens/backend/chat/domain/Message.java b/src/main/java/com/aliens/backend/chat/domain/Message.java index bb505568..15d0119c 100644 --- a/src/main/java/com/aliens/backend/chat/domain/Message.java +++ b/src/main/java/com/aliens/backend/chat/domain/Message.java @@ -1,5 +1,8 @@ package com.aliens.backend.chat.domain; +import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; +import com.aliens.backend.global.error.ChatError; +import com.aliens.backend.global.exception.RestApiException; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; @@ -18,51 +21,20 @@ public class Message { private Date sendTime; private Boolean isRead; - public static class MessageBuilder { - private MessageType type; - private String content; - private Long roomId; - private Long senderId; - private Long receiverId; - - public MessageBuilder type(MessageType type) { - this.type = type; - return this; - } - - public MessageBuilder content(String content) { - this.content = content; - return this; - } - - public MessageBuilder roomId(Long roomId) { - this.roomId = roomId; - return this; - } - - public MessageBuilder senderId(Long senderId) { - this.senderId = senderId; - return this; - } - - public MessageBuilder receiverId(Long receiverId) { - this.receiverId = receiverId; - return this; - } - - public Message build() { - return new Message(this); - } + protected Message() { } - private Message(MessageBuilder builder) { - this.type = builder.type; - this.content = builder.content; - this.roomId = builder.roomId; - this.senderId = builder.senderId; - this.receiverId = builder.receiverId; - this.sendTime = new Date(); - this.isRead = false; + public static Message of(MessageSendRequest messageSendRequest){ + Message message = new Message(); + message.type = MessageType.fromString(messageSendRequest.type()) + .orElseThrow(() -> new RestApiException(ChatError.INVALID_MESSAGE_TYPE)); + message.content = messageSendRequest.content(); + message.roomId = messageSendRequest.roomId(); + message.senderId = messageSendRequest.senderId(); + message.receiverId = messageSendRequest.receiverId(); + message.sendTime = new Date(); + message.isRead = false; + return message; } @Override From 8ddeb645d36b8cf7c65eebcd9ac218405d48a24d Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 01:08:50 +0900 Subject: [PATCH 117/215] =?UTF-8?q?feat(MessageType):=20=EB=A9=94=EC=8B=9C?= =?UTF-8?q?=EC=A7=80=20=ED=83=80=EC=9E=85=20Enum=20fromString=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/chat/domain/MessageType.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/chat/domain/MessageType.java b/src/main/java/com/aliens/backend/chat/domain/MessageType.java index 4704d4a8..18742e9c 100644 --- a/src/main/java/com/aliens/backend/chat/domain/MessageType.java +++ b/src/main/java/com/aliens/backend/chat/domain/MessageType.java @@ -1,5 +1,16 @@ package com.aliens.backend.chat.domain; +import java.util.Optional; + public enum MessageType { - NORMAL, BALANCE_GAME + NORMAL, BALANCE_GAME; + + public static Optional fromString(String type) { + for (MessageType messageType : MessageType.values()) { + if (messageType.name().equalsIgnoreCase(type)) { + return Optional.of(messageType); + } + } + return Optional.empty(); + } } From 4a8bc7d86952b63e8cd0214b3c1dc4fb35940472 Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 01:09:17 +0900 Subject: [PATCH 118/215] =?UTF-8?q?feat(ChatError):=20=EC=B1=84=ED=8C=85?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/error/ChatError.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/error/ChatError.java diff --git a/src/main/java/com/aliens/backend/global/error/ChatError.java b/src/main/java/com/aliens/backend/global/error/ChatError.java new file mode 100644 index 00000000..bd5edb3d --- /dev/null +++ b/src/main/java/com/aliens/backend/global/error/ChatError.java @@ -0,0 +1,34 @@ +package com.aliens.backend.global.error; + +import org.springframework.http.HttpStatus; + +public enum ChatError implements ErrorCode { + + INVALID_MESSAGE_TYPE(HttpStatus.BAD_REQUEST, "CH1", "Invalid message type"), + ; + + private final HttpStatus httpStatusCode; + private final String developCode; + private final String message; + + ChatError(final HttpStatus httpStatusCode, final String code, final String message) { + this.httpStatusCode = httpStatusCode; + this.developCode = code; + this.message = message; + } + + @Override + public HttpStatus getHttpStatus() { + return httpStatusCode; + } + + @Override + public String getMessage() { + return message; + } + + @Override + public String getDevelopCode() { + return developCode; + } +} \ No newline at end of file From a308c20be1d5178f729458e724b1a4c480333772 Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 01:11:32 +0900 Subject: [PATCH 119/215] =?UTF-8?q?feat(ChatController):=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=A0=84=EC=86=A1=20Payload=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/chat/controller/ChatController.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatController.java b/src/main/java/com/aliens/backend/chat/controller/ChatController.java index 83a9c351..d7a4cbd8 100644 --- a/src/main/java/com/aliens/backend/chat/controller/ChatController.java +++ b/src/main/java/com/aliens/backend/chat/controller/ChatController.java @@ -1,7 +1,9 @@ package com.aliens.backend.chat.controller; +import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; import com.aliens.backend.chat.service.ChatService; import org.springframework.messaging.handler.annotation.MessageMapping; +import org.springframework.messaging.handler.annotation.Payload; import org.springframework.stereotype.Controller; @@ -15,18 +17,17 @@ public ChatController(ChatService chatService) { } @MessageMapping("/send") - public void sendMessage() { - chatService.sendMessage(); + public void sendMessage(@Payload MessageSendRequest messageSendRequest) { + chatService.sendMessage(messageSendRequest); } @MessageMapping("/read") public void readMessage() { - chatService.readMessage(); + chatService.readMessages(); } @MessageMapping("/summary") public void getChatSummary() { chatService.getChatSummary(); } - } From cd3ac32748e0de2b5236c3438069b0a31ef25c9d Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 02:59:31 +0900 Subject: [PATCH 120/215] =?UTF-8?q?feat(ChatService):=20=EB=A9=94=EC=8B=9C?= =?UTF-8?q?=EC=A7=80=20=EC=A0=84=EC=86=A1,=20=EB=A9=94=EC=8B=9C=EC=A7=80?= =?UTF-8?q?=20=EC=9D=BD=EC=9D=8C=20=EC=B2=98=EB=A6=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/chat/service/ChatService.java | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/aliens/backend/chat/service/ChatService.java b/src/main/java/com/aliens/backend/chat/service/ChatService.java index 6c56bb01..dc842f26 100644 --- a/src/main/java/com/aliens/backend/chat/service/ChatService.java +++ b/src/main/java/com/aliens/backend/chat/service/ChatService.java @@ -1,15 +1,72 @@ package com.aliens.backend.chat.service; +import com.aliens.backend.chat.controller.dto.request.ReadRequest; +import com.aliens.backend.chat.controller.dto.response.ChatSummary; +import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; +import com.aliens.backend.chat.controller.dto.response.ReadResponse; +import com.aliens.backend.chat.domain.ChatRepository.MessageRepository; +import com.aliens.backend.chat.domain.Message; +import com.aliens.backend.global.property.WebSocketProperties; +import com.aliens.backend.global.success.ChatSuccessCode; +import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + @Service public class ChatService { - public void sendMessage() { + private final MessageRepository messageRepository; + private final SimpMessagingTemplate messagingTemplate; + private final WebSocketProperties webSocketProperties; + + public ChatService(MessageRepository messageRepository, SimpMessagingTemplate messagingTemplate, WebSocketProperties webSocketProperties) { + this.messageRepository = messageRepository; + this.messagingTemplate = messagingTemplate; + this.webSocketProperties = webSocketProperties; + } + + public String sendMessage(MessageSendRequest messageSendRequest) { + Message message = Message.of(messageSendRequest); + saveMessage(message); + publishMessage(message,messageSendRequest.roomId()); + sendNotification(message); + return ChatSuccessCode.SEND_MESSAGE_SUCCESS.getMessage(); + } + + public String readMessages(ReadRequest readRequest) { + updateReadState(readRequest.roomId(), readRequest.memberId()); + publishReadState(readRequest.roomId(), readRequest.memberId()); + return ChatSuccessCode.READ_MESSAGES_SUCCESS.getMessage(); + } + + public List getChatSummary() { + List chatSummarys = new ArrayList<>(); + return chatSummarys; + } + + public List getMessages() { + List messages = new ArrayList<>(); + return messages; + } + + private void saveMessage(Message message) { + messageRepository.save(message); + } + + private void publishMessage(Message message, Long ChatRoomId) { + messagingTemplate.convertAndSend(webSocketProperties.getTopic()+"/"+ChatRoomId, message); + } + + private void sendNotification(Message message) { } - public void readMessage() { + private void updateReadState(Long chatRoomId, Long readBy) { + messageRepository.markMessagesAsRead(chatRoomId, readBy); } - public void getChatSummary() { + private void publishReadState(Long chatRoomId, Long memberId) { + ReadResponse readResponse = new ReadResponse(memberId); + messagingTemplate.convertAndSend(webSocketProperties.getTopic()+"/"+chatRoomId, readResponse); } } From ebd18e62d96e7aa17256717878aebfcedb244f1d Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 03:00:16 +0900 Subject: [PATCH 121/215] =?UTF-8?q?feat(ReadRequest):=20=EC=9D=BD=EC=9D=8C?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC=20=EC=9A=94=EC=B2=AD=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/chat/controller/ChatController.java | 5 +++-- .../backend/chat/controller/dto/request/ReadRequest.java | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/aliens/backend/chat/controller/dto/request/ReadRequest.java diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatController.java b/src/main/java/com/aliens/backend/chat/controller/ChatController.java index d7a4cbd8..0b1e95a5 100644 --- a/src/main/java/com/aliens/backend/chat/controller/ChatController.java +++ b/src/main/java/com/aliens/backend/chat/controller/ChatController.java @@ -1,6 +1,7 @@ package com.aliens.backend.chat.controller; import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; +import com.aliens.backend.chat.controller.dto.request.ReadRequest; import com.aliens.backend.chat.service.ChatService; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.Payload; @@ -22,8 +23,8 @@ public void sendMessage(@Payload MessageSendRequest messageSendRequest) { } @MessageMapping("/read") - public void readMessage() { - chatService.readMessages(); + public void readMessage(@Payload ReadRequest readRequest) { + chatService.readMessages(readRequest); } @MessageMapping("/summary") diff --git a/src/main/java/com/aliens/backend/chat/controller/dto/request/ReadRequest.java b/src/main/java/com/aliens/backend/chat/controller/dto/request/ReadRequest.java new file mode 100644 index 00000000..4573c04c --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/controller/dto/request/ReadRequest.java @@ -0,0 +1,4 @@ +package com.aliens.backend.chat.controller.dto.request; + +public record ReadRequest(Long roomId, Long memberId) { +} \ No newline at end of file From 2df00b046f3811ba121df24adae05744b06c5ee9 Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 03:02:11 +0900 Subject: [PATCH 122/215] =?UTF-8?q?test(ChatServiceTest):=20=EC=9D=BD?= =?UTF-8?q?=EC=9D=8C=20=EC=B2=98=EB=A6=AC=20=EC=9A=94=EC=B2=AD=20=EB=A0=88?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/aliens/backend/chatting/WebSocketTest.java | 8 ++++++-- .../aliens/backend/chatting/service/ChatServiceTest.java | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java index 2c95b662..9fb8dd38 100644 --- a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java +++ b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java @@ -2,6 +2,7 @@ import com.aliens.backend.chat.controller.ChatController; import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; +import com.aliens.backend.chat.controller.dto.request.ReadRequest; import com.aliens.backend.chatting.util.ChatClient; import com.aliens.backend.global.property.WebSocketProperties; import org.junit.jupiter.api.BeforeEach; @@ -59,11 +60,14 @@ public void WebSocketSendMessage() throws Exception { @DisplayName("웹소켓 - 읽음 처리 요청 시 readMessage() 호출") public void WebSocketReadMessage() throws Exception { //given + Long chatRoomId = 1L; + Long memberId = 1L; + ReadRequest readRequest = new ReadRequest(chatRoomId, memberId); StompSession session = chatClient.connect(); //when - session.send(properties.getRequest()+"/read",""); + session.send(properties.getRequest()+"/read",readRequest); //then - verify(chatController, timeout(100).times(1)).readMessage(); + verify(chatController, timeout(100).times(1)).readMessage(readRequest); } @Test diff --git a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java index cc5ef843..5bfa6553 100644 --- a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java +++ b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java @@ -1,5 +1,6 @@ package com.aliens.backend.chatting.service; +import com.aliens.backend.chat.controller.dto.request.ReadRequest; import com.aliens.backend.chat.controller.dto.response.ChatSummary; import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; import com.aliens.backend.chat.domain.ChatRepository.MessageRepository; @@ -42,8 +43,11 @@ void sendMessage() { @DisplayName("메시지 읽음 처리") void readMessages() { //given + Long chatRoomId = 1L; + Long memberId = 1L; + ReadRequest readRequest = new ReadRequest(chatRoomId, memberId); //when - String result = chatService.readMessages(); + String result = chatService.readMessages(readRequest); //then Assertions.assertEquals(ChatSuccessCode.READ_MESSAGES_SUCCESS.getMessage(), result); } From 289de3f566a94caa3e31d4002f7408bbe6533b78 Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 03:02:54 +0900 Subject: [PATCH 123/215] =?UTF-8?q?feat(ReadResponse):=20=EC=9D=BD?= =?UTF-8?q?=EC=9D=8C=20=EC=B2=98=EB=A6=AC=20=EC=9D=91=EB=8B=B5=20=EB=A0=88?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/chat/controller/dto/response/ReadResponse.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/controller/dto/response/ReadResponse.java diff --git a/src/main/java/com/aliens/backend/chat/controller/dto/response/ReadResponse.java b/src/main/java/com/aliens/backend/chat/controller/dto/response/ReadResponse.java new file mode 100644 index 00000000..6591f41d --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/controller/dto/response/ReadResponse.java @@ -0,0 +1,4 @@ +package com.aliens.backend.chat.controller.dto.response; + +public record ReadResponse(Long readBy) { +} \ No newline at end of file From a3bcede20f7f79ba502fe82db03a668bac9e6eb8 Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 03:05:39 +0900 Subject: [PATCH 124/215] =?UTF-8?q?feat(CustomMessageRepository):=20?= =?UTF-8?q?=EB=8B=A4=EC=A4=91=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=9D=BD?= =?UTF-8?q?=EC=9D=8C=20=EC=B2=98=EB=A6=AC=20=EA=B5=AC=ED=98=84=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20MongoTemplate=20=ED=99=9C=EC=9A=A9=20?= =?UTF-8?q?=EC=BB=A4=EC=8A=A4=ED=85=80=20=EB=A0=88=ED=8F=AC=EC=A7=80?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomMessageRepository.java | 5 ++++ .../CustomMessageRepositoryImpl.java | 29 +++++++++++++++++++ .../ChatRepository/MessageRepository.java | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java create mode 100644 src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java new file mode 100644 index 00000000..8bfd9802 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java @@ -0,0 +1,5 @@ +package com.aliens.backend.chat.domain.ChatRepository; + +public interface CustomMessageRepository { + void markMessagesAsRead(Long chatRoomId, Long readBy); +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java new file mode 100644 index 00000000..8d8e43dd --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java @@ -0,0 +1,29 @@ +package com.aliens.backend.chat.domain.ChatRepository; + +import com.aliens.backend.chat.domain.Message; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.data.mongodb.core.query.Update; +import org.springframework.stereotype.Repository; + +@Repository +public class CustomMessageRepositoryImpl implements CustomMessageRepository { + private final MongoTemplate mongoTemplate; + + @Autowired + public CustomMessageRepositoryImpl(MongoTemplate mongoTemplate) { + this.mongoTemplate = mongoTemplate; + } + + @Override + public void markMessagesAsRead(Long chatRoomId, Long readBy) { + Query query = new Query(Criteria.where("roomId").is(chatRoomId) + .and("receiverId").is(readBy) + .and("isRead").is(false)); + Update update = new Update(); + update.set("isRead", true); + mongoTemplate.updateMulti(query, update, Message.class); + } +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/MessageRepository.java b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/MessageRepository.java index d593de10..823469c5 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/MessageRepository.java +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/MessageRepository.java @@ -6,5 +6,5 @@ @Repository -public interface MessageRepository extends MongoRepository { +public interface MessageRepository extends MongoRepository, CustomMessageRepository { } From b11edce371404dfd9a11dd00b48da00bc122af70 Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 03:49:31 +0900 Subject: [PATCH 125/215] =?UTF-8?q?feat(ChatService):=20Stomp=20Publish=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/chat/service/ChatService.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/aliens/backend/chat/service/ChatService.java b/src/main/java/com/aliens/backend/chat/service/ChatService.java index dc842f26..dd1f2b2f 100644 --- a/src/main/java/com/aliens/backend/chat/service/ChatService.java +++ b/src/main/java/com/aliens/backend/chat/service/ChatService.java @@ -1,12 +1,11 @@ package com.aliens.backend.chat.service; +import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; import com.aliens.backend.chat.controller.dto.request.ReadRequest; import com.aliens.backend.chat.controller.dto.response.ChatSummary; -import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; import com.aliens.backend.chat.controller.dto.response.ReadResponse; import com.aliens.backend.chat.domain.ChatRepository.MessageRepository; import com.aliens.backend.chat.domain.Message; -import com.aliens.backend.global.property.WebSocketProperties; import com.aliens.backend.global.success.ChatSuccessCode; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.stereotype.Service; @@ -18,12 +17,10 @@ public class ChatService { private final MessageRepository messageRepository; private final SimpMessagingTemplate messagingTemplate; - private final WebSocketProperties webSocketProperties; - public ChatService(MessageRepository messageRepository, SimpMessagingTemplate messagingTemplate, WebSocketProperties webSocketProperties) { + public ChatService(MessageRepository messageRepository, SimpMessagingTemplate messagingTemplate) { this.messageRepository = messageRepository; this.messagingTemplate = messagingTemplate; - this.webSocketProperties = webSocketProperties; } public String sendMessage(MessageSendRequest messageSendRequest) { @@ -55,7 +52,7 @@ private void saveMessage(Message message) { } private void publishMessage(Message message, Long ChatRoomId) { - messagingTemplate.convertAndSend(webSocketProperties.getTopic()+"/"+ChatRoomId, message); + messagingTemplate.convertAndSend("/room/"+ChatRoomId, message); } private void sendNotification(Message message) { @@ -67,6 +64,6 @@ private void updateReadState(Long chatRoomId, Long readBy) { private void publishReadState(Long chatRoomId, Long memberId) { ReadResponse readResponse = new ReadResponse(memberId); - messagingTemplate.convertAndSend(webSocketProperties.getTopic()+"/"+chatRoomId, readResponse); + messagingTemplate.convertAndSend("/room/"+chatRoomId, readResponse); } } From 0a205a10ffe16a5e4e7afcb1a878dad7ee3342c7 Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 03:51:13 +0900 Subject: [PATCH 126/215] =?UTF-8?q?feat(WebSocketConfig):=20Stomp=20?= =?UTF-8?q?=EC=97=94=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/config/WebSocketConfig.java | 3 +-- .../global/property/WebSocketProperties.java | 13 +++---------- .../com/aliens/backend/chatting/WebSocketTest.java | 10 +++++++--- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java b/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java index fe5cfd06..58a1fecc 100644 --- a/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java +++ b/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java @@ -26,8 +26,7 @@ public WebSocketConfig(WebSocketProperties properties) { @Override public void configureMessageBroker(MessageBrokerRegistry registry) { - registry.setApplicationDestinationPrefixes(properties.getRequest()); - registry.setUserDestinationPrefix(properties.getTopic()); + registry.setApplicationDestinationPrefixes(properties.getAppDestinationPrefix()); } @Override diff --git a/src/main/java/com/aliens/backend/global/property/WebSocketProperties.java b/src/main/java/com/aliens/backend/global/property/WebSocketProperties.java index bbf059dc..c2261464 100644 --- a/src/main/java/com/aliens/backend/global/property/WebSocketProperties.java +++ b/src/main/java/com/aliens/backend/global/property/WebSocketProperties.java @@ -10,10 +10,7 @@ public class WebSocketProperties { private String port; @Value("${websocket.request}") - private String request; - - @Value("${websocket.topic}") - private String topic; + private String appDestinationPrefix; @Value("${websocket.endpoint}") private String endpoint; @@ -22,12 +19,8 @@ public String getPort() { return port; } - public String getRequest() { - return request; - } - - public String getTopic() { - return topic; + public String getAppDestinationPrefix() { + return appDestinationPrefix; } public String getEndpoint() { diff --git a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java index 9fb8dd38..d110d496 100644 --- a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java +++ b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java @@ -5,6 +5,7 @@ import com.aliens.backend.chat.controller.dto.request.ReadRequest; import com.aliens.backend.chatting.util.ChatClient; import com.aliens.backend.global.property.WebSocketProperties; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -24,6 +25,7 @@ public class WebSocketTest { @MockBean private ChatController chatController; private ChatClient chatClient; + private ObjectMapper objectMapper = new ObjectMapper(); @BeforeEach public void setup() { @@ -50,8 +52,9 @@ public void WebSocketSendMessage() throws Exception { Long senderId = 1L; Long receiverId = 2L; MessageSendRequest messageSendRequest = new MessageSendRequest(type, content, roomId, senderId, receiverId); + String jsonMessage = objectMapper.writeValueAsString(messageSendRequest); //when - session.send(properties.getRequest()+"/send", messageSendRequest); + session.send(properties.getAppDestinationPrefix()+"/send", jsonMessage.getBytes()); //then verify(chatController, timeout(100).times(1)).sendMessage(messageSendRequest); } @@ -63,9 +66,10 @@ public void WebSocketReadMessage() throws Exception { Long chatRoomId = 1L; Long memberId = 1L; ReadRequest readRequest = new ReadRequest(chatRoomId, memberId); + String jsonMessage = objectMapper.writeValueAsString(readRequest); StompSession session = chatClient.connect(); //when - session.send(properties.getRequest()+"/read",readRequest); + session.send(properties.getAppDestinationPrefix()+"/read", jsonMessage.getBytes()); //then verify(chatController, timeout(100).times(1)).readMessage(readRequest); } @@ -76,7 +80,7 @@ public void WebSocketGetChatSummary() throws Exception { //given StompSession session = chatClient.connect(); //when - session.send(properties.getRequest()+"/summary",""); + session.send(properties.getAppDestinationPrefix()+"/summary",""); //then verify(chatController, timeout(100).times(1)).getChatSummary(); } From 245d12eac2f85aa27e70ca9d4b92f3a0e3fb5a90 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Tue, 6 Feb 2024 13:06:38 +0900 Subject: [PATCH 127/215] =?UTF-8?q?fix(delete)=20:=20MatchingConverter,=20?= =?UTF-8?q?MatchingQueueBuilder=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/util/MatchingConverter.java | 27 ----------------- .../mathcing/util/MatchingQueueBuilder.java | 29 ------------------- 2 files changed, 56 deletions(-) delete mode 100644 src/main/java/com/aliens/backend/mathcing/util/MatchingConverter.java delete mode 100644 src/main/java/com/aliens/backend/mathcing/util/MatchingQueueBuilder.java diff --git a/src/main/java/com/aliens/backend/mathcing/util/MatchingConverter.java b/src/main/java/com/aliens/backend/mathcing/util/MatchingConverter.java deleted file mode 100644 index fcf6469c..00000000 --- a/src/main/java/com/aliens/backend/mathcing/util/MatchingConverter.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.aliens.backend.mathcing.util; - -import com.aliens.backend.mathcing.domain.MatchingApplication; -import com.aliens.backend.mathcing.service.model.Participant; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -@Component -public class MatchingConverter { - public List toParticipantList(final List matchingApplications) { - return matchingApplications.stream() - .map(this::toParticipantList) - .collect(Collectors.toList()); - } - - private Participant toParticipantList(final MatchingApplication matchingApplication) { - return new Participant( - matchingApplication.getId().getMemberId(), - matchingApplication.getFirstPreferLanguage(), - matchingApplication.getSecondPreferLanguage(), - new ArrayList<>() - ); - } -} diff --git a/src/main/java/com/aliens/backend/mathcing/util/MatchingQueueBuilder.java b/src/main/java/com/aliens/backend/mathcing/util/MatchingQueueBuilder.java deleted file mode 100644 index 480dbdc0..00000000 --- a/src/main/java/com/aliens/backend/mathcing/util/MatchingQueueBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.aliens.backend.mathcing.util; - -import com.aliens.backend.mathcing.service.model.Language; -import com.aliens.backend.mathcing.service.model.Participant; -import com.aliens.backend.mathcing.service.model.MatchingMode; -import org.springframework.stereotype.Component; - -import java.util.*; - -@Component -public class MatchingQueueBuilder { - public Map> buildLanguageQueues(final List participants) { - Map> languageQueue = createQueuesByLanguage(); - - for (Participant participant : participants) { - languageQueue.get(participant.getPreferLanguage(MatchingMode.FIRST_PREFER_LANGUAGE)).add(participant); - } - - return languageQueue; - } - - private Map> createQueuesByLanguage() { - Map> languageQueue = new HashMap<>(); - for (Language language : Language.values()) { - languageQueue.put(language, new LinkedList<>()); - } - return languageQueue; - } -} From 6751094e01ada80613e247f7eac89e77e9432663 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Tue, 6 Feb 2024 15:44:09 +0900 Subject: [PATCH 128/215] =?UTF-8?q?test=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20API=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dto/input/MatchingInput.java | 4 ++ .../MatchingApplicationApiTest.java | 52 ++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java index f5317b6b..aab490eb 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java @@ -15,6 +15,10 @@ public MatchingApplicationRequest toRequest(final Long memberId){ return new MatchingApplicationRequest(memberId, firstPreferLanguage, secondPreferLanguage); } + public static MatchingApplicationInput of(Language firstPreferLanguage, Language secondPreferLanguage) { + return new MatchingApplicationInput(firstPreferLanguage, secondPreferLanguage); + } + private void validateInput() { if (firstPreferLanguage.equals(secondPreferLanguage)) { throw new RestApiException(MatchingError.INVALID_LANGUAGE_INPUT); diff --git a/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java b/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java index 5761b458..e61b9151 100644 --- a/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java +++ b/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java @@ -1,20 +1,70 @@ package com.aliens.backend.matching.integration; +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.domain.MemberRole; +import com.aliens.backend.mathcing.service.MatchingApplicationService; +import com.aliens.backend.mathcing.service.model.Language; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; + +import static com.aliens.backend.mathcing.controller.dto.input.MatchingInput.*; +import static org.mockito.BDDMockito.*; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.restdocs.request.RequestDocumentation.partWithName; +import static org.springframework.restdocs.request.RequestDocumentation.requestParts; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringBootTest +@AutoConfigureMockMvc +@AutoConfigureRestDocs public class MatchingApplicationApiTest { + @Autowired MockMvc mockMvc; + @SpyBean MatchingApplicationService matchingApplicationService; + + ObjectMapper objectMapper = new ObjectMapper(); + String accessToken; + MatchingApplicationInput matchingApplicationInput; + LoginMember loginMember; + @BeforeEach void setUp() { + accessToken = "accessToken"; + loginMember = new LoginMember(1L, MemberRole.MEMBER); + matchingApplicationInput = MatchingApplicationInput.of(Language.KOREAN, Language.ENGLISH); } @Test @DisplayName("매칭 신청 API 테스트") - void applyMatchApiTest() { + void applyMatchApiTest() throws Exception { + doNothing().when(matchingApplicationService).saveParticipant(matchingApplicationInput.toRequest(any())); + + mockMvc.perform(post("/matchings/applications") + .header("Authorization", accessToken) + .content(objectMapper.writeValueAsString(matchingApplicationInput)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().is4xxClientError()); +// .andDo(document("post-matching-application", +// requestParts( +// partWithName("matchingApplicationInput").description("매칭 신청 정보 입력") +// ), +// responseFields( +// fieldWithPath("response").description("매칭 신청 결과") +// ) +// ) +// ); } } From 2810d66772c4d25ac72c7bbdf16b878e589d2abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Tue, 6 Feb 2024 22:11:30 +0900 Subject: [PATCH 129/215] =?UTF-8?q?refactor(DatabaseCleanup)=20:=20yml=20?= =?UTF-8?q?=EC=B0=B8=EC=A1=B0=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/aliens/backend/global/DatabaseCleanup.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/aliens/backend/global/DatabaseCleanup.java b/src/test/java/com/aliens/backend/global/DatabaseCleanup.java index 3aad2d37..c9631006 100644 --- a/src/test/java/com/aliens/backend/global/DatabaseCleanup.java +++ b/src/test/java/com/aliens/backend/global/DatabaseCleanup.java @@ -13,7 +13,6 @@ import java.util.stream.Collectors; @Component -@ActiveProfiles("test") public class DatabaseCleanup implements InitializingBean { @PersistenceContext @@ -41,4 +40,4 @@ public void execute() { entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 1").executeUpdate(); } -} \ No newline at end of file +} From eba51c639e88d9ccc1ad144068ab219fd4aacf2a Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 23:43:27 +0900 Subject: [PATCH 130/215] =?UTF-8?q?feat(ChatService):=20=EB=A9=94=EC=8B=9C?= =?UTF-8?q?=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/chat/service/ChatService.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/aliens/backend/chat/service/ChatService.java b/src/main/java/com/aliens/backend/chat/service/ChatService.java index dd1f2b2f..fb4e6cdd 100644 --- a/src/main/java/com/aliens/backend/chat/service/ChatService.java +++ b/src/main/java/com/aliens/backend/chat/service/ChatService.java @@ -26,7 +26,7 @@ public ChatService(MessageRepository messageRepository, SimpMessagingTemplate me public String sendMessage(MessageSendRequest messageSendRequest) { Message message = Message.of(messageSendRequest); saveMessage(message); - publishMessage(message,messageSendRequest.roomId()); + publishMessage(message, messageSendRequest.roomId()); sendNotification(message); return ChatSuccessCode.SEND_MESSAGE_SUCCESS.getMessage(); } @@ -42,8 +42,8 @@ public List getChatSummary() { return chatSummarys; } - public List getMessages() { - List messages = new ArrayList<>(); + public List getMessages(Long chatRoomId, String lastMessageId) { + List messages = findMessages(chatRoomId, lastMessageId); return messages; } @@ -52,7 +52,7 @@ private void saveMessage(Message message) { } private void publishMessage(Message message, Long ChatRoomId) { - messagingTemplate.convertAndSend("/room/"+ChatRoomId, message); + messagingTemplate.convertAndSend("/room/"+ ChatRoomId, message); } private void sendNotification(Message message) { @@ -64,6 +64,6 @@ private void updateReadState(Long chatRoomId, Long readBy) { private void publishReadState(Long chatRoomId, Long memberId) { ReadResponse readResponse = new ReadResponse(memberId); - messagingTemplate.convertAndSend("/room/"+chatRoomId, readResponse); + messagingTemplate.convertAndSend("/room/" + chatRoomId, readResponse); } } From 4d1e1b440c71fcacba64a34518cd2071e62b8aaf Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 23:44:03 +0900 Subject: [PATCH 131/215] =?UTF-8?q?feat(ChatController):=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/chat/controller/ChatController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatController.java b/src/main/java/com/aliens/backend/chat/controller/ChatController.java index 0b1e95a5..5e349843 100644 --- a/src/main/java/com/aliens/backend/chat/controller/ChatController.java +++ b/src/main/java/com/aliens/backend/chat/controller/ChatController.java @@ -31,4 +31,12 @@ public void readMessage(@Payload ReadRequest readRequest) { public void getChatSummary() { chatService.getChatSummary(); } + + @GetMapping("/chat/room/{roomId}/messages") + public ResponseEntity> getMessages(@PathVariable("roomId") Long chatRoomId, + @RequestParam("lastMessageId") String lastMessageId) { + List messages = chatService.getMessages(chatRoomId,lastMessageId); + Map response = Collections.singletonMap("response", messages); + return ResponseEntity.ok(response); + } } From d134eb9298de40e4a0f7f8e043bad5a45138babc Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 23:45:23 +0900 Subject: [PATCH 132/215] =?UTF-8?q?feat(CustomMessageRepository):=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ChatRepository/CustomMessageRepository.java | 5 +++++ .../CustomMessageRepositoryImpl.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java index 8bfd9802..178f9cdf 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java @@ -1,5 +1,10 @@ package com.aliens.backend.chat.domain.ChatRepository; +import com.aliens.backend.chat.domain.Message; + +import java.util.List; + public interface CustomMessageRepository { void markMessagesAsRead(Long chatRoomId, Long readBy); + List findMessages(Long chatRoomId, String lastMessageId); } \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java index 8d8e43dd..f434d677 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java @@ -1,13 +1,17 @@ package com.aliens.backend.chat.domain.ChatRepository; import com.aliens.backend.chat.domain.Message; +import org.bson.types.ObjectId; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public class CustomMessageRepositoryImpl implements CustomMessageRepository { private final MongoTemplate mongoTemplate; @@ -26,4 +30,17 @@ public void markMessagesAsRead(Long chatRoomId, Long readBy) { update.set("isRead", true); mongoTemplate.updateMulti(query, update, Message.class); } + + @Override + public List findMessages(Long chatRoomID, String lastMessageId) { + Query query = new Query( + Criteria.where("roomId").is(chatRoomID) + ).with(Sort.by(Sort.Direction.DESC, "_id")).limit(100); // "_id"를 사용하여 정렬 + + if (lastMessageId != null) { + query.addCriteria(Criteria.where("_id").lt(new ObjectId(lastMessageId))); + } + + return mongoTemplate.find(query, Message.class); + } } \ No newline at end of file From 674ecd276b29c1f27339d4730c0dca399c6b0613 Mon Sep 17 00:00:00 2001 From: coke98 Date: Tue, 6 Feb 2024 23:46:51 +0900 Subject: [PATCH 133/215] =?UTF-8?q?test(ChatServiceTest):=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/chatting/service/ChatServiceTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java index 5bfa6553..e39d0b6f 100644 --- a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java +++ b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java @@ -66,8 +66,9 @@ void getChatSummary() { @DisplayName("메시지 조회") void getMessages() { //given + Long chatRoomId = 1L; //when - List result = chatService.getMessages(); + List result = chatService.getMessages(chatRoomId, null); //then Assertions.assertNotNull(result); } From ba33ab0279e780b6757ef3ccb492f4fe70b89559 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 02:45:47 +0900 Subject: [PATCH 134/215] =?UTF-8?q?feat(ChatSummaryResponse):=20ChatSummar?= =?UTF-8?q?y=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20ChatSummaryResponse=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/controller/dto/response/ChatSummary.java | 6 ------ .../controller/dto/response/ChatSummaryResponse.java | 9 +++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) delete mode 100644 src/main/java/com/aliens/backend/chat/controller/dto/response/ChatSummary.java create mode 100644 src/main/java/com/aliens/backend/chat/controller/dto/response/ChatSummaryResponse.java diff --git a/src/main/java/com/aliens/backend/chat/controller/dto/response/ChatSummary.java b/src/main/java/com/aliens/backend/chat/controller/dto/response/ChatSummary.java deleted file mode 100644 index 711b2118..00000000 --- a/src/main/java/com/aliens/backend/chat/controller/dto/response/ChatSummary.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.aliens.backend.chat.controller.dto.response; - -import com.aliens.backend.chat.domain.Message; - -public record ChatSummary(Long roomId, Long partnerId, Message lastMessage, Long numberOfUnreadMessages) { -} diff --git a/src/main/java/com/aliens/backend/chat/controller/dto/response/ChatSummaryResponse.java b/src/main/java/com/aliens/backend/chat/controller/dto/response/ChatSummaryResponse.java new file mode 100644 index 00000000..d74d6d2b --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/controller/dto/response/ChatSummaryResponse.java @@ -0,0 +1,9 @@ +package com.aliens.backend.chat.controller.dto.response; + +import com.aliens.backend.chat.domain.ChatRoom; +import com.aliens.backend.chat.service.model.ChatMessageSummary; + +import java.util.List; + +public record ChatSummaryResponse(List chatRooms, List chatMessageSummaries) { +} \ No newline at end of file From 1d47846972e4f3f34a756ff5f2bf65561b602d8f Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 02:48:28 +0900 Subject: [PATCH 135/215] =?UTF-8?q?test(ChatDocTest):=20=EC=B1=84=ED=8C=85?= =?UTF-8?q?=20=EB=AC=B8=EC=84=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/docs/ChatDocTest.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/test/java/com/aliens/backend/docs/ChatDocTest.java diff --git a/src/test/java/com/aliens/backend/docs/ChatDocTest.java b/src/test/java/com/aliens/backend/docs/ChatDocTest.java new file mode 100644 index 00000000..1ed63e56 --- /dev/null +++ b/src/test/java/com/aliens/backend/docs/ChatDocTest.java @@ -0,0 +1,85 @@ +package com.aliens.backend.docs; + +import com.aliens.backend.auth.service.TokenProvider; +import com.aliens.backend.chat.controller.dto.response.ChatSummaryResponse; +import com.aliens.backend.chat.domain.Message; +import com.aliens.backend.chat.service.ChatService; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.test.web.servlet.MockMvc; + +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.Mockito.when; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@AutoConfigureMockMvc +@AutoConfigureRestDocs +@SpringBootTest +class ChatDocTest { + @Autowired + private MockMvc mockMvc; + @MockBean + private ChatService chatService; + @MockBean + private TokenProvider tokenProvider; + + ObjectMapper objectMapper; + MockMultipartFile multipartFile; + String accessToken; + + @BeforeEach + void setUp() { + accessToken= "accessToken"; + objectMapper = new ObjectMapper(); + } + + @Test + @DisplayName("채팅 메시지 조회") + void getMessages() throws Exception { + Long chatRoomId = 1L; + List response = new ArrayList<>(); + when(chatService.getMessages(chatRoomId, null)).thenReturn(response); + + mockMvc.perform(get("/chat/room/{roomId}/messages", chatRoomId) + .header("Authorization", accessToken) + ) + .andExpect(status().isOk()) + .andDo(document("chat-get-messages", + responseFields( + fieldWithPath("response").description("메시지 목록 조회 결과") + ) + )); + } + + @Test + @DisplayName("채팅 요약 정보 조회") + void getChatSummary() throws Exception { + Long memberId = 1L; + ChatSummaryResponse response = new ChatSummaryResponse(new ArrayList<>(), new ArrayList<>()); + when(chatService.getChatSummaries(memberId)).thenReturn(response); + + mockMvc.perform(get("/chat/summaries") + .header("Authorization", accessToken) + ) + .andExpect(status().isOk()) + .andDo(document("chat-get-summary", + responseFields( + fieldWithPath("response").description("채팅방 요약 정보 조회 결과") + ) + )); + } +} \ No newline at end of file From fe5bd2ac2955c2e252efc24978c11ab3c76b8a85 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 02:50:24 +0900 Subject: [PATCH 136/215] =?UTF-8?q?feat(ChatController):=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=9A=94=EC=95=BD=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/controller/ChatController.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatController.java b/src/main/java/com/aliens/backend/chat/controller/ChatController.java index 5e349843..892772ea 100644 --- a/src/main/java/com/aliens/backend/chat/controller/ChatController.java +++ b/src/main/java/com/aliens/backend/chat/controller/ChatController.java @@ -2,10 +2,21 @@ import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; import com.aliens.backend.chat.controller.dto.request.ReadRequest; +import com.aliens.backend.chat.controller.dto.response.ChatSummaryResponse; +import com.aliens.backend.chat.domain.Message; import com.aliens.backend.chat.service.ChatService; +import com.aliens.backend.global.config.resolver.Login; +import org.springframework.http.ResponseEntity; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.Collections; +import java.util.List; +import java.util.Map; @Controller @@ -27,14 +38,16 @@ public void readMessage(@Payload ReadRequest readRequest) { chatService.readMessages(readRequest); } - @MessageMapping("/summary") - public void getChatSummary() { - chatService.getChatSummary(); + @GetMapping("chat/summaries") + public ResponseEntity> getChatSummaries(@Login Long memberId) { + ChatSummaryResponse chatSummaryResponse = chatService.getChatSummaries(memberId); + Map response = Collections.singletonMap("response", chatSummaryResponse); + return ResponseEntity.ok(response); } @GetMapping("/chat/room/{roomId}/messages") public ResponseEntity> getMessages(@PathVariable("roomId") Long chatRoomId, - @RequestParam("lastMessageId") String lastMessageId) { + @RequestParam(value = "lastMessageId", required = false) String lastMessageId) { List messages = chatService.getMessages(chatRoomId,lastMessageId); Map response = Collections.singletonMap("response", messages); return ResponseEntity.ok(response); From a9a1e76d17487c67f812b256d8ad21e849074c13 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 02:51:22 +0900 Subject: [PATCH 137/215] =?UTF-8?q?test(WebSocketTest):=20=EC=9B=B9?= =?UTF-8?q?=EC=86=8C=EC=BC=93=20=EC=B1=84=ED=8C=85=20=EC=9A=94=EC=95=BD=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=9A=94=EC=B2=AD=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/chatting/WebSocketTest.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java index d110d496..d26adf23 100644 --- a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java +++ b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java @@ -73,15 +73,4 @@ public void WebSocketReadMessage() throws Exception { //then verify(chatController, timeout(100).times(1)).readMessage(readRequest); } - - @Test - @DisplayName("웹소켓 - 채팅 요약 정보 요청 시 getChatSummary() 호출") - public void WebSocketGetChatSummary() throws Exception { - //given - StompSession session = chatClient.connect(); - //when - session.send(properties.getAppDestinationPrefix()+"/summary",""); - //then - verify(chatController, timeout(100).times(1)).getChatSummary(); - } } \ No newline at end of file From 967d81d5b8e86df2d47ab3225cf058290195f1b1 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 02:52:34 +0900 Subject: [PATCH 138/215] =?UTF-8?q?feat(ChatServiceTest):=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=9A=94=EC=95=BD=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/chatting/service/ChatServiceTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java index e39d0b6f..c1e9904c 100644 --- a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java +++ b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java @@ -1,7 +1,7 @@ package com.aliens.backend.chatting.service; import com.aliens.backend.chat.controller.dto.request.ReadRequest; -import com.aliens.backend.chat.controller.dto.response.ChatSummary; +import com.aliens.backend.chat.controller.dto.response.ChatSummaryResponse; import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; import com.aliens.backend.chat.domain.ChatRepository.MessageRepository; import com.aliens.backend.chat.domain.Message; @@ -56,8 +56,9 @@ void readMessages() { @DisplayName("채팅 요약 정보 조회") void getChatSummary() { //given + Long memberId = 1L; //when - List result = chatService.getChatSummary(); + ChatSummaryResponse result = chatService.getChatSummaries(memberId); //then Assertions.assertNotNull(result); } From 633d9bbaa403abd057a6ae6244904771a119076e Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 02:54:14 +0900 Subject: [PATCH 139/215] =?UTF-8?q?feat(ChatService):=20getChatSummary=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/chat/service/ChatService.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/aliens/backend/chat/service/ChatService.java b/src/main/java/com/aliens/backend/chat/service/ChatService.java index fb4e6cdd..d1da28ad 100644 --- a/src/main/java/com/aliens/backend/chat/service/ChatService.java +++ b/src/main/java/com/aliens/backend/chat/service/ChatService.java @@ -2,24 +2,28 @@ import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; import com.aliens.backend.chat.controller.dto.request.ReadRequest; -import com.aliens.backend.chat.controller.dto.response.ChatSummary; +import com.aliens.backend.chat.controller.dto.response.ChatSummaryResponse; import com.aliens.backend.chat.controller.dto.response.ReadResponse; +import com.aliens.backend.chat.domain.ChatRepository.ChatRepository; import com.aliens.backend.chat.domain.ChatRepository.MessageRepository; +import com.aliens.backend.chat.domain.ChatRoom; import com.aliens.backend.chat.domain.Message; +import com.aliens.backend.chat.service.model.ChatMessageSummary; import com.aliens.backend.global.success.ChatSuccessCode; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.stereotype.Service; -import java.util.ArrayList; import java.util.List; @Service public class ChatService { private final MessageRepository messageRepository; private final SimpMessagingTemplate messagingTemplate; + private final ChatRepository chatRepository; - public ChatService(MessageRepository messageRepository, SimpMessagingTemplate messagingTemplate) { + public ChatService(MessageRepository messageRepository, ChatRepository chatRepository, SimpMessagingTemplate messagingTemplate) { this.messageRepository = messageRepository; + this.chatRepository = chatRepository; this.messagingTemplate = messagingTemplate; } @@ -37,9 +41,12 @@ public String readMessages(ReadRequest readRequest) { return ChatSuccessCode.READ_MESSAGES_SUCCESS.getMessage(); } - public List getChatSummary() { - List chatSummarys = new ArrayList<>(); - return chatSummarys; + public ChatSummaryResponse getChatSummaries(Long memberId) { + List chatRooms = chatRepository.findByMemberId(memberId); + List chatRoomIds = chatRooms.stream().map(ChatRoom::getId).toList(); + List chatMessageSummaries = messageRepository.aggregateMessageSummaries(chatRoomIds, memberId); + ChatSummaryResponse chatSummaryResponse = new ChatSummaryResponse(chatRooms, chatMessageSummaries); + return chatSummaryResponse; } public List getMessages(Long chatRoomId, String lastMessageId) { @@ -66,4 +73,8 @@ private void publishReadState(Long chatRoomId, Long memberId) { ReadResponse readResponse = new ReadResponse(memberId); messagingTemplate.convertAndSend("/room/" + chatRoomId, readResponse); } + + private List findMessages(Long chatRoomId, String lastMessageId) { + return messageRepository.findMessages(chatRoomId,lastMessageId); + } } From 64730b60f5670a35f0f602c8a8c8868ba66e2e55 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 02:56:56 +0900 Subject: [PATCH 140/215] =?UTF-8?q?feat(CustomMessageRepository):=20aggreg?= =?UTF-8?q?ation=EC=9D=84=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=ED=95=9C=EB=B2=88=EC=9D=98=20=EC=BF=BC=EB=A6=AC=EB=A1=9C=20?= =?UTF-8?q?=EC=B1=84=ED=8C=85=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=9A=94?= =?UTF-8?q?=EC=95=BD=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomMessageRepository.java | 2 ++ .../CustomMessageRepositoryImpl.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java index 178f9cdf..d66a8691 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java @@ -1,10 +1,12 @@ package com.aliens.backend.chat.domain.ChatRepository; import com.aliens.backend.chat.domain.Message; +import com.aliens.backend.chat.service.model.ChatMessageSummary; import java.util.List; public interface CustomMessageRepository { void markMessagesAsRead(Long chatRoomId, Long readBy); List findMessages(Long chatRoomId, String lastMessageId); + List aggregateMessageSummaries(List chatRoomIds, Long memberId); } \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java index f434d677..bde58613 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java @@ -1,16 +1,23 @@ package com.aliens.backend.chat.domain.ChatRepository; import com.aliens.backend.chat.domain.Message; +import com.aliens.backend.chat.service.model.ChatMessageSummary; import org.bson.types.ObjectId; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.aggregation.Aggregation; +import org.springframework.data.mongodb.core.aggregation.AggregationOperation; +import org.springframework.data.mongodb.core.aggregation.AggregationResults; +import org.springframework.data.mongodb.core.aggregation.ConditionalOperators; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; import org.springframework.stereotype.Repository; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; @Repository public class CustomMessageRepositoryImpl implements CustomMessageRepository { @@ -43,4 +50,15 @@ public List findMessages(Long chatRoomID, String lastMessageId) { return mongoTemplate.find(query, Message.class); } + + @Override + public List aggregateMessageSummaries(List chatRoomIds, Long memberId) { + AggregationOperation match = Aggregation.match(Criteria.where("roomId").in(chatRoomIds)); + AggregationOperation group = Aggregation.group("roomId") + .last("content").as("lastMessageContent") + .sum(ConditionalOperators.when(Criteria.where("receiverId").is(memberId).and("isRead").is(false)).then(1).otherwise(0)).as("unreadCount"); + Aggregation aggregation = Aggregation.newAggregation(match, group); + AggregationResults results = mongoTemplate.aggregate(aggregation, "message", ChatMessageSummary.class); + return new ArrayList<>(results.getMappedResults()); + } } \ No newline at end of file From e99dd8c18c9b172c80c46dbfe3510ca42e8d033e Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 03:00:51 +0900 Subject: [PATCH 141/215] =?UTF-8?q?feat(ChatRepository,=20ChatRoom,=20Chat?= =?UTF-8?q?RoomStatus):=20=EC=B1=84=ED=8C=85=EB=B0=A9=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0,=20=EB=A0=88=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC,=20?= =?UTF-8?q?=EC=B1=84=ED=8C=85=EB=B0=A9=20=EC=83=81=ED=83=9C=20Enum=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/ChatRepository/ChatRepository.java | 12 +++++++ .../aliens/backend/chat/domain/ChatRoom.java | 33 +++++++++++++++++++ .../backend/chat/domain/ChatRoomStatus.java | 5 +++ 3 files changed, 50 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/domain/ChatRepository/ChatRepository.java create mode 100644 src/main/java/com/aliens/backend/chat/domain/ChatRoom.java create mode 100644 src/main/java/com/aliens/backend/chat/domain/ChatRoomStatus.java diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/ChatRepository.java b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/ChatRepository.java new file mode 100644 index 00000000..091475ff --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRepository/ChatRepository.java @@ -0,0 +1,12 @@ +package com.aliens.backend.chat.domain.ChatRepository; + +import com.aliens.backend.chat.domain.ChatRoom; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface ChatRepository extends JpaRepository { + List findByMemberId(Long memberId); +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java b/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java new file mode 100644 index 00000000..52fa49fd --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java @@ -0,0 +1,33 @@ +package com.aliens.backend.chat.domain; + +import jakarta.persistence.*; + +@Entity +@Table(name = "CHAT_ROOM ") +public class ChatRoom { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column + private Long id; + @Column(name = "member_id") + private Long memberId; + @Column(name = "partner_id") + private Long partnerId; + @Column + private ChatRoomStatus status; + + protected ChatRoom() { + } + + public Long getId() { + return id; + } + + public Long getPartnerId() { + return partnerId; + } + + public ChatRoomStatus getStatus() { + return status; + } +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRoomStatus.java b/src/main/java/com/aliens/backend/chat/domain/ChatRoomStatus.java new file mode 100644 index 00000000..0e9229d6 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRoomStatus.java @@ -0,0 +1,5 @@ +package com.aliens.backend.chat.domain; + +public enum ChatRoomStatus { + WAITING, OPEN, CLOSE, BLOCKED; +} From 6ee031143c14de827b54763d8fe15301d7a06675 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 03:01:51 +0900 Subject: [PATCH 142/215] =?UTF-8?q?feat(ChatMessageSummary):=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=9A=94=EC=95=BD=20=EC=A0=95=EB=B3=B4=20=EC=A4=91?= =?UTF-8?q?=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=ED=8C=8C=ED=8A=B8=EB=A5=BC=20?= =?UTF-8?q?=EB=82=98=ED=83=80=EB=82=B4=EB=8A=94=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/chat/service/model/ChatMessageSummary.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/service/model/ChatMessageSummary.java diff --git a/src/main/java/com/aliens/backend/chat/service/model/ChatMessageSummary.java b/src/main/java/com/aliens/backend/chat/service/model/ChatMessageSummary.java new file mode 100644 index 00000000..d15d9276 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/service/model/ChatMessageSummary.java @@ -0,0 +1,4 @@ +package com.aliens.backend.chat.service.model; + +public record ChatMessageSummary(Long roomId, String lastMessageContent, Long numberOfUnreadMessages) { +} \ No newline at end of file From 11992d9b6a3f116a7d65065d2f3c7e248b74e252 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 04:58:28 +0900 Subject: [PATCH 143/215] =?UTF-8?q?feat(ChatHandshakeInterceptor):=20?= =?UTF-8?q?=EC=9B=B9=EC=86=8C=EC=BC=93=20=EC=A0=91=EC=86=8D=EC=8B=9C=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=EC=9D=B8=ED=84=B0=EC=85=89=ED=84=B0=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interceptor/ChatHandshakeInterceptor.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/interceptor/ChatHandshakeInterceptor.java diff --git a/src/main/java/com/aliens/backend/global/interceptor/ChatHandshakeInterceptor.java b/src/main/java/com/aliens/backend/global/interceptor/ChatHandshakeInterceptor.java new file mode 100644 index 00000000..ce8a9f1c --- /dev/null +++ b/src/main/java/com/aliens/backend/global/interceptor/ChatHandshakeInterceptor.java @@ -0,0 +1,53 @@ +package com.aliens.backend.global.interceptor; + +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.service.TokenProvider; +import com.aliens.backend.chat.domain.ChatRoom; +import com.aliens.backend.chat.service.ChatService; +import org.springframework.context.annotation.Lazy; +import org.springframework.http.server.ServerHttpRequest; +import org.springframework.http.server.ServerHttpResponse; +import org.springframework.http.server.ServletServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.server.HandshakeInterceptor; + +import java.util.List; +import java.util.Map; + +@Component +public class ChatHandshakeInterceptor implements HandshakeInterceptor { + + private final TokenProvider tokenProvider; + private final ChatService chatService; + + public ChatHandshakeInterceptor(TokenProvider tokenProvider, @Lazy ChatService chatService) { + this.tokenProvider = tokenProvider; + this.chatService = chatService; + } + + @Override + public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, + WebSocketHandler wsHandler, Map attributes) { + + if (request instanceof ServletServerHttpRequest) { + ServletServerHttpRequest servletRequest = (ServletServerHttpRequest) request; + String accessToken = servletRequest.getServletRequest().getHeader("Authorization"); + LoginMember loginMember = tokenProvider.getLoginMemberFromToken(accessToken); + + if (loginMember != null) { + List chatRooms = chatService.getChatRooms(loginMember.memberId()); + attributes.put("loginMember", loginMember); + attributes.put("chatRooms", chatRooms); + + return true; + } + } + return false; + } + + @Override + public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, + WebSocketHandler wsHandler, Exception exception) { + } +} \ No newline at end of file From d7c5109c5a1073cb05b75bbdb688aa82d04fe4de Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 05:00:40 +0900 Subject: [PATCH 144/215] =?UTF-8?q?feat(ChatChannelInterceptor):=20?= =?UTF-8?q?=EC=9D=B8=EA=B0=80=20=ED=99=95=EC=9D=B8=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=EC=B1=84=EB=84=90=20=EC=9D=B8=ED=84=B0=EC=85=89?= =?UTF-8?q?=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interceptor/ChatChannelInterceptor.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java diff --git a/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java b/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java new file mode 100644 index 00000000..edc3b309 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java @@ -0,0 +1,30 @@ +package com.aliens.backend.global.interceptor; + +import com.aliens.backend.chat.domain.ChatRoom; +import com.aliens.backend.chat.service.ChatAuthValidator; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.simp.stomp.StompCommand; +import org.springframework.messaging.simp.stomp.StompHeaderAccessor; +import org.springframework.messaging.support.ChannelInterceptor; +import org.springframework.messaging.support.MessageHeaderAccessor; +import org.springframework.stereotype.Component; + +@Component +public class ChatChannelInterceptor implements ChannelInterceptor { + + ChatAuthValidator chatAuthValidator; + + public ChatChannelInterceptor(ChatAuthValidator chatAuthValidator) { + this.chatAuthValidator = chatAuthValidator; + } + + @Override + public Message preSend(Message message, MessageChannel channel) { + StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); + ChatRoom chatRoom = (ChatRoom) accessor.getSessionAttributes().get("chatRooms"); + if (accessor != null && StompCommand.SUBSCRIBE.equals(accessor.getCommand())) { + } + return message; + } +} \ No newline at end of file From df47060cb015546b44aa38a464cf64f68dd20b70 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 05:01:30 +0900 Subject: [PATCH 145/215] =?UTF-8?q?feat(WebSocketConfig):=20=EC=9B=B9?= =?UTF-8?q?=EC=86=8C=EC=BC=93=20=EC=84=A4=EC=A0=95=EC=97=90=20ChatChannelI?= =?UTF-8?q?nterceptor,=20ChatHandshakeInterceptor=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/config/WebSocketConfig.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java b/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java index 58a1fecc..6ef5d3b0 100644 --- a/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java +++ b/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java @@ -1,11 +1,14 @@ package com.aliens.backend.global.config; +import com.aliens.backend.global.interceptor.ChatChannelInterceptor; +import com.aliens.backend.global.interceptor.ChatHandshakeInterceptor; import com.aliens.backend.global.property.WebSocketProperties; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.converter.DefaultContentTypeResolver; import org.springframework.messaging.converter.MappingJackson2MessageConverter; import org.springframework.messaging.converter.MessageConverter; +import org.springframework.messaging.simp.config.ChannelRegistration; import org.springframework.messaging.simp.config.MessageBrokerRegistry; import org.springframework.util.MimeTypeUtils; import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; @@ -19,9 +22,13 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { private final WebSocketProperties properties; + private final ChatChannelInterceptor chatChannelInterceptor; + private final ChatHandshakeInterceptor chatHandshakeInterceptor; - public WebSocketConfig(WebSocketProperties properties) { + public WebSocketConfig(WebSocketProperties properties, ChatChannelInterceptor chatChannelInterceptor, ChatHandshakeInterceptor chatHandshakeInterceptor) { this.properties = properties; + this.chatChannelInterceptor = chatChannelInterceptor; + this.chatHandshakeInterceptor = chatHandshakeInterceptor; } @Override @@ -32,7 +39,14 @@ public void configureMessageBroker(MessageBrokerRegistry registry) { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint(properties.getEndpoint()) - .setAllowedOrigins("*"); + .setAllowedOrigins("*") + .withSockJS() + .setInterceptors(chatHandshakeInterceptor); + } + + @Override + public void configureClientInboundChannel(ChannelRegistration registration) { + registration.interceptors(chatChannelInterceptor); } @Override From 8403e42d22fae3a8188c82e09f0bcaad7bcff900 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 05:03:25 +0900 Subject: [PATCH 146/215] =?UTF-8?q?test(ChatClient):=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=9A=A9=20=ED=81=B4=EB=9D=BC=EC=9D=B4=EC=96=B8?= =?UTF-8?q?=ED=8A=B8=EB=A5=BC=20SockJsClient=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/chatting/util/ChatClient.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/aliens/backend/chatting/util/ChatClient.java b/src/test/java/com/aliens/backend/chatting/util/ChatClient.java index d2c95c30..55ac4293 100644 --- a/src/test/java/com/aliens/backend/chatting/util/ChatClient.java +++ b/src/test/java/com/aliens/backend/chatting/util/ChatClient.java @@ -5,6 +5,12 @@ import org.springframework.web.socket.client.WebSocketClient; import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.messaging.WebSocketStompClient; +import org.springframework.web.socket.sockjs.client.SockJsClient; +import org.springframework.web.socket.sockjs.client.Transport; +import org.springframework.web.socket.sockjs.client.WebSocketTransport; + +import java.util.ArrayList; +import java.util.List; public class ChatClient { private final String endPoint; @@ -26,8 +32,14 @@ public StompSession connect() throws Exception { } private WebSocketStompClient createStompClient() { - WebSocketClient webSocketClient = new StandardWebSocketClient(); + WebSocketClient webSocketClient = new SockJsClient(createTransport()); WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient); return stompClient; } + + private List createTransport() { + List transports = new ArrayList<>(); + transports.add(new WebSocketTransport(new StandardWebSocketClient())); + return transports; + } } From 8025c900d29f4433b6a51effbad033d246a20b09 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 05:04:52 +0900 Subject: [PATCH 147/215] =?UTF-8?q?test(WebSocketTest):=20=EC=9B=B9?= =?UTF-8?q?=EC=86=8C=EC=BC=93=20=EC=97=B0=EA=B2=B0=EC=8B=9C=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/chatting/WebSocketTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java index d26adf23..e7a4cc84 100644 --- a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java +++ b/src/test/java/com/aliens/backend/chatting/WebSocketTest.java @@ -1,5 +1,8 @@ package com.aliens.backend.chatting; +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.domain.MemberRole; +import com.aliens.backend.auth.service.TokenProvider; import com.aliens.backend.chat.controller.ChatController; import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; import com.aliens.backend.chat.controller.dto.request.ReadRequest; @@ -14,8 +17,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.messaging.simp.stomp.StompSession; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.*; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) public class WebSocketTest { @@ -24,11 +26,15 @@ public class WebSocketTest { private WebSocketProperties properties; @MockBean private ChatController chatController; + @MockBean + private TokenProvider tokenProvider; private ChatClient chatClient; private ObjectMapper objectMapper = new ObjectMapper(); @BeforeEach public void setup() { + LoginMember loginMember = new LoginMember(1L, MemberRole.MEMBER); + when(tokenProvider.getLoginMemberFromToken(any())).thenReturn(loginMember); chatClient = new ChatClient(properties); } From 64d35faf2a179b4f52cf91132a209ed1ded11878 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 05:05:52 +0900 Subject: [PATCH 148/215] =?UTF-8?q?feat(ChatService):=20=EC=B1=84=ED=8C=85?= =?UTF-8?q?=EB=B0=A9=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/aliens/backend/chat/service/ChatService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/aliens/backend/chat/service/ChatService.java b/src/main/java/com/aliens/backend/chat/service/ChatService.java index d1da28ad..b25632dd 100644 --- a/src/main/java/com/aliens/backend/chat/service/ChatService.java +++ b/src/main/java/com/aliens/backend/chat/service/ChatService.java @@ -54,6 +54,10 @@ public List getMessages(Long chatRoomId, String lastMessageId) { return messages; } + public List getChatRooms(Long memberId) { + return chatRepository.findByMemberId(memberId); + } + private void saveMessage(Message message) { messageRepository.save(message); } From ed11b91a769e5f3515a6e4b10b6dda359583cb85 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 05:27:02 +0900 Subject: [PATCH 149/215] =?UTF-8?q?feat(ChatChannelInterceptor):=20?= =?UTF-8?q?=EC=B1=84=ED=8C=85=EB=B0=A9=20=EA=B5=AC=EB=8F=85=EC=8B=9C=20?= =?UTF-8?q?=EC=9D=B8=EA=B0=80=20=EA=B2=80=EC=A6=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/interceptor/ChatChannelInterceptor.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java b/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java index edc3b309..30768884 100644 --- a/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java +++ b/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java @@ -10,6 +10,8 @@ import org.springframework.messaging.support.MessageHeaderAccessor; import org.springframework.stereotype.Component; +import java.util.List; + @Component public class ChatChannelInterceptor implements ChannelInterceptor { @@ -22,8 +24,9 @@ public ChatChannelInterceptor(ChatAuthValidator chatAuthValidator) { @Override public Message preSend(Message message, MessageChannel channel) { StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); - ChatRoom chatRoom = (ChatRoom) accessor.getSessionAttributes().get("chatRooms"); + List chatRooms = (List) accessor.getSessionAttributes().get("chatRooms"); if (accessor != null && StompCommand.SUBSCRIBE.equals(accessor.getCommand())) { + chatAuthValidator.validateRoom(accessor.getDestination(), chatRooms); } return message; } From 3640499fa1fc0db5687566e982851c6853ad4141 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 05:27:43 +0900 Subject: [PATCH 150/215] =?UTF-8?q?feat(ChatAuthValidator):=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EA=B6=8C=ED=95=9C=20=EA=B2=80=EC=A6=9D=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/service/ChatAuthValidator.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/service/ChatAuthValidator.java diff --git a/src/main/java/com/aliens/backend/chat/service/ChatAuthValidator.java b/src/main/java/com/aliens/backend/chat/service/ChatAuthValidator.java new file mode 100644 index 00000000..3aa6bd0c --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/service/ChatAuthValidator.java @@ -0,0 +1,26 @@ +package com.aliens.backend.chat.service; + +import com.aliens.backend.chat.domain.ChatRoom; +import com.aliens.backend.global.error.ChatError; +import com.aliens.backend.global.exception.RestApiException; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class ChatAuthValidator { + public void validateRoom(String topic, List validChatRooms) { + Long roomId = getRoomIdFromTopic(topic); + if(!isValidRoom(validChatRooms, roomId)) { + throw new RestApiException(ChatError.INVALID_ROOM_ACCESS); + } + } + + private boolean isValidRoom (List validChatRooms, Long roomId) { + return validChatRooms.stream().anyMatch(chatRoom -> chatRoom.getId().equals(roomId)); + } + + private long getRoomIdFromTopic(String topic) { + return Long.parseLong(topic.split("/")[1]); + } +} From 6bd0da8bd9c0476d1f6e8e15adce8d468b3bf662 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 05:28:24 +0900 Subject: [PATCH 151/215] =?UTF-8?q?feat(ChatError):=20=EC=B1=84=ED=8C=85?= =?UTF-8?q?=EB=B0=A9=20=EC=A0=91=EA=B7=BC=20=EA=B6=8C=ED=95=9C=20=EC=97=86?= =?UTF-8?q?=EC=9D=8C=20=EC=97=90=EB=9F=AC=20=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/aliens/backend/global/error/ChatError.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/global/error/ChatError.java b/src/main/java/com/aliens/backend/global/error/ChatError.java index bd5edb3d..e6c6a9c3 100644 --- a/src/main/java/com/aliens/backend/global/error/ChatError.java +++ b/src/main/java/com/aliens/backend/global/error/ChatError.java @@ -4,7 +4,8 @@ public enum ChatError implements ErrorCode { - INVALID_MESSAGE_TYPE(HttpStatus.BAD_REQUEST, "CH1", "Invalid message type"), + INVALID_MESSAGE_TYPE(HttpStatus.BAD_REQUEST, "CH1", "메시지 타입이 잘못되었습니다."), + INVALID_ROOM_ACCESS(HttpStatus.FORBIDDEN, "CH2", "채팅방 접근 권한이 없습니다.") ; private final HttpStatus httpStatusCode; From 232143ac0bafc3f46ae5e27277f78a7f35e84da0 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 06:25:41 +0900 Subject: [PATCH 152/215] =?UTF-8?q?refactor(repository):=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80,=20=ED=85=8C=EC=9D=B4=EB=B8=94=EB=AA=85=20?= =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/chat/domain/ChatRoom.java | 2 +- .../ChatRoomRepository.java} | 4 ++-- .../CustomMessageRepository.java | 2 +- .../CustomMessageRepositoryImpl.java | 3 +-- .../MessageRepository.java | 2 +- .../aliens/backend/chat/service/ChatService.java | 14 +++++++------- .../backend/global/success/ChatSuccessCode.java | 1 + .../backend/chatting/service/ChatServiceTest.java | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) rename src/main/java/com/aliens/backend/chat/domain/{ChatRepository/ChatRepository.java => repository/ChatRoomRepository.java} (66%) rename src/main/java/com/aliens/backend/chat/domain/{ChatRepository => repository}/CustomMessageRepository.java (88%) rename src/main/java/com/aliens/backend/chat/domain/{ChatRepository => repository}/CustomMessageRepositoryImpl.java (97%) rename src/main/java/com/aliens/backend/chat/domain/{ChatRepository => repository}/MessageRepository.java (83%) diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java b/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java index 52fa49fd..43d15f81 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java @@ -3,7 +3,7 @@ import jakarta.persistence.*; @Entity -@Table(name = "CHAT_ROOM ") +@Table(name = "CHAT_ROOM") public class ChatRoom { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/ChatRepository.java b/src/main/java/com/aliens/backend/chat/domain/repository/ChatRoomRepository.java similarity index 66% rename from src/main/java/com/aliens/backend/chat/domain/ChatRepository/ChatRepository.java rename to src/main/java/com/aliens/backend/chat/domain/repository/ChatRoomRepository.java index 091475ff..d8417ec7 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/ChatRepository.java +++ b/src/main/java/com/aliens/backend/chat/domain/repository/ChatRoomRepository.java @@ -1,4 +1,4 @@ -package com.aliens.backend.chat.domain.ChatRepository; +package com.aliens.backend.chat.domain.repository; import com.aliens.backend.chat.domain.ChatRoom; import org.springframework.data.jpa.repository.JpaRepository; @@ -7,6 +7,6 @@ import java.util.List; @Repository -public interface ChatRepository extends JpaRepository { +public interface ChatRoomRepository extends JpaRepository { List findByMemberId(Long memberId); } \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java b/src/main/java/com/aliens/backend/chat/domain/repository/CustomMessageRepository.java similarity index 88% rename from src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java rename to src/main/java/com/aliens/backend/chat/domain/repository/CustomMessageRepository.java index d66a8691..8d9a02b1 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepository.java +++ b/src/main/java/com/aliens/backend/chat/domain/repository/CustomMessageRepository.java @@ -1,4 +1,4 @@ -package com.aliens.backend.chat.domain.ChatRepository; +package com.aliens.backend.chat.domain.repository; import com.aliens.backend.chat.domain.Message; import com.aliens.backend.chat.service.model.ChatMessageSummary; diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java b/src/main/java/com/aliens/backend/chat/domain/repository/CustomMessageRepositoryImpl.java similarity index 97% rename from src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java rename to src/main/java/com/aliens/backend/chat/domain/repository/CustomMessageRepositoryImpl.java index bde58613..50ac7fba 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/CustomMessageRepositoryImpl.java +++ b/src/main/java/com/aliens/backend/chat/domain/repository/CustomMessageRepositoryImpl.java @@ -1,4 +1,4 @@ -package com.aliens.backend.chat.domain.ChatRepository; +package com.aliens.backend.chat.domain.repository; import com.aliens.backend.chat.domain.Message; import com.aliens.backend.chat.service.model.ChatMessageSummary; @@ -17,7 +17,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Optional; @Repository public class CustomMessageRepositoryImpl implements CustomMessageRepository { diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/MessageRepository.java b/src/main/java/com/aliens/backend/chat/domain/repository/MessageRepository.java similarity index 83% rename from src/main/java/com/aliens/backend/chat/domain/ChatRepository/MessageRepository.java rename to src/main/java/com/aliens/backend/chat/domain/repository/MessageRepository.java index 823469c5..db7a5587 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRepository/MessageRepository.java +++ b/src/main/java/com/aliens/backend/chat/domain/repository/MessageRepository.java @@ -1,4 +1,4 @@ -package com.aliens.backend.chat.domain.ChatRepository; +package com.aliens.backend.chat.domain.repository; import com.aliens.backend.chat.domain.Message; import org.springframework.data.mongodb.repository.MongoRepository; diff --git a/src/main/java/com/aliens/backend/chat/service/ChatService.java b/src/main/java/com/aliens/backend/chat/service/ChatService.java index b25632dd..fe14d294 100644 --- a/src/main/java/com/aliens/backend/chat/service/ChatService.java +++ b/src/main/java/com/aliens/backend/chat/service/ChatService.java @@ -4,8 +4,8 @@ import com.aliens.backend.chat.controller.dto.request.ReadRequest; import com.aliens.backend.chat.controller.dto.response.ChatSummaryResponse; import com.aliens.backend.chat.controller.dto.response.ReadResponse; -import com.aliens.backend.chat.domain.ChatRepository.ChatRepository; -import com.aliens.backend.chat.domain.ChatRepository.MessageRepository; +import com.aliens.backend.chat.domain.repository.ChatRoomRepository; +import com.aliens.backend.chat.domain.repository.MessageRepository; import com.aliens.backend.chat.domain.ChatRoom; import com.aliens.backend.chat.domain.Message; import com.aliens.backend.chat.service.model.ChatMessageSummary; @@ -19,11 +19,11 @@ public class ChatService { private final MessageRepository messageRepository; private final SimpMessagingTemplate messagingTemplate; - private final ChatRepository chatRepository; + private final ChatRoomRepository chatRoomRepository; - public ChatService(MessageRepository messageRepository, ChatRepository chatRepository, SimpMessagingTemplate messagingTemplate) { + public ChatService(MessageRepository messageRepository, ChatRoomRepository chatRoomRepository, SimpMessagingTemplate messagingTemplate) { this.messageRepository = messageRepository; - this.chatRepository = chatRepository; + this.chatRoomRepository = chatRoomRepository; this.messagingTemplate = messagingTemplate; } @@ -42,7 +42,7 @@ public String readMessages(ReadRequest readRequest) { } public ChatSummaryResponse getChatSummaries(Long memberId) { - List chatRooms = chatRepository.findByMemberId(memberId); + List chatRooms = chatRoomRepository.findByMemberId(memberId); List chatRoomIds = chatRooms.stream().map(ChatRoom::getId).toList(); List chatMessageSummaries = messageRepository.aggregateMessageSummaries(chatRoomIds, memberId); ChatSummaryResponse chatSummaryResponse = new ChatSummaryResponse(chatRooms, chatMessageSummaries); @@ -55,7 +55,7 @@ public List getMessages(Long chatRoomId, String lastMessageId) { } public List getChatRooms(Long memberId) { - return chatRepository.findByMemberId(memberId); + return chatRoomRepository.findByMemberId(memberId); } private void saveMessage(Message message) { diff --git a/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java b/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java index 79c90653..3bab87ea 100644 --- a/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java +++ b/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java @@ -5,6 +5,7 @@ public enum ChatSuccessCode implements SuccessCode { SEND_MESSAGE_SUCCESS(HttpStatus.CREATED, "CH001", "메시지 전송 성공"), READ_MESSAGES_SUCCESS(HttpStatus.OK, "CH002", "메시지 읽음 처리 성공"), + REPORT_SUCCESS(HttpStatus.CREATED, "CH003", "신고 성공") ; private final HttpStatus httpStatus; diff --git a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java index c1e9904c..a734aaeb 100644 --- a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java +++ b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java @@ -3,7 +3,7 @@ import com.aliens.backend.chat.controller.dto.request.ReadRequest; import com.aliens.backend.chat.controller.dto.response.ChatSummaryResponse; import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; -import com.aliens.backend.chat.domain.ChatRepository.MessageRepository; +import com.aliens.backend.chat.domain.repository.MessageRepository; import com.aliens.backend.chat.domain.Message; import com.aliens.backend.chat.service.ChatService; import com.aliens.backend.global.success.ChatSuccessCode; From 81c8c416b06b5ff3a9f087825aed1d5a31e04a92 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 06:32:59 +0900 Subject: [PATCH 153/215] =?UTF-8?q?test(ChatDocTest):=20=EC=B1=84=ED=8C=85?= =?UTF-8?q?=20=EC=8B=A0=EA=B3=A0=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/docs/ChatDocTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/com/aliens/backend/docs/ChatDocTest.java b/src/test/java/com/aliens/backend/docs/ChatDocTest.java index 1ed63e56..bfd17d07 100644 --- a/src/test/java/com/aliens/backend/docs/ChatDocTest.java +++ b/src/test/java/com/aliens/backend/docs/ChatDocTest.java @@ -1,9 +1,12 @@ package com.aliens.backend.docs; import com.aliens.backend.auth.service.TokenProvider; +import com.aliens.backend.chat.controller.dto.request.ChatReportRequest; import com.aliens.backend.chat.controller.dto.response.ChatSummaryResponse; import com.aliens.backend.chat.domain.Message; +import com.aliens.backend.chat.service.ChatReportService; import com.aliens.backend.chat.service.ChatService; +import com.aliens.backend.global.success.ChatSuccessCode; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -19,9 +22,11 @@ import java.util.ArrayList; import java.util.List; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -35,6 +40,8 @@ class ChatDocTest { @MockBean private ChatService chatService; @MockBean + private ChatReportService chatReportService; + @MockBean private TokenProvider tokenProvider; ObjectMapper objectMapper; @@ -82,4 +89,27 @@ void getChatSummary() throws Exception { ) )); } + + @Test + @DisplayName("채팅 상대 신고") + void reportPartner() throws Exception { + Long memberId = 1L; + Long chatRoomId = 1L; + String reportCategory = "ETC"; + String reportContent = "신고 사유"; + ChatReportRequest request = new ChatReportRequest(memberId, chatRoomId, reportCategory, reportContent); + String response = ChatSuccessCode.REPORT_SUCCESS.getMessage(); + when(chatReportService.reportPartner(any(), any())).thenReturn(response); + mockMvc.perform(post("/chat/report") + .header("Authorization", accessToken) + .content(objectMapper.writeValueAsString(request)) + .contentType("application/json") + ) + .andExpect(status().isOk()) + .andDo(document("chat-report", + responseFields( + fieldWithPath("response").description("채팅 상대 신고 결과") + ) + )); + } } \ No newline at end of file From ae98257d28eb54538f4e60dcfcdea68bdf6809fc Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 06:34:19 +0900 Subject: [PATCH 154/215] =?UTF-8?q?feat(ChatReportController):=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=8B=A0=EA=B3=A0=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/controller/ChatReportController.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/controller/ChatReportController.java diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatReportController.java b/src/main/java/com/aliens/backend/chat/controller/ChatReportController.java new file mode 100644 index 00000000..26700fbb --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/controller/ChatReportController.java @@ -0,0 +1,30 @@ +package com.aliens.backend.chat.controller; + +import com.aliens.backend.chat.controller.dto.request.ChatReportRequest; +import com.aliens.backend.chat.service.ChatReportService; +import com.aliens.backend.global.config.resolver.Login; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.Collections; +import java.util.Map; + + +@Controller +public class ChatReportController { + + private final ChatReportService chatReportService; + + public ChatReportController(ChatReportService chatReportService) { + this.chatReportService = chatReportService; + } + + @PostMapping("/chat/report") + public ResponseEntity> reportPartner(@Login Long memberId, @RequestBody ChatReportRequest chatReportRequest) { + String result = chatReportService.reportPartner(memberId, chatReportRequest); + Map response = Collections.singletonMap("response", result); + return ResponseEntity.ok(response); + } +} \ No newline at end of file From d667243a692316caa767b7b0d2f546ed2d426ea4 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 06:36:42 +0900 Subject: [PATCH 155/215] =?UTF-8?q?feat(ChatReportService):=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=8B=A0=EA=B3=A0=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/service/ChatReportService.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/service/ChatReportService.java diff --git a/src/main/java/com/aliens/backend/chat/service/ChatReportService.java b/src/main/java/com/aliens/backend/chat/service/ChatReportService.java new file mode 100644 index 00000000..97debaf2 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/service/ChatReportService.java @@ -0,0 +1,23 @@ +package com.aliens.backend.chat.service; + +import com.aliens.backend.chat.controller.dto.request.ChatReportRequest; +import com.aliens.backend.chat.domain.ChatReport; +import com.aliens.backend.chat.domain.repository.ChatReportRepository; +import com.aliens.backend.global.success.ChatSuccessCode; +import org.springframework.stereotype.Service; + +@Service +public class ChatReportService { + + private final ChatReportRepository chatReportRepository; + + public ChatReportService(ChatReportRepository chatReportRepository) { + this.chatReportRepository = chatReportRepository; + } + + public String reportPartner(Long memberId, ChatReportRequest chatReportRequest) { + ChatReport chatReport = ChatReport.of(memberId, chatReportRequest); + chatReportRepository.save(chatReport); + return ChatSuccessCode.REPORT_SUCCESS.getMessage(); + } +} From b9371bc1198bf8a8b9cd67e196b8209635709d5a Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 06:37:08 +0900 Subject: [PATCH 156/215] =?UTF-8?q?feat(ChatReportRequest):=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=8B=A0=EA=B3=A0=20=EC=9A=94=EC=B2=AD=20=EB=A0=88?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/controller/dto/request/ChatReportRequest.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/controller/dto/request/ChatReportRequest.java diff --git a/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatReportRequest.java b/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatReportRequest.java new file mode 100644 index 00000000..90c80b8f --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatReportRequest.java @@ -0,0 +1,4 @@ +package com.aliens.backend.chat.controller.dto.request; + +public record ChatReportRequest(Long partnerId, Long chatRoomId, String category, String content) { +} \ No newline at end of file From 13909b926821ef78a3b29b1e9642f7a8374529ab Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 06:38:01 +0900 Subject: [PATCH 157/215] =?UTF-8?q?feat(ChatReport,=20ChatReportCategory,?= =?UTF-8?q?=20ChatReportRepository):=20=EC=B1=84=ED=8C=85=20=EC=8B=A0?= =?UTF-8?q?=EA=B3=A0=20=EC=97=94=ED=8B=B0=ED=8B=B0,=20=EB=A0=88=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC,=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=9D=B4=EB=84=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/chat/domain/ChatReport.java | 36 +++++++++++++++++++ .../chat/domain/ChatReportCategory.java | 16 +++++++++ .../repository/ChatReportRepository.java | 7 ++++ 3 files changed, 59 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/domain/ChatReport.java create mode 100644 src/main/java/com/aliens/backend/chat/domain/ChatReportCategory.java create mode 100644 src/main/java/com/aliens/backend/chat/domain/repository/ChatReportRepository.java diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatReport.java b/src/main/java/com/aliens/backend/chat/domain/ChatReport.java new file mode 100644 index 00000000..491ae6c3 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/ChatReport.java @@ -0,0 +1,36 @@ +package com.aliens.backend.chat.domain; + +import com.aliens.backend.chat.controller.dto.request.ChatReportRequest; +import com.aliens.backend.global.error.ChatError; +import com.aliens.backend.global.exception.RestApiException; +import jakarta.persistence.*; + +@Entity +@Table(name = "CHAT_REPORT") +public class ChatReport { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column + private Long id; + @Column(name = "reported_member_id") + private Long reportedMemberId; + @Column(name = "reporting_member_id") + private Long reportingMemberId; + @Column + private ChatReportCategory category; + @Column + private String content; + + protected ChatReport() { + } + + public static ChatReport of(Long reportingMemberId, ChatReportRequest chatReportRequest) { + ChatReport chatReport = new ChatReport(); + chatReport.reportedMemberId = chatReportRequest.partnerId(); + chatReport.reportingMemberId = reportingMemberId; + chatReport.category = ChatReportCategory.fromString(chatReportRequest.category()) + .orElseThrow(() -> new RestApiException(ChatError.INVALID_REPORT_CATEGORY)); + chatReport.content = chatReportRequest.content(); + return chatReport; + } +} diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatReportCategory.java b/src/main/java/com/aliens/backend/chat/domain/ChatReportCategory.java new file mode 100644 index 00000000..3af9e734 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/ChatReportCategory.java @@ -0,0 +1,16 @@ +package com.aliens.backend.chat.domain; + +import java.util.Optional; + +public enum ChatReportCategory { + SEXUAL_HARASSMENT, VIOLENCE, SPAM, SCAM, ETC; + + public static Optional fromString(String category) { + for (ChatReportCategory reportCategory : ChatReportCategory.values()) { + if (reportCategory.name().equalsIgnoreCase(category)) { + return Optional.of(reportCategory); + } + } + return Optional.empty(); + } +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/domain/repository/ChatReportRepository.java b/src/main/java/com/aliens/backend/chat/domain/repository/ChatReportRepository.java new file mode 100644 index 00000000..2388635b --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/repository/ChatReportRepository.java @@ -0,0 +1,7 @@ +package com.aliens.backend.chat.domain.repository; + +import com.aliens.backend.chat.domain.ChatReport; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ChatReportRepository extends JpaRepository { +} From 8b9a467baff1b193cbd1e80c00680b519652d355 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 06:38:57 +0900 Subject: [PATCH 158/215] =?UTF-8?q?feat(ChatError):=20INVALID=5FREPORT=5FC?= =?UTF-8?q?ATEGORY=20=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/aliens/backend/global/error/ChatError.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/global/error/ChatError.java b/src/main/java/com/aliens/backend/global/error/ChatError.java index e6c6a9c3..f75d6e4a 100644 --- a/src/main/java/com/aliens/backend/global/error/ChatError.java +++ b/src/main/java/com/aliens/backend/global/error/ChatError.java @@ -5,7 +5,8 @@ public enum ChatError implements ErrorCode { INVALID_MESSAGE_TYPE(HttpStatus.BAD_REQUEST, "CH1", "메시지 타입이 잘못되었습니다."), - INVALID_ROOM_ACCESS(HttpStatus.FORBIDDEN, "CH2", "채팅방 접근 권한이 없습니다.") + INVALID_ROOM_ACCESS(HttpStatus.FORBIDDEN, "CH2", "채팅방 접근 권한이 없습니다."), + INVALID_REPORT_CATEGORY(HttpStatus.BAD_REQUEST, "CH3", "신고 카테고리가 잘못되었습니다.") ; private final HttpStatus httpStatusCode; From b9c04fc9e317d5de1c35b8f509c04a0baccfabb5 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 06:58:27 +0900 Subject: [PATCH 159/215] =?UTF-8?q?feat(ChatDocTest):=20=EC=B1=84=ED=8C=85?= =?UTF-8?q?=20=EC=B0=A8=EB=8B=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/docs/ChatDocTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/test/java/com/aliens/backend/docs/ChatDocTest.java b/src/test/java/com/aliens/backend/docs/ChatDocTest.java index bfd17d07..07225e4e 100644 --- a/src/test/java/com/aliens/backend/docs/ChatDocTest.java +++ b/src/test/java/com/aliens/backend/docs/ChatDocTest.java @@ -1,9 +1,11 @@ package com.aliens.backend.docs; import com.aliens.backend.auth.service.TokenProvider; +import com.aliens.backend.chat.controller.dto.request.ChatBlockRequest; import com.aliens.backend.chat.controller.dto.request.ChatReportRequest; import com.aliens.backend.chat.controller.dto.response.ChatSummaryResponse; import com.aliens.backend.chat.domain.Message; +import com.aliens.backend.chat.service.ChatBlockService; import com.aliens.backend.chat.service.ChatReportService; import com.aliens.backend.chat.service.ChatService; import com.aliens.backend.global.success.ChatSuccessCode; @@ -42,6 +44,8 @@ class ChatDocTest { @MockBean private ChatReportService chatReportService; @MockBean + private ChatBlockService chatBlockService; + @MockBean private TokenProvider tokenProvider; ObjectMapper objectMapper; @@ -112,4 +116,25 @@ void reportPartner() throws Exception { ) )); } + + @Test + @DisplayName("채팅 상대 차단") + void blockPartner() throws Exception { + Long chatRoomId = 1L; + Long memberId = 1L; + ChatBlockRequest request = new ChatBlockRequest(memberId, chatRoomId); + String response = ChatSuccessCode.BLOCK_SUCCESS.getMessage(); + when(chatBlockService.blockPartner(any(), any())).thenReturn(response); + mockMvc.perform(post("/chat/block") + .header("Authorization", accessToken) + .content(objectMapper.writeValueAsString(request)) + .contentType("application/json") + ) + .andExpect(status().isOk()) + .andDo(document("chat-block", + responseFields( + fieldWithPath("response").description("채팅 상대 차단 결과") + ) + )); + } } \ No newline at end of file From ecb842ad12e060cb76c57461c548387223bce8ea Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 07:00:00 +0900 Subject: [PATCH 160/215] =?UTF-8?q?feat(ChatBlockController,=20ChatBlockRe?= =?UTF-8?q?quest):=20=EC=B1=84=ED=8C=85=20=EC=B0=A8=EB=8B=A8=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EC=B6=94=EA=B0=80,=20=EC=B0=A8?= =?UTF-8?q?=EB=8B=A8=20=EC=9A=94=EC=B2=AD=20=EB=A0=88=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/controller/ChatBlockController.java | 30 +++++++++++++++++++ .../dto/request/ChatBlockRequest.java | 4 +++ 2 files changed, 34 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/controller/ChatBlockController.java create mode 100644 src/main/java/com/aliens/backend/chat/controller/dto/request/ChatBlockRequest.java diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatBlockController.java b/src/main/java/com/aliens/backend/chat/controller/ChatBlockController.java new file mode 100644 index 00000000..e60f09b6 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/controller/ChatBlockController.java @@ -0,0 +1,30 @@ +package com.aliens.backend.chat.controller; + +import com.aliens.backend.chat.controller.dto.request.ChatBlockRequest; +import com.aliens.backend.chat.service.ChatBlockService; +import com.aliens.backend.global.config.resolver.Login; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.Collections; +import java.util.Map; + + +@Controller +public class ChatBlockController { + + private final ChatBlockService chatBlockService; + + public ChatBlockController(ChatBlockService chatBlockService) { + this.chatBlockService = chatBlockService; + } + + @PostMapping("/chat/block") + public ResponseEntity> blockPartner(@Login Long memberId, @RequestBody ChatBlockRequest chatBlockRequest) { + String result = chatBlockService.blockPartner(memberId, chatBlockRequest); + Map response = Collections.singletonMap("response", result); + return ResponseEntity.ok(response); + } +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatBlockRequest.java b/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatBlockRequest.java new file mode 100644 index 00000000..ac92562a --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatBlockRequest.java @@ -0,0 +1,4 @@ +package com.aliens.backend.chat.controller.dto.request; + +public record ChatBlockRequest(Long partnerId, Long chatRoomId) { +} From 1897b21386c04811ff1afa6de8f8487ffb0a0978 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 07:00:34 +0900 Subject: [PATCH 161/215] =?UTF-8?q?feat(ChatBlockService):=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=B0=A8=EB=8B=A8=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/service/ChatBlockService.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/service/ChatBlockService.java diff --git a/src/main/java/com/aliens/backend/chat/service/ChatBlockService.java b/src/main/java/com/aliens/backend/chat/service/ChatBlockService.java new file mode 100644 index 00000000..9cc4348d --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/service/ChatBlockService.java @@ -0,0 +1,36 @@ +package com.aliens.backend.chat.service; + +import com.aliens.backend.chat.controller.dto.request.ChatBlockRequest; +import com.aliens.backend.chat.domain.ChatBlock; +import com.aliens.backend.chat.domain.ChatRoom; +import com.aliens.backend.chat.domain.repository.ChatBlockRepository; +import com.aliens.backend.chat.domain.repository.ChatRoomRepository; +import com.aliens.backend.global.error.ChatError; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.success.ChatSuccessCode; +import org.springframework.stereotype.Service; + +@Service +public class ChatBlockService { + private final ChatBlockRepository chatBlockRepository; + private final ChatRoomRepository chatRoomRepository; + + public ChatBlockService(ChatBlockRepository chatBlockRepository, ChatRoomRepository chatRoomRepository) { + this.chatBlockRepository = chatBlockRepository; + this.chatRoomRepository = chatRoomRepository; + } + + public String blockPartner(Long memberId, ChatBlockRequest chatBlockRequest) { + ChatBlock chatBlock = ChatBlock.of(memberId, chatBlockRequest); + chatBlockRepository.save(chatBlock); + blockChatRoom(chatBlockRequest.chatRoomId()); + return ChatSuccessCode.BLOCK_SUCCESS.getMessage(); + } + + private void blockChatRoom(Long chatRoomId) { + ChatRoom chatRoom = chatRoomRepository.findById(chatRoomId) + .orElseThrow(() -> new RestApiException(ChatError.CHAT_ROOM_NOT_FOUND)); + chatRoom.block(); + chatRoomRepository.save(chatRoom); + } +} \ No newline at end of file From 2290eb36cee4b83902e02619a7a90d92df26befa Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 07:02:50 +0900 Subject: [PATCH 162/215] =?UTF-8?q?feat(ChatBlock,=20ChatBlockRepository):?= =?UTF-8?q?=20=EC=B1=84=ED=8C=85=20=EC=B0=A8=EB=8B=A8=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0,=20=EB=A0=88=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/chat/domain/ChatBlock.java | 27 +++++++++++++++++++ .../repository/ChatBlockRepository.java | 10 +++++++ 2 files changed, 37 insertions(+) create mode 100644 src/main/java/com/aliens/backend/chat/domain/ChatBlock.java create mode 100644 src/main/java/com/aliens/backend/chat/domain/repository/ChatBlockRepository.java diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatBlock.java b/src/main/java/com/aliens/backend/chat/domain/ChatBlock.java new file mode 100644 index 00000000..cfb8cce8 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/ChatBlock.java @@ -0,0 +1,27 @@ +package com.aliens.backend.chat.domain; + +import com.aliens.backend.chat.controller.dto.request.ChatBlockRequest; +import jakarta.persistence.*; + +@Entity +@Table(name = "CHAT_BLOCK") +public class ChatBlock { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column + private Long id; + @Column(name = "blocked_member_id") + private Long blockedMemberId; + @Column(name = "blocking_member_id") + private Long blockingMemberId; + + protected ChatBlock() { + } + + public static ChatBlock of(Long blockingMemberId, ChatBlockRequest chatBlockRequest) { + ChatBlock chatBlock = new ChatBlock(); + chatBlock.blockedMemberId = chatBlockRequest.partnerId(); + chatBlock.blockingMemberId = blockingMemberId; + return chatBlock; + } +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/domain/repository/ChatBlockRepository.java b/src/main/java/com/aliens/backend/chat/domain/repository/ChatBlockRepository.java new file mode 100644 index 00000000..b4d063f6 --- /dev/null +++ b/src/main/java/com/aliens/backend/chat/domain/repository/ChatBlockRepository.java @@ -0,0 +1,10 @@ +package com.aliens.backend.chat.domain.repository; + +import com.aliens.backend.chat.domain.ChatBlock; +import com.aliens.backend.chat.domain.ChatReport; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ChatBlockRepository extends JpaRepository { +} From 2f51ba5871502c2d39ff30ced4c7df52a71b491b Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 07:03:52 +0900 Subject: [PATCH 163/215] =?UTF-8?q?feat(ChatRoom):=20=EC=B1=84=ED=8C=85?= =?UTF-8?q?=EB=B0=A9=EC=9D=84=20=EC=B0=A8=EB=8B=A8=ED=95=98=EB=8A=94=20blo?= =?UTF-8?q?ck=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/aliens/backend/chat/domain/ChatRoom.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java b/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java index 43d15f81..6ed710cd 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java @@ -30,4 +30,8 @@ public Long getPartnerId() { public ChatRoomStatus getStatus() { return status; } + + public void block() { + this.status = ChatRoomStatus.BLOCKED; + } } \ No newline at end of file From 9853e39c361bb4a490ce2936de8f87e5b3f8f804 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 07:04:11 +0900 Subject: [PATCH 164/215] =?UTF-8?q?feat(ChatError,=20ChatSuccessCode):=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EB=B0=8F=20=EC=84=B1=EA=B3=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/aliens/backend/global/error/ChatError.java | 3 ++- .../com/aliens/backend/global/success/ChatSuccessCode.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/aliens/backend/global/error/ChatError.java b/src/main/java/com/aliens/backend/global/error/ChatError.java index f75d6e4a..a62faa48 100644 --- a/src/main/java/com/aliens/backend/global/error/ChatError.java +++ b/src/main/java/com/aliens/backend/global/error/ChatError.java @@ -6,7 +6,8 @@ public enum ChatError implements ErrorCode { INVALID_MESSAGE_TYPE(HttpStatus.BAD_REQUEST, "CH1", "메시지 타입이 잘못되었습니다."), INVALID_ROOM_ACCESS(HttpStatus.FORBIDDEN, "CH2", "채팅방 접근 권한이 없습니다."), - INVALID_REPORT_CATEGORY(HttpStatus.BAD_REQUEST, "CH3", "신고 카테고리가 잘못되었습니다.") + INVALID_REPORT_CATEGORY(HttpStatus.BAD_REQUEST, "CH3", "신고 카테고리가 잘못되었습니다."), + CHAT_ROOM_NOT_FOUND(HttpStatus.NOT_FOUND, "CH4", "채팅방을 찾을 수 없습니다.") ; private final HttpStatus httpStatusCode; diff --git a/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java b/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java index 3bab87ea..b4ca5944 100644 --- a/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java +++ b/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java @@ -5,7 +5,8 @@ public enum ChatSuccessCode implements SuccessCode { SEND_MESSAGE_SUCCESS(HttpStatus.CREATED, "CH001", "메시지 전송 성공"), READ_MESSAGES_SUCCESS(HttpStatus.OK, "CH002", "메시지 읽음 처리 성공"), - REPORT_SUCCESS(HttpStatus.CREATED, "CH003", "신고 성공") + REPORT_SUCCESS(HttpStatus.CREATED, "CH003", "신고 성공"), + BLOCK_SUCCESS(HttpStatus.CREATED, "CH004", "차단 성공") ; private final HttpStatus httpStatus; From 818505dd8a2c19113dc200865da09582be8daba9 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 12:28:09 +0900 Subject: [PATCH 165/215] =?UTF-8?q?feat(ChatRoom):=20=EC=B1=84=ED=8C=85?= =?UTF-8?q?=EB=B0=A9=20=EC=8B=9D=EB=B3=84=EC=9D=84=20=EC=9C=84=ED=95=B4=20?= =?UTF-8?q?id=20=EB=8C=80=EC=8B=A0=20roomId=EB=A5=BC=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/chat/domain/ChatRoom.java | 5 +++-- .../chat/domain/repository/ChatRoomRepository.java | 1 + .../backend/chat/service/ChatAuthValidator.java | 2 +- .../backend/chat/service/ChatBlockService.java | 13 +++++++------ .../aliens/backend/chat/service/ChatService.java | 6 +++--- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java b/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java index 6ed710cd..d6b7b88b 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java @@ -9,6 +9,7 @@ public class ChatRoom { @GeneratedValue(strategy = GenerationType.IDENTITY) @Column private Long id; + private Long roomId; @Column(name = "member_id") private Long memberId; @Column(name = "partner_id") @@ -19,8 +20,8 @@ public class ChatRoom { protected ChatRoom() { } - public Long getId() { - return id; + public Long getRoomId() { + return roomId; } public Long getPartnerId() { diff --git a/src/main/java/com/aliens/backend/chat/domain/repository/ChatRoomRepository.java b/src/main/java/com/aliens/backend/chat/domain/repository/ChatRoomRepository.java index d8417ec7..1d12c0e9 100644 --- a/src/main/java/com/aliens/backend/chat/domain/repository/ChatRoomRepository.java +++ b/src/main/java/com/aliens/backend/chat/domain/repository/ChatRoomRepository.java @@ -9,4 +9,5 @@ @Repository public interface ChatRoomRepository extends JpaRepository { List findByMemberId(Long memberId); + List findByRoomId(Long chatRoomId); } \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/service/ChatAuthValidator.java b/src/main/java/com/aliens/backend/chat/service/ChatAuthValidator.java index 3aa6bd0c..f9f0c537 100644 --- a/src/main/java/com/aliens/backend/chat/service/ChatAuthValidator.java +++ b/src/main/java/com/aliens/backend/chat/service/ChatAuthValidator.java @@ -17,7 +17,7 @@ public void validateRoom(String topic, List validChatRooms) { } private boolean isValidRoom (List validChatRooms, Long roomId) { - return validChatRooms.stream().anyMatch(chatRoom -> chatRoom.getId().equals(roomId)); + return validChatRooms.stream().anyMatch(chatRoom -> chatRoom.getRoomId().equals(roomId)); } private long getRoomIdFromTopic(String topic) { diff --git a/src/main/java/com/aliens/backend/chat/service/ChatBlockService.java b/src/main/java/com/aliens/backend/chat/service/ChatBlockService.java index 9cc4348d..52f74308 100644 --- a/src/main/java/com/aliens/backend/chat/service/ChatBlockService.java +++ b/src/main/java/com/aliens/backend/chat/service/ChatBlockService.java @@ -5,11 +5,12 @@ import com.aliens.backend.chat.domain.ChatRoom; import com.aliens.backend.chat.domain.repository.ChatBlockRepository; import com.aliens.backend.chat.domain.repository.ChatRoomRepository; -import com.aliens.backend.global.error.ChatError; -import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.success.ChatSuccessCode; +import jakarta.transaction.Transactional; import org.springframework.stereotype.Service; +import java.util.List; + @Service public class ChatBlockService { private final ChatBlockRepository chatBlockRepository; @@ -20,6 +21,7 @@ public ChatBlockService(ChatBlockRepository chatBlockRepository, ChatRoomReposit this.chatRoomRepository = chatRoomRepository; } + @Transactional public String blockPartner(Long memberId, ChatBlockRequest chatBlockRequest) { ChatBlock chatBlock = ChatBlock.of(memberId, chatBlockRequest); chatBlockRepository.save(chatBlock); @@ -28,9 +30,8 @@ public String blockPartner(Long memberId, ChatBlockRequest chatBlockRequest) { } private void blockChatRoom(Long chatRoomId) { - ChatRoom chatRoom = chatRoomRepository.findById(chatRoomId) - .orElseThrow(() -> new RestApiException(ChatError.CHAT_ROOM_NOT_FOUND)); - chatRoom.block(); - chatRoomRepository.save(chatRoom); + List chatRooms = chatRoomRepository.findByRoomId(chatRoomId); + chatRooms.forEach(ChatRoom::block); + chatRoomRepository.saveAll(chatRooms); } } \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/service/ChatService.java b/src/main/java/com/aliens/backend/chat/service/ChatService.java index fe14d294..9c76effb 100644 --- a/src/main/java/com/aliens/backend/chat/service/ChatService.java +++ b/src/main/java/com/aliens/backend/chat/service/ChatService.java @@ -4,10 +4,10 @@ import com.aliens.backend.chat.controller.dto.request.ReadRequest; import com.aliens.backend.chat.controller.dto.response.ChatSummaryResponse; import com.aliens.backend.chat.controller.dto.response.ReadResponse; -import com.aliens.backend.chat.domain.repository.ChatRoomRepository; -import com.aliens.backend.chat.domain.repository.MessageRepository; import com.aliens.backend.chat.domain.ChatRoom; import com.aliens.backend.chat.domain.Message; +import com.aliens.backend.chat.domain.repository.ChatRoomRepository; +import com.aliens.backend.chat.domain.repository.MessageRepository; import com.aliens.backend.chat.service.model.ChatMessageSummary; import com.aliens.backend.global.success.ChatSuccessCode; import org.springframework.messaging.simp.SimpMessagingTemplate; @@ -43,7 +43,7 @@ public String readMessages(ReadRequest readRequest) { public ChatSummaryResponse getChatSummaries(Long memberId) { List chatRooms = chatRoomRepository.findByMemberId(memberId); - List chatRoomIds = chatRooms.stream().map(ChatRoom::getId).toList(); + List chatRoomIds = chatRooms.stream().map(ChatRoom::getRoomId).toList(); List chatMessageSummaries = messageRepository.aggregateMessageSummaries(chatRoomIds, memberId); ChatSummaryResponse chatSummaryResponse = new ChatSummaryResponse(chatRooms, chatMessageSummaries); return chatSummaryResponse; From 2e5d56394fcc51219ac842b69021ab9efc518193 Mon Sep 17 00:00:00 2001 From: coke98 Date: Wed, 7 Feb 2024 12:29:51 +0900 Subject: [PATCH 166/215] =?UTF-8?q?feat(ChatBlockServiceTest,=20ChatReport?= =?UTF-8?q?ServiceTest):=20=EC=B1=84=ED=8C=85=20=EC=8B=A0=EA=B3=A0,=20?= =?UTF-8?q?=EC=B0=A8=EB=8B=A8=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ChatBlockServiceTest.java | 37 +++++++++++++++++++ .../service/ChatReportServiceTest.java | 36 ++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/test/java/com/aliens/backend/chatting/service/ChatBlockServiceTest.java create mode 100644 src/test/java/com/aliens/backend/chatting/service/ChatReportServiceTest.java diff --git a/src/test/java/com/aliens/backend/chatting/service/ChatBlockServiceTest.java b/src/test/java/com/aliens/backend/chatting/service/ChatBlockServiceTest.java new file mode 100644 index 00000000..27d2f86a --- /dev/null +++ b/src/test/java/com/aliens/backend/chatting/service/ChatBlockServiceTest.java @@ -0,0 +1,37 @@ +package com.aliens.backend.chatting.service; + +import com.aliens.backend.chat.controller.dto.request.ChatBlockRequest; +import com.aliens.backend.chat.domain.repository.ChatBlockRepository; +import com.aliens.backend.chat.domain.repository.ChatRoomRepository; +import com.aliens.backend.chat.service.ChatBlockService; +import com.aliens.backend.global.success.ChatSuccessCode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; + +@SpringBootTest +public class ChatBlockServiceTest { + @Autowired + ChatBlockService chatBlockService; + @MockBean + ChatRoomRepository chatRoomRepository; + @MockBean + ChatBlockRepository chatBlockRepository; + + @Test + @DisplayName("채팅 상대 차단") + void blockPartner() { + //given + Long memberId = 1L; + Long partnerId = 2L; + Long roomId = 1L; + ChatBlockRequest chatBlockRequest = new ChatBlockRequest(partnerId, roomId); + //when + String result = chatBlockService.blockPartner(memberId, chatBlockRequest); + //then + Assertions.assertEquals(ChatSuccessCode.BLOCK_SUCCESS.getMessage(), result); + } +} \ No newline at end of file diff --git a/src/test/java/com/aliens/backend/chatting/service/ChatReportServiceTest.java b/src/test/java/com/aliens/backend/chatting/service/ChatReportServiceTest.java new file mode 100644 index 00000000..e5ec3a14 --- /dev/null +++ b/src/test/java/com/aliens/backend/chatting/service/ChatReportServiceTest.java @@ -0,0 +1,36 @@ +package com.aliens.backend.chatting.service; + +import com.aliens.backend.chat.controller.dto.request.ChatReportRequest; +import com.aliens.backend.chat.domain.repository.ChatReportRepository; +import com.aliens.backend.chat.service.ChatReportService; +import com.aliens.backend.global.success.ChatSuccessCode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; + +@SpringBootTest +public class ChatReportServiceTest { + @Autowired + ChatReportService chatReportService; + @MockBean + ChatReportRepository chatReportRepository; + + @Test + @DisplayName("채팅 상대 신고") + void blockPartner() { + //given + Long memberId = 1L; + Long partnerId = 2L; + Long roomId = 1L; + String category = "ETC"; + String content = "신고 사유"; + ChatReportRequest chatReportRequest = new ChatReportRequest(partnerId, roomId, category, content); + //when + String result = chatReportService.reportPartner(memberId, chatReportRequest); + //then + Assertions.assertEquals(ChatSuccessCode.REPORT_SUCCESS.getMessage(), result); + } +} \ No newline at end of file From beee1b938340e26a5115c2d120eba7e9e3c999ff Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 7 Feb 2024 13:26:38 +0900 Subject: [PATCH 167/215] =?UTF-8?q?fix(MemberController)=20:=20ResponseEnt?= =?UTF-8?q?ity=20=EC=9D=BC=EB=B0=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/success/MemberSuccessCode.java | 42 ++++++++++++ .../member/controller/MemberController.java | 68 ++++++++----------- 2 files changed, 72 insertions(+), 38 deletions(-) create mode 100644 src/main/java/com/aliens/backend/global/success/MemberSuccessCode.java diff --git a/src/main/java/com/aliens/backend/global/success/MemberSuccessCode.java b/src/main/java/com/aliens/backend/global/success/MemberSuccessCode.java new file mode 100644 index 00000000..2124c9a5 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/success/MemberSuccessCode.java @@ -0,0 +1,42 @@ +package com.aliens.backend.global.success; + +import org.springframework.http.HttpStatus; + +public enum MemberSuccessCode implements SuccessCode { + SIGN_UP_SUCCESS(HttpStatus.CREATED, "M001", "회원가입이 완료되었습니다."), + WITHDRAW_SUCCESS(HttpStatus.OK, "M002", "회원 탈퇴되었습니다."), + TEMPORARY_PASSWORD_GENERATED_SUCCESS(HttpStatus.OK, "M003", "임시 비밀번호가 발급되었습니다. 이메일을 확인해주세요."), + PASSWORD_CHANGE_SUCCESS(HttpStatus.OK, "M004", "비밀번호 변경이 완료되었습니다."), + PROFILE_IMAGE_CHANGE_SUCCESS(HttpStatus.OK, "M005", "프로필 이미지 변경이 완료되었습니다."), + ABOUT_ME_CHANGE_SUCCESS(HttpStatus.OK, "M006", "자기소개 변경이 완료되었습니다."), + MBTI_CHANGE_SUCCESS(HttpStatus.OK, "M007", "MBTI 변경이 완료되었습니다."), + GET_MEMBER_MATCHING_STATUS_SUCCESS(HttpStatus.OK, "M008", "회원 상태 조회를 완료했습니다."), + GET_MEMBER_PAGE_SUCCESS(HttpStatus.OK, "M009", "회원 페이지 조회를 완료했습니다."), + + ; + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + MemberSuccessCode(final HttpStatus httpStatus, final String code, final String message) { + this.httpStatus = httpStatus; + this.code = code; + this.message = message; + } + + @Override + public HttpStatus getHttpStatus() { + return httpStatus; + } + + @Override + public String getCode() { + return code; + } + + @Override + public String getMessage() { + return message; + } +} diff --git a/src/main/java/com/aliens/backend/member/controller/MemberController.java b/src/main/java/com/aliens/backend/member/controller/MemberController.java index 83b30708..067a2d7a 100644 --- a/src/main/java/com/aliens/backend/member/controller/MemberController.java +++ b/src/main/java/com/aliens/backend/member/controller/MemberController.java @@ -2,6 +2,9 @@ import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.global.config.resolver.Login; +import com.aliens.backend.global.success.MemberSuccessCode; +import com.aliens.backend.global.success.SuccessResponse; +import com.aliens.backend.global.success.SuccessResponseWithoutResult; import com.aliens.backend.member.controller.dto.request.SignUpRequest; import com.aliens.backend.member.controller.dto.request.TemporaryPasswordRequest; import com.aliens.backend.member.controller.dto.response.MemberPageResponse; @@ -10,9 +13,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import java.util.Collections; -import java.util.Map; - @RequestMapping("/members") @RestController public class MemberController { @@ -24,69 +24,61 @@ public MemberController(final MemberInfoService memberInfoService) { } @PostMapping() - public ResponseEntity> signUp(@RequestPart SignUpRequest signUpRequest, + public ResponseEntity signUp(@RequestPart SignUpRequest signUpRequest, @RequestPart MultipartFile profileImage) { - String result = memberInfoService.signUp(signUpRequest, profileImage); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); + memberInfoService.signUp(signUpRequest, profileImage); + return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.SIGN_UP_SUCCESS); } @PostMapping("/temporary-password") - public ResponseEntity> temporaryPassword(@RequestBody TemporaryPasswordRequest request) { - String result = memberInfoService.generateTemporaryPassword(request); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); + public ResponseEntity temporaryPassword(@RequestBody TemporaryPasswordRequest request) { + memberInfoService.generateTemporaryPassword(request); + return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.TEMPORARY_PASSWORD_GENERATED_SUCCESS); } @PatchMapping("/password") - public ResponseEntity> changePassword(@Login LoginMember loginMember, + public ResponseEntity changePassword(@Login LoginMember loginMember, @RequestBody String newPassword ) { - String result = memberInfoService.changePassword(loginMember, newPassword); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); + memberInfoService.changePassword(loginMember, newPassword); + return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.PASSWORD_CHANGE_SUCCESS); } @PostMapping("/profile-image") - public ResponseEntity> changeProfileImage(@Login LoginMember loginMember, + public ResponseEntity changeProfileImage(@Login LoginMember loginMember, @RequestPart MultipartFile newProfileImage) { - String result = memberInfoService.changeProfileImage(loginMember, newProfileImage); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); + memberInfoService.changeProfileImage(loginMember, newProfileImage); + return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.PROFILE_IMAGE_CHANGE_SUCCESS); } @PatchMapping("/about-me") - public ResponseEntity> changeAboutMe(@Login LoginMember loginMember, + public ResponseEntity changeAboutMe(@Login LoginMember loginMember, @RequestBody String newAboutMe) { - String result = memberInfoService.changeAboutMe(loginMember, newAboutMe); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); + memberInfoService.changeAboutMe(loginMember, newAboutMe); + return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.ABOUT_ME_CHANGE_SUCCESS); } @PatchMapping("/mbti") - public ResponseEntity> changeMBTI(@Login LoginMember loginMember, + public ResponseEntity changeMBTI(@Login LoginMember loginMember, @RequestBody String newMBTI) { - String result = memberInfoService.changeMBTI(loginMember, newMBTI); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); + memberInfoService.changeMBTI(loginMember, newMBTI); + return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.MBTI_CHANGE_SUCCESS); } @PatchMapping("/withdraw") - public ResponseEntity> withdraw(@Login LoginMember loginMember) { - String result = memberInfoService.withdraw(loginMember); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); + public ResponseEntity withdraw(@Login LoginMember loginMember) { + memberInfoService.withdraw(loginMember); + return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.WITHDRAW_SUCCESS); } @GetMapping("/status") - public ResponseEntity> getStatus(@Login LoginMember loginMember) { - String result = memberInfoService.getStatus(loginMember); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); + public ResponseEntity getStatus(@Login LoginMember loginMember) { + return SuccessResponse.toResponseEntity(MemberSuccessCode.GET_MEMBER_MATCHING_STATUS_SUCCESS, + memberInfoService.getStatus(loginMember)); } @GetMapping() - public ResponseEntity getMemberPage(@Login LoginMember loginMember) { - MemberPageResponse result = memberInfoService.getMemberPage(loginMember); - return ResponseEntity.ok(result); + public ResponseEntity getMemberPage(@Login LoginMember loginMember) { + return SuccessResponse.toResponseEntity(MemberSuccessCode.GET_MEMBER_PAGE_SUCCESS, + memberInfoService.getMemberPage(loginMember)); } } From 653cdc9356c26f4e1ca96bf88822ca0f5cad33d0 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 7 Feb 2024 13:33:08 +0900 Subject: [PATCH 168/215] =?UTF-8?q?fix(AuthController)=20:=20ResponseEntit?= =?UTF-8?q?y=20=EC=9D=BC=EB=B0=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/controller/AuthController.java | 18 +++++----- .../global/success/AuthSuccessCode.java | 36 +++++++++++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/aliens/backend/global/success/AuthSuccessCode.java diff --git a/src/main/java/com/aliens/backend/auth/controller/AuthController.java b/src/main/java/com/aliens/backend/auth/controller/AuthController.java index 5d1dd941..de802e63 100644 --- a/src/main/java/com/aliens/backend/auth/controller/AuthController.java +++ b/src/main/java/com/aliens/backend/auth/controller/AuthController.java @@ -3,6 +3,9 @@ import com.aliens.backend.auth.service.AuthService; import com.aliens.backend.auth.controller.dto.AuthToken; import com.aliens.backend.auth.controller.dto.LoginRequest; +import com.aliens.backend.global.success.AuthSuccessCode; +import com.aliens.backend.global.success.SuccessResponse; +import com.aliens.backend.global.success.SuccessResponseWithoutResult; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -17,20 +20,17 @@ public AuthController(final AuthService authService) { } @PostMapping - public ResponseEntity login(@RequestBody final LoginRequest loginRequest) { - AuthToken authToken = authService.login(loginRequest); - return ResponseEntity.ok(authToken); + public ResponseEntity login(@RequestBody final LoginRequest loginRequest) { + return SuccessResponse.toResponseEntity(AuthSuccessCode.GENERATE_AUTHTOKEN_SUCCESS, authService.login(loginRequest)); } @PostMapping("/logout") - public ResponseEntity logout(@RequestBody final AuthToken authToken) { - String result = authService.logout(authToken); - return ResponseEntity.ok(result); + public ResponseEntity logout(@RequestBody final AuthToken authToken) { + return SuccessResponseWithoutResult.toResponseEntity(AuthSuccessCode.LOGOUT_SUCCESS); } @PostMapping("/reissue") - public ResponseEntity reissue(@RequestBody final AuthToken authToken) { - AuthToken newAuthToken = authService.reissue(authToken); - return ResponseEntity.ok(newAuthToken); + public ResponseEntity reissue(@RequestBody final AuthToken authToken) { + return SuccessResponse.toResponseEntity(AuthSuccessCode.REISSUE_AUTHTOKEN_SUCCESS, authService.reissue(authToken)); } } \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/global/success/AuthSuccessCode.java b/src/main/java/com/aliens/backend/global/success/AuthSuccessCode.java new file mode 100644 index 00000000..3f9e8ff2 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/success/AuthSuccessCode.java @@ -0,0 +1,36 @@ +package com.aliens.backend.global.success; + +import org.springframework.http.HttpStatus; + +public enum AuthSuccessCode implements SuccessCode { + GENERATE_AUTHTOKEN_SUCCESS(HttpStatus.CREATED, "A001", "인증 토큰 발행에 성공했습니다."), + LOGOUT_SUCCESS(HttpStatus.OK, "A002", "로그아웃에 성공했습니다."), + REISSUE_AUTHTOKEN_SUCCESS(HttpStatus.CREATED, "A003", "토큰 재발급에 성공했습니다"), + + ; + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + AuthSuccessCode(final HttpStatus httpStatus, final String code, final String message) { + this.httpStatus = httpStatus; + this.code = code; + this.message = message; + } + + @Override + public HttpStatus getHttpStatus() { + return httpStatus; + } + + @Override + public String getCode() { + return code; + } + + @Override + public String getMessage() { + return message; + } +} From df7e007714842411a0d980898444cd588f65c195 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 7 Feb 2024 15:06:09 +0900 Subject: [PATCH 169/215] =?UTF-8?q?fix=20:=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MatchingApplicationService.java | 14 ++++++++------ .../backend/mathcing/service/MatchingService.java | 13 ++++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index e74daee2..71d8166e 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -33,9 +33,7 @@ public MatchingApplicationService(final MatchingApplicationRepository matchingAp @Transactional public void saveParticipant(final MatchingApplicationRequest matchingApplicationRequest) { MatchingRound currentRound = getCurrentRound(); - if (!currentRound.isReceptionTime(LocalDateTime.now(clock))) { - throw new RestApiException(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME); - } + checkReceptionTime(currentRound); matchingApplicationRepository.save(matchingApplicationRequest.toEntity(currentRound)); } @@ -51,9 +49,7 @@ public MatchingApplicationResponse findMatchingApplication(final Long memberId) @Transactional public void deleteMatchingApplication(final Long memberId) { MatchingRound currentRound = getCurrentRound(); - if (!currentRound.isReceptionTime(LocalDateTime.now(clock))) { - throw new RestApiException(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME); - } + checkReceptionTime(currentRound); MatchingApplication matchingApplication = matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, memberId)) .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); @@ -64,4 +60,10 @@ private MatchingRound getCurrentRound() { return matchingRoundRepository.findCurrentRound() .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); } + + private void checkReceptionTime(MatchingRound matchingRound) { + if (!matchingRound.isReceptionTime(LocalDateTime.now(clock))) { + throw new RestApiException(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME); + } + } } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java index be7962d2..5c0e43d1 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -55,20 +55,23 @@ public List findMatchingResult(final Long memberId) { .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); List matchingResults = matchingResultRepository.findAllByMatchingRoundAndMemberId(currentRound, memberId); - if (matchingResults.isEmpty()) { - throw new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO); - } + checkHasApplied(matchingResults); return matchingResults.stream().map(MatchingResultResponse::of).toList(); } private void saveMatchingResult(final List participants) { for (Participant participant : participants) { - Long memberId = participant.memberId(); for (Partner partner : participant.partners()) { matchingResultRepository.save( - MatchingResult.of(currentRound, memberId, partner.memberId(), partner.relationship())); + MatchingResult.of(currentRound, partner.memberId(), partner.memberId(), partner.relationship())); } // TODO : 매칭 완료 알림 이벤트 발송 & 채팅방 개설 이벤트 발송 } } + + private void checkHasApplied(List matchingResults) { + if (matchingResults.isEmpty()) { + throw new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO); + } + } } From a5a0590b6341182c8a1d48871d9e850428836bae Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 7 Feb 2024 15:10:39 +0900 Subject: [PATCH 170/215] =?UTF-8?q?fix=20:=20Participant=20=EC=97=90=20of?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/mathcing/domain/MatchingApplication.java | 11 +---------- .../backend/mathcing/service/model/Participant.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java index 074bfc1d..730921da 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java @@ -56,19 +56,10 @@ public static MatchingApplication of(final MatchingRound matchingRound, public static List toParticipantList(final List matchingApplications) { return matchingApplications.stream() - .map(MatchingApplication::of) + .map(Participant::of) .collect(Collectors.toList()); } - private static Participant of(final MatchingApplication matchingApplication) { - return new Participant( - matchingApplication.getId().getMemberId(), - matchingApplication.getFirstPreferLanguage(), - matchingApplication.getSecondPreferLanguage(), - new ArrayList<>() - ); - } - @Override public String toString() { return "MatchingApplication{" + diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java b/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java index 727f2f66..5159f461 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java +++ b/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java @@ -2,7 +2,9 @@ import com.aliens.backend.global.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.mathcing.domain.MatchingApplication; +import java.util.ArrayList; import java.util.List; public record Participant( @@ -21,6 +23,14 @@ public Language getPreferLanguage(MatchingMode matchingMode) { throw new RestApiException(MatchingError.NOT_FOUND_PREFER_LANGUAGE); } + public static Participant of(final MatchingApplication matchingApplication) { + return new Participant( + matchingApplication.getId().getMemberId(), + matchingApplication.getFirstPreferLanguage(), + matchingApplication.getSecondPreferLanguage(), + new ArrayList<>() + ); + } public int getNumberOfPartners() { return partners.size(); } From c6602000947b0de936fbd211f9278683c39188cb Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 7 Feb 2024 15:24:26 +0900 Subject: [PATCH 171/215] =?UTF-8?q?fix=20:=20=EC=8B=A4=ED=8C=A8=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=8B=9C,?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=20=EB=A9=94=EC=8B=9C=EC=A7=80=EA=B0=80=20?= =?UTF-8?q?=EC=95=84=EB=8B=8C=20=EC=97=90=EB=9F=AC=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A5=BC=20=EA=B2=80=EC=A6=9D=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unit/service/MatchingApplicationServiceTest.java | 11 +++++------ .../matching/unit/service/MatchingServiceTest.java | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index e2d750fd..4614fcf2 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -69,8 +69,7 @@ void applyMatchIfNotValidTime() { // when & then assertThatThrownBy(() -> matchingApplicationService.saveParticipant(matchingApplicationRequest)) - .isInstanceOf(RestApiException.class) - .hasMessage(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME.getMessage()); + .hasMessage(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME.getDevelopCode()); } @@ -95,7 +94,7 @@ void getMatchingApplicationTest() { void getMatchingApplicationIfNotApplied() { // when & then assertThatThrownBy(() -> matchingApplicationService.findMatchingApplication(matchingApplicationRequest.memberId())) - .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getMessage()); + .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } @Test @@ -111,7 +110,7 @@ void deleteMatchingApplicationTest() { // then assertThatThrownBy(() -> matchingApplicationService.findMatchingApplication(matchingApplicationRequest.memberId())) - .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getMessage()); + .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } @Test @@ -124,7 +123,7 @@ void deleteMatchIfNotValidTime() { // when & then assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId())) - .hasMessage(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME.getMessage()); + .hasMessage(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME.getDevelopCode()); } @Test @@ -135,7 +134,7 @@ void deleteMatchIfNotApplied() { mockClock.mockTime(VALID_TIME); assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId())) - .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getMessage()); + .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } private void applyToMatch() { diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java index c033ab9d..166b070b 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java @@ -38,6 +38,6 @@ void setUp() { @DisplayName("매칭을 신청한 적이 없는 회원이 매칭 조회") void getMatchingResultTest() { assertThatThrownBy(() -> matchingService.findMatchingResult(1L)) - .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getMessage()); + .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } } From 23ca0312ddf9053b929e0a283bf61d7fb32ef682 Mon Sep 17 00:00:00 2001 From: coke98 Date: Thu, 8 Feb 2024 17:25:53 +0900 Subject: [PATCH 172/215] =?UTF-8?q?chore(application.yml):=20=EC=9B=B9?= =?UTF-8?q?=EC=86=8C=EC=BC=93=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f266cd1d..d11d161c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,3 +11,9 @@ spring: profiles: include: secret + +websocket: + port: 8080 + endpoint: /ws + topic: /room + request: /chatting \ No newline at end of file From 4769400f4c336ef95e6f6012440c5779393e59a9 Mon Sep 17 00:00:00 2001 From: coke98 Date: Fri, 9 Feb 2024 20:19:12 +0900 Subject: [PATCH 173/215] =?UTF-8?q?feat(ChatChannelInterceptor):=20ChatAut?= =?UTF-8?q?hValidator=EC=9D=98=20=EC=A0=91=EA=B7=BC=20=EC=A0=9C=ED=95=9C?= =?UTF-8?q?=EC=9E=90=EB=A5=BC=20private=20final=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/interceptor/ChatChannelInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java b/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java index 30768884..79919bf4 100644 --- a/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java +++ b/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java @@ -15,7 +15,7 @@ @Component public class ChatChannelInterceptor implements ChannelInterceptor { - ChatAuthValidator chatAuthValidator; + private final ChatAuthValidator chatAuthValidator; public ChatChannelInterceptor(ChatAuthValidator chatAuthValidator) { this.chatAuthValidator = chatAuthValidator; From 8825189cc9bf5d81712d17d684c33d27be131161 Mon Sep 17 00:00:00 2001 From: coke98 Date: Fri, 9 Feb 2024 20:21:09 +0900 Subject: [PATCH 174/215] =?UTF-8?q?feat(ChatBlockController,=20ChatControl?= =?UTF-8?q?ler,=20ChatReportController):=20Controller=EB=A5=BC=20RestContr?= =?UTF-8?q?oller=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/chat/controller/ChatBlockController.java | 4 ++-- .../com/aliens/backend/chat/controller/ChatController.java | 4 ++-- .../aliens/backend/chat/controller/ChatReportController.java | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatBlockController.java b/src/main/java/com/aliens/backend/chat/controller/ChatBlockController.java index e60f09b6..630c640d 100644 --- a/src/main/java/com/aliens/backend/chat/controller/ChatBlockController.java +++ b/src/main/java/com/aliens/backend/chat/controller/ChatBlockController.java @@ -4,15 +4,15 @@ import com.aliens.backend.chat.service.ChatBlockService; import com.aliens.backend.global.config.resolver.Login; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; import java.util.Collections; import java.util.Map; -@Controller +@RestController public class ChatBlockController { private final ChatBlockService chatBlockService; diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatController.java b/src/main/java/com/aliens/backend/chat/controller/ChatController.java index 892772ea..bf9ccdf0 100644 --- a/src/main/java/com/aliens/backend/chat/controller/ChatController.java +++ b/src/main/java/com/aliens/backend/chat/controller/ChatController.java @@ -9,17 +9,17 @@ import org.springframework.http.ResponseEntity; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.Payload; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.Collections; import java.util.List; import java.util.Map; -@Controller +@RestController public class ChatController { private final ChatService chatService; diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatReportController.java b/src/main/java/com/aliens/backend/chat/controller/ChatReportController.java index 26700fbb..74d3d0d7 100644 --- a/src/main/java/com/aliens/backend/chat/controller/ChatReportController.java +++ b/src/main/java/com/aliens/backend/chat/controller/ChatReportController.java @@ -7,12 +7,13 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; import java.util.Collections; import java.util.Map; -@Controller +@RestController public class ChatReportController { private final ChatReportService chatReportService; From 208aa590d200b8083ff78d3099a461b53abb68d8 Mon Sep 17 00:00:00 2001 From: coke98 Date: Fri, 9 Feb 2024 20:21:54 +0900 Subject: [PATCH 175/215] =?UTF-8?q?feat(ChatController):=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/aliens/backend/chat/controller/ChatController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatController.java b/src/main/java/com/aliens/backend/chat/controller/ChatController.java index bf9ccdf0..d7810366 100644 --- a/src/main/java/com/aliens/backend/chat/controller/ChatController.java +++ b/src/main/java/com/aliens/backend/chat/controller/ChatController.java @@ -38,7 +38,7 @@ public void readMessage(@Payload ReadRequest readRequest) { chatService.readMessages(readRequest); } - @GetMapping("chat/summaries") + @GetMapping("/chat/summaries") public ResponseEntity> getChatSummaries(@Login Long memberId) { ChatSummaryResponse chatSummaryResponse = chatService.getChatSummaries(memberId); Map response = Collections.singletonMap("response", chatSummaryResponse); From 86155c6307ccb944adc7a0300e0074d39352afe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Sat, 10 Feb 2024 13:49:18 +0900 Subject: [PATCH 176/215] =?UTF-8?q?refactor(MockTime):=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EC=83=9D=EC=84=B1=EC=9E=90?= =?UTF-8?q?=EC=97=90=20private=20=ED=95=9C=EC=A0=95=EC=9E=90=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/aliens/backend/matching/util/MockTime.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/aliens/backend/matching/util/MockTime.java b/src/test/java/com/aliens/backend/matching/util/MockTime.java index 235bcbab..612a3707 100644 --- a/src/test/java/com/aliens/backend/matching/util/MockTime.java +++ b/src/test/java/com/aliens/backend/matching/util/MockTime.java @@ -8,7 +8,7 @@ public enum MockTime { public LocalDateTime time; - private MockTime(LocalDateTime time) { + MockTime(LocalDateTime time) { this.time = time; } } From 40c8e24c893cc2c5d1b32041cd66d71360ee68bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:36:17 +0900 Subject: [PATCH 177/215] =?UTF-8?q?feat(SuccessResponse):=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=EA=B0=9D=EC=B2=B4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/response/SuccessResponse.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/response/SuccessResponse.java diff --git a/src/main/java/com/aliens/backend/global/response/SuccessResponse.java b/src/main/java/com/aliens/backend/global/response/SuccessResponse.java new file mode 100644 index 00000000..2b795b1c --- /dev/null +++ b/src/main/java/com/aliens/backend/global/response/SuccessResponse.java @@ -0,0 +1,17 @@ +package com.aliens.backend.global.response; + +import com.aliens.backend.global.response.success.SuccessCode; +import org.springframework.http.ResponseEntity; + +public class SuccessResponse extends ResponseEntity { + + public SuccessResponse(final SuccessCode successCode, final T result) { + super(new CustomResponseDto<>(successCode.getCode(), result), + successCode.getHttpStatus() + ); + } + + public static SuccessResponse of(final SuccessCode successCode, final T result) { + return new SuccessResponse<>(successCode, result); + } +} \ No newline at end of file From f8dab733581a0eb6b5d9cbfb777e616b6582b478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:36:43 +0900 Subject: [PATCH 178/215] =?UTF-8?q?remove:=20=EB=B0=98=ED=99=98=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=83=9D=EC=84=B1=EC=9C=BC=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/success/SuccessResponse.java | 22 --------------- .../success/SuccessResponseWithoutResult.java | 27 ------------------- 2 files changed, 49 deletions(-) delete mode 100644 src/main/java/com/aliens/backend/global/success/SuccessResponse.java delete mode 100644 src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java diff --git a/src/main/java/com/aliens/backend/global/success/SuccessResponse.java b/src/main/java/com/aliens/backend/global/success/SuccessResponse.java deleted file mode 100644 index 7dc7e221..00000000 --- a/src/main/java/com/aliens/backend/global/success/SuccessResponse.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.aliens.backend.global.success; - -import org.springframework.http.ResponseEntity; - -public class SuccessResponse { - - private String code; - private String message; - private T result; - - public SuccessResponse(final String code, final String message, final T result) { - this.code = code; - this.message = message; - this.result = result; - } - - - public static ResponseEntity toResponseEntity(final SuccessCode successCode, final Object result) { - SuccessResponse res = new SuccessResponse(successCode.getCode(), successCode.getMessage(), result); - return new ResponseEntity<>(res, successCode.getHttpStatus()); - } -} diff --git a/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java b/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java deleted file mode 100644 index fff3a18b..00000000 --- a/src/main/java/com/aliens/backend/global/success/SuccessResponseWithoutResult.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.aliens.backend.global.success; - -import org.springframework.http.ResponseEntity; - -public class SuccessResponseWithoutResult { - private String code; - private String message; - - public SuccessResponseWithoutResult(final String code, final String message) { - this.code = code; - this.message = message; - } - - - public static ResponseEntity toResponseEntity(final SuccessCode successCode) { - SuccessResponseWithoutResult res = new SuccessResponseWithoutResult(successCode.getCode(), successCode.getMessage()); - return new ResponseEntity<>(res, successCode.getHttpStatus()); - } - - public String getCode() { - return code; - } - - public String getMessage() { - return message; - } -} From 63e7ad4a0ece0d63a12da18f9d8b145183427ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:02:36 +0900 Subject: [PATCH 179/215] =?UTF-8?q?feat(DummyGenerator)=20:=20=EB=8D=94?= =?UTF-8?q?=EB=AF=B8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=A5=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=ED=95=98=EB=8A=94=20=EA=B0=9D=EC=B2=B4=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20#50?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/global/DummyGenerator.java | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 src/test/java/com/aliens/backend/global/DummyGenerator.java diff --git a/src/test/java/com/aliens/backend/global/DummyGenerator.java b/src/test/java/com/aliens/backend/global/DummyGenerator.java new file mode 100644 index 00000000..a4a8c677 --- /dev/null +++ b/src/test/java/com/aliens/backend/global/DummyGenerator.java @@ -0,0 +1,133 @@ +package com.aliens.backend.global; + +import com.aliens.backend.auth.domain.Member; +import com.aliens.backend.auth.service.PasswordEncoder; +import com.aliens.backend.auth.service.TokenProvider; +import com.aliens.backend.mathcing.controller.dto.request.MatchingRequest; +import com.aliens.backend.mathcing.service.MatchingApplicationService; +import com.aliens.backend.mathcing.service.model.Language; +import com.aliens.backend.member.controller.dto.EncodedMember; +import com.aliens.backend.member.controller.dto.EncodedSignUp; +import com.aliens.backend.member.domain.Image; +import com.aliens.backend.member.domain.MemberInfo; +import com.aliens.backend.member.domain.repository.MemberInfoRepository; +import com.aliens.backend.member.sevice.SymmetricKeyEncoder; +import com.aliens.backend.uploader.dto.S3File; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +@Component +public class DummyGenerator { + @Autowired + MatchingApplicationService matchingApplicationService; + + @Autowired + MemberInfoRepository memberInfoRepository; + + @Autowired + PasswordEncoder passwordEncoder; + + @Autowired + SymmetricKeyEncoder encoder; + + @Autowired + TokenProvider tokenProvider; + + public static final String GIVEN_EMAIL = "tmp@example.com"; + public static final String GIVEN_PASSWORD = "tmpPassword"; + public static final String GIVEN_NAME = "tmpName"; + public static final String GIVEN_MBTI = "tmpMbTI"; + public static final String GIVEN_GENDER = "MALE"; + public static final String GIVEN_NATIONALITY = "KOREA"; + public static final String GIVEN_BIRTHDAY = "1998-11-25"; + public static final String GIVEN_ABOUT_ME = "nice to meet you"; + public static final String GIVEN_FILE_NAME = "test"; + public static final String GIVEN_FILE_URL = "/test"; + + // 다수 멤버 생성 메서드 + public List generateMultiMember(Integer memberCounts) { + ArrayList result = new ArrayList<>(); + + for (int i = 0; i < memberCounts; i++) { + String tmpEmail = GIVEN_EMAIL + i; + Image image = makeImage(); + Member member = makeMember(tmpEmail, image); + result.add(member); + } + + result.forEach(this::saveAsMemberInfo); + return result; + } + + // 단일 멤버 생성 메서드 + public Member generateSingleMember() { + String tmpEmail = GIVEN_EMAIL; + Image image = makeImage(); + Member member = makeMember(tmpEmail, image); + saveAsMemberInfo(member); + return member; + } + + private Image makeImage() { + return Image.from(new S3File(GIVEN_FILE_NAME, GIVEN_FILE_URL)); + } + + private Member makeMember(String email, Image image) { + String encodedPassword = passwordEncoder.encrypt(GIVEN_PASSWORD); + EncodedSignUp signUp = new EncodedSignUp(GIVEN_NAME, email, encodedPassword); + return Member.of(signUp, image); + } + + private void saveAsMemberInfo(final Member member) { + EncodedMember encodedRequest = new EncodedMember(encoder.encrypt(GIVEN_GENDER), + encoder.encrypt(GIVEN_MBTI), + encoder.encrypt(GIVEN_BIRTHDAY), + encoder.encrypt(GIVEN_NATIONALITY), + encoder.encrypt(GIVEN_ABOUT_ME)); + + MemberInfo memberInfo = MemberInfo.of(encodedRequest, member); + memberInfoRepository.save(memberInfo); + } + // MultipartFile 생성 메서드 + public MultipartFile generateMultipartFile() { + String fileName = "test"; + String path = "/test"; + String contentType = "image/png"; + byte[] content = fileName.getBytes(); + return new MockMultipartFile(fileName, path, contentType, content); + } + + + //AccessToken 생성 메서드 + public String generateAccessToken(Member member) { + return tokenProvider.generateAccessToken(member.getLoginMember()); + } + + //지원자 생성 메서드 + public void generateAppliersToMatch(Long numberOfMember) { + Random random = new Random(); + + for (long i = 1L; i <= numberOfMember; i++) { + Language firstPreferLanguage = getRandomLanguage(random); + Language secondPreferLanguage; + + do { + secondPreferLanguage = getRandomLanguage(random); + } while (firstPreferLanguage == secondPreferLanguage); + + MatchingRequest.MatchingApplicationRequest request = new MatchingRequest.MatchingApplicationRequest(i, firstPreferLanguage, secondPreferLanguage); + matchingApplicationService.saveParticipant(request); + } + } + + private Language getRandomLanguage(Random random) { + Language[] languages = Language.values(); + return languages[random.nextInt(languages.length)]; + } +} From a9791b9154b9344eec0065716b765dfe138cfa48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:04:38 +0900 Subject: [PATCH 180/215] =?UTF-8?q?style(BaseServiceTest)=20:=20=EB=8D=94?= =?UTF-8?q?=EB=AF=B8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EC=83=81?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80,=20=EB=B0=8F=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EA=B0=9D=EC=B2=B4=20=EB=82=98=EC=97=B4=20=EC=88=9C?= =?UTF-8?q?=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #50 --- .../global/response/CustomResponseDto.java | 4 ++++ .../{BaseTest.java => BaseServiceTest.java} | 21 ++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/aliens/backend/global/response/CustomResponseDto.java rename src/test/java/com/aliens/backend/global/{BaseTest.java => BaseServiceTest.java} (76%) diff --git a/src/main/java/com/aliens/backend/global/response/CustomResponseDto.java b/src/main/java/com/aliens/backend/global/response/CustomResponseDto.java new file mode 100644 index 00000000..a187ff17 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/response/CustomResponseDto.java @@ -0,0 +1,4 @@ +package com.aliens.backend.global.response; + +public record CustomResponseDto(String code, T result) { +} diff --git a/src/test/java/com/aliens/backend/global/BaseTest.java b/src/test/java/com/aliens/backend/global/BaseServiceTest.java similarity index 76% rename from src/test/java/com/aliens/backend/global/BaseTest.java rename to src/test/java/com/aliens/backend/global/BaseServiceTest.java index 7019cccb..fc4f4d2a 100644 --- a/src/test/java/com/aliens/backend/global/BaseTest.java +++ b/src/test/java/com/aliens/backend/global/BaseServiceTest.java @@ -20,22 +20,13 @@ import static org.mockito.Mockito.doReturn; @SpringBootTest -public abstract class BaseTest { +public abstract class BaseServiceTest { - @SpyBean - protected AwsS3Uploader awsS3Uploader; + @SpyBean protected AwsS3Uploader awsS3Uploader; + @SpyBean protected JavaMailSender javaMailSender; + @SpyBean protected FcmSender fcmSender; - @SpyBean - protected JavaMailSender javaMailSender; - - @SpyBean - protected FcmSender fcmSender; - - @Autowired - private DatabaseCleanup databaseCleanUp; - - private static final String GIVEN_FILE_NAME = "test"; - private static final String GIVEN_FILE_URL = "/test"; + @Autowired private DatabaseCleanup databaseCleanUp; @BeforeEach void setUpSpy() { @@ -50,7 +41,7 @@ void setUpSpy() { doNothing().when(fcmSender).listenSingleMessageRequest(any(Message.class)); //AWS - S3File tmpFile = new S3File(GIVEN_FILE_NAME, GIVEN_FILE_URL); + S3File tmpFile = new S3File(DummyGenerator.GIVEN_FILE_NAME,DummyGenerator.GIVEN_FILE_URL); doReturn(tmpFile).when(awsS3Uploader).singleUpload(any(MultipartFile.class)); doReturn(List.of(tmpFile)).when(awsS3Uploader).multiUpload(any()); } From 9a8f4c69b65ee5c4bbc1518931e996f72bd2a07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:08:09 +0900 Subject: [PATCH 181/215] =?UTF-8?q?refactor(docTests)=20:=20Doc=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/docs/AuthDocTest.java | 217 ++++++++------- .../com/aliens/backend/docs/BlockDocTest.java | 75 +++++ .../com/aliens/backend/docs/ChatDocTest.java | 235 +++++++--------- .../com/aliens/backend/docs/EmailDocTest.java | 261 +++++++++--------- .../aliens/backend/docs/MatchingDocTest.java | 74 +++++ .../aliens/backend/docs/ReportDocTest.java | 80 ++++++ 6 files changed, 569 insertions(+), 373 deletions(-) create mode 100644 src/test/java/com/aliens/backend/docs/BlockDocTest.java create mode 100644 src/test/java/com/aliens/backend/docs/MatchingDocTest.java create mode 100644 src/test/java/com/aliens/backend/docs/ReportDocTest.java diff --git a/src/test/java/com/aliens/backend/docs/AuthDocTest.java b/src/test/java/com/aliens/backend/docs/AuthDocTest.java index c612434c..7be98206 100644 --- a/src/test/java/com/aliens/backend/docs/AuthDocTest.java +++ b/src/test/java/com/aliens/backend/docs/AuthDocTest.java @@ -1,104 +1,113 @@ -package com.aliens.backend.docs; - -import com.aliens.backend.auth.controller.dto.AuthToken; -import com.aliens.backend.auth.controller.dto.LoginRequest; -import com.aliens.backend.auth.service.AuthService; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; -import static org.springframework.restdocs.payload.PayloadDocumentation.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@AutoConfigureMockMvc -@AutoConfigureRestDocs -@SpringBootTest -class AuthDocTest { - - @Autowired - private MockMvc mockMvc; - - @MockBean - private AuthService authService; - - @Test - @DisplayName("로그인 API 테스트") - void login() throws Exception { - final LoginRequest request = new LoginRequest("email","password"); - final AuthToken response = new AuthToken("accessToken", "refreshToken"); - when(authService.login(any())).thenReturn(response); - - ObjectMapper objectMapper = new ObjectMapper(); - this.mockMvc.perform(post("/authentication") - .content(objectMapper.writeValueAsString(request)) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andDo(document("auth-login", - requestFields( - fieldWithPath("email").description("이메일"), - fieldWithPath("password").description("비밀번호") - ), - - responseFields( - fieldWithPath("accessToken").description("발급된 엑세스토큰"), - fieldWithPath("refreshToken").description("발급된 리프레쉬토큰") - ) - )); - } - - @Test - @DisplayName("로그아웃 API 테스트") - void logout() throws Exception { - final AuthToken request = new AuthToken("accessToken", "refreshToken"); - final String response = AuthService.LOGOUT_SUCCESS; - when(authService.logout(any())).thenReturn(response); - - ObjectMapper objectMapper = new ObjectMapper(); - this.mockMvc.perform(post("/authentication/logout") - .content(objectMapper.writeValueAsString(request)) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andDo(document("auth-logout", - requestFields( - fieldWithPath("accessToken").description("엑세스토큰"), - fieldWithPath("refreshToken").description("리프레쉬토큰") - ) - )); - } - - @Test - @DisplayName("토큰 재발급 API 테스트") - void reissue() throws Exception { - final AuthToken request = new AuthToken("expiredAccessToken", "refreshToken"); - final AuthToken response = new AuthToken("newAccessToken", "refreshToken"); - when(authService.reissue(any())).thenReturn(response); - - ObjectMapper objectMapper = new ObjectMapper(); - this.mockMvc.perform(post("/authentication/reissue") - .content(objectMapper.writeValueAsString(request)) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andDo(document("auth-reissue", - requestFields( - fieldWithPath("accessToken").description("만료된 엑세스토큰"), - fieldWithPath("refreshToken").description("재발급을 위한 리프레쉬토큰") - ), - - responseFields( - fieldWithPath("accessToken").description("새로 발급된 엑세스토큰"), - fieldWithPath("refreshToken").description("기존의 리프레쉬토큰") - ) - )); - } -} +//package com.aliens.backend.auth.controller; +// +//import com.aliens.backend.auth.controller.dto.AuthToken; +//import com.aliens.backend.auth.controller.dto.LoginRequest; +//import com.aliens.backend.auth.service.AuthService; +//import com.aliens.backend.global.response.SuccessResponse; +//import com.aliens.backend.global.response.success.AuthSuccess; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.mock.mockito.SpyBean; +//import org.springframework.http.MediaType; +//import org.springframework.test.web.servlet.MockMvc; +// +//import static org.mockito.ArgumentMatchers.any; +//import static org.mockito.Mockito.doReturn; +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +//import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +//import static org.springframework.restdocs.payload.PayloadDocumentation.*; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@AutoConfigureMockMvc +//@AutoConfigureRestDocs +//@SpringBootTest +//class AuthDocTest { +// +// @Autowired +// protected MockMvc mockMvc; +// +// @SpyBean +// private AuthController authController; +// +// ObjectMapper objectMapper = new ObjectMapper(); +// +// @Test +// @DisplayName("API - 로그인") +// void login() throws Exception { +// final LoginRequest request = new LoginRequest("email","password"); +// final AuthToken authToken = new AuthToken("accessToken", "refreshToken"); +// SuccessResponse response = SuccessResponse.of(AuthSuccess.GENERATE_TOKEN_SUCCESS,authToken); +// +// doReturn(response).when(authController).login(any()); +// +// this.mockMvc.perform(post("/authentication") +// .content(objectMapper.writeValueAsString(request)) +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andDo(document("auth-login", +// requestFields( +// fieldWithPath("email").description("이메일"), +// fieldWithPath("password").description("비밀번호") +// ), +// +// responseFields( +// fieldWithPath("code").description("응답 코드"), +// fieldWithPath("result.accessToken").description("발급된 엑세스토큰"), +// fieldWithPath("result.refreshToken").description("발급된 리프레쉬토큰") +// ) +// )); +// } +// +// @Test +// @DisplayName("API -로그아웃") +// void logout() throws Exception { +// final AuthToken request = new AuthToken("accessToken", "refreshToken"); +// final String message = AuthService.LOGOUT_SUCCESS; +// SuccessResponse response = SuccessResponse.of(AuthSuccess.LOGOUT_SUCCESS, message); +// +// doReturn(response).when(authController).logout(any()); +// +// this.mockMvc.perform(post("/authentication/logout") +// .content(objectMapper.writeValueAsString(request)) +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andDo(document("auth-logout", +// requestFields( +// fieldWithPath("accessToken").description("엑세스토큰"), +// fieldWithPath("refreshToken").description("리프레쉬토큰") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - 토큰 재발급") +// void reissue() throws Exception { +// final AuthToken request = new AuthToken("expiredAccessToken", "refreshToken"); +// final AuthToken result = new AuthToken("newAccessToken", "refreshToken"); +// SuccessResponse response = SuccessResponse.of(AuthSuccess.REISSUE_TOKEN_SUCCESS, result); +// +// doReturn(response).when(authController).reissue(any()); +// +// this.mockMvc.perform(post("/authentication/reissue") +// .content(objectMapper.writeValueAsString(request)) +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andDo(document("auth-reissue", +// requestFields( +// fieldWithPath("accessToken").description("만료된 엑세스토큰"), +// fieldWithPath("refreshToken").description("재발급을 위한 리프레쉬토큰") +// ), +// +// responseFields( +// fieldWithPath("code").description("응답 코드"), +// fieldWithPath("result.accessToken").description("새로 발급된 엑세스토큰"), +// fieldWithPath("result.refreshToken").description("기존의 리프레쉬토큰") +// ) +// )); +// } +//} \ No newline at end of file diff --git a/src/test/java/com/aliens/backend/docs/BlockDocTest.java b/src/test/java/com/aliens/backend/docs/BlockDocTest.java new file mode 100644 index 00000000..0e5b7c70 --- /dev/null +++ b/src/test/java/com/aliens/backend/docs/BlockDocTest.java @@ -0,0 +1,75 @@ +//package com.aliens.backend.block.controller; +// +//import com.aliens.backend.auth.controller.dto.LoginMember; +//import com.aliens.backend.auth.domain.Member; +//import com.aliens.backend.auth.domain.MemberRole; +//import com.aliens.backend.auth.service.TokenProvider; +//import com.aliens.backend.block.controller.dto.ChatBlockRequest; +//import com.aliens.backend.global.BaseControllerTest; +//import com.aliens.backend.global.DummyGenerator; +//import com.aliens.backend.global.response.SuccessResponse; +//import com.aliens.backend.global.response.success.ChatSuccess; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.mock.mockito.MockBean; +//import org.springframework.boot.test.mock.mockito.SpyBean; +//import org.springframework.test.web.servlet.MockMvc; +// +//import static org.mockito.ArgumentMatchers.any; +//import static org.mockito.Mockito.doReturn; +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +//import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +//import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +//import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@AutoConfigureMockMvc +//@AutoConfigureRestDocs +//@SpringBootTest +//class BlockDocTest { +// +// @SpyBean BlockController blockController; +// +// @Autowired MockMvc mockMvc; +// @Autowired DummyGenerator dummyGenerator; +// +// ObjectMapper objectMapper = new ObjectMapper(); +// String GIVEN_ACCESS_TOKEN; +// +// @BeforeEach +// void setUp() { +// Member member = dummyGenerator.generateSingleMember(); +// GIVEN_ACCESS_TOKEN = dummyGenerator.generateAccessToken(member); +// } +// +// @Test +// @DisplayName("API - 채팅 상대 차단") +// void blockPartner() throws Exception { +// Long chatRoomId = 1L; +// Long memberId = 1L; +// ChatBlockRequest request = new ChatBlockRequest(memberId, chatRoomId); +// String message = ChatSuccess.BLOCK_SUCCESS.getMessage(); +// SuccessResponse response = SuccessResponse.of(ChatSuccess.REPORT_SUCCESS, message); +// +// doReturn(response).when(blockController).blockPartner(any(), any()); +// +// mockMvc.perform(post("/chat/block") +// .header("Authorization", GIVEN_ACCESS_TOKEN) +// .content(objectMapper.writeValueAsString(request)) +// .contentType("application/json") +// ) +// .andExpect(status().isOk()) +// .andDo(document("chat-block", +// responseFields( +// fieldWithPath("code").description("응답 코드"), +// fieldWithPath("result").description("채팅 상대 차단 결과") +// ) +// )); +// } +//} diff --git a/src/test/java/com/aliens/backend/docs/ChatDocTest.java b/src/test/java/com/aliens/backend/docs/ChatDocTest.java index 07225e4e..b8346e99 100644 --- a/src/test/java/com/aliens/backend/docs/ChatDocTest.java +++ b/src/test/java/com/aliens/backend/docs/ChatDocTest.java @@ -1,140 +1,95 @@ -package com.aliens.backend.docs; - -import com.aliens.backend.auth.service.TokenProvider; -import com.aliens.backend.chat.controller.dto.request.ChatBlockRequest; -import com.aliens.backend.chat.controller.dto.request.ChatReportRequest; -import com.aliens.backend.chat.controller.dto.response.ChatSummaryResponse; -import com.aliens.backend.chat.domain.Message; -import com.aliens.backend.chat.service.ChatBlockService; -import com.aliens.backend.chat.service.ChatReportService; -import com.aliens.backend.chat.service.ChatService; -import com.aliens.backend.global.success.ChatSuccessCode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.web.servlet.MockMvc; - -import java.util.ArrayList; -import java.util.List; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@AutoConfigureMockMvc -@AutoConfigureRestDocs -@SpringBootTest -class ChatDocTest { - @Autowired - private MockMvc mockMvc; - @MockBean - private ChatService chatService; - @MockBean - private ChatReportService chatReportService; - @MockBean - private ChatBlockService chatBlockService; - @MockBean - private TokenProvider tokenProvider; - - ObjectMapper objectMapper; - MockMultipartFile multipartFile; - String accessToken; - - @BeforeEach - void setUp() { - accessToken= "accessToken"; - objectMapper = new ObjectMapper(); - } - - @Test - @DisplayName("채팅 메시지 조회") - void getMessages() throws Exception { - Long chatRoomId = 1L; - List response = new ArrayList<>(); - when(chatService.getMessages(chatRoomId, null)).thenReturn(response); - - mockMvc.perform(get("/chat/room/{roomId}/messages", chatRoomId) - .header("Authorization", accessToken) - ) - .andExpect(status().isOk()) - .andDo(document("chat-get-messages", - responseFields( - fieldWithPath("response").description("메시지 목록 조회 결과") - ) - )); - } - - @Test - @DisplayName("채팅 요약 정보 조회") - void getChatSummary() throws Exception { - Long memberId = 1L; - ChatSummaryResponse response = new ChatSummaryResponse(new ArrayList<>(), new ArrayList<>()); - when(chatService.getChatSummaries(memberId)).thenReturn(response); - - mockMvc.perform(get("/chat/summaries") - .header("Authorization", accessToken) - ) - .andExpect(status().isOk()) - .andDo(document("chat-get-summary", - responseFields( - fieldWithPath("response").description("채팅방 요약 정보 조회 결과") - ) - )); - } - - @Test - @DisplayName("채팅 상대 신고") - void reportPartner() throws Exception { - Long memberId = 1L; - Long chatRoomId = 1L; - String reportCategory = "ETC"; - String reportContent = "신고 사유"; - ChatReportRequest request = new ChatReportRequest(memberId, chatRoomId, reportCategory, reportContent); - String response = ChatSuccessCode.REPORT_SUCCESS.getMessage(); - when(chatReportService.reportPartner(any(), any())).thenReturn(response); - mockMvc.perform(post("/chat/report") - .header("Authorization", accessToken) - .content(objectMapper.writeValueAsString(request)) - .contentType("application/json") - ) - .andExpect(status().isOk()) - .andDo(document("chat-report", - responseFields( - fieldWithPath("response").description("채팅 상대 신고 결과") - ) - )); - } - - @Test - @DisplayName("채팅 상대 차단") - void blockPartner() throws Exception { - Long chatRoomId = 1L; - Long memberId = 1L; - ChatBlockRequest request = new ChatBlockRequest(memberId, chatRoomId); - String response = ChatSuccessCode.BLOCK_SUCCESS.getMessage(); - when(chatBlockService.blockPartner(any(), any())).thenReturn(response); - mockMvc.perform(post("/chat/block") - .header("Authorization", accessToken) - .content(objectMapper.writeValueAsString(request)) - .contentType("application/json") - ) - .andExpect(status().isOk()) - .andDo(document("chat-block", - responseFields( - fieldWithPath("response").description("채팅 상대 차단 결과") - ) - )); - } -} \ No newline at end of file +//package com.aliens.backend.chatting.controller; +// +//import com.aliens.backend.auth.domain.Member; +//import com.aliens.backend.chat.controller.ChatController; +//import com.aliens.backend.chat.controller.dto.response.ChatSummaryResponse; +//import com.aliens.backend.chat.domain.Message; +//import com.aliens.backend.global.DummyGenerator; +//import com.aliens.backend.global.response.SuccessResponse; +//import com.aliens.backend.global.response.success.ChatSuccess; +//import com.aliens.backend.global.response.success.SuccessCode; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.mock.mockito.SpyBean; +//import org.springframework.test.web.servlet.MockMvc; +// +//import java.util.ArrayList; +//import java.util.List; +// +//import static org.mockito.ArgumentMatchers.any; +//import static org.mockito.Mockito.doReturn; +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +//import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +//import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +//import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@AutoConfigureMockMvc +//@AutoConfigureRestDocs +//@SpringBootTest +//class ChatDocTest { +// +// @SpyBean +// private ChatController chatController; +// +// @Autowired +// MockMvc mockMvc; +// +// @Autowired +// DummyGenerator dummyGenerator; +// +// String GIVEN_ACCESS_TOKEN; +// +// @BeforeEach +// void setUp() { +// Member member = dummyGenerator.generateSingleMember(); +// GIVEN_ACCESS_TOKEN = dummyGenerator.generateAccessToken(member); +// } +// +// @Test +// @DisplayName("API - 채팅 메시지 조회") +// void getMessages() throws Exception { +// Long chatRoomId = 1L; +// List result = new ArrayList<>(); +// SuccessResponse> response = SuccessResponse.of(ChatSuccess.GET_MESSAGES_SUCCESS, result); +// doReturn(response).when(chatController).getMessages(any(),any()); +// +// mockMvc.perform(get("/chat/room/{roomId}/messages", chatRoomId) +// .header("Authorization", GIVEN_ACCESS_TOKEN) +// ) +// .andExpect(status().isOk()) +// .andDo(document("chat-get-messages", +// responseFields( +// fieldWithPath("code").description("응답 코드"), +// fieldWithPath("result").description("메시지 목록 조회 결과") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - 채팅 요약 정보 조회") +// void getChatSummary() throws Exception { +// ChatSummaryResponse result = new ChatSummaryResponse(new ArrayList<>(), new ArrayList<>()); +// SuccessResponse response = SuccessResponse.of(ChatSuccess.GET_SUMMARIES_SUCCESS, result); +// doReturn(response).when(chatController).getChatSummaries(any()); +// +// +// mockMvc.perform(get("/chat/summaries") +// .header("Authorization", GIVEN_ACCESS_TOKEN) +// ) +// .andExpect(status().isOk()) +// .andDo(document("chat-get-summary", +// responseFields( +// fieldWithPath("code").description("응답 코드"), +// fieldWithPath("result").description("조회 결과"), +// fieldWithPath("result.chatRooms").description("채팅방 정보"), +// fieldWithPath("result.chatMessageSummaries").description("채팅방 요약 정보 조회 결과") +// ) +// )); +// } +//} \ No newline at end of file diff --git a/src/test/java/com/aliens/backend/docs/EmailDocTest.java b/src/test/java/com/aliens/backend/docs/EmailDocTest.java index 23659462..37b05c27 100644 --- a/src/test/java/com/aliens/backend/docs/EmailDocTest.java +++ b/src/test/java/com/aliens/backend/docs/EmailDocTest.java @@ -1,129 +1,132 @@ -package com.aliens.backend.docs; - -import com.aliens.backend.email.controller.response.EmailResponse; -import com.aliens.backend.email.service.EmailService; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import java.util.Collections; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; -import static org.springframework.restdocs.payload.PayloadDocumentation.*; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; -import static org.springframework.restdocs.request.RequestDocumentation.queryParameters; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@AutoConfigureMockMvc -@AutoConfigureRestDocs -@SpringBootTest -class EmailDocTest { - - @Autowired - private MockMvc mockMvc; - - @MockBean - private EmailService emailService; - - private ObjectMapper objectMapper; - - @BeforeEach - void setUp() { - objectMapper = new ObjectMapper(); - } - - @Test - @DisplayName("이메일 중복 API 테스트 - 사용불가") - void duplicateCheckSuccess() throws Exception { - final String request = "tmp@example.com"; - final String response = EmailResponse.DUPLICATED_EMAIL.getMessage(); - - when(emailService.duplicateCheck(any())).thenReturn(response); - - this.mockMvc.perform(get("/members/exist").param("email", request)) - .andExpect(status().isOk()) - .andDo(document("email-duplicateCheck-duplicate", - queryParameters( - parameterWithName("email").description("검증 요청 이메일") - ), - responseFields( - fieldWithPath("response").description("검증 결과") - ) - )); - } - - @Test - @DisplayName("이메일 중복 API 테스트 - 사용가능") - void duplicateCheckFail() throws Exception { - final String request = "tmp@example.com"; - final String response = EmailResponse.AVAILABLE_EMAIL.getMessage(); - - when(emailService.duplicateCheck(any())).thenReturn(response); - - this.mockMvc.perform(get("/members/exist").param("email", request)) - .andExpect(status().isOk()) - .andDo(document("email-duplicateCheck-available", - queryParameters( - parameterWithName("email").description("검증 요청 이메일") - ), - responseFields( - fieldWithPath("response").description("검증 결과") - ) - )); - } - - @Test - @DisplayName("인증 이메일 전송 API 테스트") - void sendAuthenticationEmail() throws Exception { - final String email = "tmp@example.com"; - final String response = EmailResponse.EMAIL_SEND_SUCCESS.getMessage(); - - when(emailService.sendAuthenticationEmail(any())).thenReturn(response); - - this.mockMvc.perform(post("/emails/verification/send") - .content(objectMapper.writeValueAsString(Collections.singletonMap("email", email))) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andDo(document("email-verification-send", - requestFields( - fieldWithPath("email").description("검증 요청 이메일") - ), - responseFields( - fieldWithPath("response").description("전송 결과") - ) - )); - } - - @Test - @DisplayName("이메일 검증 요청 API 테스트") - void authenticateEmail() throws Exception { - final String request = "testToken"; - final String response = EmailResponse.EMAIL_AUTHENTICATION_SUCCESS.getMessage(); - - when(emailService.authenticateEmail(any())).thenReturn(response); - - this.mockMvc.perform(get("/emails/confirm").param("token", request)) - .andExpect(status().isOk()) - .andDo(document("email-authentication-success", - queryParameters( - parameterWithName("token").description("이메일 검증을 위한 토큰") - ), - responseFields( - fieldWithPath("response").description("검증 결과") - ) - )); - } -} +//package com.aliens.backend.docs; +// +//import com.aliens.backend.email.controller.EmailController; +//import com.aliens.backend.email.controller.response.EmailResponse; +//import com.aliens.backend.global.response.SuccessResponse; +//import com.aliens.backend.global.response.success.EmailSuccess; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.mock.mockito.SpyBean; +//import org.springframework.http.MediaType; +//import org.springframework.test.web.servlet.MockMvc; +// +//import java.util.Collections; +// +//import static org.mockito.ArgumentMatchers.any; +//import static org.mockito.Mockito.doReturn; +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +//import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +//import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +//import static org.springframework.restdocs.payload.PayloadDocumentation.*; +//import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +//import static org.springframework.restdocs.request.RequestDocumentation.queryParameters; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@AutoConfigureMockMvc +//@AutoConfigureRestDocs +//@SpringBootTest +//class EmailDocTest { +// +// @Autowired +// protected MockMvc mockMvc; +// +// @SpyBean +// private EmailController emailController; +// +// ObjectMapper objectMapper = new ObjectMapper(); +// +// @Test +// @DisplayName("API - 이메일 중복(사용불가)") +// void duplicateCheckSuccess() throws Exception { +// final String request = "tmp@example.com"; +// final String message = EmailResponse.DUPLICATED_EMAIL.getMessage(); +// +// SuccessResponse response = SuccessResponse.of(EmailSuccess.DUPLICATE_CHECK_SUCCESS, message); +// doReturn(response).when(emailController).duplicateCheck(any()); +// +// this.mockMvc.perform(get("/members/exist").param("email", request)) +// .andExpect(status().isOk()) +// .andDo(document("email-duplicateCheck-duplicate", +// queryParameters( +// parameterWithName("email").description("검증 요청 이메일") +// ), +// responseFields( +// fieldWithPath("code").description("응답 코드"), +// fieldWithPath("result").description("응답 결과") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - 이메일 중복 API 테스트(사용가능)") +// void duplicateCheckFail() throws Exception { +// final String request = "tmp@example.com"; +// final String message = EmailResponse.AVAILABLE_EMAIL.getMessage(); +// +// SuccessResponse response = SuccessResponse.of(EmailSuccess.DUPLICATE_CHECK_SUCCESS, message); +// doReturn(response).when(emailController).duplicateCheck(any()); +// +// this.mockMvc.perform(get("/members/exist").param("email", request)) +// .andExpect(status().isOk()) +// .andDo(document("email-duplicateCheck-available", +// queryParameters( +// parameterWithName("email").description("검증 요청 이메일") +// ), +// responseFields( +// fieldWithPath("code").description("응답 코드"), +// fieldWithPath("result").description("응답 결과") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - 인증 이메일 전송") +// void sendAuthenticationEmail() throws Exception { +// final String email = "tmp@example.com"; +// final String message = EmailResponse.EMAIL_SEND_SUCCESS.getMessage(); +// +// SuccessResponse response = SuccessResponse.of(EmailSuccess.SEND_EMAIL_SUCCESS, message); +// doReturn(response).when(emailController).sendAuthenticationEmail(any()); +// +// this.mockMvc.perform(post("/emails/verification/send") +// .content(objectMapper.writeValueAsString(Collections.singletonMap("email", email))) +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andDo(document("email-verification-send", +// requestFields( +// fieldWithPath("email").description("검증 요청 이메일") +// ), +// responseFields( +// fieldWithPath("code").description("응답 코드"), +// fieldWithPath("result").description("응답 결과") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - 이메일 검증 요청") +// void authenticateEmail() throws Exception { +// final String request = "testToken"; +// final String message = EmailResponse.EMAIL_AUTHENTICATION_SUCCESS.getMessage(); +// +// SuccessResponse response = SuccessResponse.of(EmailSuccess.EMAIL_AUTHENTICATE_SUCCESS, message); +// doReturn(response).when(emailController).authenticateEmail(any()); +// +// this.mockMvc.perform(get("/emails/confirm").param("token", request)) +// .andExpect(status().isOk()) +// .andDo(document("email-authentication-success", +// queryParameters( +// parameterWithName("token").description("이메일 검증을 위한 토큰") +// ), +// responseFields( +// fieldWithPath("code").description("응답 코드"), +// fieldWithPath("result").description("응답 결과") +// ) +// )); +// } +//} diff --git a/src/test/java/com/aliens/backend/docs/MatchingDocTest.java b/src/test/java/com/aliens/backend/docs/MatchingDocTest.java new file mode 100644 index 00000000..755768bd --- /dev/null +++ b/src/test/java/com/aliens/backend/docs/MatchingDocTest.java @@ -0,0 +1,74 @@ +//package com.aliens.backend.matching.controller; +// +//import com.aliens.backend.auth.domain.Member; +//import com.aliens.backend.global.DummyGenerator; +//import com.aliens.backend.global.response.SuccessResponse; +//import com.aliens.backend.global.response.success.MatchingSuccess; +//import com.aliens.backend.mathcing.controller.MatchingController; +//import com.aliens.backend.mathcing.service.model.Language; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.mock.mockito.SpyBean; +//import org.springframework.http.MediaType; +//import org.springframework.test.web.servlet.MockMvc; +// +// +//import static com.aliens.backend.mathcing.controller.dto.input.MatchingInput.*; +//import static org.mockito.ArgumentMatchers.any; +//import static org.mockito.Mockito.doReturn; +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +//import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +//import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@AutoConfigureMockMvc +//@AutoConfigureRestDocs +//@SpringBootTest +//class MatchingDocTest { +// +// @Autowired +// MockMvc mockMvc; +// @SpyBean +// MatchingController matchingController; +// @Autowired +// DummyGenerator dummyGenerator; +// +// ObjectMapper objectMapper = new ObjectMapper(); +// String GIVEN_ACCESS_TOKEN; +// +// @BeforeEach +// void setUp() { +// Member member = dummyGenerator.generateSingleMember(); +// GIVEN_ACCESS_TOKEN = dummyGenerator.generateAccessToken(member); +// } +// +// @Test +// @DisplayName("API - 매칭 신청") +// void applyMatchApiTest() throws Exception { +// MatchingApplicationInput request = MatchingApplicationInput.of(Language.KOREAN, Language.ENGLISH); +// String message = MatchingSuccess.APPLY_MATCHING_SUCCESS.getMessage(); +// SuccessResponse response = SuccessResponse.of(MatchingSuccess.APPLY_MATCHING_SUCCESS, message); +// doReturn(response).when(matchingController).applyMatch(any(), any()); +// +// +// mockMvc.perform(post("/matchings/applications") +// .header("Authorization", GIVEN_ACCESS_TOKEN) +// .content(objectMapper.writeValueAsString(request)) +// .contentType(MediaType.APPLICATION_JSON) +// ) +// .andExpect(status().isOk()) +// .andDo(document("post-matching-application", +// responseFields( +// fieldWithPath("code").description("성공 코드"), +// fieldWithPath("result").description("매칭 신청 결과") +// ) +// )); +// } +//} diff --git a/src/test/java/com/aliens/backend/docs/ReportDocTest.java b/src/test/java/com/aliens/backend/docs/ReportDocTest.java new file mode 100644 index 00000000..b4955bf1 --- /dev/null +++ b/src/test/java/com/aliens/backend/docs/ReportDocTest.java @@ -0,0 +1,80 @@ +//package com.aliens.backend.chatting.controller; +// +//import com.aliens.backend.auth.domain.Member; +//import com.aliens.backend.chat.controller.ChatReportController; +//import com.aliens.backend.chat.controller.dto.request.ChatReportRequest; +//import com.aliens.backend.chat.domain.ChatReportCategory; +//import com.aliens.backend.chat.service.ChatReportService; +//import com.aliens.backend.global.DummyGenerator; +//import com.aliens.backend.global.response.SuccessResponse; +//import com.aliens.backend.global.response.success.ChatSuccess; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.mock.mockito.SpyBean; +//import org.springframework.test.web.servlet.MockMvc; +// +//import static org.mockito.ArgumentMatchers.any; +//import static org.mockito.Mockito.doReturn; +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +//import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +//import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +//import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@AutoConfigureMockMvc +//@AutoConfigureRestDocs +//@SpringBootTest +//class ReportDocTest { +// +// @SpyBean +// private ChatReportController chatReportController; +// +// @Autowired +// MockMvc mockMvc; +// +// @Autowired +// DummyGenerator dummyGenerator; +// +// ObjectMapper objectMapper = new ObjectMapper(); +// String GIVEN_ACCESS_TOKEN; +// +// @BeforeEach +// void setUp() { +// Member member = dummyGenerator.generateSingleMember(); +// GIVEN_ACCESS_TOKEN = dummyGenerator.generateAccessToken(member); +// } +// +// +// @Test +// @DisplayName("API - 채팅 상대 신고") +// void reportPartner() throws Exception { +// Long memberId = 1L; +// Long chatRoomId = 1L; +// ChatReportCategory category = ChatReportCategory.ETC; +// String reportContent = "신고 사유"; +// ChatReportRequest request = new ChatReportRequest(memberId, chatRoomId, category, reportContent); +// +// String message = ChatSuccess.REPORT_SUCCESS.getMessage(); +// SuccessResponse response = SuccessResponse.of(ChatSuccess.REPORT_SUCCESS, message); +// doReturn(response).when(chatReportController).reportPartner(any(), any()); +// +// mockMvc.perform(post("/chat/report") +// .header("Authorization", GIVEN_ACCESS_TOKEN) +// .content(objectMapper.writeValueAsString(request)) +// .contentType("application/json") +// ) +// .andExpect(status().isOk()) +// .andDo(document("chat-report", +// responseFields( +// fieldWithPath("code").description("응답 코드"), +// fieldWithPath("result").description("채팅 상대 신고 결과") +// ) +// )); +// } +//} From 7c30e0c50e7f15a50e46bb67926ecff717c258bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:08:43 +0900 Subject: [PATCH 182/215] =?UTF-8?q?feat(EmailSuccess)=20:=20=EC=9D=B4?= =?UTF-8?q?=EB=A9=94=EC=9D=BC=20=EA=B4=80=EB=A0=A8=20=EC=84=B1=EA=B3=B5?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/response/success/EmailSuccess.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/com/aliens/backend/global/response/success/EmailSuccess.java diff --git a/src/main/java/com/aliens/backend/global/response/success/EmailSuccess.java b/src/main/java/com/aliens/backend/global/response/success/EmailSuccess.java new file mode 100644 index 00000000..b08797b9 --- /dev/null +++ b/src/main/java/com/aliens/backend/global/response/success/EmailSuccess.java @@ -0,0 +1,34 @@ +package com.aliens.backend.global.response.success; + +import org.springframework.http.HttpStatus; + +public enum EmailSuccess implements SuccessCode { + DUPLICATE_CHECK_SUCCESS(HttpStatus.OK, "E001", "이메일 중복검사가 성공했습니다."), + SEND_EMAIL_SUCCESS(HttpStatus.OK, "E002", "인증 이메일이 전송되었습니다."), + EMAIL_AUTHENTICATE_SUCCESS(HttpStatus.OK, "E003", "이메일 인증에 성공했습니다."); + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + EmailSuccess(final HttpStatus httpStatus, final String code, final String message) { + this.httpStatus = httpStatus; + this.code = code; + this.message = message; + } + + @Override + public HttpStatus getHttpStatus() { + return httpStatus; + } + + @Override + public String getCode() { + return code; + } + + @Override + public String getMessage() { + return message; + } +} From 26e1211a3e7b0be464b287418fe560db73a75bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:09:54 +0900 Subject: [PATCH 183/215] =?UTF-8?q?refactor(WebSocketTest)=20:=20=EB=8D=94?= =?UTF-8?q?=EB=AF=B8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=A5=BC=20=ED=86=B5?= =?UTF-8?q?=ED=95=B4=20=EC=8B=A4=EC=A0=9C=EB=A1=9C=20=EC=A0=91=EA=B7=BC?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=ED=97=A4=EB=8D=94=EB=A5=BC=20?= =?UTF-8?q?=EC=82=BD=EC=9E=85=20=EB=B0=8F=20Mock=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EB=8C=80=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #50 --- .../chatting/{ => socket}/WebSocketTest.java | 87 +++++++++++-------- 1 file changed, 50 insertions(+), 37 deletions(-) rename src/test/java/com/aliens/backend/chatting/{ => socket}/WebSocketTest.java (57%) diff --git a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java b/src/test/java/com/aliens/backend/chatting/socket/WebSocketTest.java similarity index 57% rename from src/test/java/com/aliens/backend/chatting/WebSocketTest.java rename to src/test/java/com/aliens/backend/chatting/socket/WebSocketTest.java index e7a4cc84..27dfe34b 100644 --- a/src/test/java/com/aliens/backend/chatting/WebSocketTest.java +++ b/src/test/java/com/aliens/backend/chatting/socket/WebSocketTest.java @@ -1,12 +1,11 @@ -package com.aliens.backend.chatting; +package com.aliens.backend.chatting.socket; -import com.aliens.backend.auth.controller.dto.LoginMember; -import com.aliens.backend.auth.domain.MemberRole; -import com.aliens.backend.auth.service.TokenProvider; +import com.aliens.backend.auth.domain.Member; import com.aliens.backend.chat.controller.ChatController; import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; import com.aliens.backend.chat.controller.dto.request.ReadRequest; -import com.aliens.backend.chatting.util.ChatClient; +import com.aliens.backend.chat.domain.MessageType; +import com.aliens.backend.global.DummyGenerator; import com.aliens.backend.global.property.WebSocketProperties; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; @@ -14,69 +13,83 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.messaging.simp.stomp.StompSession; import static org.mockito.Mockito.*; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class WebSocketTest { +class WebSocketTest { @Autowired private WebSocketProperties properties; - @MockBean + + @SpyBean private ChatController chatController; - @MockBean - private TokenProvider tokenProvider; + + @Autowired + DummyGenerator dummyGenerator; + private ChatClient chatClient; - private ObjectMapper objectMapper = new ObjectMapper(); + private final ObjectMapper objectMapper = new ObjectMapper(); + private String accessToken ; @BeforeEach - public void setup() { - LoginMember loginMember = new LoginMember(1L, MemberRole.MEMBER); - when(tokenProvider.getLoginMemberFromToken(any())).thenReturn(loginMember); + void setup() { + Member member = dummyGenerator.generateSingleMember(); + accessToken = dummyGenerator.generateAccessToken(member); chatClient = new ChatClient(properties); } @Test - @DisplayName("웹소켓 - 연결") - public void WebSocketConnection() throws Exception { - //when - StompSession session = chatClient.connect(); - //then + @DisplayName("Websocket - 연결") + void WebSocketConnection() throws Exception { + // When + StompSession session = chatClient.connect(accessToken); + + // Then assert session.isConnected(); } @Test - @DisplayName("웹소켓 - 메시지 전송 요청시 sendMessage() 호출") - public void WebSocketSendMessage() throws Exception { - //given - StompSession session = chatClient.connect(); - String type = "NORMAL"; - String content = "Hello"; - Long roomId = 1L; - Long senderId = 1L; - Long receiverId = 2L; - MessageSendRequest messageSendRequest = new MessageSendRequest(type, content, roomId, senderId, receiverId); + @DisplayName("Websocket - 메시지 전송 요청시 sendMessage() 호출") + void WebSocketSendMessage() throws Exception { + //Given + StompSession session = chatClient.connect(accessToken); + MessageSendRequest messageSendRequest = makeMessageSendRequest(); String jsonMessage = objectMapper.writeValueAsString(messageSendRequest); - //when + + //When session.send(properties.getAppDestinationPrefix()+"/send", jsonMessage.getBytes()); - //then + + //Then verify(chatController, timeout(100).times(1)).sendMessage(messageSendRequest); } @Test - @DisplayName("웹소켓 - 읽음 처리 요청 시 readMessage() 호출") - public void WebSocketReadMessage() throws Exception { - //given + @DisplayName("Websocket - 읽음 처리 요청 시 readMessage() 호출") + void WebSocketReadMessage() throws Exception { + //Given Long chatRoomId = 1L; Long memberId = 1L; ReadRequest readRequest = new ReadRequest(chatRoomId, memberId); String jsonMessage = objectMapper.writeValueAsString(readRequest); - StompSession session = chatClient.connect(); - //when + StompSession session = chatClient.connect(accessToken); + + //When session.send(properties.getAppDestinationPrefix()+"/read", jsonMessage.getBytes()); - //then + + //Then verify(chatController, timeout(100).times(1)).readMessage(readRequest); } + + private MessageSendRequest makeMessageSendRequest() { + MessageType type = MessageType.NORMAL; + String content = "Hello"; + Long roomId = 1L; + Long senderId = 1L; + Long receiverId = 2L; + MessageSendRequest messageSendRequest = new MessageSendRequest(type, content, roomId, senderId, receiverId); + return messageSendRequest; + } } \ No newline at end of file From af99187449b7efd8a5db3452fcd15bc1064aa116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:18:31 +0900 Subject: [PATCH 184/215] =?UTF-8?q?refactor(response)=20:=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EA=B0=9D=EC=B2=B4=EB=A5=BC=20global=20=EB=94=94?= =?UTF-8?q?=EB=A0=89=ED=86=A0=EB=A6=AC=EC=97=90=EC=84=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99=ED=95=A8=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #44 --- .../aliens/backend/auth/service/AuthService.java | 4 ++-- .../backend/auth/service/PasswordEncoder.java | 2 +- .../backend/auth/service/TokenProvider.java | 2 +- .../backend/chat/service/ChatAuthValidator.java | 2 +- .../aliens/backend/chat/service/ChatService.java | 6 +++--- .../backend/email/service/EmailService.java | 2 +- .../aliens/backend/global/config/FCMConfig.java | 2 +- .../global/exception/ApiExceptionHandler.java | 7 ++----- .../global/exception/GlobalExceptionHandler.java | 2 +- .../global/exception/RestApiException.java | 3 ++- .../global/property/MatchingTimeProperties.java | 2 -- .../global/{ => response}/error/ChatError.java | 2 +- .../global/{ => response}/error/CommonError.java | 2 +- .../global/{ => response}/error/EmailError.java | 2 +- .../global/{ => response}/error/ErrorCode.java | 2 +- .../{ => response}/error/MatchingError.java | 2 +- .../global/{ => response}/error/MemberError.java | 2 +- .../global/{ => response}/error/TokenError.java | 2 +- .../success/AuthSuccess.java} | 11 +++++------ .../success/ChatSuccess.java} | 15 ++++++++------- .../success/MatchingSuccess.java} | 8 ++++---- .../success/MemberSuccess.java} | 8 ++++---- .../{ => response}/success/SuccessCode.java | 2 +- .../controller/dto/input/MatchingInput.java | 2 +- .../backend/mathcing/service/MatchingService.java | 2 +- .../mathcing/service/model/Participant.java | 2 +- .../backend/member/sevice/MemberInfoService.java | 4 ++-- .../member/sevice/SymmetricKeyEncoder.java | 2 +- .../aliens/backend/notification/FcmSender.java | 2 +- .../service/MatchingRoundServiceTest.java | 6 +++--- .../{unit => }/service/MatchingServiceTest.java | 7 +++---- 31 files changed, 57 insertions(+), 62 deletions(-) rename src/main/java/com/aliens/backend/global/{ => response}/error/ChatError.java (95%) rename src/main/java/com/aliens/backend/global/{ => response}/error/CommonError.java (95%) rename src/main/java/com/aliens/backend/global/{ => response}/error/EmailError.java (94%) rename src/main/java/com/aliens/backend/global/{ => response}/error/ErrorCode.java (76%) rename src/main/java/com/aliens/backend/global/{ => response}/error/MatchingError.java (96%) rename src/main/java/com/aliens/backend/global/{ => response}/error/MemberError.java (95%) rename src/main/java/com/aliens/backend/global/{ => response}/error/TokenError.java (95%) rename src/main/java/com/aliens/backend/global/{success/AuthSuccessCode.java => response/success/AuthSuccess.java} (59%) rename src/main/java/com/aliens/backend/global/{success/ChatSuccessCode.java => response/success/ChatSuccess.java} (51%) rename src/main/java/com/aliens/backend/global/{success/MatchingSuccessCode.java => response/success/MatchingSuccess.java} (74%) rename src/main/java/com/aliens/backend/global/{success/MemberSuccessCode.java => response/success/MemberSuccess.java} (82%) rename src/main/java/com/aliens/backend/global/{ => response}/success/SuccessCode.java (75%) rename src/test/java/com/aliens/backend/matching/{unit => }/service/MatchingRoundServiceTest.java (91%) rename src/test/java/com/aliens/backend/matching/{unit => }/service/MatchingServiceTest.java (89%) diff --git a/src/main/java/com/aliens/backend/auth/service/AuthService.java b/src/main/java/com/aliens/backend/auth/service/AuthService.java index 2bfaa408..3ad48edd 100644 --- a/src/main/java/com/aliens/backend/auth/service/AuthService.java +++ b/src/main/java/com/aliens/backend/auth/service/AuthService.java @@ -6,8 +6,8 @@ import com.aliens.backend.auth.domain.*; import com.aliens.backend.auth.domain.repository.MemberRepository; import com.aliens.backend.auth.domain.repository.TokenRepository; -import com.aliens.backend.global.error.MemberError; -import com.aliens.backend.global.error.TokenError; +import com.aliens.backend.global.response.error.MemberError; +import com.aliens.backend.global.response.error.TokenError; import com.aliens.backend.global.exception.RestApiException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/aliens/backend/auth/service/PasswordEncoder.java b/src/main/java/com/aliens/backend/auth/service/PasswordEncoder.java index 6092023e..08f8d4b4 100644 --- a/src/main/java/com/aliens/backend/auth/service/PasswordEncoder.java +++ b/src/main/java/com/aliens/backend/auth/service/PasswordEncoder.java @@ -1,6 +1,6 @@ package com.aliens.backend.auth.service; -import com.aliens.backend.global.error.MemberError; +import com.aliens.backend.global.response.error.MemberError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.PasswordEncodeProperties; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/aliens/backend/auth/service/TokenProvider.java b/src/main/java/com/aliens/backend/auth/service/TokenProvider.java index 0fc38ea0..843f62b8 100644 --- a/src/main/java/com/aliens/backend/auth/service/TokenProvider.java +++ b/src/main/java/com/aliens/backend/auth/service/TokenProvider.java @@ -2,7 +2,7 @@ import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.auth.domain.MemberRole; -import com.aliens.backend.global.error.TokenError; +import com.aliens.backend.global.response.error.TokenError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.JWTProperties; import io.jsonwebtoken.Claims; diff --git a/src/main/java/com/aliens/backend/chat/service/ChatAuthValidator.java b/src/main/java/com/aliens/backend/chat/service/ChatAuthValidator.java index f9f0c537..b2b7dee8 100644 --- a/src/main/java/com/aliens/backend/chat/service/ChatAuthValidator.java +++ b/src/main/java/com/aliens/backend/chat/service/ChatAuthValidator.java @@ -1,7 +1,7 @@ package com.aliens.backend.chat.service; import com.aliens.backend.chat.domain.ChatRoom; -import com.aliens.backend.global.error.ChatError; +import com.aliens.backend.global.response.error.ChatError; import com.aliens.backend.global.exception.RestApiException; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/aliens/backend/chat/service/ChatService.java b/src/main/java/com/aliens/backend/chat/service/ChatService.java index 9c76effb..b1c38606 100644 --- a/src/main/java/com/aliens/backend/chat/service/ChatService.java +++ b/src/main/java/com/aliens/backend/chat/service/ChatService.java @@ -9,7 +9,7 @@ import com.aliens.backend.chat.domain.repository.ChatRoomRepository; import com.aliens.backend.chat.domain.repository.MessageRepository; import com.aliens.backend.chat.service.model.ChatMessageSummary; -import com.aliens.backend.global.success.ChatSuccessCode; +import com.aliens.backend.global.response.success.ChatSuccess; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.stereotype.Service; @@ -32,13 +32,13 @@ public String sendMessage(MessageSendRequest messageSendRequest) { saveMessage(message); publishMessage(message, messageSendRequest.roomId()); sendNotification(message); - return ChatSuccessCode.SEND_MESSAGE_SUCCESS.getMessage(); + return ChatSuccess.SEND_MESSAGE_SUCCESS.getMessage(); } public String readMessages(ReadRequest readRequest) { updateReadState(readRequest.roomId(), readRequest.memberId()); publishReadState(readRequest.roomId(), readRequest.memberId()); - return ChatSuccessCode.READ_MESSAGES_SUCCESS.getMessage(); + return ChatSuccess.READ_MESSAGES_SUCCESS.getMessage(); } public ChatSummaryResponse getChatSummaries(Long memberId) { diff --git a/src/main/java/com/aliens/backend/email/service/EmailService.java b/src/main/java/com/aliens/backend/email/service/EmailService.java index 776c5973..2da1330f 100644 --- a/src/main/java/com/aliens/backend/email/service/EmailService.java +++ b/src/main/java/com/aliens/backend/email/service/EmailService.java @@ -4,7 +4,7 @@ import com.aliens.backend.email.domain.EmailAuthentication; import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; import com.aliens.backend.member.sevice.SymmetricKeyEncoder; -import com.aliens.backend.global.error.EmailError; +import com.aliens.backend.global.response.error.EmailError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.member.controller.dto.event.TemporaryPasswordEvent; import org.springframework.context.event.EventListener; diff --git a/src/main/java/com/aliens/backend/global/config/FCMConfig.java b/src/main/java/com/aliens/backend/global/config/FCMConfig.java index 5a8ca532..02d7ff0b 100644 --- a/src/main/java/com/aliens/backend/global/config/FCMConfig.java +++ b/src/main/java/com/aliens/backend/global/config/FCMConfig.java @@ -1,6 +1,6 @@ package com.aliens.backend.global.config; -import com.aliens.backend.global.error.CommonError; +import com.aliens.backend.global.response.error.CommonError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.FCMProperties; import com.google.auth.oauth2.GoogleCredentials; diff --git a/src/main/java/com/aliens/backend/global/exception/ApiExceptionHandler.java b/src/main/java/com/aliens/backend/global/exception/ApiExceptionHandler.java index 738d79e4..5eada3e5 100644 --- a/src/main/java/com/aliens/backend/global/exception/ApiExceptionHandler.java +++ b/src/main/java/com/aliens/backend/global/exception/ApiExceptionHandler.java @@ -1,6 +1,6 @@ package com.aliens.backend.global.exception; -import com.aliens.backend.global.error.ErrorCode; +import com.aliens.backend.global.response.error.ErrorCode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.annotation.Order; @@ -18,11 +18,8 @@ public class ApiExceptionHandler { public ResponseEntity apiException(RestApiException apiException) { ErrorCode errorCode = apiException.getErrorCode(); logger.info(errorCode.getMessage()); - return ResponseEntity .status(errorCode.getHttpStatus()) - .body( - errorCode.getDevelopCode() - ); + .body(errorCode.getDevelopCode()); } } \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/global/exception/GlobalExceptionHandler.java b/src/main/java/com/aliens/backend/global/exception/GlobalExceptionHandler.java index a764c412..be4f909c 100644 --- a/src/main/java/com/aliens/backend/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/aliens/backend/global/exception/GlobalExceptionHandler.java @@ -1,6 +1,6 @@ package com.aliens.backend.global.exception; -import com.aliens.backend.global.error.CommonError; +import com.aliens.backend.global.response.error.CommonError; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.annotation.Order; diff --git a/src/main/java/com/aliens/backend/global/exception/RestApiException.java b/src/main/java/com/aliens/backend/global/exception/RestApiException.java index 74b9deb3..dd558608 100644 --- a/src/main/java/com/aliens/backend/global/exception/RestApiException.java +++ b/src/main/java/com/aliens/backend/global/exception/RestApiException.java @@ -1,12 +1,13 @@ package com.aliens.backend.global.exception; -import com.aliens.backend.global.error.ErrorCode; +import com.aliens.backend.global.response.error.ErrorCode; public class RestApiException extends RuntimeException { private final ErrorCode errorCode; public RestApiException(final ErrorCode errorCode) { + super(errorCode.getDevelopCode()); this.errorCode = errorCode; } diff --git a/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java b/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java index 7be71410..e199d2ee 100644 --- a/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java +++ b/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java @@ -1,7 +1,5 @@ package com.aliens.backend.global.property; -import com.aliens.backend.global.error.MatchingError; -import com.aliens.backend.global.exception.RestApiException; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/aliens/backend/global/error/ChatError.java b/src/main/java/com/aliens/backend/global/response/error/ChatError.java similarity index 95% rename from src/main/java/com/aliens/backend/global/error/ChatError.java rename to src/main/java/com/aliens/backend/global/response/error/ChatError.java index a62faa48..d90cb6b7 100644 --- a/src/main/java/com/aliens/backend/global/error/ChatError.java +++ b/src/main/java/com/aliens/backend/global/response/error/ChatError.java @@ -1,4 +1,4 @@ -package com.aliens.backend.global.error; +package com.aliens.backend.global.response.error; import org.springframework.http.HttpStatus; diff --git a/src/main/java/com/aliens/backend/global/error/CommonError.java b/src/main/java/com/aliens/backend/global/response/error/CommonError.java similarity index 95% rename from src/main/java/com/aliens/backend/global/error/CommonError.java rename to src/main/java/com/aliens/backend/global/response/error/CommonError.java index d35b30df..14db5f83 100644 --- a/src/main/java/com/aliens/backend/global/error/CommonError.java +++ b/src/main/java/com/aliens/backend/global/response/error/CommonError.java @@ -1,4 +1,4 @@ -package com.aliens.backend.global.error; +package com.aliens.backend.global.response.error; import org.springframework.http.HttpStatus; diff --git a/src/main/java/com/aliens/backend/global/error/EmailError.java b/src/main/java/com/aliens/backend/global/response/error/EmailError.java similarity index 94% rename from src/main/java/com/aliens/backend/global/error/EmailError.java rename to src/main/java/com/aliens/backend/global/response/error/EmailError.java index 2d0ff139..1e0bde65 100644 --- a/src/main/java/com/aliens/backend/global/error/EmailError.java +++ b/src/main/java/com/aliens/backend/global/response/error/EmailError.java @@ -1,4 +1,4 @@ -package com.aliens.backend.global.error; +package com.aliens.backend.global.response.error; import org.springframework.http.HttpStatus; diff --git a/src/main/java/com/aliens/backend/global/error/ErrorCode.java b/src/main/java/com/aliens/backend/global/response/error/ErrorCode.java similarity index 76% rename from src/main/java/com/aliens/backend/global/error/ErrorCode.java rename to src/main/java/com/aliens/backend/global/response/error/ErrorCode.java index 6e658fe9..03ca619a 100644 --- a/src/main/java/com/aliens/backend/global/error/ErrorCode.java +++ b/src/main/java/com/aliens/backend/global/response/error/ErrorCode.java @@ -1,4 +1,4 @@ -package com.aliens.backend.global.error; +package com.aliens.backend.global.response.error; import org.springframework.http.HttpStatus; diff --git a/src/main/java/com/aliens/backend/global/error/MatchingError.java b/src/main/java/com/aliens/backend/global/response/error/MatchingError.java similarity index 96% rename from src/main/java/com/aliens/backend/global/error/MatchingError.java rename to src/main/java/com/aliens/backend/global/response/error/MatchingError.java index 96bc0678..88363e4d 100644 --- a/src/main/java/com/aliens/backend/global/error/MatchingError.java +++ b/src/main/java/com/aliens/backend/global/response/error/MatchingError.java @@ -1,4 +1,4 @@ -package com.aliens.backend.global.error; +package com.aliens.backend.global.response.error; import org.springframework.http.HttpStatus; diff --git a/src/main/java/com/aliens/backend/global/error/MemberError.java b/src/main/java/com/aliens/backend/global/response/error/MemberError.java similarity index 95% rename from src/main/java/com/aliens/backend/global/error/MemberError.java rename to src/main/java/com/aliens/backend/global/response/error/MemberError.java index d8ef8ac4..725b5819 100644 --- a/src/main/java/com/aliens/backend/global/error/MemberError.java +++ b/src/main/java/com/aliens/backend/global/response/error/MemberError.java @@ -1,4 +1,4 @@ -package com.aliens.backend.global.error; +package com.aliens.backend.global.response.error; import org.springframework.http.HttpStatus; diff --git a/src/main/java/com/aliens/backend/global/error/TokenError.java b/src/main/java/com/aliens/backend/global/response/error/TokenError.java similarity index 95% rename from src/main/java/com/aliens/backend/global/error/TokenError.java rename to src/main/java/com/aliens/backend/global/response/error/TokenError.java index 243c2501..26e242a6 100644 --- a/src/main/java/com/aliens/backend/global/error/TokenError.java +++ b/src/main/java/com/aliens/backend/global/response/error/TokenError.java @@ -1,4 +1,4 @@ -package com.aliens.backend.global.error; +package com.aliens.backend.global.response.error; import org.springframework.http.HttpStatus; diff --git a/src/main/java/com/aliens/backend/global/success/AuthSuccessCode.java b/src/main/java/com/aliens/backend/global/response/success/AuthSuccess.java similarity index 59% rename from src/main/java/com/aliens/backend/global/success/AuthSuccessCode.java rename to src/main/java/com/aliens/backend/global/response/success/AuthSuccess.java index 3f9e8ff2..f90b18b1 100644 --- a/src/main/java/com/aliens/backend/global/success/AuthSuccessCode.java +++ b/src/main/java/com/aliens/backend/global/response/success/AuthSuccess.java @@ -1,19 +1,18 @@ -package com.aliens.backend.global.success; +package com.aliens.backend.global.response.success; import org.springframework.http.HttpStatus; -public enum AuthSuccessCode implements SuccessCode { - GENERATE_AUTHTOKEN_SUCCESS(HttpStatus.CREATED, "A001", "인증 토큰 발행에 성공했습니다."), +public enum AuthSuccess implements SuccessCode { + GENERATE_TOKEN_SUCCESS(HttpStatus.OK, "A001", "인증 토큰 발행에 성공했습니다."), LOGOUT_SUCCESS(HttpStatus.OK, "A002", "로그아웃에 성공했습니다."), - REISSUE_AUTHTOKEN_SUCCESS(HttpStatus.CREATED, "A003", "토큰 재발급에 성공했습니다"), - + REISSUE_TOKEN_SUCCESS(HttpStatus.OK, "A003", "토큰 재발급에 성공했습니다"), ; private final HttpStatus httpStatus; private final String code; private final String message; - AuthSuccessCode(final HttpStatus httpStatus, final String code, final String message) { + AuthSuccess(final HttpStatus httpStatus, final String code, final String message) { this.httpStatus = httpStatus; this.code = code; this.message = message; diff --git a/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java b/src/main/java/com/aliens/backend/global/response/success/ChatSuccess.java similarity index 51% rename from src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java rename to src/main/java/com/aliens/backend/global/response/success/ChatSuccess.java index b4ca5944..ddd5182d 100644 --- a/src/main/java/com/aliens/backend/global/success/ChatSuccessCode.java +++ b/src/main/java/com/aliens/backend/global/response/success/ChatSuccess.java @@ -1,19 +1,20 @@ -package com.aliens.backend.global.success; +package com.aliens.backend.global.response.success; import org.springframework.http.HttpStatus; -public enum ChatSuccessCode implements SuccessCode { - SEND_MESSAGE_SUCCESS(HttpStatus.CREATED, "CH001", "메시지 전송 성공"), +public enum ChatSuccess implements SuccessCode { + SEND_MESSAGE_SUCCESS(HttpStatus.OK, "CH001", "메시지 전송 성공"), READ_MESSAGES_SUCCESS(HttpStatus.OK, "CH002", "메시지 읽음 처리 성공"), - REPORT_SUCCESS(HttpStatus.CREATED, "CH003", "신고 성공"), - BLOCK_SUCCESS(HttpStatus.CREATED, "CH004", "차단 성공") - ; + GET_SUMMARIES_SUCCESS(HttpStatus.OK, "CH003", "채팅요약 조회 성공"), + GET_MESSAGES_SUCCESS(HttpStatus.OK, "CH004", "채팅 메시지들 조회 성공"), + REPORT_SUCCESS(HttpStatus.OK, "CH005", "신고 성공"), + BLOCK_SUCCESS(HttpStatus.OK, "CH006", "차단 성공"); private final HttpStatus httpStatus; private final String code; private final String message; - ChatSuccessCode(final HttpStatus httpStatus, final String code, final String message) { + ChatSuccess(final HttpStatus httpStatus, final String code, final String message) { this.httpStatus = httpStatus; this.code = code; this.message = message; diff --git a/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java b/src/main/java/com/aliens/backend/global/response/success/MatchingSuccess.java similarity index 74% rename from src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java rename to src/main/java/com/aliens/backend/global/response/success/MatchingSuccess.java index b78b34de..84c918ba 100644 --- a/src/main/java/com/aliens/backend/global/success/MatchingSuccessCode.java +++ b/src/main/java/com/aliens/backend/global/response/success/MatchingSuccess.java @@ -1,9 +1,9 @@ -package com.aliens.backend.global.success; +package com.aliens.backend.global.response.success; import org.springframework.http.HttpStatus; -public enum MatchingSuccessCode implements SuccessCode { - APPLY_MATCHING_SUCCESS(HttpStatus.CREATED, "MA001", "매칭 신청 성공"), +public enum MatchingSuccess implements SuccessCode { + APPLY_MATCHING_SUCCESS(HttpStatus.OK, "MA001", "매칭 신청 성공"), GET_MATCHING_APPLICATION_STATUS_SUCCESS(HttpStatus.OK, "MA002", "매칭 신청 정보 조회 성공"), CANCEL_MATCHING_APPLICATION_SUCCESS(HttpStatus.OK, "MA003", "매칭 신청 취소 성공"), GET_MATCHING_PARTNERS_SUCCESS(HttpStatus.OK, "MA004", "매칭 파트너 조회 성공"), @@ -14,7 +14,7 @@ public enum MatchingSuccessCode implements SuccessCode { private final String code; private final String message; - MatchingSuccessCode(final HttpStatus httpStatus, final String code, final String message) { + MatchingSuccess(final HttpStatus httpStatus, final String code, final String message) { this.httpStatus = httpStatus; this.code = code; this.message = message; diff --git a/src/main/java/com/aliens/backend/global/success/MemberSuccessCode.java b/src/main/java/com/aliens/backend/global/response/success/MemberSuccess.java similarity index 82% rename from src/main/java/com/aliens/backend/global/success/MemberSuccessCode.java rename to src/main/java/com/aliens/backend/global/response/success/MemberSuccess.java index 2124c9a5..26f0c17c 100644 --- a/src/main/java/com/aliens/backend/global/success/MemberSuccessCode.java +++ b/src/main/java/com/aliens/backend/global/response/success/MemberSuccess.java @@ -1,9 +1,9 @@ -package com.aliens.backend.global.success; +package com.aliens.backend.global.response.success; import org.springframework.http.HttpStatus; -public enum MemberSuccessCode implements SuccessCode { - SIGN_UP_SUCCESS(HttpStatus.CREATED, "M001", "회원가입이 완료되었습니다."), +public enum MemberSuccess implements SuccessCode { + SIGN_UP_SUCCESS(HttpStatus.OK, "M001", "회원가입이 완료되었습니다."), WITHDRAW_SUCCESS(HttpStatus.OK, "M002", "회원 탈퇴되었습니다."), TEMPORARY_PASSWORD_GENERATED_SUCCESS(HttpStatus.OK, "M003", "임시 비밀번호가 발급되었습니다. 이메일을 확인해주세요."), PASSWORD_CHANGE_SUCCESS(HttpStatus.OK, "M004", "비밀번호 변경이 완료되었습니다."), @@ -19,7 +19,7 @@ public enum MemberSuccessCode implements SuccessCode { private final String code; private final String message; - MemberSuccessCode(final HttpStatus httpStatus, final String code, final String message) { + MemberSuccess(final HttpStatus httpStatus, final String code, final String message) { this.httpStatus = httpStatus; this.code = code; this.message = message; diff --git a/src/main/java/com/aliens/backend/global/success/SuccessCode.java b/src/main/java/com/aliens/backend/global/response/success/SuccessCode.java similarity index 75% rename from src/main/java/com/aliens/backend/global/success/SuccessCode.java rename to src/main/java/com/aliens/backend/global/response/success/SuccessCode.java index 517468fe..f114dd6a 100644 --- a/src/main/java/com/aliens/backend/global/success/SuccessCode.java +++ b/src/main/java/com/aliens/backend/global/response/success/SuccessCode.java @@ -1,4 +1,4 @@ -package com.aliens.backend.global.success; +package com.aliens.backend.global.response.success; import org.springframework.http.HttpStatus; diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java index aab490eb..cc1365e7 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java @@ -1,6 +1,6 @@ package com.aliens.backend.mathcing.controller.dto.input; -import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.service.model.Language; diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java index 5c0e43d1..e6e4c41c 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -1,6 +1,6 @@ package com.aliens.backend.mathcing.service; -import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.business.MatchingBusiness; import com.aliens.backend.mathcing.domain.MatchingResult; diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java b/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java index 5159f461..2ddd3895 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java +++ b/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java @@ -1,6 +1,6 @@ package com.aliens.backend.mathcing.service.model; -import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.domain.MatchingApplication; diff --git a/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java b/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java index b574c38b..a8b87c02 100644 --- a/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java +++ b/src/main/java/com/aliens/backend/member/sevice/MemberInfoService.java @@ -6,8 +6,8 @@ import com.aliens.backend.auth.service.PasswordEncoder; import com.aliens.backend.email.domain.EmailAuthentication; import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; -import com.aliens.backend.global.error.EmailError; -import com.aliens.backend.global.error.MemberError; +import com.aliens.backend.global.response.error.EmailError; +import com.aliens.backend.global.response.error.MemberError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.S3UploadProperties; import com.aliens.backend.member.controller.dto.*; diff --git a/src/main/java/com/aliens/backend/member/sevice/SymmetricKeyEncoder.java b/src/main/java/com/aliens/backend/member/sevice/SymmetricKeyEncoder.java index e82e9863..a5e89f24 100644 --- a/src/main/java/com/aliens/backend/member/sevice/SymmetricKeyEncoder.java +++ b/src/main/java/com/aliens/backend/member/sevice/SymmetricKeyEncoder.java @@ -1,6 +1,6 @@ package com.aliens.backend.member.sevice; -import com.aliens.backend.global.error.CommonError; +import com.aliens.backend.global.response.error.CommonError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.SymmetricEncoderProperties; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/aliens/backend/notification/FcmSender.java b/src/main/java/com/aliens/backend/notification/FcmSender.java index 3d9d1b67..98b655ff 100644 --- a/src/main/java/com/aliens/backend/notification/FcmSender.java +++ b/src/main/java/com/aliens/backend/notification/FcmSender.java @@ -1,6 +1,6 @@ package com.aliens.backend.notification; -import com.aliens.backend.global.error.CommonError; +import com.aliens.backend.global.response.error.CommonError; import com.aliens.backend.global.exception.RestApiException; import com.google.firebase.messaging.FirebaseMessaging; import com.google.firebase.messaging.Message; diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java b/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java similarity index 91% rename from src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java rename to src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java index 50d25c11..60024e53 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java @@ -1,6 +1,6 @@ -package com.aliens.backend.matching.unit.service; +package com.aliens.backend.matching.service; -import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; import com.aliens.backend.mathcing.domain.MatchingRound; @@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.*; @SpringBootTest -public class MatchingRoundServiceTest { +class MatchingRoundServiceTest { @Autowired MatchingRoundRepository matchingRoundRepository; @Autowired MatchingTimeProperties matchingTimeProperties; diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java b/src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java similarity index 89% rename from src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java rename to src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java index 166b070b..40131857 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java @@ -1,12 +1,11 @@ -package com.aliens.backend.matching.unit.service; +package com.aliens.backend.matching.service; -import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.MatchingService; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -18,7 +17,7 @@ import static org.assertj.core.api.Assertions.*; @SpringBootTest -public class MatchingServiceTest { +class MatchingServiceTest { @Autowired MatchingService matchingService; @Autowired MatchingRoundRepository matchingRoundRepository; From 07c02c87cfa4b7910b0122d40a0666db5e291d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:19:30 +0900 Subject: [PATCH 185/215] =?UTF-8?q?refactor(time)=20:=20=EA=B0=80=EB=8F=85?= =?UTF-8?q?=EC=84=B1=EC=9D=84=20=EC=9C=84=ED=95=B4=20time=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20=EC=98=81=EC=97=AD=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=ED=8C=90=EB=8B=A8=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20time=20=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC?= =?UTF-8?q?=EB=A1=9C=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/matching/{util => time}/MockClock.java | 6 +++--- .../aliens/backend/matching/{util => time}/MockTime.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/test/java/com/aliens/backend/matching/{util => time}/MockClock.java (83%) rename src/test/java/com/aliens/backend/matching/{util => time}/MockTime.java (86%) diff --git a/src/test/java/com/aliens/backend/matching/util/MockClock.java b/src/test/java/com/aliens/backend/matching/time/MockClock.java similarity index 83% rename from src/test/java/com/aliens/backend/matching/util/MockClock.java rename to src/test/java/com/aliens/backend/matching/time/MockClock.java index a6d23e79..cd850598 100644 --- a/src/test/java/com/aliens/backend/matching/util/MockClock.java +++ b/src/test/java/com/aliens/backend/matching/time/MockClock.java @@ -1,6 +1,6 @@ -package com.aliens.backend.matching.util; +package com.aliens.backend.matching.time; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.stereotype.Component; import java.time.Clock; @@ -11,7 +11,7 @@ @Component public class MockClock { - @MockBean + @SpyBean private Clock clock; public void mockTime(MockTime mockTime) { diff --git a/src/test/java/com/aliens/backend/matching/util/MockTime.java b/src/test/java/com/aliens/backend/matching/time/MockTime.java similarity index 86% rename from src/test/java/com/aliens/backend/matching/util/MockTime.java rename to src/test/java/com/aliens/backend/matching/time/MockTime.java index 612a3707..9a1538c7 100644 --- a/src/test/java/com/aliens/backend/matching/util/MockTime.java +++ b/src/test/java/com/aliens/backend/matching/time/MockTime.java @@ -1,4 +1,4 @@ -package com.aliens.backend.matching.util; +package com.aliens.backend.matching.time; import java.time.LocalDateTime; From 068d559b346cbd8bfd1266e06eecca91013ac1c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:20:53 +0900 Subject: [PATCH 186/215] =?UTF-8?q?refactor(MessageSendRequest)=20:=20Stri?= =?UTF-8?q?ng=EC=9C=BC=EB=A1=9C=20=EB=B0=9B=EB=8D=98=20=EA=B0=92=EC=9D=84?= =?UTF-8?q?=20enum=20=EC=9C=BC=EB=A1=9C=20=EB=B0=9B=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #46 --- .../chat/controller/dto/request/MessageSendRequest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/chat/controller/dto/request/MessageSendRequest.java b/src/main/java/com/aliens/backend/chat/controller/dto/request/MessageSendRequest.java index ca223419..42c8fcdf 100644 --- a/src/main/java/com/aliens/backend/chat/controller/dto/request/MessageSendRequest.java +++ b/src/main/java/com/aliens/backend/chat/controller/dto/request/MessageSendRequest.java @@ -1,4 +1,6 @@ package com.aliens.backend.chat.controller.dto.request; -public record MessageSendRequest(String type, String content, Long roomId, Long senderId, Long receiverId) { +import com.aliens.backend.chat.domain.MessageType; + +public record MessageSendRequest(MessageType type, String content, Long roomId, Long senderId, Long receiverId) { } \ No newline at end of file From e6b32443992a800c22fc0fdafe74a80dee04db4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:21:44 +0900 Subject: [PATCH 187/215] =?UTF-8?q?refactor(Message)=20:=20enum=EC=9D=84?= =?UTF-8?q?=20=EB=B0=9B=EB=8A=94=20controller=20=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EC=98=88=EC=99=B8=EB=A5=BC=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #46 --- src/main/java/com/aliens/backend/chat/domain/Message.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/aliens/backend/chat/domain/Message.java b/src/main/java/com/aliens/backend/chat/domain/Message.java index 15d0119c..a59eac32 100644 --- a/src/main/java/com/aliens/backend/chat/domain/Message.java +++ b/src/main/java/com/aliens/backend/chat/domain/Message.java @@ -1,8 +1,6 @@ package com.aliens.backend.chat.domain; import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; -import com.aliens.backend.global.error.ChatError; -import com.aliens.backend.global.exception.RestApiException; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; @@ -13,6 +11,7 @@ public class Message { @Id private String id; + private MessageType type; private String content; private Long roomId; @@ -26,8 +25,7 @@ protected Message() { public static Message of(MessageSendRequest messageSendRequest){ Message message = new Message(); - message.type = MessageType.fromString(messageSendRequest.type()) - .orElseThrow(() -> new RestApiException(ChatError.INVALID_MESSAGE_TYPE)); + message.type = messageSendRequest.type(); message.content = messageSendRequest.content(); message.roomId = messageSendRequest.roomId(); message.senderId = messageSendRequest.senderId(); From 74f30ddddc0e7ddec77e5d8399c1b548609fe94b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:22:16 +0900 Subject: [PATCH 188/215] =?UTF-8?q?refactor(MemberDocTest)=20:=20Doc=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/docs/MemberDocTest.java | 620 ++++++++++-------- 1 file changed, 333 insertions(+), 287 deletions(-) diff --git a/src/test/java/com/aliens/backend/docs/MemberDocTest.java b/src/test/java/com/aliens/backend/docs/MemberDocTest.java index e9d1e5dc..7af8280f 100644 --- a/src/test/java/com/aliens/backend/docs/MemberDocTest.java +++ b/src/test/java/com/aliens/backend/docs/MemberDocTest.java @@ -1,287 +1,333 @@ -package com.aliens.backend.docs; - -import com.aliens.backend.auth.service.TokenProvider; -import com.aliens.backend.member.controller.dto.request.SignUpRequest; -import com.aliens.backend.member.controller.dto.request.TemporaryPasswordRequest; -import com.aliens.backend.member.controller.dto.response.MemberPageResponse; -import com.aliens.backend.member.controller.dto.response.MemberResponse; -import com.aliens.backend.member.domain.MemberStatus; -import com.aliens.backend.member.sevice.MemberInfoService; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.web.servlet.MockMvc; - -import java.nio.charset.StandardCharsets; -import java.util.Collections; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; -import static org.springframework.restdocs.payload.PayloadDocumentation.*; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.request.RequestDocumentation.partWithName; -import static org.springframework.restdocs.request.RequestDocumentation.requestParts; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@AutoConfigureMockMvc -@AutoConfigureRestDocs -@SpringBootTest -class MemberDocTest { - - @Autowired - private MockMvc mockMvc; - @MockBean - private MemberInfoService memberInfoService; - @MockBean - private TokenProvider tokenProvider; - - ObjectMapper objectMapper; - MockMultipartFile multipartFile; - String accessToken; - - @BeforeEach - void setUp() { - multipartFile = new MockMultipartFile("profile-data", - "profile-data", - "image/png", - "test data".getBytes()); - accessToken= "accessToken"; - objectMapper = new ObjectMapper(); - } - - @Test - @DisplayName("회원가입 API 테스트") - void signUp() throws Exception { - final SignUpRequest request = createSignUpRequest(); - final String response = MemberResponse.SIGN_UP_SUCCESS.getMessage(); - when(memberInfoService.signUp(any(),any())).thenReturn(response); - - MockMultipartFile signUpRequestFile = getSignUpRequestFile(request); - - // When and Then - mockMvc.perform(multipart("/members") - .file(signUpRequestFile) - .file("profileImage", multipartFile.getBytes()) - .contentType(MediaType.MULTIPART_FORM_DATA) - .accept(MediaType.APPLICATION_JSON) - .characterEncoding("UTF-8") - ) - .andExpect(status().isOk()) - .andDo(document("member-signup", - requestParts( - partWithName("signUpRequest").description("회원가입 요청 데이터"), - partWithName("profileImage").description("프로필 이미지 파일") - ), - responseFields( - fieldWithPath("response").description("회원가입 결과") - ) - )); - } - - @Test - @DisplayName("프로필 이미지 변경 API 테스트") - void changeProfileImage() throws Exception { - String response = MemberResponse.PROFILE_IMAGE_CHANGE_SUCCESS.getMessage(); - when(memberInfoService.changeProfileImage(any(),any())).thenReturn(response); - - mockMvc.perform(multipart("/members/profile-image") - .file("newProfileImage", multipartFile.getBytes()) - .header("Authorization", accessToken) - .contentType(MediaType.MULTIPART_FORM_DATA)) - .andExpect(status().isOk()) - .andDo(document("member-change-profile-image", - requestParts( - partWithName("newProfileImage").description("새로운 프로필 이미지 파일") - ), - responseFields( - fieldWithPath("response").description("프로필 이미지 변경 결과") - ) - )); - } - - @Test - @DisplayName("임시 비밀번호 발급 API 테스트") - void generateTemporaryPassword() throws Exception { - final TemporaryPasswordRequest request = new TemporaryPasswordRequest("tmp@example.com", "tmpName"); - final String response = MemberResponse.TEMPORARY_PASSWORD_GENERATED_SUCCESS.getMessage(); - when(memberInfoService.generateTemporaryPassword(any())).thenReturn(response); - - this.mockMvc.perform(post("/members/temporary-password") - .content(objectMapper.writeValueAsString(request)) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andDo(document("member-temporary-password", - requestFields( - fieldWithPath("email").description("이메일"), - fieldWithPath("name").description("이름") - ), - responseFields( - fieldWithPath("response").description("임시 비밀번호 발급 결과") - ) - )); - } - - @Test - @DisplayName("비밀번호 변경 API 테스트") - void changePassword() throws Exception { - String newPassword = "newPassword"; - String response = MemberResponse.PASSWORD_CHANGE_SUCCESS.getMessage(); - when(memberInfoService.changePassword(any(), any())).thenReturn(response); - - this.mockMvc.perform(patch("/members/password") - .header("Authorization", accessToken) - .content(objectMapper.writeValueAsString(Collections.singletonMap("newPassword", newPassword))) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andDo(document("member-change-password", - requestFields( - fieldWithPath("newPassword").description("새로운 비밀번호") - ), - responseFields( - fieldWithPath("response").description("비밀번호 변경 결과") - ) - )); - } - - @Test - @DisplayName("회원 탈퇴 API 테스트") - void withdraw() throws Exception { - String response = MemberResponse.WITHDRAW_SUCCESS.getMessage(); - when(memberInfoService.withdraw(any())).thenReturn(response); - - mockMvc.perform(patch("/members/withdraw") - .header("Authorization", accessToken) - ) - .andExpect(status().isOk()) - .andDo(document("member-withdraw", - responseFields( - fieldWithPath("response").description("회원 탈퇴 결과") - ) - )); - } - - @Test - @DisplayName("상태 요청 API 테스트") - void getStatus() throws Exception { - String response = MemberStatus.NOT_APPLIED_NOT_MATCHED.getMessage(); - when(memberInfoService.getStatus(any())).thenReturn(response); - - mockMvc.perform(get("/members/status") - .header("Authorization", accessToken) - ) - .andExpect(status().isOk()) - .andDo(document("member-get-status", - responseFields( - fieldWithPath("response").description("상태 요청 결과") - ) - )); - } - - @Test - @DisplayName("회원 개인정보 요청 API 테스트") - void getMemberPage() throws Exception { - MemberPageResponse response = getMemberPageResponse(); - when(memberInfoService.getMemberPage(any())).thenReturn(response); - - mockMvc.perform(get("/members") - .header("Authorization", accessToken) - ) - .andExpect(status().isOk()) - .andDo(document("member-get-member-page", - responseFields( - fieldWithPath("name").description("이름"), - fieldWithPath("mbti").description("MBTI"), - fieldWithPath("gender").description("성별"), - fieldWithPath("nationality").description("국적"), - fieldWithPath("birthday").description("생년월일"), - fieldWithPath("selfIntroduction").description("자기 소개"), - fieldWithPath("profileImageURL").description("프로필 이미지 주소") - ) - )); - } - - - @Test - @DisplayName("자기소개 변경 API 테스트") - void changeAboutMe() throws Exception { - String newAboutMe = "새로운 자기소개"; - String response = MemberResponse.PASSWORD_CHANGE_SUCCESS.getMessage(); - when(memberInfoService.changeAboutMe(any(),any())).thenReturn(response); - - mockMvc.perform(patch("/members/about-me") - .header("Authorization", accessToken) - .content(objectMapper.writeValueAsString(Collections.singletonMap("newAboutMe", newAboutMe))) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andDo(document("member-change-about-me", - requestFields( - fieldWithPath("newAboutMe").description("새로운 자기소개") - ), - responseFields( - fieldWithPath("response").description("자기소개 변경 결과") - ) - )); - } - - @Test - @DisplayName("MBTI 변경 API 테스트") - void changeMBTI() throws Exception { - String newMBTI = "ENFP"; - String response = MemberResponse.MBTI_CHANGE_SUCCESS.getMessage(); - when(memberInfoService.changeMBTI(any(),any())).thenReturn(response); - - mockMvc.perform(patch("/members/mbti") - .header("Authorization", accessToken) - .content(objectMapper.writeValueAsString(Collections.singletonMap("newMBTI", newMBTI))) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andDo(document("member-change-mbti", - requestFields( - fieldWithPath("newMBTI").description("새로운 MBTI") - ), - responseFields( - fieldWithPath("response").description("MBTI 변경 결과") - ) - )); - } - - public SignUpRequest createSignUpRequest() { - SignUpRequest signUpRequest = new SignUpRequest("tmp@example.com", - "password", - "tmpName", - "INTJ", - "MALE", - "KOREA", - "1998-11-25", - "반갑습니다" - ); - return signUpRequest; - } - - public MockMultipartFile getSignUpRequestFile(final SignUpRequest request) throws JsonProcessingException { - String signupRequestJson = objectMapper.writeValueAsString(request); - MockMultipartFile signUpRequestFile = new MockMultipartFile( - "signUpRequest", - "signupRequest.json", - MediaType.APPLICATION_JSON_VALUE, - signupRequestJson.getBytes(StandardCharsets.UTF_8) - ); - return signUpRequestFile; - } - - public MemberPageResponse getMemberPageResponse() { - MemberPageResponse response = new MemberPageResponse("name","MBTI","MALE","KOREA","1998-11-25","반갑습니다","tmpImage.com"); - return response; - } -} \ No newline at end of file +//package com.aliens.backend.member.controller; +// +// +//import com.aliens.backend.auth.controller.dto.LoginMember; +//import com.aliens.backend.auth.domain.Member; +//import com.aliens.backend.auth.domain.MemberRole; +//import com.aliens.backend.auth.service.TokenProvider; +//import com.aliens.backend.global.BaseControllerTest; +//import com.aliens.backend.global.DummyGenerator; +//import com.aliens.backend.global.MockTokenInfoResolver; +//import com.aliens.backend.global.response.SuccessResponse; +//import com.aliens.backend.global.response.success.MemberSuccess; +//import com.aliens.backend.member.controller.dto.request.SignUpRequest; +//import com.aliens.backend.member.controller.dto.request.TemporaryPasswordRequest; +//import com.aliens.backend.member.controller.dto.response.MemberPageResponse; +//import com.aliens.backend.member.controller.dto.response.MemberResponse; +//import com.aliens.backend.member.domain.MemberStatus; +//import com.fasterxml.jackson.core.JsonProcessingException; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.mockito.Mock; +//import org.mockito.junit.MockitoJUnitRunner; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.mock.mockito.SpyBean; +//import org.springframework.http.MediaType; +//import org.springframework.mock.web.MockMultipartFile; +//import org.springframework.test.context.junit.jupiter.SpringExtension; +//import org.springframework.test.web.servlet.MockMvc; +//import org.springframework.test.web.servlet.setup.MockMvcBuilders; +//import org.springframework.web.multipart.MultipartFile; +//import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; +// +//import java.nio.charset.StandardCharsets; +//import java.util.Collections; +// +//import static org.mockito.ArgumentMatchers.any; +//import static org.mockito.Mockito.doReturn; +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +//import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; +//import static org.springframework.restdocs.payload.PayloadDocumentation.*; +//import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +//import static org.springframework.restdocs.request.RequestDocumentation.partWithName; +//import static org.springframework.restdocs.request.RequestDocumentation.requestParts; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@AutoConfigureMockMvc +//@AutoConfigureRestDocs +//@SpringBootTest +//class MemberDocTest { +// @SpyBean MemberController memberController; +// +// @Autowired MockMvc mockMvc; +// @Autowired DummyGenerator dummyGenerator; +// +// ObjectMapper objectMapper = new ObjectMapper(); +// String GIVEN_ACCESS_TOKEN; +// +// @BeforeEach +// void setUp() { +// Member member = dummyGenerator.generateSingleMember(); +// GIVEN_ACCESS_TOKEN = dummyGenerator.generateAccessToken(member); +// } +// +// @Test +// @DisplayName("API - 회원가입") +// void signUp() throws Exception { +// final SignUpRequest request = createSignUpRequest(); +// MockMultipartFile signUpRequestFile = getSignUpRequestFile(request); +// final String message = MemberResponse.SIGN_UP_SUCCESS.getMessage(); +// SuccessResponse response = SuccessResponse.of(MemberSuccess.SIGN_UP_SUCCESS, message); +// MockMultipartFile multipartFile = createMultipartFile(); +// +// doReturn(response).when(memberController).signUp(any(), any()); +// +// // When and Then +// mockMvc.perform(multipart("/members") +// .file(signUpRequestFile) +// .file("profileImage", multipartFile.getBytes()) +// .contentType(MediaType.MULTIPART_FORM_DATA) +// .accept(MediaType.APPLICATION_JSON) +// .characterEncoding("UTF-8") +// ) +// .andExpect(status().is2xxSuccessful()) +// .andDo(document("member-signup", +// requestParts( +// partWithName("signUpRequest").description("회원가입 요청 데이터"), +// partWithName("profileImage").description("프로필 이미지 파일") +// ), +// responseFields( +// fieldWithPath("code").description("성공 코드"), +// fieldWithPath("result").description("회원가입 결과") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - 프로필 이미지 변경") +// void changeProfileImage() throws Exception { +// String message = MemberResponse.PROFILE_IMAGE_CHANGE_SUCCESS.getMessage(); +// SuccessResponse response = SuccessResponse.of(MemberSuccess.PROFILE_IMAGE_CHANGE_SUCCESS, message); +// MultipartFile multipartFile = createMultipartFile(); +// doReturn(response).when(memberController).changeProfileImage(any(), any()); +// +// // When and Then +// mockMvc.perform(multipart("/members/profile-image") +// .file("newProfileImage", multipartFile.getBytes()) +// .header("Authorization", GIVEN_ACCESS_TOKEN) +// .contentType(MediaType.MULTIPART_FORM_DATA)) +// .andExpect(status().isOk()) +// .andDo(document("member-change-profile-image", +// requestParts( +// partWithName("newProfileImage").description("새로운 프로필 이미지 파일") +// ), +// responseFields( +// fieldWithPath("code").description("성공 코드"), +// fieldWithPath("result").description("프로필 이미지 변경 결과") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - 임시 비밀번호 발급") +// void generateTemporaryPassword() throws Exception { +// final TemporaryPasswordRequest request = new TemporaryPasswordRequest("tmp@example.com", "tmpName"); +// final String message = MemberResponse.TEMPORARY_PASSWORD_GENERATED_SUCCESS.getMessage(); +// SuccessResponse response = SuccessResponse.of(MemberSuccess.TEMPORARY_PASSWORD_GENERATED_SUCCESS, message); +// +// doReturn(response).when(memberController).temporaryPassword(any()); +// +// // When and Then +// this.mockMvc.perform(post("/members/temporary-password") +// .content(objectMapper.writeValueAsString(request)) +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andDo(document("member-temporary-password", +// requestFields( +// fieldWithPath("email").description("이메일"), +// fieldWithPath("name").description("이름") +// ), +// responseFields( +// fieldWithPath("code").description("성공 코드"), +// fieldWithPath("result").description("임시 비밀번호 발급 결과") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - 비밀번호 변경") +// void changePassword() throws Exception { +// String newPassword = "newPassword"; +// String message = MemberResponse.PASSWORD_CHANGE_SUCCESS.getMessage(); +// SuccessResponse response = SuccessResponse.of(MemberSuccess.PASSWORD_CHANGE_SUCCESS, message); +// +// doReturn(response).when(memberController).changePassword(any(), any()); +// +// // When and Then +// this.mockMvc.perform(patch("/members/password") +// .header("Authorization", GIVEN_ACCESS_TOKEN) +// .content(objectMapper.writeValueAsString(Collections.singletonMap("newPassword", newPassword))) +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andDo(document("member-change-password", +// requestFields( +// fieldWithPath("newPassword").description("새로운 비밀번호") +// ), +// responseFields( +// fieldWithPath("code").description("성공 코드"), +// fieldWithPath("result").description("비밀번호 변경 결과") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - 회원 탈퇴") +// void withdraw() throws Exception { +// String message = MemberResponse.WITHDRAW_SUCCESS.getMessage(); +// SuccessResponse response = SuccessResponse.of(MemberSuccess.WITHDRAW_SUCCESS, message); +// doReturn(response).when(memberController).withdraw(any()); +// +// // When and Then +// mockMvc.perform(patch("/members/withdraw") +// .header("Authorization", GIVEN_ACCESS_TOKEN) +// ) +// .andExpect(status().isOk()) +// .andDo(document("member-withdraw", +// responseFields( +// fieldWithPath("code").description("성공 코드"), +// fieldWithPath("result").description("회원 탈퇴 결과") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - 상태 요청") +// void getStatus() throws Exception { +// String message = MemberStatus.NOT_APPLIED_NOT_MATCHED.getMessage(); +// SuccessResponse response = SuccessResponse.of(MemberSuccess.GET_MEMBER_MATCHING_STATUS_SUCCESS, message); +// doReturn(response).when(memberController).getStatus(any()); +// +// // When and Then +// mockMvc.perform(get("/members/status") +// .header("Authorization", GIVEN_ACCESS_TOKEN) +// ) +// .andExpect(status().isOk()) +// .andDo(document("member-get-status", +// responseFields( +// fieldWithPath("code").description("성공 코드"), +// fieldWithPath("result").description("상태 요청 결과") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - 회원 개인정보 요청") +// void getMemberPage() throws Exception { +// MemberPageResponse result = getMemberPageResponse(); +// SuccessResponse response = SuccessResponse.of(MemberSuccess.GET_MEMBER_MATCHING_STATUS_SUCCESS, result); +// doReturn(response).when(memberController).getMemberPage(any()); +// +// // When and Then +// mockMvc.perform(get("/members") +// .header("Authorization", GIVEN_ACCESS_TOKEN) +// ) +// .andExpect(status().isOk()) +// .andDo(document("member-get-member-page", +// responseFields( +// fieldWithPath("code").description("응답 코드"), +// subsectionWithPath("result").description("응답 객체"), +// fieldWithPath("result.name").description("이름"), +// fieldWithPath("result.mbti").description("MBTI"), +// fieldWithPath("result.gender").description("성별"), +// fieldWithPath("result.nationality").description("국적"), +// fieldWithPath("result.birthday").description("생년월일"), +// fieldWithPath("result.selfIntroduction").description("자기 소개"), +// fieldWithPath("result.profileImageURL").description("프로필 이미지 주소") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - 자기소개 변경") +// void changeAboutMe() throws Exception { +// String newAboutMe = "새로운 자기소개"; +// String message = MemberResponse.PASSWORD_CHANGE_SUCCESS.getMessage(); +// SuccessResponse response = SuccessResponse.of(MemberSuccess.PASSWORD_CHANGE_SUCCESS, message); +// doReturn(response).when(memberController).changeAboutMe(any(),any()); +// +// // When and Then +// mockMvc.perform(patch("/members/about-me") +// .header("Authorization", GIVEN_ACCESS_TOKEN) +// .content(objectMapper.writeValueAsString(Collections.singletonMap("newAboutMe", newAboutMe))) +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andDo(document("member-change-about-me", +// requestFields( +// fieldWithPath("newAboutMe").description("새로운 자기소개") +// ), +// responseFields( +// fieldWithPath("code").description("성공 코드"), +// fieldWithPath("result").description("자기소개 변경 결과") +// ) +// )); +// } +// +// @Test +// @DisplayName("API - MBTI 변경") +// void changeMBTI() throws Exception { +// String newMBTI = "ENFP"; +// String message = MemberResponse.MBTI_CHANGE_SUCCESS.getMessage(); +// +// SuccessResponse response = SuccessResponse.of(MemberSuccess.PASSWORD_CHANGE_SUCCESS, message); +// doReturn(response).when(memberController).changeMBTI(any(),any()); +// +// // When and Then +// mockMvc.perform(patch("/members/mbti") +// .header("Authorization", GIVEN_ACCESS_TOKEN) +// .content(objectMapper.writeValueAsString(Collections.singletonMap("newMBTI", newMBTI))) +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andDo(document("member-change-mbti", +// requestFields( +// fieldWithPath("newMBTI").description("새로운 MBTI") +// ), +// responseFields( +// fieldWithPath("code").description("성공 코드"), +// fieldWithPath("result").description("MBTI 변경 결과") +// ) +// )); +// } +// +// private SignUpRequest createSignUpRequest() { +// SignUpRequest signUpRequest = new SignUpRequest("tmp@example.com", +// "password", +// "tmpName", +// "INTJ", +// "MALE", +// "KOREA", +// "1998-11-25", +// "반갑습니다" +// ); +// return signUpRequest; +// } +// +// private MockMultipartFile getSignUpRequestFile(final SignUpRequest request) throws JsonProcessingException { +// String signupRequestJson = objectMapper.writeValueAsString(request); +// MockMultipartFile signUpRequestFile = new MockMultipartFile( +// "signUpRequest", +// "signupRequest.json", +// MediaType.APPLICATION_JSON_VALUE, +// signupRequestJson.getBytes(StandardCharsets.UTF_8) +// ); +// return signUpRequestFile; +// } +// +// private MemberPageResponse getMemberPageResponse() { +// MemberPageResponse response = new MemberPageResponse("name","MBTI","MALE","KOREA","1998-11-25","반갑습니다","tmpImage.com"); +// return response; +// } +// +// private MockMultipartFile createMultipartFile() { +// return new MockMultipartFile("profile-data", +// "profile-data", +// "image/png", +// "test data".getBytes()); +// } +//} \ No newline at end of file From 8556edba309354200adc54ef925b2ca0bd46eeb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:27:44 +0900 Subject: [PATCH 189/215] =?UTF-8?q?refactor(SuccessResponse)=20:=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EA=B0=9D=EC=B2=B4=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #44 --- .../auth/controller/AuthController.java | 30 ++++-- .../chat/controller/ChatController.java | 28 +++--- .../chat/controller/ChatReportController.java | 19 ++-- .../email/controller/EmailController.java | 35 ++++--- .../controller/MatchingController.java | 49 +++++---- .../member/controller/MemberController.java | 99 ++++++++++++------- 6 files changed, 158 insertions(+), 102 deletions(-) diff --git a/src/main/java/com/aliens/backend/auth/controller/AuthController.java b/src/main/java/com/aliens/backend/auth/controller/AuthController.java index de802e63..76683346 100644 --- a/src/main/java/com/aliens/backend/auth/controller/AuthController.java +++ b/src/main/java/com/aliens/backend/auth/controller/AuthController.java @@ -3,10 +3,8 @@ import com.aliens.backend.auth.service.AuthService; import com.aliens.backend.auth.controller.dto.AuthToken; import com.aliens.backend.auth.controller.dto.LoginRequest; -import com.aliens.backend.global.success.AuthSuccessCode; -import com.aliens.backend.global.success.SuccessResponse; -import com.aliens.backend.global.success.SuccessResponseWithoutResult; -import org.springframework.http.ResponseEntity; +import com.aliens.backend.global.response.success.AuthSuccess; +import com.aliens.backend.global.response.SuccessResponse; import org.springframework.web.bind.annotation.*; @@ -20,17 +18,29 @@ public AuthController(final AuthService authService) { } @PostMapping - public ResponseEntity login(@RequestBody final LoginRequest loginRequest) { - return SuccessResponse.toResponseEntity(AuthSuccessCode.GENERATE_AUTHTOKEN_SUCCESS, authService.login(loginRequest)); + public SuccessResponse login(@RequestBody final LoginRequest loginRequest) { + + return SuccessResponse.of( + AuthSuccess.GENERATE_TOKEN_SUCCESS, + authService.login(loginRequest) + ); } @PostMapping("/logout") - public ResponseEntity logout(@RequestBody final AuthToken authToken) { - return SuccessResponseWithoutResult.toResponseEntity(AuthSuccessCode.LOGOUT_SUCCESS); + public SuccessResponse logout(@RequestBody final AuthToken authToken) { + + return SuccessResponse.of( + AuthSuccess.LOGOUT_SUCCESS, + authService.logout(authToken) + ); } @PostMapping("/reissue") - public ResponseEntity reissue(@RequestBody final AuthToken authToken) { - return SuccessResponse.toResponseEntity(AuthSuccessCode.REISSUE_AUTHTOKEN_SUCCESS, authService.reissue(authToken)); + public SuccessResponse reissue(@RequestBody final AuthToken authToken) { + + return SuccessResponse.of( + AuthSuccess.REISSUE_TOKEN_SUCCESS, + authService.reissue(authToken) + ); } } \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatController.java b/src/main/java/com/aliens/backend/chat/controller/ChatController.java index d7810366..fa9bf490 100644 --- a/src/main/java/com/aliens/backend/chat/controller/ChatController.java +++ b/src/main/java/com/aliens/backend/chat/controller/ChatController.java @@ -6,7 +6,8 @@ import com.aliens.backend.chat.domain.Message; import com.aliens.backend.chat.service.ChatService; import com.aliens.backend.global.config.resolver.Login; -import org.springframework.http.ResponseEntity; +import com.aliens.backend.global.response.SuccessResponse; +import com.aliens.backend.global.response.success.ChatSuccess; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.web.bind.annotation.GetMapping; @@ -14,9 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.util.Collections; import java.util.List; -import java.util.Map; @RestController @@ -39,17 +38,22 @@ public void readMessage(@Payload ReadRequest readRequest) { } @GetMapping("/chat/summaries") - public ResponseEntity> getChatSummaries(@Login Long memberId) { - ChatSummaryResponse chatSummaryResponse = chatService.getChatSummaries(memberId); - Map response = Collections.singletonMap("response", chatSummaryResponse); - return ResponseEntity.ok(response); + public SuccessResponse getChatSummaries(@Login Long memberId) { + + return SuccessResponse.of( + ChatSuccess.GET_SUMMARIES_SUCCESS, + chatService.getChatSummaries(memberId) + ); } @GetMapping("/chat/room/{roomId}/messages") - public ResponseEntity> getMessages(@PathVariable("roomId") Long chatRoomId, - @RequestParam(value = "lastMessageId", required = false) String lastMessageId) { - List messages = chatService.getMessages(chatRoomId,lastMessageId); - Map response = Collections.singletonMap("response", messages); - return ResponseEntity.ok(response); + public SuccessResponse> getMessages(@PathVariable("roomId") Long chatRoomId, + @RequestParam(value = "lastMessageId", required = false) String messageId) { + + return SuccessResponse.of( + ChatSuccess.GET_MESSAGES_SUCCESS, + chatService.getMessages(chatRoomId,messageId) + ); + } } diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatReportController.java b/src/main/java/com/aliens/backend/chat/controller/ChatReportController.java index 74d3d0d7..a20f2922 100644 --- a/src/main/java/com/aliens/backend/chat/controller/ChatReportController.java +++ b/src/main/java/com/aliens/backend/chat/controller/ChatReportController.java @@ -1,17 +1,15 @@ package com.aliens.backend.chat.controller; +import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.chat.controller.dto.request.ChatReportRequest; import com.aliens.backend.chat.service.ChatReportService; import com.aliens.backend.global.config.resolver.Login; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; +import com.aliens.backend.global.response.SuccessResponse; +import com.aliens.backend.global.response.success.ChatSuccess; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; -import java.util.Collections; -import java.util.Map; - @RestController public class ChatReportController { @@ -23,9 +21,12 @@ public ChatReportController(ChatReportService chatReportService) { } @PostMapping("/chat/report") - public ResponseEntity> reportPartner(@Login Long memberId, @RequestBody ChatReportRequest chatReportRequest) { - String result = chatReportService.reportPartner(memberId, chatReportRequest); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); + public SuccessResponse reportPartner(@Login LoginMember loginMember, + @RequestBody ChatReportRequest chatReportRequest) { + + return SuccessResponse.of( + ChatSuccess.REPORT_SUCCESS, + chatReportService.reportPartner(loginMember, chatReportRequest) + ); } } \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/email/controller/EmailController.java b/src/main/java/com/aliens/backend/email/controller/EmailController.java index 091c6f82..a7a3242d 100644 --- a/src/main/java/com/aliens/backend/email/controller/EmailController.java +++ b/src/main/java/com/aliens/backend/email/controller/EmailController.java @@ -1,11 +1,10 @@ package com.aliens.backend.email.controller; import com.aliens.backend.email.service.EmailService; -import org.springframework.http.ResponseEntity; +import com.aliens.backend.global.response.SuccessResponse; +import com.aliens.backend.global.response.success.EmailSuccess; import org.springframework.web.bind.annotation.*; -import java.util.Collections; -import java.util.Map; @RestController public class EmailController { @@ -16,23 +15,29 @@ public EmailController(final EmailService emailService) { } @GetMapping("/members/exist") - public ResponseEntity> duplicateCheck(@RequestParam("email") String email) { - String result = emailService.duplicateCheck(email); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); + public SuccessResponse duplicateCheck(@RequestParam("email") String email) { + + return SuccessResponse.of( + EmailSuccess.DUPLICATE_CHECK_SUCCESS, + emailService.duplicateCheck(email) + ); } @PostMapping("/emails/verification/send") - public ResponseEntity> sendAuthenticationEmail(@RequestBody String email) throws Exception { - String result = emailService.sendAuthenticationEmail(email); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); + public SuccessResponse sendAuthenticationEmail(@RequestBody String email) throws Exception { + + return SuccessResponse.of( + EmailSuccess.SEND_EMAIL_SUCCESS, + emailService.sendAuthenticationEmail(email) + ); } @GetMapping("/emails/confirm") - public ResponseEntity> authenticateEmail(@RequestParam("token") String token) throws Exception { - String result = emailService.authenticateEmail(token); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); + public SuccessResponse authenticateEmail(@RequestParam("token") String token) throws Exception { + + return SuccessResponse.of( + EmailSuccess.EMAIL_AUTHENTICATE_SUCCESS, + emailService.authenticateEmail(token) + ); } } diff --git a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java index f6905269..ce50db2a 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java @@ -2,15 +2,15 @@ import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.global.config.resolver.Login; -import com.aliens.backend.global.success.MatchingSuccessCode; -import com.aliens.backend.global.success.SuccessResponse; -import com.aliens.backend.global.success.SuccessResponseWithoutResult; +import com.aliens.backend.global.response.success.MatchingSuccess; +import com.aliens.backend.global.response.SuccessResponse; +import com.aliens.backend.mathcing.controller.dto.response.MatchingResponse; import com.aliens.backend.mathcing.service.MatchingApplicationService; import com.aliens.backend.mathcing.service.MatchingService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.List; + import static com.aliens.backend.mathcing.controller.dto.input.MatchingInput.*; @RestController @@ -19,7 +19,6 @@ public class MatchingController { private final MatchingApplicationService matchingApplicationService; private final MatchingService matchingService; - @Autowired public MatchingController(final MatchingApplicationService matchingApplicationService, final MatchingService matchingService) { this.matchingApplicationService = matchingApplicationService; @@ -27,27 +26,39 @@ public MatchingController(final MatchingApplicationService matchingApplicationSe } @PostMapping("/applications") - public ResponseEntity applyMatch(final @Login LoginMember loginMember, - final @RequestBody MatchingApplicationInput matchingApplicationInput) { - matchingApplicationService.saveParticipant(matchingApplicationInput.toRequest(loginMember.memberId())); - return SuccessResponseWithoutResult.toResponseEntity(MatchingSuccessCode.APPLY_MATCHING_SUCCESS); + public SuccessResponse applyMatch(final @Login LoginMember loginMember, + final @RequestBody MatchingApplicationInput input) { + + return SuccessResponse.of( + MatchingSuccess.APPLY_MATCHING_SUCCESS, + matchingApplicationService.saveParticipant(input.toRequest(loginMember.memberId())) + ); } @GetMapping("/applications") - public ResponseEntity getMatchingApplication(final @Login LoginMember loginMember) { - return SuccessResponse.toResponseEntity(MatchingSuccessCode.GET_MATCHING_APPLICATION_STATUS_SUCCESS, - matchingApplicationService.findMatchingApplication(loginMember.memberId())); + public SuccessResponse getMatchingApplication(final @Login LoginMember loginMember) { + + return SuccessResponse.of( + MatchingSuccess.GET_MATCHING_APPLICATION_STATUS_SUCCESS, + matchingApplicationService.findMatchingApplication(loginMember.memberId()) + ); } @DeleteMapping("/applications") - public ResponseEntity cancelMatchingApplication(final @Login LoginMember loginMember) { - matchingApplicationService.deleteMatchingApplication(loginMember.memberId()); - return SuccessResponseWithoutResult.toResponseEntity(MatchingSuccessCode.CANCEL_MATCHING_APPLICATION_SUCCESS); + public SuccessResponse cancelMatchingApplication(final @Login LoginMember loginMember) { + + return SuccessResponse.of( + MatchingSuccess.CANCEL_MATCHING_APPLICATION_SUCCESS, + matchingApplicationService.deleteMatchingApplication(loginMember.memberId()) + ); } @GetMapping("/partners") - public ResponseEntity getMatchingPartners(final @Login LoginMember loginMember) { - return SuccessResponse.toResponseEntity(MatchingSuccessCode.GET_MATCHING_PARTNERS_SUCCESS, - matchingService.findMatchingResult(loginMember.memberId())); + public SuccessResponse> getMatchingPartners(final @Login LoginMember loginMember) { + + return SuccessResponse.of( + MatchingSuccess.GET_MATCHING_PARTNERS_SUCCESS, + matchingService.findMatchingResult(loginMember.memberId()) + ); } } diff --git a/src/main/java/com/aliens/backend/member/controller/MemberController.java b/src/main/java/com/aliens/backend/member/controller/MemberController.java index 067a2d7a..c05ee1e2 100644 --- a/src/main/java/com/aliens/backend/member/controller/MemberController.java +++ b/src/main/java/com/aliens/backend/member/controller/MemberController.java @@ -2,14 +2,12 @@ import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.global.config.resolver.Login; -import com.aliens.backend.global.success.MemberSuccessCode; -import com.aliens.backend.global.success.SuccessResponse; -import com.aliens.backend.global.success.SuccessResponseWithoutResult; +import com.aliens.backend.global.response.success.MemberSuccess; +import com.aliens.backend.global.response.SuccessResponse; import com.aliens.backend.member.controller.dto.request.SignUpRequest; import com.aliens.backend.member.controller.dto.request.TemporaryPasswordRequest; import com.aliens.backend.member.controller.dto.response.MemberPageResponse; import com.aliens.backend.member.sevice.MemberInfoService; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -24,61 +22,88 @@ public MemberController(final MemberInfoService memberInfoService) { } @PostMapping() - public ResponseEntity signUp(@RequestPart SignUpRequest signUpRequest, - @RequestPart MultipartFile profileImage) { - memberInfoService.signUp(signUpRequest, profileImage); - return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.SIGN_UP_SUCCESS); + public SuccessResponse signUp(@RequestPart SignUpRequest signUpRequest, + @RequestPart MultipartFile profileImage) { + + return SuccessResponse.of( + MemberSuccess.SIGN_UP_SUCCESS, + memberInfoService.signUp(signUpRequest, profileImage) + ); } @PostMapping("/temporary-password") - public ResponseEntity temporaryPassword(@RequestBody TemporaryPasswordRequest request) { - memberInfoService.generateTemporaryPassword(request); - return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.TEMPORARY_PASSWORD_GENERATED_SUCCESS); + public SuccessResponse temporaryPassword(@RequestBody TemporaryPasswordRequest request) { + + return SuccessResponse.of( + MemberSuccess.TEMPORARY_PASSWORD_GENERATED_SUCCESS, + memberInfoService.generateTemporaryPassword(request) + ); } @PatchMapping("/password") - public ResponseEntity changePassword(@Login LoginMember loginMember, - @RequestBody String newPassword ) { - memberInfoService.changePassword(loginMember, newPassword); - return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.PASSWORD_CHANGE_SUCCESS); + public SuccessResponse changePassword(@Login LoginMember loginMember, + @RequestBody String newPassword ) { + + return SuccessResponse.of( + MemberSuccess.PASSWORD_CHANGE_SUCCESS, + memberInfoService.changePassword(loginMember, newPassword) + ); } @PostMapping("/profile-image") - public ResponseEntity changeProfileImage(@Login LoginMember loginMember, - @RequestPart MultipartFile newProfileImage) { - memberInfoService.changeProfileImage(loginMember, newProfileImage); - return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.PROFILE_IMAGE_CHANGE_SUCCESS); + public SuccessResponse changeProfileImage(@Login LoginMember loginMember, + @RequestPart MultipartFile newProfileImage) { + + return SuccessResponse.of( + MemberSuccess.PROFILE_IMAGE_CHANGE_SUCCESS, + memberInfoService.changeProfileImage(loginMember, newProfileImage) + ); } @PatchMapping("/about-me") - public ResponseEntity changeAboutMe(@Login LoginMember loginMember, - @RequestBody String newAboutMe) { - memberInfoService.changeAboutMe(loginMember, newAboutMe); - return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.ABOUT_ME_CHANGE_SUCCESS); + public SuccessResponse changeAboutMe(@Login LoginMember loginMember, + @RequestBody String newAboutMe) { + + return SuccessResponse.of( + MemberSuccess.ABOUT_ME_CHANGE_SUCCESS, + memberInfoService.changeAboutMe(loginMember, newAboutMe) + ); } @PatchMapping("/mbti") - public ResponseEntity changeMBTI(@Login LoginMember loginMember, - @RequestBody String newMBTI) { - memberInfoService.changeMBTI(loginMember, newMBTI); - return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.MBTI_CHANGE_SUCCESS); + public SuccessResponse changeMBTI(@Login LoginMember loginMember, + @RequestBody String newMBTI) { + + return SuccessResponse.of( + MemberSuccess.MBTI_CHANGE_SUCCESS, + memberInfoService.changeMBTI(loginMember, newMBTI) + ); } @PatchMapping("/withdraw") - public ResponseEntity withdraw(@Login LoginMember loginMember) { - memberInfoService.withdraw(loginMember); - return SuccessResponseWithoutResult.toResponseEntity(MemberSuccessCode.WITHDRAW_SUCCESS); + public SuccessResponse withdraw(@Login LoginMember loginMember) { + + return SuccessResponse.of( + MemberSuccess.WITHDRAW_SUCCESS, + memberInfoService.withdraw(loginMember) + ); } @GetMapping("/status") - public ResponseEntity getStatus(@Login LoginMember loginMember) { - return SuccessResponse.toResponseEntity(MemberSuccessCode.GET_MEMBER_MATCHING_STATUS_SUCCESS, - memberInfoService.getStatus(loginMember)); + public SuccessResponse getStatus(@Login LoginMember loginMember) { + + return SuccessResponse.of( + MemberSuccess.GET_MEMBER_MATCHING_STATUS_SUCCESS, + memberInfoService.getStatus(loginMember) + ); } - @GetMapping() - public ResponseEntity getMemberPage(@Login LoginMember loginMember) { - return SuccessResponse.toResponseEntity(MemberSuccessCode.GET_MEMBER_PAGE_SUCCESS, - memberInfoService.getMemberPage(loginMember)); + @GetMapping + public SuccessResponse getMemberPage(@Login LoginMember loginMember) { + + return SuccessResponse.of( + MemberSuccess.GET_MEMBER_PAGE_SUCCESS, + memberInfoService.getMemberPage(loginMember) + ); } } From 72172455e7dbc4daa8d99f1e2340e6dada323283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:31:18 +0900 Subject: [PATCH 190/215] =?UTF-8?q?refactor(AuthServiceTest)=20:=20?= =?UTF-8?q?=EB=8D=94=EB=AF=B8=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EA=B0=9D=EC=B2=B4=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #50 --- ...eTest.java => AuthServiceServiceTest.java} | 49 ++++++------------- 1 file changed, 14 insertions(+), 35 deletions(-) rename src/test/java/com/aliens/backend/auth/service/{AuthServiceTest.java => AuthServiceServiceTest.java} (71%) diff --git a/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java b/src/test/java/com/aliens/backend/auth/service/AuthServiceServiceTest.java similarity index 71% rename from src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java rename to src/test/java/com/aliens/backend/auth/service/AuthServiceServiceTest.java index 019d985b..cdb86797 100644 --- a/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java +++ b/src/test/java/com/aliens/backend/auth/service/AuthServiceServiceTest.java @@ -2,51 +2,30 @@ import com.aliens.backend.auth.controller.dto.AuthToken; import com.aliens.backend.auth.controller.dto.LoginRequest; -import com.aliens.backend.auth.domain.Member; -import com.aliens.backend.auth.domain.repository.MemberRepository; -import com.aliens.backend.global.BaseTest; +import com.aliens.backend.global.BaseServiceTest; +import com.aliens.backend.global.DummyGenerator; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.JWTProperties; -import com.aliens.backend.member.controller.dto.EncodedSignUp; -import com.aliens.backend.member.domain.Image; -import com.aliens.backend.member.domain.repository.ImageRepository; -import com.aliens.backend.uploader.dto.S3File; import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class AuthServiceTest extends BaseTest { - - @Autowired - AuthService authService; - @Autowired - JWTProperties jwtProperties; - @Autowired - MemberRepository memberRepository; - @Autowired - ImageRepository imageRepository; - @Autowired - PasswordEncoder passwordEncoder; - - Member member; - String name; - String email; - String password; + +class AuthServiceServiceTest extends BaseServiceTest { + + @Autowired AuthService authService; + @Autowired JWTProperties jwtProperties; + @Autowired DummyGenerator dummyGenerator; + LoginRequest loginRequest; @BeforeEach void setUp() { - name = "김명준"; - email = "tmp@example.com"; - password = "tmpPassword"; - EncodedSignUp encodedSignUp = new EncodedSignUp(name, email, passwordEncoder.encrypt(password)); - Image image = Image.from(new S3File("tmpFileName", "tmpFileURL")); - member = Member.of(encodedSignUp, image); - memberRepository.save(member); - loginRequest = new LoginRequest(email, password); + dummyGenerator.generateSingleMember(); + loginRequest = new LoginRequest( + DummyGenerator.GIVEN_EMAIL, + DummyGenerator.GIVEN_PASSWORD + ); } @Test From 86546e5183eccb3f1e79391c89a230bad02d5e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:31:55 +0900 Subject: [PATCH 191/215] =?UTF-8?q?style(DatabaseCleanup)=20:=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=EC=97=86=EB=8A=94=20import=20=EB=AC=B8=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/aliens/backend/global/DatabaseCleanup.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/aliens/backend/global/DatabaseCleanup.java b/src/test/java/com/aliens/backend/global/DatabaseCleanup.java index c9631006..c86fcbf4 100644 --- a/src/test/java/com/aliens/backend/global/DatabaseCleanup.java +++ b/src/test/java/com/aliens/backend/global/DatabaseCleanup.java @@ -3,7 +3,6 @@ import com.google.common.base.CaseFormat; import org.springframework.beans.factory.InitializingBean; import org.springframework.stereotype.Component; -import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.annotation.Transactional; import jakarta.persistence.Entity; From 30787fb0fa8d235e57a5425bdd385e8e56ebd7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:32:54 +0900 Subject: [PATCH 192/215] =?UTF-8?q?refactor(ChatReportRequest)=20:=20reque?= =?UTF-8?q?st=EC=97=90=EC=84=9C=20enum=20=EA=B0=92=EC=9D=84=20=EB=B0=9B?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #46 --- .../chat/controller/dto/request/ChatReportRequest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatReportRequest.java b/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatReportRequest.java index 90c80b8f..1b99f741 100644 --- a/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatReportRequest.java +++ b/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatReportRequest.java @@ -1,4 +1,6 @@ package com.aliens.backend.chat.controller.dto.request; -public record ChatReportRequest(Long partnerId, Long chatRoomId, String category, String content) { +import com.aliens.backend.chat.domain.ChatReportCategory; + +public record ChatReportRequest(Long partnerId, Long chatRoomId, ChatReportCategory category, String content) { } \ No newline at end of file From ef78c37a47d2507af55786beefdd51ed28fe6a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:33:49 +0900 Subject: [PATCH 193/215] =?UTF-8?q?style(AwsS3UploaderServiceTest)=20:=20B?= =?UTF-8?q?aseTest=EC=97=90=EC=84=9C=20@SpringBoot=20=EC=95=A0=EB=84=88?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=EC=9D=84=20=EA=B0=96=EA=B3=A0=20?= =?UTF-8?q?=EC=9E=88=EA=B8=B0=EB=95=8C=EB=AC=B8=EC=97=90=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...AwsS3UploaderTest.java => AwsS3UploaderServiceTest.java} | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) rename src/test/java/com/aliens/backend/uploader/{AwsS3UploaderTest.java => AwsS3UploaderServiceTest.java} (88%) diff --git a/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java b/src/test/java/com/aliens/backend/uploader/AwsS3UploaderServiceTest.java similarity index 88% rename from src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java rename to src/test/java/com/aliens/backend/uploader/AwsS3UploaderServiceTest.java index 550b20ce..8676636e 100644 --- a/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java +++ b/src/test/java/com/aliens/backend/uploader/AwsS3UploaderServiceTest.java @@ -1,19 +1,17 @@ package com.aliens.backend.uploader; -import com.aliens.backend.global.BaseTest; +import com.aliens.backend.global.BaseServiceTest; import com.aliens.backend.uploader.dto.S3File; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; import java.util.List; -@SpringBootTest -class AwsS3UploaderTest extends BaseTest { +class AwsS3UploaderServiceTest extends BaseServiceTest { @Autowired private AwsS3Uploader awsS3Uploader; From e6466c5a96451acabe4e4dba6dc94549598f1a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:40:09 +0900 Subject: [PATCH 194/215] =?UTF-8?q?refatctor(block)=20:=20Chatting=20?= =?UTF-8?q?=EB=8F=84=EB=A9=94=EC=9D=B8=EC=97=90=EC=84=9C=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=9E=91=EC=84=B1=20=EB=B0=8F=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../block/controller/BlockController.java | 30 +++++++++ .../block/controller/dto/BlockRequest.java | 4 ++ .../aliens/backend/block/domain/Block.java | 30 +++++++++ .../domain/repository/BlockRepository.java | 9 +++ .../backend/block/service/BlockService.java | 63 +++++++++++++++++++ .../chat/controller/ChatBlockController.java | 30 --------- .../dto/request/ChatBlockRequest.java | 4 -- .../aliens/backend/chat/domain/ChatBlock.java | 27 -------- .../repository/ChatBlockRepository.java | 10 --- .../chat/service/ChatBlockService.java | 37 ----------- .../service/BlockServiceServiceTest.java | 53 ++++++++++++++++ .../service/ChatBlockServiceTest.java | 37 ----------- 12 files changed, 189 insertions(+), 145 deletions(-) create mode 100644 src/main/java/com/aliens/backend/block/controller/BlockController.java create mode 100644 src/main/java/com/aliens/backend/block/controller/dto/BlockRequest.java create mode 100644 src/main/java/com/aliens/backend/block/domain/Block.java create mode 100644 src/main/java/com/aliens/backend/block/domain/repository/BlockRepository.java create mode 100644 src/main/java/com/aliens/backend/block/service/BlockService.java delete mode 100644 src/main/java/com/aliens/backend/chat/controller/ChatBlockController.java delete mode 100644 src/main/java/com/aliens/backend/chat/controller/dto/request/ChatBlockRequest.java delete mode 100644 src/main/java/com/aliens/backend/chat/domain/ChatBlock.java delete mode 100644 src/main/java/com/aliens/backend/chat/domain/repository/ChatBlockRepository.java delete mode 100644 src/main/java/com/aliens/backend/chat/service/ChatBlockService.java create mode 100644 src/test/java/com/aliens/backend/block/service/BlockServiceServiceTest.java delete mode 100644 src/test/java/com/aliens/backend/chatting/service/ChatBlockServiceTest.java diff --git a/src/main/java/com/aliens/backend/block/controller/BlockController.java b/src/main/java/com/aliens/backend/block/controller/BlockController.java new file mode 100644 index 00000000..7cc65477 --- /dev/null +++ b/src/main/java/com/aliens/backend/block/controller/BlockController.java @@ -0,0 +1,30 @@ +package com.aliens.backend.block.controller; + +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.block.controller.dto.BlockRequest; +import com.aliens.backend.block.service.BlockService; +import com.aliens.backend.global.config.resolver.Login; +import com.aliens.backend.global.response.SuccessResponse; +import com.aliens.backend.global.response.success.ChatSuccess; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class BlockController { + + private final BlockService blockService; + + public BlockController(BlockService blockService) { + this.blockService = blockService; + } + + @PostMapping("/chat/block") + public SuccessResponse blockPartner(@Login LoginMember loginMember, + @RequestBody BlockRequest request) { + return SuccessResponse.of( + ChatSuccess.BLOCK_SUCCESS, + blockService.blockPartner(loginMember, request) + ); + } +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/block/controller/dto/BlockRequest.java b/src/main/java/com/aliens/backend/block/controller/dto/BlockRequest.java new file mode 100644 index 00000000..160d621c --- /dev/null +++ b/src/main/java/com/aliens/backend/block/controller/dto/BlockRequest.java @@ -0,0 +1,4 @@ +package com.aliens.backend.block.controller.dto; + +public record BlockRequest(Long partnerId, Long chatRoomId) { +} diff --git a/src/main/java/com/aliens/backend/block/domain/Block.java b/src/main/java/com/aliens/backend/block/domain/Block.java new file mode 100644 index 00000000..1c2a0ad6 --- /dev/null +++ b/src/main/java/com/aliens/backend/block/domain/Block.java @@ -0,0 +1,30 @@ +package com.aliens.backend.block.domain; + +import com.aliens.backend.auth.domain.Member; +import jakarta.persistence.*; + +@Entity +public class Block { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column + private Long id; + + @ManyToOne + @JoinColumn(name = "blocking_member_id") + private Member blockingMember; + + @ManyToOne + @JoinColumn(name = "blocked_member_id") + private Member blockedMember; + + protected Block() { + } + + public static Block of(Member blockedMember, Member blockingMember) { + Block block = new Block(); + block.blockingMember = blockingMember; + block.blockedMember = blockedMember; + return block; + } +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/block/domain/repository/BlockRepository.java b/src/main/java/com/aliens/backend/block/domain/repository/BlockRepository.java new file mode 100644 index 00000000..92b85c4b --- /dev/null +++ b/src/main/java/com/aliens/backend/block/domain/repository/BlockRepository.java @@ -0,0 +1,9 @@ +package com.aliens.backend.block.domain.repository; + +import com.aliens.backend.block.domain.Block; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface BlockRepository extends JpaRepository { +} diff --git a/src/main/java/com/aliens/backend/block/service/BlockService.java b/src/main/java/com/aliens/backend/block/service/BlockService.java new file mode 100644 index 00000000..31beb66a --- /dev/null +++ b/src/main/java/com/aliens/backend/block/service/BlockService.java @@ -0,0 +1,63 @@ +package com.aliens.backend.block.service; + +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.domain.Member; +import com.aliens.backend.auth.domain.repository.MemberRepository; +import com.aliens.backend.block.domain.repository.BlockRepository; +import com.aliens.backend.block.controller.dto.BlockRequest; +import com.aliens.backend.block.domain.Block; +import com.aliens.backend.chat.domain.ChatRoom; +import com.aliens.backend.chat.domain.repository.ChatRoomRepository; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.response.error.MemberError; +import com.aliens.backend.global.response.success.ChatSuccess; +import jakarta.transaction.Transactional; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class BlockService { + private final BlockRepository blockRepository; + private final ChatRoomRepository chatRoomRepository; + private final MemberRepository memberRepository; + + public BlockService(BlockRepository blockRepository, ChatRoomRepository chatRoomRepository, final MemberRepository memberRepository) { + this.blockRepository = blockRepository; + this.chatRoomRepository = chatRoomRepository; + this.memberRepository = memberRepository; + } + + @Transactional + public String blockPartner(LoginMember loginMember, BlockRequest blockRequest) { + blockMember(loginMember, blockRequest); + blockChatRoom(blockRequest); + return ChatSuccess.BLOCK_SUCCESS.getMessage(); + } + + private void blockMember(final LoginMember loginMember, final BlockRequest blockRequest) { + Member blockingMember = getMember(loginMember); + Member blockedMember = findMemberById(blockRequest.partnerId()); + + Block block = Block.of(blockingMember, blockedMember); + blockRepository.save(block); + } + + private void blockChatRoom(final BlockRequest blockRequest) { + List chatRooms = findChatRoomsById(blockRequest.chatRoomId()); + chatRooms.forEach(ChatRoom::block); + chatRoomRepository.saveAll(chatRooms); + } + + private List findChatRoomsById(final Long chatRoomId) { + return chatRoomRepository.findByRoomId(chatRoomId); + } + + private Member findMemberById(final Long partnerId) { + return memberRepository.findById(partnerId).orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER)); + } + + private Member getMember(final LoginMember loginMember) { + return memberRepository.findById(loginMember.memberId()).orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER)); + } +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/controller/ChatBlockController.java b/src/main/java/com/aliens/backend/chat/controller/ChatBlockController.java deleted file mode 100644 index 630c640d..00000000 --- a/src/main/java/com/aliens/backend/chat/controller/ChatBlockController.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.aliens.backend.chat.controller; - -import com.aliens.backend.chat.controller.dto.request.ChatBlockRequest; -import com.aliens.backend.chat.service.ChatBlockService; -import com.aliens.backend.global.config.resolver.Login; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Collections; -import java.util.Map; - - -@RestController -public class ChatBlockController { - - private final ChatBlockService chatBlockService; - - public ChatBlockController(ChatBlockService chatBlockService) { - this.chatBlockService = chatBlockService; - } - - @PostMapping("/chat/block") - public ResponseEntity> blockPartner(@Login Long memberId, @RequestBody ChatBlockRequest chatBlockRequest) { - String result = chatBlockService.blockPartner(memberId, chatBlockRequest); - Map response = Collections.singletonMap("response", result); - return ResponseEntity.ok(response); - } -} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatBlockRequest.java b/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatBlockRequest.java deleted file mode 100644 index ac92562a..00000000 --- a/src/main/java/com/aliens/backend/chat/controller/dto/request/ChatBlockRequest.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.aliens.backend.chat.controller.dto.request; - -public record ChatBlockRequest(Long partnerId, Long chatRoomId) { -} diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatBlock.java b/src/main/java/com/aliens/backend/chat/domain/ChatBlock.java deleted file mode 100644 index cfb8cce8..00000000 --- a/src/main/java/com/aliens/backend/chat/domain/ChatBlock.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.aliens.backend.chat.domain; - -import com.aliens.backend.chat.controller.dto.request.ChatBlockRequest; -import jakarta.persistence.*; - -@Entity -@Table(name = "CHAT_BLOCK") -public class ChatBlock { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column - private Long id; - @Column(name = "blocked_member_id") - private Long blockedMemberId; - @Column(name = "blocking_member_id") - private Long blockingMemberId; - - protected ChatBlock() { - } - - public static ChatBlock of(Long blockingMemberId, ChatBlockRequest chatBlockRequest) { - ChatBlock chatBlock = new ChatBlock(); - chatBlock.blockedMemberId = chatBlockRequest.partnerId(); - chatBlock.blockingMemberId = blockingMemberId; - return chatBlock; - } -} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/chat/domain/repository/ChatBlockRepository.java b/src/main/java/com/aliens/backend/chat/domain/repository/ChatBlockRepository.java deleted file mode 100644 index b4d063f6..00000000 --- a/src/main/java/com/aliens/backend/chat/domain/repository/ChatBlockRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.aliens.backend.chat.domain.repository; - -import com.aliens.backend.chat.domain.ChatBlock; -import com.aliens.backend.chat.domain.ChatReport; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface ChatBlockRepository extends JpaRepository { -} diff --git a/src/main/java/com/aliens/backend/chat/service/ChatBlockService.java b/src/main/java/com/aliens/backend/chat/service/ChatBlockService.java deleted file mode 100644 index 52f74308..00000000 --- a/src/main/java/com/aliens/backend/chat/service/ChatBlockService.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.aliens.backend.chat.service; - -import com.aliens.backend.chat.controller.dto.request.ChatBlockRequest; -import com.aliens.backend.chat.domain.ChatBlock; -import com.aliens.backend.chat.domain.ChatRoom; -import com.aliens.backend.chat.domain.repository.ChatBlockRepository; -import com.aliens.backend.chat.domain.repository.ChatRoomRepository; -import com.aliens.backend.global.success.ChatSuccessCode; -import jakarta.transaction.Transactional; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class ChatBlockService { - private final ChatBlockRepository chatBlockRepository; - private final ChatRoomRepository chatRoomRepository; - - public ChatBlockService(ChatBlockRepository chatBlockRepository, ChatRoomRepository chatRoomRepository) { - this.chatBlockRepository = chatBlockRepository; - this.chatRoomRepository = chatRoomRepository; - } - - @Transactional - public String blockPartner(Long memberId, ChatBlockRequest chatBlockRequest) { - ChatBlock chatBlock = ChatBlock.of(memberId, chatBlockRequest); - chatBlockRepository.save(chatBlock); - blockChatRoom(chatBlockRequest.chatRoomId()); - return ChatSuccessCode.BLOCK_SUCCESS.getMessage(); - } - - private void blockChatRoom(Long chatRoomId) { - List chatRooms = chatRoomRepository.findByRoomId(chatRoomId); - chatRooms.forEach(ChatRoom::block); - chatRoomRepository.saveAll(chatRooms); - } -} \ No newline at end of file diff --git a/src/test/java/com/aliens/backend/block/service/BlockServiceServiceTest.java b/src/test/java/com/aliens/backend/block/service/BlockServiceServiceTest.java new file mode 100644 index 00000000..c91dffa5 --- /dev/null +++ b/src/test/java/com/aliens/backend/block/service/BlockServiceServiceTest.java @@ -0,0 +1,53 @@ +package com.aliens.backend.block.service; + +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.domain.Member; +import com.aliens.backend.block.controller.dto.BlockRequest; +import com.aliens.backend.chat.domain.ChatRoom; +import com.aliens.backend.block.domain.repository.BlockRepository; +import com.aliens.backend.chat.domain.repository.ChatRoomRepository; +import com.aliens.backend.global.BaseServiceTest; +import com.aliens.backend.global.DummyGenerator; +import com.aliens.backend.global.response.success.ChatSuccess; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +class BlockServiceServiceTest extends BaseServiceTest { + + @Autowired BlockService blockService; + @Autowired BlockRepository blockRepository; + @Autowired ChatRoomRepository chatRoomRepository; + @Autowired DummyGenerator dummyGenerator; + + + @Test + @DisplayName("채팅 상대 차단") + void blockPartner() { + //Given + List members = dummyGenerator.generateMultiMember(2); + Member member = members.get(0); + Member partner = members.get(1); + LoginMember myLoginMember = member.getLoginMember(); + + ChatRoom chatRoom = setChatRoom(member, partner); + + BlockRequest blockRequest = new BlockRequest(partner.getId(), chatRoom.getRoomId()); + + //When + String result = blockService.blockPartner(myLoginMember, blockRequest); + + //Then + String expectedResponse = ChatSuccess.BLOCK_SUCCESS.getMessage(); + Assertions.assertEquals(expectedResponse, result); + } + + private ChatRoom setChatRoom(final Member member, final Member partner) { + ChatRoom chatRoom = ChatRoom.of(member, partner); + chatRoomRepository.save(chatRoom); + return chatRoom; + } +} \ No newline at end of file diff --git a/src/test/java/com/aliens/backend/chatting/service/ChatBlockServiceTest.java b/src/test/java/com/aliens/backend/chatting/service/ChatBlockServiceTest.java deleted file mode 100644 index 27d2f86a..00000000 --- a/src/test/java/com/aliens/backend/chatting/service/ChatBlockServiceTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.aliens.backend.chatting.service; - -import com.aliens.backend.chat.controller.dto.request.ChatBlockRequest; -import com.aliens.backend.chat.domain.repository.ChatBlockRepository; -import com.aliens.backend.chat.domain.repository.ChatRoomRepository; -import com.aliens.backend.chat.service.ChatBlockService; -import com.aliens.backend.global.success.ChatSuccessCode; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; - -@SpringBootTest -public class ChatBlockServiceTest { - @Autowired - ChatBlockService chatBlockService; - @MockBean - ChatRoomRepository chatRoomRepository; - @MockBean - ChatBlockRepository chatBlockRepository; - - @Test - @DisplayName("채팅 상대 차단") - void blockPartner() { - //given - Long memberId = 1L; - Long partnerId = 2L; - Long roomId = 1L; - ChatBlockRequest chatBlockRequest = new ChatBlockRequest(partnerId, roomId); - //when - String result = chatBlockService.blockPartner(memberId, chatBlockRequest); - //then - Assertions.assertEquals(ChatSuccessCode.BLOCK_SUCCESS.getMessage(), result); - } -} \ No newline at end of file From 3c5b56df3e01f49971b053ff1d613a454686eb42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:41:23 +0900 Subject: [PATCH 195/215] =?UTF-8?q?style(MemberInfoServiceTest)=20:=20Base?= =?UTF-8?q?Test=20=EC=83=81=EC=86=8D=ED=95=A8=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20@SpringBoot=20=EC=95=A0=EB=84=88=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=20=EA=B0=9D=EC=B2=B4=20=EB=82=98=EC=97=B4=20=EC=8A=A4=ED=83=80?= =?UTF-8?q?=EC=9D=BC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/member/MemberInfoServiceTest.java | 237 ------------------ .../member/service/MemberInfoServiceTest.java | 187 ++++++++++++++ 2 files changed, 187 insertions(+), 237 deletions(-) delete mode 100644 src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java create mode 100644 src/test/java/com/aliens/backend/member/service/MemberInfoServiceTest.java diff --git a/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java b/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java deleted file mode 100644 index ca96f5bd..00000000 --- a/src/test/java/com/aliens/backend/member/MemberInfoServiceTest.java +++ /dev/null @@ -1,237 +0,0 @@ -package com.aliens.backend.member; - -import com.aliens.backend.auth.controller.dto.LoginMember; -import com.aliens.backend.auth.domain.Member; -import com.aliens.backend.auth.domain.repository.MemberRepository; -import com.aliens.backend.auth.service.PasswordEncoder; -import com.aliens.backend.email.domain.EmailAuthentication; -import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; -import com.aliens.backend.global.BaseTest; -import com.aliens.backend.member.sevice.SymmetricKeyEncoder; -import com.aliens.backend.member.controller.dto.*; -import com.aliens.backend.member.controller.dto.request.SignUpRequest; -import com.aliens.backend.member.controller.dto.request.TemporaryPasswordRequest; -import com.aliens.backend.member.controller.dto.response.MemberPageResponse; -import com.aliens.backend.member.controller.dto.response.MemberResponse; -import com.aliens.backend.member.domain.Image; -import com.aliens.backend.member.domain.MemberInfo; -import com.aliens.backend.member.domain.repository.ImageRepository; -import com.aliens.backend.member.domain.repository.MemberInfoRepository; -import com.aliens.backend.member.domain.MemberStatus; -import com.aliens.backend.member.sevice.MemberInfoService; -import com.aliens.backend.uploader.dto.S3File; -import org.junit.jupiter.api.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.web.multipart.MultipartFile; - - -@SpringBootTest -class MemberInfoServiceTest extends BaseTest { - - @Autowired - MemberInfoService memberInfoService; - @Autowired - MemberInfoRepository memberInfoRepository; - @Autowired - EmailAuthenticationRepository emailAuthenticationRepository; - @Autowired - ImageRepository imageRepository; - @Autowired - MemberRepository memberRepository; - @Autowired - SymmetricKeyEncoder symmetricKeyEncoder; - @Autowired - PasswordEncoder passwordEncoder; - - MultipartFile file; - LoginMember loginMember; - String givenName = "김명준"; - String givenEmail = "tmp@example"; - String givenPassword = "tmpPassword"; - String givenGender = "MALE"; - String givenMbti = "INTJ"; - String givenBirthday = "1998-11-25"; - String givenNationality = "KOREA"; - String givenAboutMe = "반갑습니다."; - String givenFileName = "tmpFile"; - String givenFileURL = "example.com"; - - @BeforeEach - void setUp() { - setUpEmailEntity(givenEmail); - Image image = setUpImage(); - Member member = setUpMember(image); - setUpMemberInfo(member); - setUpLoginMember(member); - file = setUpMockMultipartFile(); - } - - @Test - @DisplayName("회원가입") - void signUpTest() { - //Given - SignUpRequest signUpRequest = createSignUpRequest(); - - //When - String result = memberInfoService.signUp(signUpRequest, file); - - //Then - Assertions.assertEquals(MemberResponse.SIGN_UP_SUCCESS.getMessage(), result); - } - - @Test - @DisplayName("회원 탈퇴") - void withdrawTest() { - //When - String result = memberInfoService.withdraw(loginMember); - - //Then - Assertions.assertEquals(MemberResponse.WITHDRAW_SUCCESS.getMessage(),result); - } - - @Test - @DisplayName("임시 비밀번호 발급") - void temporaryPassword() { - //Given - TemporaryPasswordRequest temporaryPasswordRequest = new TemporaryPasswordRequest(givenEmail,givenName); - - //When - String result = memberInfoService.generateTemporaryPassword(temporaryPasswordRequest); - - //Then - Assertions.assertEquals(MemberResponse.TEMPORARY_PASSWORD_GENERATED_SUCCESS.getMessage(),result); - } - - @Test - @DisplayName("비밀번호 변경") - void changePassword() { - //Given - String newPassword = "newPassword"; - - //When - String result = memberInfoService.changePassword(loginMember, newPassword); - - //Then - Assertions.assertEquals(MemberResponse.PASSWORD_CHANGE_SUCCESS.getMessage(),result); - } - - @Test - @DisplayName("프로필 이미지 변경") - void changeProfileImage() { - //When - String result = memberInfoService.changeProfileImage(loginMember, file); - - //Then - Assertions.assertEquals(MemberResponse.PROFILE_IMAGE_CHANGE_SUCCESS.getMessage(),result); - } - - @Test - @DisplayName("자기소개 변경") - void changeAboutMe() { - //Given - String newAboutMe = "newAboutMe"; - - //When - String result = memberInfoService.changeAboutMe(loginMember, newAboutMe); - - //Then - Assertions.assertEquals(MemberResponse.ABOUT_ME_CHANGE_SUCCESS.getMessage(),result); - } - - @Test - @DisplayName("MBTI 변경") - void changeMBTI() { - //Given - String newMBTI = "ESTJ"; - - //When - String result = memberInfoService.changeMBTI(loginMember, newMBTI); - - //Then - Assertions.assertEquals(MemberResponse.MBTI_CHANGE_SUCCESS.getMessage(),result); - } - - @Test - @DisplayName("상태 요청") - void getStatus() { - //When - String result = memberInfoService.getStatus(loginMember); - - //Then - Assertions.assertEquals(MemberStatus.NOT_APPLIED_NOT_MATCHED.getMessage(),result); - } - - @Test - @DisplayName("회원 개인정보 요청") - void getMemberInfo() { - //Given - MemberPageResponse expectedResponse = new MemberPageResponse(givenName, - givenMbti, - givenGender, - givenNationality, - givenBirthday, - givenAboutMe, - givenFileURL); - - //When - MemberPageResponse result = memberInfoService.getMemberPage(loginMember); - - //Then - Assertions.assertEquals(expectedResponse,result); - } - - private void setUpLoginMember(final Member member) { - loginMember = member.getLoginMember(); - } - - private void setUpMemberInfo(final Member member) { - EncodedMember encodedRequest = new EncodedMember(symmetricKeyEncoder.encrypt(givenGender), - symmetricKeyEncoder.encrypt(givenMbti), - symmetricKeyEncoder.encrypt(givenBirthday), - symmetricKeyEncoder.encrypt(givenNationality), - symmetricKeyEncoder.encrypt(givenAboutMe)); - - MemberInfo memberInfo = MemberInfo.of(encodedRequest, member); - memberInfoRepository.save(memberInfo); - } - - private Member setUpMember(final Image image) { - EncodedSignUp signUp = new EncodedSignUp(givenName, givenEmail, passwordEncoder.encrypt(givenPassword)); - Member member = Member.of(signUp, image); - return member; - } - - private Image setUpImage() { - Image image = Image.from(new S3File(givenFileName, givenFileURL)); - return image; - } - - private MultipartFile setUpMockMultipartFile() { - String fileName = "test"; - String path = "/test"; - String contentType = "image/png"; - byte[] content = fileName.getBytes(); - return new MockMultipartFile(fileName, path, contentType, content); - } - - private void setUpEmailEntity(final String givenEmail) { - EmailAuthentication emailEntity = new EmailAuthentication(givenEmail); - emailEntity.authenticate(); - emailAuthenticationRepository.save(emailEntity); - } - - private SignUpRequest createSignUpRequest() { - SignUpRequest signUpRequest = new SignUpRequest(givenEmail, - "password", - "tmpName", - "INTJ", - "MALE", - "KOREA", - "1998-11-25", - "반갑습니다" - ); - return signUpRequest; - } -} diff --git a/src/test/java/com/aliens/backend/member/service/MemberInfoServiceTest.java b/src/test/java/com/aliens/backend/member/service/MemberInfoServiceTest.java new file mode 100644 index 00000000..56c45566 --- /dev/null +++ b/src/test/java/com/aliens/backend/member/service/MemberInfoServiceTest.java @@ -0,0 +1,187 @@ +package com.aliens.backend.member.service; + +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.domain.Member; +import com.aliens.backend.email.domain.EmailAuthentication; +import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; +import com.aliens.backend.global.BaseServiceTest; +import com.aliens.backend.global.DummyGenerator; +import com.aliens.backend.member.controller.dto.request.SignUpRequest; +import com.aliens.backend.member.controller.dto.request.TemporaryPasswordRequest; +import com.aliens.backend.member.controller.dto.response.MemberPageResponse; +import com.aliens.backend.member.controller.dto.response.MemberResponse; +import com.aliens.backend.member.domain.MemberStatus; +import com.aliens.backend.member.sevice.MemberInfoService; +import org.junit.jupiter.api.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.multipart.MultipartFile; + + +class MemberInfoServiceTest extends BaseServiceTest { + + @Autowired MemberInfoService memberInfoService; + @Autowired EmailAuthenticationRepository emailRepository; + @Autowired DummyGenerator dummyGenerator; + + MultipartFile file; + LoginMember loginMember; + + @BeforeEach + void setUp() { + setUpEmailEntity(DummyGenerator.GIVEN_EMAIL); + Member member = dummyGenerator.generateSingleMember(); + loginMember = member.getLoginMember(); + file = dummyGenerator.generateMultipartFile(); + } + + @Test + @DisplayName("회원가입") + void signUpTest() { + //Given + String expectedMessage = MemberResponse.SIGN_UP_SUCCESS.getMessage(); + SignUpRequest signUpRequest = createSignUpRequest(); + + //When + String result = memberInfoService.signUp(signUpRequest, file); + + //Then + Assertions.assertEquals(expectedMessage, result); + } + + @Test + @DisplayName("회원 탈퇴") + void withdrawTest() { + //Given + String expectedMessage = MemberResponse.WITHDRAW_SUCCESS.getMessage(); + + //When + String result = memberInfoService.withdraw(loginMember); + + //Then + Assertions.assertEquals(expectedMessage,result); + } + + @Test + @DisplayName("임시 비밀번호 발급") + void temporaryPassword() { + //Given + String expectedMessage = MemberResponse.TEMPORARY_PASSWORD_GENERATED_SUCCESS.getMessage(); + TemporaryPasswordRequest request = new TemporaryPasswordRequest( + DummyGenerator.GIVEN_EMAIL, + DummyGenerator.GIVEN_NAME + ); + + //When + String result = memberInfoService.generateTemporaryPassword(request); + + //Then + Assertions.assertEquals(expectedMessage, result); + } + + @Test + @DisplayName("비밀번호 변경") + void changePassword() { + //Given + String expectedMessage = MemberResponse.PASSWORD_CHANGE_SUCCESS.getMessage(); + String newPassword = "newPassword"; + + //When + String result = memberInfoService.changePassword(loginMember, newPassword); + + //Then + Assertions.assertEquals(expectedMessage,result); + } + + @Test + @DisplayName("프로필 이미지 변경") + void changeProfileImage() { + //Given + String expectedMessage = MemberResponse.PROFILE_IMAGE_CHANGE_SUCCESS.getMessage(); + + //When + String result = memberInfoService.changeProfileImage(loginMember, file); + + //Then + Assertions.assertEquals(expectedMessage,result); + } + + @Test + @DisplayName("자기소개 변경") + void changeAboutMe() { + //Given + String expectedMessage = MemberResponse.ABOUT_ME_CHANGE_SUCCESS.getMessage(); + String newAboutMe = "newAboutMe"; + + //When + String result = memberInfoService.changeAboutMe(loginMember, newAboutMe); + + //Then + Assertions.assertEquals(expectedMessage,result); + } + + @Test + @DisplayName("MBTI 변경") + void changeMBTI() { + //Given + String expectedMessage = MemberResponse.MBTI_CHANGE_SUCCESS.getMessage(); + String newMBTI = "ESTJ"; + + //When + String result = memberInfoService.changeMBTI(loginMember, newMBTI); + + //Then + Assertions.assertEquals(expectedMessage,result); + } + + @Test + @DisplayName("상태 요청") + void getStatus() { + //Given + String expectedMessage = MemberStatus.NOT_APPLIED_NOT_MATCHED.getMessage(); + + //When + String result = memberInfoService.getStatus(loginMember); + + //Then + Assertions.assertEquals(expectedMessage, result); + } + + @Test + @DisplayName("회원 개인정보 요청") + void getMemberInfo() { + //Given + MemberPageResponse expectedResponse = new MemberPageResponse( + DummyGenerator.GIVEN_NAME, + DummyGenerator.GIVEN_MBTI, + DummyGenerator.GIVEN_GENDER, + DummyGenerator.GIVEN_NATIONALITY, + DummyGenerator.GIVEN_BIRTHDAY, + DummyGenerator.GIVEN_ABOUT_ME, + DummyGenerator.GIVEN_FILE_URL); + + //When + MemberPageResponse result = memberInfoService.getMemberPage(loginMember); + + //Then + Assertions.assertEquals(expectedResponse,result); + } + + private void setUpEmailEntity(final String givenEmail) { + EmailAuthentication emailEntity = new EmailAuthentication(givenEmail); + emailEntity.authenticate(); + emailRepository.save(emailEntity); + } + + private SignUpRequest createSignUpRequest() { + SignUpRequest signUpRequest = new SignUpRequest( + DummyGenerator.GIVEN_EMAIL, + DummyGenerator.GIVEN_PASSWORD, + DummyGenerator.GIVEN_NAME, + DummyGenerator.GIVEN_MBTI, + DummyGenerator.GIVEN_GENDER, + DummyGenerator.GIVEN_NATIONALITY, + DummyGenerator.GIVEN_BIRTHDAY, + DummyGenerator.GIVEN_ABOUT_ME); + return signUpRequest; + } +} From 1bfb4677cf33d2f8ba03c83aa687299ecac9f787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:42:20 +0900 Subject: [PATCH 196/215] =?UTF-8?q?style(MatchingApplicationService)=20:?= =?UTF-8?q?=20private=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8A=94=20public=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=95=84=EB=9E=98=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MatchingApplicationService.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index 71d8166e..8decf16f 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -1,7 +1,8 @@ package com.aliens.backend.mathcing.service; -import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.response.success.MatchingSuccess; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; @@ -31,10 +32,11 @@ public MatchingApplicationService(final MatchingApplicationRepository matchingAp } @Transactional - public void saveParticipant(final MatchingApplicationRequest matchingApplicationRequest) { + public String saveParticipant(final MatchingApplicationRequest matchingApplicationRequest) { MatchingRound currentRound = getCurrentRound(); checkReceptionTime(currentRound); matchingApplicationRepository.save(matchingApplicationRequest.toEntity(currentRound)); + return MatchingSuccess.APPLY_MATCHING_SUCCESS.getMessage(); } @Transactional(readOnly = true) @@ -46,19 +48,20 @@ public MatchingApplicationResponse findMatchingApplication(final Long memberId) return MatchingApplicationResponse.of(matchingApplication); } + private MatchingRound getCurrentRound() { + return matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } + @Transactional - public void deleteMatchingApplication(final Long memberId) { + public String deleteMatchingApplication(final Long memberId) { MatchingRound currentRound = getCurrentRound(); checkReceptionTime(currentRound); MatchingApplication matchingApplication = matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, memberId)) .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); matchingApplicationRepository.delete(matchingApplication); - } - - private MatchingRound getCurrentRound() { - return matchingRoundRepository.findCurrentRound() - .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + return MatchingSuccess.CANCEL_MATCHING_APPLICATION_SUCCESS.getMessage(); } private void checkReceptionTime(MatchingRound matchingRound) { From 9c72755b1fe0f607d0a68c168ec06b4ab5c4f385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:43:01 +0900 Subject: [PATCH 197/215] =?UTF-8?q?refactor(MatchingApplicationServiceTest?= =?UTF-8?q?)=20:=20=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=9C=BC=EB=A1=9C=EC=9D=B8=ED=95=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MatchingApplicationServiceTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) rename src/test/java/com/aliens/backend/matching/{unit => }/service/MatchingApplicationServiceTest.java (94%) diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java similarity index 94% rename from src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java rename to src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java index 4614fcf2..3dc96c3b 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java @@ -1,9 +1,9 @@ -package com.aliens.backend.matching.unit.service; +package com.aliens.backend.matching.service; -import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; -import com.aliens.backend.matching.util.MockClock; +import com.aliens.backend.matching.time.MockClock; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; @@ -20,15 +20,15 @@ import java.time.LocalDateTime; -import static com.aliens.backend.matching.util.MockTime.INVALID_TIME; -import static com.aliens.backend.matching.util.MockTime.VALID_TIME; +import static com.aliens.backend.matching.time.MockTime.INVALID_TIME; +import static com.aliens.backend.matching.time.MockTime.VALID_TIME; import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; import static com.aliens.backend.mathcing.controller.dto.response.MatchingResponse.*; import static org.assertj.core.api.Assertions.*; @SpringBootTest -public class MatchingApplicationServiceTest { +class MatchingApplicationServiceTest { @Autowired MatchingApplicationService matchingApplicationService; @Autowired MatchingApplicationRepository matchingApplicationRepository; @Autowired MatchingRoundRepository matchingRoundRepository; From 779faf39947e1c36b91bf027adb3828fbae76e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:43:35 +0900 Subject: [PATCH 198/215] =?UTF-8?q?refactor(MatchingBusinessTest)=20:=20Ma?= =?UTF-8?q?tchingApplicationGenerator=20=EB=A5=BC=20DummyGenerator?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/MatchingBusinessTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename src/test/java/com/aliens/backend/matching/{unit => }/business/MatchingBusinessTest.java (84%) diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java similarity index 84% rename from src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java rename to src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java index 8270d79b..32c76cf2 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java @@ -1,17 +1,17 @@ -package com.aliens.backend.matching.unit.business; +package com.aliens.backend.matching.business; -import com.aliens.backend.global.error.MatchingError; +import com.aliens.backend.global.DummyGenerator; +import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; -import com.aliens.backend.matching.util.MockClock; -import com.aliens.backend.matching.util.MockTime; +import com.aliens.backend.matching.time.MockClock; +import com.aliens.backend.matching.time.MockTime; import com.aliens.backend.mathcing.business.MatchingBusiness; import com.aliens.backend.mathcing.domain.MatchingResult; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingResultRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; -import com.aliens.backend.mathcing.service.MatchingApplicationService; import com.aliens.backend.mathcing.service.MatchingService; import com.aliens.backend.mathcing.service.model.Participant; import org.assertj.core.api.Assertions; @@ -28,13 +28,13 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @SpringBootTest -public class MatchingBusinessTest { +class MatchingBusinessTest { @Autowired MatchingService matchingService; @Autowired MatchingApplicationRepository matchingApplicationRepository; @Autowired MatchingRoundRepository matchingRoundRepository; @Autowired MatchingResultRepository matchingResultRepository; @Autowired MatchingBusiness matchingBusiness; - @Autowired MatchingApplicationGenerator matchingApplicationGenerator; + @Autowired DummyGenerator dummyGenerator; @Autowired MatchingTimeProperties matchingTimeProperties; @Autowired MockClock mockClock; @@ -53,7 +53,7 @@ void setUp() { @DisplayName("매칭 로직 실행 테스트") void matchingLogicTest() { mockClock.mockTime(MockTime.VALID_TIME); - matchingApplicationGenerator.applyToMatch(15L); + dummyGenerator.generateAppliersToMatch(15L); List result = matchingBusiness.operateMatching(matchingApplicationRepository.findAllByMatchingRound(currentRound)); @@ -66,7 +66,7 @@ void matchingLogicTest() { void operateMatchingTest() { // given mockClock.mockTime(MockTime.VALID_TIME); - matchingApplicationGenerator.applyToMatch(20L); + dummyGenerator.generateAppliersToMatch(20L); // when matchingService.operateMatching(); From 21e69ba1d2c1da33a5c9570b720b16deb50a5104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:44:08 +0900 Subject: [PATCH 199/215] =?UTF-8?q?feat(Member)=20:=20Chat=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=EC=97=90=EC=84=9C=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EB=90=98=EB=8A=94=20get=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/aliens/backend/auth/domain/Member.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/aliens/backend/auth/domain/Member.java b/src/main/java/com/aliens/backend/auth/domain/Member.java index 0f139d69..b0fec300 100644 --- a/src/main/java/com/aliens/backend/auth/domain/Member.java +++ b/src/main/java/com/aliens/backend/auth/domain/Member.java @@ -103,6 +103,10 @@ public void changeProfileImage(final S3File newFile) { image.change(newFile); } + public Long getId() { + return id; + } + @Override public String toString() { return String.format("email: %s, role : %s", this.email, this.role); From b3521b7ac056407d759d6d63c6336b3e8e390b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:45:02 +0900 Subject: [PATCH 200/215] =?UTF-8?q?style(socket)=20:=20=EC=86=8C=EC=BC=93?= =?UTF-8?q?=EA=B3=BC=20=EA=B4=80=EB=A0=A8=EB=90=9C=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A5=BC=20=EB=AA=85=EC=8B=9C=EC=A0=81=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EA=B5=AC=EB=B6=84=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=B4=20?= =?UTF-8?q?=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/chatting/{util => socket}/ChatClient.java | 10 +++++++--- .../chatting/{util => socket}/ChatClientHandler.java | 11 ++++------- 2 files changed, 11 insertions(+), 10 deletions(-) rename src/test/java/com/aliens/backend/chatting/{util => socket}/ChatClient.java (78%) rename src/test/java/com/aliens/backend/chatting/{util => socket}/ChatClientHandler.java (75%) diff --git a/src/test/java/com/aliens/backend/chatting/util/ChatClient.java b/src/test/java/com/aliens/backend/chatting/socket/ChatClient.java similarity index 78% rename from src/test/java/com/aliens/backend/chatting/util/ChatClient.java rename to src/test/java/com/aliens/backend/chatting/socket/ChatClient.java index 55ac4293..fdbc68cd 100644 --- a/src/test/java/com/aliens/backend/chatting/util/ChatClient.java +++ b/src/test/java/com/aliens/backend/chatting/socket/ChatClient.java @@ -1,7 +1,9 @@ -package com.aliens.backend.chatting.util; +package com.aliens.backend.chatting.socket; import com.aliens.backend.global.property.WebSocketProperties; +import org.springframework.messaging.simp.stomp.StompHeaders; import org.springframework.messaging.simp.stomp.StompSession; +import org.springframework.web.socket.WebSocketHttpHeaders; import org.springframework.web.socket.client.WebSocketClient; import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.messaging.WebSocketStompClient; @@ -25,9 +27,11 @@ public ChatClient(WebSocketProperties properties) { this.chatClientHandler = new ChatClientHandler(); } - public StompSession connect() throws Exception { + public StompSession connect(String accessToken) throws Exception { String url = "ws://localhost:" + port + endPoint; - StompSession session = stompClient.connect(url, chatClientHandler).get(); + WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); + headers.add("Authorization", accessToken); + StompSession session = stompClient.connectAsync(url, headers, chatClientHandler).get(); return session; } diff --git a/src/test/java/com/aliens/backend/chatting/util/ChatClientHandler.java b/src/test/java/com/aliens/backend/chatting/socket/ChatClientHandler.java similarity index 75% rename from src/test/java/com/aliens/backend/chatting/util/ChatClientHandler.java rename to src/test/java/com/aliens/backend/chatting/socket/ChatClientHandler.java index 590e0d7c..39739022 100644 --- a/src/test/java/com/aliens/backend/chatting/util/ChatClientHandler.java +++ b/src/test/java/com/aliens/backend/chatting/socket/ChatClientHandler.java @@ -1,18 +1,15 @@ -package com.aliens.backend.chatting.util; +package com.aliens.backend.chatting.socket; import org.springframework.messaging.simp.stomp.StompHeaders; import org.springframework.messaging.simp.stomp.StompSession; import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter; public class ChatClientHandler extends StompSessionHandlerAdapter { - public ChatClientHandler() { - } + public ChatClientHandler() {} @Override - public void afterConnected(StompSession session, StompHeaders connectedHeaders) { - } + public void afterConnected(StompSession session, StompHeaders connectedHeaders) {} @Override - public void handleFrame(StompHeaders headers, Object payload) { - } + public void handleFrame(StompHeaders headers, Object payload) {} } \ No newline at end of file From 4f1058a51d43ac4f0a6a785d107ea8efd25527e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:46:14 +0900 Subject: [PATCH 201/215] =?UTF-8?q?refactor(ChatReport,ChatRoom)=20:=20?= =?UTF-8?q?=EB=A9=A4=EB=B2=84=20=EA=B0=9D=EC=B2=B4=EC=99=80=20=EC=97=B0?= =?UTF-8?q?=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #47 --- .../backend/chat/domain/ChatReport.java | 32 +++++++++++-------- .../aliens/backend/chat/domain/ChatRoom.java | 28 ++++++++++------ 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatReport.java b/src/main/java/com/aliens/backend/chat/domain/ChatReport.java index 491ae6c3..2af9f3e8 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatReport.java +++ b/src/main/java/com/aliens/backend/chat/domain/ChatReport.java @@ -1,21 +1,23 @@ package com.aliens.backend.chat.domain; -import com.aliens.backend.chat.controller.dto.request.ChatReportRequest; -import com.aliens.backend.global.error.ChatError; -import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.auth.domain.Member; import jakarta.persistence.*; @Entity -@Table(name = "CHAT_REPORT") public class ChatReport { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column private Long id; - @Column(name = "reported_member_id") - private Long reportedMemberId; - @Column(name = "reporting_member_id") - private Long reportingMemberId; + + @ManyToOne + @JoinColumn(name = "reporting_member_id") + private Member reportingMember; + + @ManyToOne + @JoinColumn(name = "reported_member_id") + private Member reportedMember; + @Column private ChatReportCategory category; @Column @@ -24,13 +26,15 @@ public class ChatReport { protected ChatReport() { } - public static ChatReport of(Long reportingMemberId, ChatReportRequest chatReportRequest) { + public static ChatReport of(Member reportingMember, + Member reportedMember, + ChatReportCategory category, + String content) { ChatReport chatReport = new ChatReport(); - chatReport.reportedMemberId = chatReportRequest.partnerId(); - chatReport.reportingMemberId = reportingMemberId; - chatReport.category = ChatReportCategory.fromString(chatReportRequest.category()) - .orElseThrow(() -> new RestApiException(ChatError.INVALID_REPORT_CATEGORY)); - chatReport.content = chatReportRequest.content(); + chatReport.reportingMember = reportingMember; + chatReport.reportedMember = reportedMember; + chatReport.category = category; + chatReport.content = content; return chatReport; } } diff --git a/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java b/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java index d6b7b88b..15e66a3c 100644 --- a/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java +++ b/src/main/java/com/aliens/backend/chat/domain/ChatRoom.java @@ -1,31 +1,41 @@ package com.aliens.backend.chat.domain; +import com.aliens.backend.auth.domain.Member; import jakarta.persistence.*; @Entity -@Table(name = "CHAT_ROOM") public class ChatRoom { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column private Long id; + private Long roomId; - @Column(name = "member_id") - private Long memberId; - @Column(name = "partner_id") - private Long partnerId; + @Column private ChatRoomStatus status; + @ManyToOne + @JoinColumn(name = "member_id") + private Member member; + + @ManyToOne + @JoinColumn(name = "partner_id") + private Member partner; + protected ChatRoom() { } - public Long getRoomId() { - return roomId; + public static ChatRoom of(final Member me, final Member partner) { + ChatRoom chatRoom = new ChatRoom(); + chatRoom.member = me; + chatRoom.partner = partner; + return chatRoom; } - public Long getPartnerId() { - return partnerId; + public Long getRoomId() { + return roomId; } public ChatRoomStatus getStatus() { From cacd90bfef49e41e0bdfbc80e5b27cd3b03ee626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:46:55 +0900 Subject: [PATCH 202/215] =?UTF-8?q?refactor(ChatReportService)=20:=20?= =?UTF-8?q?=EB=A9=A4=EB=B2=84=20=EA=B0=9D=EC=B2=B4=EC=99=80=20=EC=97=B0?= =?UTF-8?q?=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=B6=94=EA=B0=80=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #47 --- .../chat/service/ChatReportService.java | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/aliens/backend/chat/service/ChatReportService.java b/src/main/java/com/aliens/backend/chat/service/ChatReportService.java index 97debaf2..af0dc51c 100644 --- a/src/main/java/com/aliens/backend/chat/service/ChatReportService.java +++ b/src/main/java/com/aliens/backend/chat/service/ChatReportService.java @@ -1,23 +1,47 @@ package com.aliens.backend.chat.service; +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.domain.Member; +import com.aliens.backend.auth.domain.repository.MemberRepository; import com.aliens.backend.chat.controller.dto.request.ChatReportRequest; import com.aliens.backend.chat.domain.ChatReport; import com.aliens.backend.chat.domain.repository.ChatReportRepository; -import com.aliens.backend.global.success.ChatSuccessCode; +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.response.error.MemberError; +import com.aliens.backend.global.response.success.ChatSuccess; import org.springframework.stereotype.Service; @Service public class ChatReportService { private final ChatReportRepository chatReportRepository; + private final MemberRepository memberRepository; - public ChatReportService(ChatReportRepository chatReportRepository) { + public ChatReportService(ChatReportRepository chatReportRepository, final MemberRepository memberRepository) { this.chatReportRepository = chatReportRepository; + this.memberRepository = memberRepository; } - public String reportPartner(Long memberId, ChatReportRequest chatReportRequest) { - ChatReport chatReport = ChatReport.of(memberId, chatReportRequest); + public String reportPartner(LoginMember loginMember, ChatReportRequest chatReportRequest) { + Member member = getMember(loginMember); + Member partner = findMemberById(chatReportRequest.partnerId()); + + ChatReport chatReport = ChatReport.of( + member, + partner, + chatReportRequest.category(), + chatReportRequest.content()); + chatReportRepository.save(chatReport); - return ChatSuccessCode.REPORT_SUCCESS.getMessage(); + + return ChatSuccess.REPORT_SUCCESS.getMessage(); + } + + private Member findMemberById(final Long partnerId) { + return memberRepository.findById(partnerId).orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER)); + } + + private Member getMember(final LoginMember loginMember) { + return memberRepository.findById(loginMember.memberId()).orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER)); } } From 0a1bc416114e6b0be498fc57a8081ed3becf9b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:47:57 +0900 Subject: [PATCH 203/215] =?UTF-8?q?refactor(ChatReportServiceTest)=20:=20?= =?UTF-8?q?=EC=8B=A4=EC=A0=9C=20=EB=A9=A4=EB=B2=84=EB=A5=BC=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20BaseTest=20=EC=83=81=EC=86=8D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ChatReportServiceTest.java | 61 +++++++++++++------ 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/src/test/java/com/aliens/backend/chatting/service/ChatReportServiceTest.java b/src/test/java/com/aliens/backend/chatting/service/ChatReportServiceTest.java index e5ec3a14..3f8ba842 100644 --- a/src/test/java/com/aliens/backend/chatting/service/ChatReportServiceTest.java +++ b/src/test/java/com/aliens/backend/chatting/service/ChatReportServiceTest.java @@ -1,36 +1,57 @@ package com.aliens.backend.chatting.service; +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.domain.Member; import com.aliens.backend.chat.controller.dto.request.ChatReportRequest; -import com.aliens.backend.chat.domain.repository.ChatReportRepository; +import com.aliens.backend.chat.domain.ChatReportCategory; +import com.aliens.backend.chat.domain.ChatRoom; +import com.aliens.backend.chat.domain.repository.ChatRoomRepository; import com.aliens.backend.chat.service.ChatReportService; -import com.aliens.backend.global.success.ChatSuccessCode; +import com.aliens.backend.global.BaseServiceTest; +import com.aliens.backend.global.DummyGenerator; +import com.aliens.backend.global.response.success.ChatSuccess; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -@SpringBootTest -public class ChatReportServiceTest { - @Autowired - ChatReportService chatReportService; - @MockBean - ChatReportRepository chatReportRepository; +import java.util.List; + +class ChatReportServiceTest extends BaseServiceTest { + + @Autowired ChatReportService chatReportService; + @Autowired ChatRoomRepository chatRoomRepository; + @Autowired DummyGenerator dummyGenerator; @Test @DisplayName("채팅 상대 신고") void blockPartner() { //given - Long memberId = 1L; - Long partnerId = 2L; - Long roomId = 1L; - String category = "ETC"; - String content = "신고 사유"; - ChatReportRequest chatReportRequest = new ChatReportRequest(partnerId, roomId, category, content); - //when - String result = chatReportService.reportPartner(memberId, chatReportRequest); - //then - Assertions.assertEquals(ChatSuccessCode.REPORT_SUCCESS.getMessage(), result); + List members = dummyGenerator.generateMultiMember(2); + Member member = members.get(0); + Member partner = members.get(1); + LoginMember loginMember = member.getLoginMember(); + + ChatRoom chatRoom = ChatRoom.of(member, partner); + chatRoomRepository.save(chatRoom); + + ChatReportRequest request = createRequest(partner, chatRoom); + + //When + String result = chatReportService.reportPartner(loginMember, request); + + //Then + Assertions.assertEquals(ChatSuccess.REPORT_SUCCESS.getMessage(), result); + } + + private ChatReportRequest createRequest(final Member partner, final ChatRoom chatRoom) { + ChatReportCategory givenCategory = ChatReportCategory.ETC; + String givenContent = "신고 사유"; + + return new ChatReportRequest(partner.getId(), + chatRoom.getRoomId(), + givenCategory, + givenContent + ); } } \ No newline at end of file From 28f1d0909643beefdadbe73a8cdc217a97163dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:48:58 +0900 Subject: [PATCH 204/215] =?UTF-8?q?refactor(ChatServiceTest)=20:=20message?= =?UTF-8?q?Repository=EB=A5=BC=20MockBean=EC=9C=BC=EB=A1=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A=EA=B8=B0=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20=EC=88=98=EC=A0=95=20+=20=EC=8B=A4=EC=A0=9C=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=B2=A0=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=ED=95=A0=20=EC=98=88=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chatting/service/ChatServiceTest.java | 93 ++++++++++++------- 1 file changed, 62 insertions(+), 31 deletions(-) diff --git a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java index a734aaeb..64037823 100644 --- a/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java +++ b/src/test/java/com/aliens/backend/chatting/service/ChatServiceTest.java @@ -3,74 +3,105 @@ import com.aliens.backend.chat.controller.dto.request.ReadRequest; import com.aliens.backend.chat.controller.dto.response.ChatSummaryResponse; import com.aliens.backend.chat.controller.dto.request.MessageSendRequest; +import com.aliens.backend.chat.domain.MessageType; import com.aliens.backend.chat.domain.repository.MessageRepository; import com.aliens.backend.chat.domain.Message; import com.aliens.backend.chat.service.ChatService; -import com.aliens.backend.global.success.ChatSuccessCode; +import com.aliens.backend.chat.service.model.ChatMessageSummary; +import com.aliens.backend.global.BaseServiceTest; +import com.aliens.backend.global.response.success.ChatSuccess; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; import java.util.List; -@SpringBootTest -public class ChatServiceTest { - @Autowired - ChatService chatService; - @MockBean - MessageRepository messageRepository; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +class ChatServiceTest extends BaseServiceTest { + + @Autowired ChatService chatService; + @SpyBean MessageRepository messageRepository; + + @BeforeEach + void setUp() { + Message message = Message.of(makeMessageSendRequest()); + doReturn(message).when(messageRepository).save(any()); + doNothing().when(messageRepository).markMessagesAsRead(any(),any()); + + ChatMessageSummary summary = new ChatMessageSummary(1L,"g",1L); + List givenSummary = List.of(summary,summary) ; + doReturn(givenSummary).when(messageRepository).aggregateMessageSummaries(any(),any()); + + List givenMessages = List.of(message,message); + doReturn(givenMessages).when(messageRepository).findMessages(any(),any()); + } @Test @DisplayName("메시지 전송") void sendMessage() { - //given - String type = "NORMAL"; - String content = "Hello"; - Long roomId = 1L; - Long senderId = 1L; - Long receiverId = 2L; - MessageSendRequest messageSendRequest = new MessageSendRequest(type, content, roomId, senderId, receiverId); - //when - String result = chatService.sendMessage(messageSendRequest); - //then - Assertions.assertEquals(ChatSuccessCode.SEND_MESSAGE_SUCCESS.getMessage(), result); + //Given + MessageSendRequest request = makeMessageSendRequest(); + + //When + String result = chatService.sendMessage(request); + + //Then + Assertions.assertEquals(ChatSuccess.SEND_MESSAGE_SUCCESS.getMessage(), result); } @Test @DisplayName("메시지 읽음 처리") void readMessages() { - //given + //Given Long chatRoomId = 1L; Long memberId = 1L; ReadRequest readRequest = new ReadRequest(chatRoomId, memberId); - //when + String expectedResponse = ChatSuccess.READ_MESSAGES_SUCCESS.getMessage(); + + //When String result = chatService.readMessages(readRequest); - //then - Assertions.assertEquals(ChatSuccessCode.READ_MESSAGES_SUCCESS.getMessage(), result); + + //Then + Assertions.assertEquals(expectedResponse, result); } @Test @DisplayName("채팅 요약 정보 조회") void getChatSummary() { - //given + //Given Long memberId = 1L; - //when + + //When ChatSummaryResponse result = chatService.getChatSummaries(memberId); - //then + + //Then Assertions.assertNotNull(result); } @Test @DisplayName("메시지 조회") void getMessages() { - //given + //Given Long chatRoomId = 1L; - //when + + //When List result = chatService.getMessages(chatRoomId, null); - //then + + //Then Assertions.assertNotNull(result); } -} + + private MessageSendRequest makeMessageSendRequest() { + MessageType type = MessageType.NORMAL; + String content = "Hello"; + Long roomId = 1L; + Long senderId = 1L; + Long receiverId = 2L; + return new MessageSendRequest(type, content, roomId, senderId, receiverId); + } +} \ No newline at end of file From 905fd253d067794de4978380af22d565ad555a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:55:42 +0900 Subject: [PATCH 205/215] =?UTF-8?q?refactor(EmailSenderTest,=20EventPublis?= =?UTF-8?q?herTest)=20:=20BaseServiceTest=EC=97=90=EC=84=9C=20@SpringBoot?= =?UTF-8?q?=20=EC=95=A0=EB=84=88=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=A8=EC=97=90=EB=94=B0=EB=A5=B8=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=B0=8F=20=EC=9D=98=EC=A1=B4=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=20=EB=82=98=EC=97=B4=20=EC=8A=A4=ED=83=80=EC=9D=BC=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...lSenderTest.java => EmailSenderServiceTest.java} | 9 +++------ ...erviceTest.java => EmailServiceServiceTest.java} | 6 ++---- .../aliens/backend/event/EventPublisherTest.java | 13 ++++--------- 3 files changed, 9 insertions(+), 19 deletions(-) rename src/test/java/com/aliens/backend/email/sender/{EmailSenderTest.java => EmailSenderServiceTest.java} (85%) rename src/test/java/com/aliens/backend/email/service/{EmailServiceTest.java => EmailServiceServiceTest.java} (93%) diff --git a/src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java b/src/test/java/com/aliens/backend/email/sender/EmailSenderServiceTest.java similarity index 85% rename from src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java rename to src/test/java/com/aliens/backend/email/sender/EmailSenderServiceTest.java index dc981911..309d08ab 100644 --- a/src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java +++ b/src/test/java/com/aliens/backend/email/sender/EmailSenderServiceTest.java @@ -1,22 +1,19 @@ package com.aliens.backend.email.sender; import com.aliens.backend.email.service.EmailSender; -import com.aliens.backend.global.BaseTest; +import com.aliens.backend.global.BaseServiceTest; import com.aliens.backend.member.controller.dto.event.TemporaryPasswordEvent; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mail.SimpleMailMessage; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; -@SpringBootTest -class EmailSenderTest extends BaseTest { +class EmailSenderServiceTest extends BaseServiceTest { - @Autowired - private EmailSender emailSender; + @Autowired private EmailSender emailSender; @Test @DisplayName("인증 이메일 전송 테스트") diff --git a/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java b/src/test/java/com/aliens/backend/email/service/EmailServiceServiceTest.java similarity index 93% rename from src/test/java/com/aliens/backend/email/service/EmailServiceTest.java rename to src/test/java/com/aliens/backend/email/service/EmailServiceServiceTest.java index 8949424e..5b0a2609 100644 --- a/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java +++ b/src/test/java/com/aliens/backend/email/service/EmailServiceServiceTest.java @@ -3,14 +3,12 @@ import com.aliens.backend.email.controller.response.EmailResponse; import com.aliens.backend.email.domain.EmailAuthentication; import com.aliens.backend.email.domain.repository.EmailAuthenticationRepository; -import com.aliens.backend.global.BaseTest; +import com.aliens.backend.global.BaseServiceTest; import com.aliens.backend.member.sevice.SymmetricKeyEncoder; import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest -class EmailServiceTest extends BaseTest { +class EmailServiceServiceTest extends BaseServiceTest { @Autowired EmailService emailService; diff --git a/src/test/java/com/aliens/backend/event/EventPublisherTest.java b/src/test/java/com/aliens/backend/event/EventPublisherTest.java index d8ce7af2..b0a67090 100644 --- a/src/test/java/com/aliens/backend/event/EventPublisherTest.java +++ b/src/test/java/com/aliens/backend/event/EventPublisherTest.java @@ -1,13 +1,12 @@ package com.aliens.backend.event; -import com.aliens.backend.global.BaseTest; +import com.aliens.backend.global.BaseServiceTest; import com.aliens.backend.notification.FcmSender; import com.google.firebase.messaging.Message; import com.google.firebase.messaging.MulticastMessage; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationEventPublisher; import java.util.List; @@ -16,14 +15,10 @@ import static org.mockito.Mockito.verify; import static org.mockito.internal.verification.VerificationModeFactory.times; -@SpringBootTest -class EventPublisherTest extends BaseTest { +class EventPublisherTest extends BaseServiceTest { - @Autowired - ApplicationEventPublisher publisher; - - @Autowired - FcmSender fcmSender; + @Autowired ApplicationEventPublisher publisher; + @Autowired FcmSender fcmSender; String givenType = "normal"; String giveContent = "content"; From b5db37b5abde3ba8e60da635438a377ff761c0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:56:25 +0900 Subject: [PATCH 206/215] =?UTF-8?q?remove(MatchingApplicationGenerator)=20?= =?UTF-8?q?:=20DummyGenerator=20=EA=B0=9D=EC=B2=B4=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #50 --- .../MatchingApplicationGenerator.java | 38 ------------------- 1 file changed, 38 deletions(-) delete mode 100644 src/test/java/com/aliens/backend/matching/unit/business/MatchingApplicationGenerator.java diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingApplicationGenerator.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingApplicationGenerator.java deleted file mode 100644 index 0afc342b..00000000 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingApplicationGenerator.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.aliens.backend.matching.unit.business; - -import com.aliens.backend.mathcing.service.MatchingApplicationService; -import com.aliens.backend.mathcing.service.model.Language; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.Random; - -import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; - -@Component -public class MatchingApplicationGenerator { - @Autowired MatchingApplicationService matchingApplicationService; - - - - public void applyToMatch(Long numberOfMember) { - Random random = new Random(); - - for (long i = 1L; i <= numberOfMember; i++) { - Language firstPreferLanguage = getRandomLanguage(random); - Language secondPreferLanguage; - - do { - secondPreferLanguage = getRandomLanguage(random); - } while (firstPreferLanguage == secondPreferLanguage); - - MatchingApplicationRequest request = new MatchingApplicationRequest(i, firstPreferLanguage, secondPreferLanguage); - matchingApplicationService.saveParticipant(request); - } - } - - private Language getRandomLanguage(Random random) { - Language[] languages = Language.values(); - return languages[random.nextInt(languages.length)]; - } -} From 9417cf3a6eb46c9db70d167ceb5a25cc6dd7de7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:57:02 +0900 Subject: [PATCH 207/215] =?UTF-8?q?remove(MatchingApplicationApiTest)=20:?= =?UTF-8?q?=20=EB=8B=A8=EC=9D=BC=EB=A1=9C=20=EC=8B=A4=ED=96=89=ED=96=88?= =?UTF-8?q?=EC=9D=84=20=EB=95=8C=20=EB=8F=99=EC=9E=91=ED=95=A0=20=EC=88=98?= =?UTF-8?q?=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=83=88=EB=A1=9C=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MatchingApplicationApiTest.java | 70 ------------------- 1 file changed, 70 deletions(-) delete mode 100644 src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java diff --git a/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java b/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java deleted file mode 100644 index e61b9151..00000000 --- a/src/test/java/com/aliens/backend/matching/integration/MatchingApplicationApiTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.aliens.backend.matching.integration; - -import com.aliens.backend.auth.controller.dto.LoginMember; -import com.aliens.backend.auth.domain.MemberRole; -import com.aliens.backend.mathcing.service.MatchingApplicationService; -import com.aliens.backend.mathcing.service.model.Language; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.SpyBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import static com.aliens.backend.mathcing.controller.dto.input.MatchingInput.*; -import static org.mockito.BDDMockito.*; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; -import static org.springframework.restdocs.request.RequestDocumentation.partWithName; -import static org.springframework.restdocs.request.RequestDocumentation.requestParts; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@SpringBootTest -@AutoConfigureMockMvc -@AutoConfigureRestDocs -public class MatchingApplicationApiTest { - - @Autowired MockMvc mockMvc; - @SpyBean MatchingApplicationService matchingApplicationService; - - ObjectMapper objectMapper = new ObjectMapper(); - String accessToken; - MatchingApplicationInput matchingApplicationInput; - LoginMember loginMember; - - @BeforeEach - void setUp() { - accessToken = "accessToken"; - loginMember = new LoginMember(1L, MemberRole.MEMBER); - matchingApplicationInput = MatchingApplicationInput.of(Language.KOREAN, Language.ENGLISH); - } - - @Test - @DisplayName("매칭 신청 API 테스트") - void applyMatchApiTest() throws Exception { - doNothing().when(matchingApplicationService).saveParticipant(matchingApplicationInput.toRequest(any())); - - mockMvc.perform(post("/matchings/applications") - .header("Authorization", accessToken) - .content(objectMapper.writeValueAsString(matchingApplicationInput)) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().is4xxClientError()); -// .andDo(document("post-matching-application", -// requestParts( -// partWithName("matchingApplicationInput").description("매칭 신청 정보 입력") -// ), -// responseFields( -// fieldWithPath("response").description("매칭 신청 결과") -// ) -// ) -// ); - - } -} From 288f7b45d71a24ad51e0cfce322471a5bcd528dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:57:40 +0900 Subject: [PATCH 208/215] =?UTF-8?q?style(BlockServiceTest)=20:=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=EC=97=86=EB=8A=94=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{BlockServiceServiceTest.java => BlockServiceTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/test/java/com/aliens/backend/block/service/{BlockServiceServiceTest.java => BlockServiceTest.java} (97%) diff --git a/src/test/java/com/aliens/backend/block/service/BlockServiceServiceTest.java b/src/test/java/com/aliens/backend/block/service/BlockServiceTest.java similarity index 97% rename from src/test/java/com/aliens/backend/block/service/BlockServiceServiceTest.java rename to src/test/java/com/aliens/backend/block/service/BlockServiceTest.java index c91dffa5..b64f8f8f 100644 --- a/src/test/java/com/aliens/backend/block/service/BlockServiceServiceTest.java +++ b/src/test/java/com/aliens/backend/block/service/BlockServiceTest.java @@ -16,7 +16,7 @@ import java.util.List; -class BlockServiceServiceTest extends BaseServiceTest { +class BlockServiceTest extends BaseServiceTest { @Autowired BlockService blockService; @Autowired BlockRepository blockRepository; From c703663392b08b30d360c34455b5bb82e524277a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:59:00 +0900 Subject: [PATCH 209/215] =?UTF-8?q?style(AuthServiceTest,=20EmailServiceTe?= =?UTF-8?q?st)=20:=20=ED=95=84=EC=9A=94=EC=97=86=EB=8A=94=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{AuthServiceServiceTest.java => AuthServiceTest.java} | 2 +- .../{EmailServiceServiceTest.java => EmailServiceTest.java} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/test/java/com/aliens/backend/auth/service/{AuthServiceServiceTest.java => AuthServiceTest.java} (98%) rename src/test/java/com/aliens/backend/email/service/{EmailServiceServiceTest.java => EmailServiceTest.java} (97%) diff --git a/src/test/java/com/aliens/backend/auth/service/AuthServiceServiceTest.java b/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java similarity index 98% rename from src/test/java/com/aliens/backend/auth/service/AuthServiceServiceTest.java rename to src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java index cdb86797..cc784c2a 100644 --- a/src/test/java/com/aliens/backend/auth/service/AuthServiceServiceTest.java +++ b/src/test/java/com/aliens/backend/auth/service/AuthServiceTest.java @@ -11,7 +11,7 @@ import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; -class AuthServiceServiceTest extends BaseServiceTest { +class AuthServiceTest extends BaseServiceTest { @Autowired AuthService authService; @Autowired JWTProperties jwtProperties; diff --git a/src/test/java/com/aliens/backend/email/service/EmailServiceServiceTest.java b/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java similarity index 97% rename from src/test/java/com/aliens/backend/email/service/EmailServiceServiceTest.java rename to src/test/java/com/aliens/backend/email/service/EmailServiceTest.java index 5b0a2609..6f1fc5dc 100644 --- a/src/test/java/com/aliens/backend/email/service/EmailServiceServiceTest.java +++ b/src/test/java/com/aliens/backend/email/service/EmailServiceTest.java @@ -8,7 +8,7 @@ import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; -class EmailServiceServiceTest extends BaseServiceTest { +class EmailServiceTest extends BaseServiceTest { @Autowired EmailService emailService; From 8ff4c139842946633880068273dfabe0146d5149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 20:00:10 +0900 Subject: [PATCH 210/215] =?UTF-8?q?style(AwsS3UploaderTest,=20EmailSenderT?= =?UTF-8?q?est)=20:=20=ED=95=84=EC=9A=94=EC=97=86=EB=8A=94=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{EmailSenderServiceTest.java => EmailSenderTest.java} | 2 +- .../{AwsS3UploaderServiceTest.java => AwsS3UploaderTest.java} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/test/java/com/aliens/backend/email/sender/{EmailSenderServiceTest.java => EmailSenderTest.java} (95%) rename src/test/java/com/aliens/backend/uploader/{AwsS3UploaderServiceTest.java => AwsS3UploaderTest.java} (95%) diff --git a/src/test/java/com/aliens/backend/email/sender/EmailSenderServiceTest.java b/src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java similarity index 95% rename from src/test/java/com/aliens/backend/email/sender/EmailSenderServiceTest.java rename to src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java index 309d08ab..c0090bfb 100644 --- a/src/test/java/com/aliens/backend/email/sender/EmailSenderServiceTest.java +++ b/src/test/java/com/aliens/backend/email/sender/EmailSenderTest.java @@ -11,7 +11,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; -class EmailSenderServiceTest extends BaseServiceTest { +class EmailSenderTest extends BaseServiceTest { @Autowired private EmailSender emailSender; diff --git a/src/test/java/com/aliens/backend/uploader/AwsS3UploaderServiceTest.java b/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java similarity index 95% rename from src/test/java/com/aliens/backend/uploader/AwsS3UploaderServiceTest.java rename to src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java index 8676636e..20bddb55 100644 --- a/src/test/java/com/aliens/backend/uploader/AwsS3UploaderServiceTest.java +++ b/src/test/java/com/aliens/backend/uploader/AwsS3UploaderTest.java @@ -11,7 +11,7 @@ import java.util.List; -class AwsS3UploaderServiceTest extends BaseServiceTest { +class AwsS3UploaderTest extends BaseServiceTest { @Autowired private AwsS3Uploader awsS3Uploader; From aebc86315959f8f4829ba2084e1992dcc4185190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 20:04:31 +0900 Subject: [PATCH 211/215] =?UTF-8?q?refactor(interceptor)=20:=20config=20?= =?UTF-8?q?=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/global/config/WebSocketConfig.java | 4 ++-- .../{ => config}/interceptor/ChatChannelInterceptor.java | 2 +- .../{ => config}/interceptor/ChatHandshakeInterceptor.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/com/aliens/backend/global/{ => config}/interceptor/ChatChannelInterceptor.java (96%) rename src/main/java/com/aliens/backend/global/{ => config}/interceptor/ChatHandshakeInterceptor.java (97%) diff --git a/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java b/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java index 6ef5d3b0..50edb42d 100644 --- a/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java +++ b/src/main/java/com/aliens/backend/global/config/WebSocketConfig.java @@ -1,7 +1,7 @@ package com.aliens.backend.global.config; -import com.aliens.backend.global.interceptor.ChatChannelInterceptor; -import com.aliens.backend.global.interceptor.ChatHandshakeInterceptor; +import com.aliens.backend.global.config.interceptor.ChatChannelInterceptor; +import com.aliens.backend.global.config.interceptor.ChatHandshakeInterceptor; import com.aliens.backend.global.property.WebSocketProperties; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java b/src/main/java/com/aliens/backend/global/config/interceptor/ChatChannelInterceptor.java similarity index 96% rename from src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java rename to src/main/java/com/aliens/backend/global/config/interceptor/ChatChannelInterceptor.java index 79919bf4..59346d06 100644 --- a/src/main/java/com/aliens/backend/global/interceptor/ChatChannelInterceptor.java +++ b/src/main/java/com/aliens/backend/global/config/interceptor/ChatChannelInterceptor.java @@ -1,4 +1,4 @@ -package com.aliens.backend.global.interceptor; +package com.aliens.backend.global.config.interceptor; import com.aliens.backend.chat.domain.ChatRoom; import com.aliens.backend.chat.service.ChatAuthValidator; diff --git a/src/main/java/com/aliens/backend/global/interceptor/ChatHandshakeInterceptor.java b/src/main/java/com/aliens/backend/global/config/interceptor/ChatHandshakeInterceptor.java similarity index 97% rename from src/main/java/com/aliens/backend/global/interceptor/ChatHandshakeInterceptor.java rename to src/main/java/com/aliens/backend/global/config/interceptor/ChatHandshakeInterceptor.java index ce8a9f1c..c8e7ae34 100644 --- a/src/main/java/com/aliens/backend/global/interceptor/ChatHandshakeInterceptor.java +++ b/src/main/java/com/aliens/backend/global/config/interceptor/ChatHandshakeInterceptor.java @@ -1,4 +1,4 @@ -package com.aliens.backend.global.interceptor; +package com.aliens.backend.global.config.interceptor; import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.auth.service.TokenProvider; From 8cd39dce299fa8fd8199e2933fc9bc10e68db43a Mon Sep 17 00:00:00 2001 From: Oniqued Date: Mon, 12 Feb 2024 20:47:09 +0900 Subject: [PATCH 212/215] =?UTF-8?q?chore=20:=20firebase=5Fservice=5Fkey.js?= =?UTF-8?q?on=20=EA=B5=AC=EC=84=B1=20#53?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-pipeline.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test-pipeline.yml b/.github/workflows/test-pipeline.yml index bf72b761..85db0d9f 100644 --- a/.github/workflows/test-pipeline.yml +++ b/.github/workflows/test-pipeline.yml @@ -25,6 +25,12 @@ jobs: touch ./application-secret.yml echo "${{ secrets.APPLICATION_SECRET }}" > ./application-secret.yml + - name: firebase_service_key.json 구성 + run: | + cd ./src/main/resources + touch ./firebase_service_key.json + echo "${{ secrets.FCM_KEY }}" > ./firebase_service_key.json + - name: Gradle 권한 허용 run: chmod +x gradlew - name: PR 및 PUSH 전, 테스트 확인 From c7ce85fdf9ff817901a81170eb3a30590cedc0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A4=80?= <86913355+mjj111@users.noreply.github.com> Date: Mon, 12 Feb 2024 21:04:33 +0900 Subject: [PATCH 213/215] =?UTF-8?q?chore=20:=20fcm=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-pipeline.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test-pipeline.yml b/.github/workflows/test-pipeline.yml index bf72b761..85db0d9f 100644 --- a/.github/workflows/test-pipeline.yml +++ b/.github/workflows/test-pipeline.yml @@ -25,6 +25,12 @@ jobs: touch ./application-secret.yml echo "${{ secrets.APPLICATION_SECRET }}" > ./application-secret.yml + - name: firebase_service_key.json 구성 + run: | + cd ./src/main/resources + touch ./firebase_service_key.json + echo "${{ secrets.FCM_KEY }}" > ./firebase_service_key.json + - name: Gradle 권한 허용 run: chmod +x gradlew - name: PR 및 PUSH 전, 테스트 확인 From fb45dfc644227164ffd20fcaf19bf1f4f43a0f5f Mon Sep 17 00:00:00 2001 From: Oniqued Date: Mon, 12 Feb 2024 21:20:55 +0900 Subject: [PATCH 214/215] =?UTF-8?q?chore=20:=20pipeline=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EB=A1=9C=EA=B7=B8=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-pipeline.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-pipeline.yml b/.github/workflows/test-pipeline.yml index 85db0d9f..66cc3e71 100644 --- a/.github/workflows/test-pipeline.yml +++ b/.github/workflows/test-pipeline.yml @@ -23,13 +23,15 @@ jobs: run: | cd ./src/main/resources touch ./application-secret.yml - echo "${{ secrets.APPLICATION_SECRET }}" > ./application-secret.yml + echo "${{ secrets.APPLICATION_SECRET }}" > ./application-secret.yml + ls -a . - name: firebase_service_key.json 구성 run: | cd ./src/main/resources touch ./firebase_service_key.json echo "${{ secrets.FCM_KEY }}" > ./firebase_service_key.json + ls -a . - name: Gradle 권한 허용 run: chmod +x gradlew From b20c3369fbb59ff67692f63ee47ba61319de1b06 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Mon, 12 Feb 2024 22:01:33 +0900 Subject: [PATCH 215/215] =?UTF-8?q?chore=20:=20Git=20Actions=EC=97=90=20JS?= =?UTF-8?q?ON=20=EC=82=AC=EC=9A=A9=EB=B6=88=EA=B0=80=20=EC=9D=B4=EC=8A=88?= =?UTF-8?q?=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-pipeline.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-pipeline.yml b/.github/workflows/test-pipeline.yml index 85db0d9f..d6cc1f4a 100644 --- a/.github/workflows/test-pipeline.yml +++ b/.github/workflows/test-pipeline.yml @@ -25,11 +25,19 @@ jobs: touch ./application-secret.yml echo "${{ secrets.APPLICATION_SECRET }}" > ./application-secret.yml - - name: firebase_service_key.json 구성 + - name: firebase_service_key.json 파일 생성 + id: create-json + uses: jsdaniell/create-json@1.1.2 + with: + name: "firebase_service_key.json" + json: ${{ secrets.FCM_KEY }} + + + - name: JSON 파일 이동 및 로그 확인 run: | + mv ./firebase_service_key.json ./src/main/resources/firebase_service_key.json cd ./src/main/resources - touch ./firebase_service_key.json - echo "${{ secrets.FCM_KEY }}" > ./firebase_service_key.json + ls -a . - name: Gradle 권한 허용 run: chmod +x gradlew