From 7025d22fcc125cbce54d1016263640b8d5457804 Mon Sep 17 00:00:00 2001 From: Kim Dae Hwi <121790935+marooo326@users.noreply.github.com> Date: Sun, 4 Feb 2024 12:03:12 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=A8=20feat:=20=EC=A0=9C=EC=95=88=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?(#110)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 공고 삭제 기능 구현 * fix: 에러코드 오타 수정 (공지사항 > 공고) --- .../exception/AnnouncementErrorCode.java | 4 ++-- .../propose/controller/ProposeController.java | 10 +++++++++ .../propose/service/ProposeService.java | 21 +++++++++++++------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sponus/sponusbe/domain/announcement/exception/AnnouncementErrorCode.java b/src/main/java/com/sponus/sponusbe/domain/announcement/exception/AnnouncementErrorCode.java index d28e229d..ebda95e8 100644 --- a/src/main/java/com/sponus/sponusbe/domain/announcement/exception/AnnouncementErrorCode.java +++ b/src/main/java/com/sponus/sponusbe/domain/announcement/exception/AnnouncementErrorCode.java @@ -11,11 +11,11 @@ @Getter @AllArgsConstructor public enum AnnouncementErrorCode implements BaseErrorCode { - ANNOUNCEMENT_ERROR(HttpStatus.BAD_REQUEST, "ANC4000", "공지사항 관련 에러"), + ANNOUNCEMENT_ERROR(HttpStatus.BAD_REQUEST, "ANC4000", "공고 관련 에러"), ANNOUNCEMENT_ALREADY_DELETED(HttpStatus.BAD_REQUEST, "ANC4001", "이미 삭제된 공지사항입니다."), INVALID_ORGANIZATION(HttpStatus.BAD_REQUEST, "ANC4002", "해당 단체의 공고가 아닙니다."), INVALID_ANNOUNCEMENT_STATUS(HttpStatus.BAD_REQUEST, "ANC4003", "해당 상태의 공고는 수정할 수 없습니다."), - ANNOUNCEMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "ANC4040", "해당 공지사항이 존재하지 않습니다."); + ANNOUNCEMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "ANC4040", "해당 공고가 존재하지 않습니다."); private final HttpStatus httpStatus; private final String code; diff --git a/src/main/java/com/sponus/sponusbe/domain/propose/controller/ProposeController.java b/src/main/java/com/sponus/sponusbe/domain/propose/controller/ProposeController.java index bf1f3372..a417e244 100644 --- a/src/main/java/com/sponus/sponusbe/domain/propose/controller/ProposeController.java +++ b/src/main/java/com/sponus/sponusbe/domain/propose/controller/ProposeController.java @@ -2,6 +2,7 @@ import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PatchMapping; @@ -66,4 +67,13 @@ public ApiResponse updatePropose( proposeService.updatePropose(authOrganization, proposeId, request); return ApiResponse.onSuccess(null); } + + @DeleteMapping("/{proposeId}") + public ApiResponse deletePropose( + @AuthOrganization Organization authOrganization, + @PathVariable Long proposeId + ) { + proposeService.deletePropose(authOrganization, proposeId); + return ApiResponse.onSuccess(null); + } } diff --git a/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeService.java b/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeService.java index 8a5e1129..8e3604c4 100644 --- a/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeService.java +++ b/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeService.java @@ -40,15 +40,15 @@ public ProposeCreateResponse createPropose(Organization authOrganization, Propos } public void updatePropose(Organization authOrganization, Long proposeId, ProposeUpdateRequest request) { - final Propose propose = proposeRepository.findById(proposeId) - .orElseThrow(() -> new ProposeException(ProposeErrorCode.PROPOSE_NOT_FOUND)); - - if (!isOrganizationsPropose(authOrganization.getId(), propose)) - throw new ProposeException(ProposeErrorCode.INVALID_ORGANIZATION); - + final Propose propose = getAccessablePropose(authOrganization, proposeId); propose.update(request.title(), request.content(), request.status()); } + public void deletePropose(Organization authOrganization, Long proposeId) { + final Propose propose = getAccessablePropose(authOrganization, proposeId); + proposeRepository.delete(propose); + } + private boolean isOrganizationsPropose(Long organizationId, Propose propose) { return propose.getProposingOrganization().getId().equals(organizationId); } @@ -58,4 +58,13 @@ private Announcement getAvailableAnnouncement(Long announcementId) { .orElseThrow(() -> new AnnouncementException(AnnouncementErrorCode.ANNOUNCEMENT_NOT_FOUND)); } + private Propose getAccessablePropose(Organization organization, Long proposeId) { + final Propose propose = proposeRepository.findById(proposeId) + .orElseThrow(() -> new ProposeException(ProposeErrorCode.PROPOSE_NOT_FOUND)); + + if (!isOrganizationsPropose(organization.getId(), propose)) + throw new ProposeException(ProposeErrorCode.INVALID_ORGANIZATION); + + return propose; + } } From 394e9491c94e1f1a07cf604034b48a1fa9e02128 Mon Sep 17 00:00:00 2001 From: seheonnn Date: Sun, 4 Feb 2024 13:47:25 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=91=B7=20ci:=20=EC=9D=B4=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=EA=B4=80=EB=A0=A8=20yml=20&=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8=20=EC=88=98=EC=A0=95=20(#112)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci_gradle.yml | 5 +++++ .../sponusbe/global/config/EmailConfig.java | 2 +- src/main/resources/application-prod.yml | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_gradle.yml b/.github/workflows/ci_gradle.yml index d84d5dbd..9926f679 100644 --- a/.github/workflows/ci_gradle.yml +++ b/.github/workflows/ci_gradle.yml @@ -42,6 +42,11 @@ jobs: cloud.aws.region.static: ${{ secrets.REGION }} cloud.aws.credentials.accessKey: ${{ secrets.S3_ACCESS_KEY }} cloud.aws.credentials.secretKey: ${{ secrets.S3_SECRET_KEY }} + mail.smtp.port: ${{ secrets.EMAIL_PORT }} + AdminMail.id: ${{ secrets.EMAIL_ID }} + AdminMail.password: ${{ secrets.EMAIL_PASSWORD }} + + - name: 3) Set prod.yml - Debug run: | diff --git a/src/main/java/com/sponus/sponusbe/global/config/EmailConfig.java b/src/main/java/com/sponus/sponusbe/global/config/EmailConfig.java index 84ce3d5c..1be3e0b1 100644 --- a/src/main/java/com/sponus/sponusbe/global/config/EmailConfig.java +++ b/src/main/java/com/sponus/sponusbe/global/config/EmailConfig.java @@ -13,7 +13,7 @@ public class EmailConfig { @Value("${mail.smtp.port}") private int port; - @Value("${mail.smtp.socketFactory.port}") + @Value("${mail.smtp.port}") private int socketPort; @Value("${mail.smtp.auth}") private boolean auth; diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index eca055e2..1a248c5e 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -39,3 +39,18 @@ cloud: credentials: accessKey: ${S3_ACCESS_KEY} secretKey: ${S3_SECRET_KEY} + +mail: + smtp: + port: ${EMAIL_PORT} + auth: true + starttls: + required: true + enable: true + socketFactory: + class: javax.net.ssl.SSLSocketFactory + fallback: false + +AdminMail: + id: ${EMAIL_ID} + password: ${EMAIL_PASSWORD} From 9541bb64f63e1f24b1659d4a5df0157157e852f9 Mon Sep 17 00:00:00 2001 From: Yuje-Lee <65337423+dbwp031@users.noreply.github.com> Date: Sun, 4 Feb 2024 14:16:39 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=E2=9C=A8=20feat:=20=EC=A1=B0=EC=A7=81=20?= =?UTF-8?q?=EB=A7=81=ED=81=AC=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B0=9C=EB=B0=9C=20(#113)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :sparkles: feat: 조직 링크 조회 기능 개발 * :white_check_mark: test: 조직 링크 조회 기능 테스트 request 작성 --------- Co-authored-by: Yuje Lee --- http/test.http | 11 ++++++++--- .../controller/OrganizationLinkController.java | 12 ++++++++---- .../exception/OrganizationLinkErrorCode.java | 2 +- .../service/OrganizationLinkQueryService.java | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/http/test.http b/http/test.http index 45214847..47473abe 100644 --- a/http/test.http +++ b/http/test.http @@ -143,6 +143,7 @@ Authorization: Bearer {{matsterToken}} ### 조직 링크 생성 (TODO: 테스트 필요) POST http://localhost:8080/api/v1/organization-links +Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwiZW1haWwiOiJzcG9udXNAZ21haWwuY29tIiwiYXV0aCI6IlNUVURFTlQiLCJpYXQiOjE3MDcwMjI2MzIsImV4cCI6MTcwODAyMjYzMn0.olnLsJGmP9hRifXYN-H85V6LBivGhRX8HcPJV1rPSoo Content-Type: application/json { @@ -150,9 +151,14 @@ Content-Type: application/json "url": "https://www.facebook.com/?locale=ko_KR" } +### 조직 링크 조회 +GET http://localhost:8080/api/v1/organization-links/1 +Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwiZW1haWwiOiJzcG9udXNAZ21haWwuY29tIiwiYXV0aCI6IlNUVURFTlQiLCJpYXQiOjE3MDcwMjMzNjEsImV4cCI6MTcwODAyMzM2MX0.g1PyXWzLoGL0Us74k62_djeVgVSsGLu5QfkQJ1U8XNs + + ### 태그 생성 POST http://localhost:8080/api/v1/tags -Authorization: Bearer {{masterToken}} +Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwiZW1haWwiOiJzcG9udXNAZ21haWwuY29tIiwiYXV0aCI6IlNUVURFTlQiLCJpYXQiOjE3MDcwMjI2MzIsImV4cCI6MTcwODAyMjYzMn0.olnLsJGmP9hRifXYN-H85V6LBivGhRX8HcPJV1rPSoo Content-Type: application/json { @@ -174,5 +180,4 @@ Content-Type: application/json ### 태그 삭제 (TODO: 테스트 필요) DELETE http://localhost:8080/api/v1/tags/1 -Authorization: Bearer {{masterToken}} - +Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwiZW1haWwiOiJzcG9udXNAZ21haWwuY29tIiwiYXV0aCI6IlNUVURFTlQiLCJpYXQiOjE3MDcwMjI0MjUsImV4cCI6MTcwODAyMjQyNX0.DxcAbDqwO-aZb6CLof2eRTtxBNHri1-mUAfdsCRPTkU diff --git a/src/main/java/com/sponus/sponusbe/domain/organizationLink/controller/OrganizationLinkController.java b/src/main/java/com/sponus/sponusbe/domain/organizationLink/controller/OrganizationLinkController.java index de4d27cd..9c8bc640 100644 --- a/src/main/java/com/sponus/sponusbe/domain/organizationLink/controller/OrganizationLinkController.java +++ b/src/main/java/com/sponus/sponusbe/domain/organizationLink/controller/OrganizationLinkController.java @@ -1,9 +1,7 @@ package com.sponus.sponusbe.domain.organizationLink.controller; -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 com.sponus.sponusbe.domain.organizationLink.dto.response.OrganizationLinkGetResponse; +import org.springframework.web.bind.annotation.*; import com.sponus.sponusbe.auth.annotation.AuthOrganization; import com.sponus.sponusbe.domain.organization.entity.Organization; @@ -29,4 +27,10 @@ public ApiResponse createOrganizationLink( return ApiResponse.onSuccess(organizationLinkService.createOrganizationLink(organization.getId(), request)); } + + @GetMapping("/{organizationLinkId}") + public ApiResponse getOrganizationLink(@PathVariable("organizationLinkId") Long organizationLinkId) { + return ApiResponse.onSuccess(organizationLinkQueryService.getOrganizationLink(organizationLinkId)); + } + } diff --git a/src/main/java/com/sponus/sponusbe/domain/organizationLink/exception/OrganizationLinkErrorCode.java b/src/main/java/com/sponus/sponusbe/domain/organizationLink/exception/OrganizationLinkErrorCode.java index 781be2f7..404683b5 100644 --- a/src/main/java/com/sponus/sponusbe/domain/organizationLink/exception/OrganizationLinkErrorCode.java +++ b/src/main/java/com/sponus/sponusbe/domain/organizationLink/exception/OrganizationLinkErrorCode.java @@ -13,7 +13,7 @@ public enum OrganizationLinkErrorCode implements BaseErrorCode { ORGANIZATION_ERROR(HttpStatus.BAD_REQUEST, "ORGLK4000", "단체 관련 에러"), INVALID_FORMAT(HttpStatus.BAD_REQUEST, "ORGLK4001", "잘못된 형식입니다."), - ORGGANIZATION_LINK_NOT_FOUND(HttpStatus.NOT_FOUND, "ORGLK4040", "존재하지 않는 조직 링크입니다."); + ORGANIZATION_LINK_NOT_FOUND(HttpStatus.NOT_FOUND, "ORGLK4040", "존재하지 않는 조직 링크입니다."); private final HttpStatus httpStatus; private final String code; diff --git a/src/main/java/com/sponus/sponusbe/domain/organizationLink/service/OrganizationLinkQueryService.java b/src/main/java/com/sponus/sponusbe/domain/organizationLink/service/OrganizationLinkQueryService.java index 19c0ed5d..0f15ce51 100644 --- a/src/main/java/com/sponus/sponusbe/domain/organizationLink/service/OrganizationLinkQueryService.java +++ b/src/main/java/com/sponus/sponusbe/domain/organizationLink/service/OrganizationLinkQueryService.java @@ -1,12 +1,26 @@ package com.sponus.sponusbe.domain.organizationLink.service; +import com.sponus.sponusbe.domain.organization.exception.OrganizationException; +import com.sponus.sponusbe.domain.organizationLink.dto.response.OrganizationLinkGetResponse; +import com.sponus.sponusbe.domain.organizationLink.entity.OrganizationLink; +import com.sponus.sponusbe.domain.organizationLink.repository.OrganizationLinkRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; +import static com.sponus.sponusbe.domain.organizationLink.exception.OrganizationLinkErrorCode.ORGANIZATION_LINK_NOT_FOUND; + @RequiredArgsConstructor @Transactional(readOnly = true) @Service public class OrganizationLinkQueryService { + private final OrganizationLinkRepository organizationLinkRepository; + public OrganizationLinkGetResponse getOrganizationLink(Long organizationLinkId) { + OrganizationLink organizationLink = organizationLinkRepository.findById(organizationLinkId) + .orElseThrow(() -> new OrganizationException(ORGANIZATION_LINK_NOT_FOUND)); + + return OrganizationLinkGetResponse.from(organizationLink); + + } } From cf33acce0a68346ad8bb4db4547f00b9ddad6461 Mon Sep 17 00:00:00 2001 From: Yuje-Lee <65337423+dbwp031@users.noreply.github.com> Date: Sun, 4 Feb 2024 15:29:11 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=E2=9C=A8=20feat:=20=EC=A1=B0=EC=A7=81=20?= =?UTF-8?q?=EB=A7=81=ED=81=AC=20=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B0=9C=EB=B0=9C=20(#114)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :sparkles: feat: 공고 링크 수정 기능 개발 * :white_check_mark: test: 공고 링크 수정 테스트 request 작성 * :sparkles: feat: OrganizationLinkUpdateRequest 추가 --------- Co-authored-by: Yuje Lee --- http/test.http | 14 ++++++++++++-- .../controller/OrganizationLinkController.java | 7 +++++++ .../dto/request/OrganizationLinkUpdateRequest.java | 7 +++++++ .../organizationLink/entity/OrganizationLink.java | 6 ++++++ .../service/OrganizationLinkService.java | 11 +++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/sponus/sponusbe/domain/organizationLink/dto/request/OrganizationLinkUpdateRequest.java diff --git a/http/test.http b/http/test.http index 47473abe..2862ec2c 100644 --- a/http/test.http +++ b/http/test.http @@ -152,10 +152,20 @@ Content-Type: application/json } ### 조직 링크 조회 -GET http://localhost:8080/api/v1/organization-links/1 -Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwiZW1haWwiOiJzcG9udXNAZ21haWwuY29tIiwiYXV0aCI6IlNUVURFTlQiLCJpYXQiOjE3MDcwMjMzNjEsImV4cCI6MTcwODAyMzM2MX0.g1PyXWzLoGL0Us74k62_djeVgVSsGLu5QfkQJ1U8XNs +GET http://localhost:8080/api/v1/organization-links/3 +Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwiZW1haWwiOiJzcG9udXNAZ21haWwuY29tIiwiYXV0aCI6IlNUVURFTlQiLCJpYXQiOjE3MDcwMjYyNTAsImV4cCI6MTcwODAyNjI1MH0.kCsg2CClbDzBbiX4k2EmxihyToIdr5stZ1ADxoMdSSI +### 조직 링크 수정 +PATCH http://localhost:8080/api/v1/organization-links/1 +Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwiZW1haWwiOiJzcG9udXNAZ21haWwuY29tIiwiYXV0aCI6IlNUVURFTlQiLCJpYXQiOjE3MDcwMjYyNTAsImV4cCI6MTcwODAyNjI1MH0.kCsg2CClbDzBbiX4k2EmxihyToIdr5stZ1ADxoMdSSI +Content-Type: application/json + +{ + "name": "페이스북 공식 계정 업데이트", + "url": "https://www.facebook.com/?locale=ko_KR 업데이트" +} + ### 태그 생성 POST http://localhost:8080/api/v1/tags Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwiZW1haWwiOiJzcG9udXNAZ21haWwuY29tIiwiYXV0aCI6IlNUVURFTlQiLCJpYXQiOjE3MDcwMjI2MzIsImV4cCI6MTcwODAyMjYzMn0.olnLsJGmP9hRifXYN-H85V6LBivGhRX8HcPJV1rPSoo diff --git a/src/main/java/com/sponus/sponusbe/domain/organizationLink/controller/OrganizationLinkController.java b/src/main/java/com/sponus/sponusbe/domain/organizationLink/controller/OrganizationLinkController.java index 9c8bc640..14500789 100644 --- a/src/main/java/com/sponus/sponusbe/domain/organizationLink/controller/OrganizationLinkController.java +++ b/src/main/java/com/sponus/sponusbe/domain/organizationLink/controller/OrganizationLinkController.java @@ -1,5 +1,6 @@ package com.sponus.sponusbe.domain.organizationLink.controller; +import com.sponus.sponusbe.domain.organizationLink.dto.request.OrganizationLinkUpdateRequest; import com.sponus.sponusbe.domain.organizationLink.dto.response.OrganizationLinkGetResponse; import org.springframework.web.bind.annotation.*; @@ -33,4 +34,10 @@ public ApiResponse getOrganizationLink(@PathVariabl return ApiResponse.onSuccess(organizationLinkQueryService.getOrganizationLink(organizationLinkId)); } + @PatchMapping("/{organizationLinkId}") + public ApiResponse updateOrganizationLink(@PathVariable("organizationLinkId") Long organizationLinkId, + @RequestBody OrganizationLinkUpdateRequest request) { + organizationLinkService.updateOrganizationLink(organizationLinkId, request); + return ApiResponse.onSuccess(null); + } } diff --git a/src/main/java/com/sponus/sponusbe/domain/organizationLink/dto/request/OrganizationLinkUpdateRequest.java b/src/main/java/com/sponus/sponusbe/domain/organizationLink/dto/request/OrganizationLinkUpdateRequest.java new file mode 100644 index 00000000..34fc66b8 --- /dev/null +++ b/src/main/java/com/sponus/sponusbe/domain/organizationLink/dto/request/OrganizationLinkUpdateRequest.java @@ -0,0 +1,7 @@ +package com.sponus.sponusbe.domain.organizationLink.dto.request; + +public record OrganizationLinkUpdateRequest( + String name, + String url +) { +} diff --git a/src/main/java/com/sponus/sponusbe/domain/organizationLink/entity/OrganizationLink.java b/src/main/java/com/sponus/sponusbe/domain/organizationLink/entity/OrganizationLink.java index 8bfb8b9e..d683cb50 100644 --- a/src/main/java/com/sponus/sponusbe/domain/organizationLink/entity/OrganizationLink.java +++ b/src/main/java/com/sponus/sponusbe/domain/organizationLink/entity/OrganizationLink.java @@ -2,6 +2,7 @@ import com.sponus.sponusbe.domain.organization.entity.Organization; +import com.sponus.sponusbe.domain.organizationLink.dto.request.OrganizationLinkUpdateRequest; import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; import jakarta.persistence.Entity; @@ -41,4 +42,9 @@ public class OrganizationLink { @ManyToOne(fetch = FetchType.LAZY, optional = false) @JoinColumn(name = "organization_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Organization organization; + + public void update(OrganizationLinkUpdateRequest request) { + this.name = request.name() == null ? this.name : request.name(); + this.url = request.name() == null ? this.url : request.url(); + } } diff --git a/src/main/java/com/sponus/sponusbe/domain/organizationLink/service/OrganizationLinkService.java b/src/main/java/com/sponus/sponusbe/domain/organizationLink/service/OrganizationLinkService.java index 43d11393..ac8576fd 100644 --- a/src/main/java/com/sponus/sponusbe/domain/organizationLink/service/OrganizationLinkService.java +++ b/src/main/java/com/sponus/sponusbe/domain/organizationLink/service/OrganizationLinkService.java @@ -1,7 +1,10 @@ package com.sponus.sponusbe.domain.organizationLink.service; import static com.sponus.sponusbe.domain.organization.exception.OrganizationErrorCode.*; +import static com.sponus.sponusbe.domain.organizationLink.exception.OrganizationLinkErrorCode.ORGANIZATION_LINK_NOT_FOUND; +import com.sponus.sponusbe.domain.organizationLink.dto.request.OrganizationLinkUpdateRequest; +import com.sponus.sponusbe.domain.organizationLink.exception.OrganizationLinkException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -39,4 +42,12 @@ public OrganizationLinkCreateResponse createOrganizationLink(Long organizationId return new OrganizationLinkCreateResponse(organizationLink.getId()); } + + @Transactional + public void updateOrganizationLink(Long organizationLinkId, OrganizationLinkUpdateRequest request) { + OrganizationLink organizationLink = organizationLinkRepository.findById(organizationLinkId) + .orElseThrow(() -> new OrganizationLinkException(ORGANIZATION_LINK_NOT_FOUND)); + + organizationLink.update(request); + } } From b7e0dd5c5124f563592959eba0257984a733c792 Mon Sep 17 00:00:00 2001 From: Yuje-Lee <65337423+dbwp031@users.noreply.github.com> Date: Sun, 4 Feb 2024 15:37:27 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=20feat:=20=EC=A1=B0=EC=A7=81=20=EB=A7=81?= =?UTF-8?q?=ED=81=AC=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B0=9C?= =?UTF-8?q?=EB=B0=9C=20(#115)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :sparkles: feat: 조직 링크 삭제 기능 개발 * :white_check_mark: test: 조직 링크 삭제 테스트 request 작성 --------- Co-authored-by: Yuje Lee --- http/test.http | 4 ++++ .../controller/OrganizationLinkController.java | 6 ++++++ .../organizationLink/service/OrganizationLinkService.java | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/http/test.http b/http/test.http index 2862ec2c..17dc3a19 100644 --- a/http/test.http +++ b/http/test.http @@ -166,6 +166,10 @@ Content-Type: application/json "url": "https://www.facebook.com/?locale=ko_KR 업데이트" } +### 조직 링크 삭제 +DELETE http://localhost:8080/api/v1/organization-links/1 +Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwiZW1haWwiOiJzcG9udXNAZ21haWwuY29tIiwiYXV0aCI6IlNUVURFTlQiLCJpYXQiOjE3MDcwMjYyNTAsImV4cCI6MTcwODAyNjI1MH0.kCsg2CClbDzBbiX4k2EmxihyToIdr5stZ1ADxoMdSSI + ### 태그 생성 POST http://localhost:8080/api/v1/tags Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwiZW1haWwiOiJzcG9udXNAZ21haWwuY29tIiwiYXV0aCI6IlNUVURFTlQiLCJpYXQiOjE3MDcwMjI2MzIsImV4cCI6MTcwODAyMjYzMn0.olnLsJGmP9hRifXYN-H85V6LBivGhRX8HcPJV1rPSoo diff --git a/src/main/java/com/sponus/sponusbe/domain/organizationLink/controller/OrganizationLinkController.java b/src/main/java/com/sponus/sponusbe/domain/organizationLink/controller/OrganizationLinkController.java index 14500789..dd92afaf 100644 --- a/src/main/java/com/sponus/sponusbe/domain/organizationLink/controller/OrganizationLinkController.java +++ b/src/main/java/com/sponus/sponusbe/domain/organizationLink/controller/OrganizationLinkController.java @@ -40,4 +40,10 @@ public ApiResponse updateOrganizationLink(@PathVariable("organizationLinkI organizationLinkService.updateOrganizationLink(organizationLinkId, request); return ApiResponse.onSuccess(null); } + + @DeleteMapping("/{organizationLinkId}") + public ApiResponse deleteOrganizationLink(@PathVariable("organizationLinkId") Long organizationLinkId) { + organizationLinkService.deleteOrganizationLink(organizationLinkId); + return ApiResponse.onSuccess(null); + } } diff --git a/src/main/java/com/sponus/sponusbe/domain/organizationLink/service/OrganizationLinkService.java b/src/main/java/com/sponus/sponusbe/domain/organizationLink/service/OrganizationLinkService.java index ac8576fd..05ed789f 100644 --- a/src/main/java/com/sponus/sponusbe/domain/organizationLink/service/OrganizationLinkService.java +++ b/src/main/java/com/sponus/sponusbe/domain/organizationLink/service/OrganizationLinkService.java @@ -50,4 +50,8 @@ public void updateOrganizationLink(Long organizationLinkId, OrganizationLinkUpda organizationLink.update(request); } + + public void deleteOrganizationLink(Long organizationLinkId) { + organizationLinkRepository.deleteById(organizationLinkId); + } } From 77c6d016cfa9a3080236b78773e1b9ea3a9b20cd Mon Sep 17 00:00:00 2001 From: JungTae Kwon Date: Sun, 4 Feb 2024 15:51:46 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=20=EC=9E=AC=EB=B0=9C=EA=B8=89=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20(#117)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🙈 chore : refreshToken 헤더 대문자화 * 🐛 fix : 리프레시 토큰 발급 로직 수정 * ♻️ refactor : 토큰 재발급 로직 분리 --- http/test.http | 5 +++ .../auth/controller/AuthController.java | 37 +++++++++++++++++++ .../jwt/filter/JwtAuthenticationFilter.java | 24 ------------ .../sponusbe/auth/jwt/util/JwtUtil.java | 7 ++-- .../sponusbe/global/config/SwaggerConfig.java | 2 +- 5 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/sponus/sponusbe/auth/controller/AuthController.java diff --git a/http/test.http b/http/test.http index 17dc3a19..3e128fac 100644 --- a/http/test.http +++ b/http/test.http @@ -29,6 +29,11 @@ Content-Type: application/json "password": "password1234" } +### 토큰 재발급 +GET http://localhost:8080/api/v1/auth/reissue +Authorization: Bearer {{masterToken}} +RefreshToken: {{refreshToken}} + ### 공고 생성 POST http://localhost:8080/api/v1/announcements Authorization: Bearer {{masterToken}} diff --git a/src/main/java/com/sponus/sponusbe/auth/controller/AuthController.java b/src/main/java/com/sponus/sponusbe/auth/controller/AuthController.java new file mode 100644 index 00000000..cd7d1ac8 --- /dev/null +++ b/src/main/java/com/sponus/sponusbe/auth/controller/AuthController.java @@ -0,0 +1,37 @@ +package com.sponus.sponusbe.auth.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.sponus.sponusbe.auth.jwt.dto.JwtPair; +import com.sponus.sponusbe.auth.jwt.exception.SecurityCustomException; +import com.sponus.sponusbe.auth.jwt.exception.SecurityErrorCode; +import com.sponus.sponusbe.auth.jwt.util.JwtUtil; +import com.sponus.sponusbe.global.common.ApiResponse; + +import io.jsonwebtoken.ExpiredJwtException; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@RequestMapping("api/v1/auth") +@RestController +public class AuthController { + + private final JwtUtil jwtUtil; + + @GetMapping("/reissue") + public ApiResponse reissueToken(@RequestHeader("RefreshToken") String refreshToken) { + try { + jwtUtil.validateRefreshToken(refreshToken); + return ApiResponse.onSuccess( + jwtUtil.reissueToken(refreshToken) + ); + } catch (ExpiredJwtException eje) { + throw new SecurityCustomException(SecurityErrorCode.TOKEN_EXPIRED, eje); + } catch (IllegalArgumentException iae) { + throw new SecurityCustomException(SecurityErrorCode.INVALID_TOKEN, iae); + } + } +} diff --git a/src/main/java/com/sponus/sponusbe/auth/jwt/filter/JwtAuthenticationFilter.java b/src/main/java/com/sponus/sponusbe/auth/jwt/filter/JwtAuthenticationFilter.java index 5c81fed2..e95e9dd2 100644 --- a/src/main/java/com/sponus/sponusbe/auth/jwt/filter/JwtAuthenticationFilter.java +++ b/src/main/java/com/sponus/sponusbe/auth/jwt/filter/JwtAuthenticationFilter.java @@ -1,8 +1,5 @@ package com.sponus.sponusbe.auth.jwt.filter; -import static com.sponus.sponusbe.auth.jwt.util.HttpResponseUtil.*; -import static org.springframework.http.HttpStatus.*; - import java.io.IOException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -10,9 +7,6 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.filter.OncePerRequestFilter; -import com.sponus.sponusbe.auth.jwt.dto.JwtPair; -import com.sponus.sponusbe.auth.jwt.exception.SecurityCustomException; -import com.sponus.sponusbe.auth.jwt.exception.SecurityErrorCode; import com.sponus.sponusbe.auth.jwt.util.JwtUtil; import com.sponus.sponusbe.auth.jwt.util.RedisUtil; import com.sponus.sponusbe.auth.user.CustomUserDetails; @@ -60,24 +54,6 @@ protected void doFilterInternal( filterChain.doFilter(request, response); } catch (ExpiredJwtException e) { logger.warn("[*] case : accessToken Expired"); - // accessToken 만료 시 Body에 있는 refreshToken 확인 - String refreshToken = request.getHeader("refreshToken"); - - logger.info("[*] refreshToken : " + refreshToken); - try { - if (jwtUtil.validateRefreshToken(refreshToken)) { - logger.info("[*] case : accessToken Expired && refreshToken in redis"); - // refreshToken 유효 시 재발급 - JwtPair reissueTokens = jwtUtil.reissueToken(refreshToken); - setSuccessResponse(response, CREATED, reissueTokens); - } - } catch (ExpiredJwtException eje) { - logger.info("[*] case : accessToken, refreshToken expired"); - throw new SecurityCustomException(SecurityErrorCode.TOKEN_EXPIRED, eje); - } catch (IllegalArgumentException iae) { - logger.info("[*] case : Invalid refreshToken"); - throw new SecurityCustomException(SecurityErrorCode.INVALID_TOKEN, iae); - } } } diff --git a/src/main/java/com/sponus/sponusbe/auth/jwt/util/JwtUtil.java b/src/main/java/com/sponus/sponusbe/auth/jwt/util/JwtUtil.java index e0accd8f..351c7c47 100644 --- a/src/main/java/com/sponus/sponusbe/auth/jwt/util/JwtUtil.java +++ b/src/main/java/com/sponus/sponusbe/auth/jwt/util/JwtUtil.java @@ -76,13 +76,15 @@ public String createJwtRefreshToken(CustomUserDetails customUserDetails) { .add("typ", "JWT") .and() .subject(customUserDetails.getId().toString()) + .claim("email", customUserDetails.getUsername()) + .claim(AUTHORITIES_CLAIM_NAME, customUserDetails.getAuthority()) .issuedAt(Date.from(issuedAt)) .expiration(Date.from(expiration)) .signWith(secretKey) .compact(); redisUtil.save( - refreshToken, + customUserDetails.getEmail(), refreshToken, refreshExpMs, TimeUnit.MILLISECONDS @@ -118,7 +120,7 @@ public String resolveAccessToken(HttpServletRequest request) { return authorization.split(" ")[1]; } - public boolean validateRefreshToken(String refreshToken) { + public void validateRefreshToken(String refreshToken) { // refreshToken 유효성 검증 String email = getEmail(refreshToken); @@ -127,7 +129,6 @@ public boolean validateRefreshToken(String refreshToken) { log.warn("[*] case : Invalid refreshToken"); throw new SecurityCustomException(SecurityErrorCode.INVALID_TOKEN); } - return true; } public Long getId(String token) { diff --git a/src/main/java/com/sponus/sponusbe/global/config/SwaggerConfig.java b/src/main/java/com/sponus/sponusbe/global/config/SwaggerConfig.java index d7cf4583..411eb2ab 100644 --- a/src/main/java/com/sponus/sponusbe/global/config/SwaggerConfig.java +++ b/src/main/java/com/sponus/sponusbe/global/config/SwaggerConfig.java @@ -63,7 +63,7 @@ private Components authSetting() { // .scheme("Bearer") // .bearerFormat("JWT") // .in(SecurityScheme.In.HEADER) - // .name("refreshToken")); + // .name("RefreshToken")); } }