diff --git a/src/main/java/com/somemore/center/domain/NEWCenter.java b/src/main/java/com/somemore/center/domain/NEWCenter.java new file mode 100644 index 000000000..22351fa2d --- /dev/null +++ b/src/main/java/com/somemore/center/domain/NEWCenter.java @@ -0,0 +1,46 @@ +package com.somemore.center.domain; + +import com.somemore.global.common.entity.BaseEntity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "new_center") // TODO prefix 삭제 +public class NEWCenter extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + @Column(name = "id", nullable = false, columnDefinition = "BINARY(16)") + private UUID id; + + @Column(name = "user_id", nullable = false, columnDefinition = "BINARY(16)") + private UUID userId; + + @Column(name = "homepage_url", nullable = false) + private String homepageUrl; + + @Builder + private NEWCenter(UUID userId, String name, String homepageUrl) { + this.userId = userId; + this.homepageUrl = homepageUrl; + } + + public static NEWCenter createDefault(UUID userId) { + return NEWCenter.builder() + .userId(userId) + .homepageUrl("") + .build(); + } +} diff --git a/src/main/java/com/somemore/center/repository/NEWCenterJpaRepository.java b/src/main/java/com/somemore/center/repository/NEWCenterJpaRepository.java new file mode 100644 index 000000000..07a93c4f5 --- /dev/null +++ b/src/main/java/com/somemore/center/repository/NEWCenterJpaRepository.java @@ -0,0 +1,11 @@ +package com.somemore.center.repository; + +import com.somemore.center.domain.NEWCenter; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.UUID; + +@Repository("newCenterJpaRepository") +public interface NEWCenterJpaRepository extends JpaRepository { +} diff --git a/src/main/java/com/somemore/center/repository/NEWCenterRepository.java b/src/main/java/com/somemore/center/repository/NEWCenterRepository.java new file mode 100644 index 000000000..4c0cb9d82 --- /dev/null +++ b/src/main/java/com/somemore/center/repository/NEWCenterRepository.java @@ -0,0 +1,15 @@ +package com.somemore.center.repository; + +import com.somemore.center.domain.NEWCenter; + +import java.util.Optional; +import java.util.UUID; + +public interface NEWCenterRepository { + + NEWCenter save(NEWCenter center); + + Optional findById(UUID id); + + Optional findByUserId(UUID userId); +} diff --git a/src/main/java/com/somemore/center/repository/NEWCenterRepositoryImpl.java b/src/main/java/com/somemore/center/repository/NEWCenterRepositoryImpl.java new file mode 100644 index 000000000..608435c3f --- /dev/null +++ b/src/main/java/com/somemore/center/repository/NEWCenterRepositoryImpl.java @@ -0,0 +1,48 @@ +package com.somemore.center.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.center.domain.NEWCenter; +import com.somemore.center.domain.QNEWCenter; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +import java.util.Optional; +import java.util.UUID; + +@Repository("newCenterRepository") +@RequiredArgsConstructor +public class NEWCenterRepositoryImpl implements NEWCenterRepository { + + private final NEWCenterJpaRepository NEWCenterJpaRepository; + private final JPAQueryFactory queryFactory; + + private static final QNEWCenter center = QNEWCenter.nEWCenter; + + @Override + public NEWCenter save(NEWCenter center) { + return NEWCenterJpaRepository.save(center); + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable( + queryFactory.selectFrom(center) + .where( + center.id.eq(id), + center.deleted.eq(false)) + .fetchOne() + ); + } + + @Override + public Optional findByUserId(UUID userId) { + return Optional.ofNullable( + queryFactory.selectFrom(center) + .where( + center.userId.eq(userId), + center.deleted.eq(false)) + .fetchOne() + + ); + } +} diff --git a/src/main/java/com/somemore/center/service/NEWRegisterCenterService.java b/src/main/java/com/somemore/center/service/NEWRegisterCenterService.java new file mode 100644 index 000000000..b8de2d471 --- /dev/null +++ b/src/main/java/com/somemore/center/service/NEWRegisterCenterService.java @@ -0,0 +1,24 @@ +package com.somemore.center.service; + +import com.somemore.center.domain.NEWCenter; +import com.somemore.center.repository.NEWCenterRepository; +import com.somemore.center.usecase.NEWRegisterCenterUseCase; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +@Transactional +public class NEWRegisterCenterService implements NEWRegisterCenterUseCase { + + private final NEWCenterRepository NEWCenterRepository; + + @Override + public void register(UUID userId) { + NEWCenter center = NEWCenter.createDefault(userId); + NEWCenterRepository.save(center); + } +} diff --git a/src/main/java/com/somemore/center/usecase/NEWRegisterCenterUseCase.java b/src/main/java/com/somemore/center/usecase/NEWRegisterCenterUseCase.java new file mode 100644 index 000000000..a56f182e2 --- /dev/null +++ b/src/main/java/com/somemore/center/usecase/NEWRegisterCenterUseCase.java @@ -0,0 +1,10 @@ +package com.somemore.center.usecase; + +import com.somemore.center.domain.NEWCenter; + +import java.util.UUID; + +public interface NEWRegisterCenterUseCase { + + void register(UUID userId); +} diff --git a/src/main/java/com/somemore/domains/center/controller/CenterProfileCommandApiController.java b/src/main/java/com/somemore/domains/center/controller/CenterProfileCommandApiController.java index 1b1017351..3201274a7 100644 --- a/src/main/java/com/somemore/domains/center/controller/CenterProfileCommandApiController.java +++ b/src/main/java/com/somemore/domains/center/controller/CenterProfileCommandApiController.java @@ -11,7 +11,10 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.security.access.annotation.Secured; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.util.UUID; diff --git a/src/main/java/com/somemore/domains/center/controller/PreferItemCommandApiController.java b/src/main/java/com/somemore/domains/center/controller/PreferItemCommandApiController.java index fdb1e62d9..a1ae4320c 100644 --- a/src/main/java/com/somemore/domains/center/controller/PreferItemCommandApiController.java +++ b/src/main/java/com/somemore/domains/center/controller/PreferItemCommandApiController.java @@ -9,10 +9,16 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.security.access.annotation.Secured; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +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 java.util.UUID; @RequiredArgsConstructor @RestController diff --git a/src/main/java/com/somemore/domains/center/domain/Center.java b/src/main/java/com/somemore/domains/center/domain/Center.java index 561680b95..eaaf36a28 100644 --- a/src/main/java/com/somemore/domains/center/domain/Center.java +++ b/src/main/java/com/somemore/domains/center/domain/Center.java @@ -2,8 +2,16 @@ import com.somemore.domains.center.dto.request.CenterProfileUpdateRequestDto; import com.somemore.global.common.entity.BaseEntity; -import jakarta.persistence.*; -import lombok.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; import java.util.UUID; @@ -34,34 +42,22 @@ public class Center extends BaseEntity { @Column(name = "homepage_link", nullable = false) private String homepageLink; - @Column(name = "account_id", nullable = false) - private String accountId; - - @Column(name = "account_pw", nullable = false) - private String accountPw; - - @Builder - private Center(String name, String contactNumber, String imgUrl, String introduce, String homepageLink, String accountId, String accountPw) { - + private Center(String name, String contactNumber, String imgUrl, String introduce, String homepageLink) { this.name = name; this.contactNumber = contactNumber; this.imgUrl = imgUrl; this.introduce = introduce; this.homepageLink = homepageLink; - this.accountId = accountId; - this.accountPw = accountPw; } - public static Center create(String name, String contactNumber, String imgUrl, String introduce, String homepageLink, String accountId, String accountPw) { + public static Center create(String name, String contactNumber, String imgUrl, String introduce, String homepageLink) { return Center.builder() .name(name) .contactNumber(contactNumber) .imgUrl(imgUrl) .introduce(introduce) .homepageLink(homepageLink) - .accountId(accountId) - .accountPw(accountPw) .build(); } diff --git a/src/main/java/com/somemore/domains/center/domain/PreferItem.java b/src/main/java/com/somemore/domains/center/domain/PreferItem.java index e8f418e1b..777942c53 100644 --- a/src/main/java/com/somemore/domains/center/domain/PreferItem.java +++ b/src/main/java/com/somemore/domains/center/domain/PreferItem.java @@ -1,6 +1,10 @@ package com.somemore.domains.center.domain; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/somemore/domains/center/dto/request/CenterProfileUpdateRequestDto.java b/src/main/java/com/somemore/domains/center/dto/request/CenterProfileUpdateRequestDto.java index 76dea39ee..734d25bcc 100644 --- a/src/main/java/com/somemore/domains/center/dto/request/CenterProfileUpdateRequestDto.java +++ b/src/main/java/com/somemore/domains/center/dto/request/CenterProfileUpdateRequestDto.java @@ -21,4 +21,5 @@ public record CenterProfileUpdateRequestDto( @Schema(description = "센터 소개", example = "저희 도서관은 유명해요") @NotBlank(message = "센터 소개는 필수 값입니다.") String introduce -) {} +) { +} diff --git a/src/main/java/com/somemore/domains/center/dto/response/CenterSimpleInfoResponseDto.java b/src/main/java/com/somemore/domains/center/dto/response/CenterSimpleInfoResponseDto.java index e446e6d39..f99332d60 100644 --- a/src/main/java/com/somemore/domains/center/dto/response/CenterSimpleInfoResponseDto.java +++ b/src/main/java/com/somemore/domains/center/dto/response/CenterSimpleInfoResponseDto.java @@ -4,30 +4,31 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.somemore.domains.center.domain.Center; import io.swagger.v3.oas.annotations.media.Schema; -import java.util.UUID; import lombok.Builder; +import java.util.UUID; + @Builder @JsonNaming(SnakeCaseStrategy.class) @Schema(description = "기관 정보 응답 DTO") public record CenterSimpleInfoResponseDto( - @Schema(description = "기관 아이디", example = "123e4567-e89b-12d3-a456-426614174000") - UUID id, - @Schema(description = "기관 이름", example = "환경 봉사 센터") - String name + @Schema(description = "기관 아이디", example = "123e4567-e89b-12d3-a456-426614174000") + UUID id, + @Schema(description = "기관 이름", example = "환경 봉사 센터") + String name ) { public static CenterSimpleInfoResponseDto from(Center center) { return CenterSimpleInfoResponseDto.builder() - .id(center.getId()) - .name(center.getName()) - .build(); + .id(center.getId()) + .name(center.getName()) + .build(); } public static CenterSimpleInfoResponseDto of(UUID centerId, String name) { return CenterSimpleInfoResponseDto.builder() - .id(centerId) - .name(name) - .build(); + .id(centerId) + .name(name) + .build(); } } diff --git a/src/main/java/com/somemore/domains/center/dto/response/PreferItemResponseDto.java b/src/main/java/com/somemore/domains/center/dto/response/PreferItemResponseDto.java index 7fdc900d6..18327394e 100644 --- a/src/main/java/com/somemore/domains/center/dto/response/PreferItemResponseDto.java +++ b/src/main/java/com/somemore/domains/center/dto/response/PreferItemResponseDto.java @@ -6,11 +6,11 @@ import java.util.UUID; @Builder -public record PreferItemResponseDto ( +public record PreferItemResponseDto( Long id, UUID centerId, String itemName -){ +) { public static PreferItemResponseDto from(PreferItem preferItem) { return PreferItemResponseDto.builder() .id(preferItem.getId()) diff --git a/src/main/java/com/somemore/domains/center/repository/center/CenterJpaRepository.java b/src/main/java/com/somemore/domains/center/repository/center/CenterJpaRepository.java index ef68ed2ea..0a0f7df70 100644 --- a/src/main/java/com/somemore/domains/center/repository/center/CenterJpaRepository.java +++ b/src/main/java/com/somemore/domains/center/repository/center/CenterJpaRepository.java @@ -2,13 +2,19 @@ import com.somemore.domains.center.domain.Center; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; import java.util.Optional; import java.util.UUID; +@Repository("centerJpaRepository") public interface CenterJpaRepository extends JpaRepository { + boolean existsById(UUID id); + Optional
findCenterById(UUID id); + Optional
findByName(String name); + boolean existsByIdAndDeletedIsFalse(UUID id); } diff --git a/src/main/java/com/somemore/domains/center/repository/center/CenterRepository.java b/src/main/java/com/somemore/domains/center/repository/center/CenterRepository.java index 1d6af166a..820d2a5e4 100644 --- a/src/main/java/com/somemore/domains/center/repository/center/CenterRepository.java +++ b/src/main/java/com/somemore/domains/center/repository/center/CenterRepository.java @@ -2,23 +2,23 @@ import com.somemore.domains.center.domain.Center; import com.somemore.domains.center.repository.mapper.CenterOverviewInfo; -import org.springframework.stereotype.Repository; import java.util.List; import java.util.Optional; import java.util.UUID; -@Repository public interface CenterRepository { Center save(Center center); + boolean existsById(UUID id); + default boolean doesNotExistById(UUID id) { return !existsById(id); } + Optional
findCenterById(UUID id); + List findCenterOverviewsByIds(List ids); - UUID findIdByAccountId(String accountId); - String findPasswordByAccountId(String accountId); - void deleteAllInBatch(); + void deleteAllInBatch(); } diff --git a/src/main/java/com/somemore/domains/center/repository/center/CenterRepositoryImpl.java b/src/main/java/com/somemore/domains/center/repository/center/CenterRepositoryImpl.java index c8d03b148..99698f066 100644 --- a/src/main/java/com/somemore/domains/center/repository/center/CenterRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/center/repository/center/CenterRepositoryImpl.java @@ -14,7 +14,7 @@ import java.util.UUID; @RequiredArgsConstructor -@Repository +@Repository("centerRepository") public class CenterRepositoryImpl implements CenterRepository { private final JPAQueryFactory queryFactory; @@ -61,28 +61,6 @@ public List findCenterOverviewsByIds(List ids) { .fetch(); } - @Override - public UUID findIdByAccountId(String accountId) { - - return queryFactory - .select(center.id) - .from(center) - .where(center.accountId.eq(accountId) - .and(isNotDeleted())) - .fetchOne(); - } - - @Override - public String findPasswordByAccountId(String accountId) { - - return queryFactory - .select(center.accountPw) - .from(center) - .where(center.accountId.eq(accountId) - .and(isNotDeleted())) - .fetchOne(); - } - @Override public void deleteAllInBatch() { centerJpaRepository.deleteAllInBatch(); diff --git a/src/main/java/com/somemore/domains/center/repository/preferitem/PreferItemRepository.java b/src/main/java/com/somemore/domains/center/repository/preferitem/PreferItemRepository.java index abb63714a..9a0e88427 100644 --- a/src/main/java/com/somemore/domains/center/repository/preferitem/PreferItemRepository.java +++ b/src/main/java/com/somemore/domains/center/repository/preferitem/PreferItemRepository.java @@ -10,7 +10,10 @@ @Repository public interface PreferItemRepository { void save(PreferItem preferItem); + void deleteById(Long preferItemId); + Optional findById(Long preferItemId); + List findByCenterId(UUID centerId); } diff --git a/src/main/java/com/somemore/domains/center/repository/preferitem/PreferItemRepositoryImpl.java b/src/main/java/com/somemore/domains/center/repository/preferitem/PreferItemRepositoryImpl.java index b7e708f6f..e22f1f68d 100644 --- a/src/main/java/com/somemore/domains/center/repository/preferitem/PreferItemRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/center/repository/preferitem/PreferItemRepositoryImpl.java @@ -10,7 +10,7 @@ @RequiredArgsConstructor @Repository -public class PreferItemRepositoryImpl implements PreferItemRepository{ +public class PreferItemRepositoryImpl implements PreferItemRepository { private final PreferItemJpaRepository preferItemJpaRepository; diff --git a/src/main/java/com/somemore/domains/center/service/command/DeletePreferItemService.java b/src/main/java/com/somemore/domains/center/service/command/DeletePreferItemService.java index 6bec1a4f2..7d19f6b7e 100644 --- a/src/main/java/com/somemore/domains/center/service/command/DeletePreferItemService.java +++ b/src/main/java/com/somemore/domains/center/service/command/DeletePreferItemService.java @@ -9,7 +9,8 @@ import java.util.UUID; -import static com.somemore.global.exception.ExceptionMessage.*; +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_PREFER_ITEM; +import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_PREFER_ITEM; @RequiredArgsConstructor @Service diff --git a/src/main/java/com/somemore/domains/center/service/query/CenterQueryService.java b/src/main/java/com/somemore/domains/center/service/query/CenterQueryService.java index ae0632d10..5fc206dcb 100644 --- a/src/main/java/com/somemore/domains/center/service/query/CenterQueryService.java +++ b/src/main/java/com/somemore/domains/center/service/query/CenterQueryService.java @@ -1,10 +1,10 @@ package com.somemore.domains.center.service.query; import com.somemore.domains.center.domain.Center; -import com.somemore.domains.center.repository.mapper.CenterOverviewInfo; import com.somemore.domains.center.dto.response.CenterProfileResponseDto; import com.somemore.domains.center.dto.response.PreferItemResponseDto; import com.somemore.domains.center.repository.center.CenterRepository; +import com.somemore.domains.center.repository.mapper.CenterOverviewInfo; import com.somemore.domains.center.usecase.query.CenterQueryUseCase; import com.somemore.domains.center.usecase.query.PreferItemQueryUseCase; import com.somemore.global.exception.BadRequestException; diff --git a/src/main/java/com/somemore/domains/center/service/query/CenterSignService.java b/src/main/java/com/somemore/domains/center/service/query/CenterSignService.java deleted file mode 100644 index 3221e09c6..000000000 --- a/src/main/java/com/somemore/domains/center/service/query/CenterSignService.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.somemore.domains.center.service.query; - -import com.somemore.domains.center.repository.center.CenterRepository; -import com.somemore.domains.center.usecase.query.CenterSignUseCase; -import com.somemore.global.exception.BadRequestException; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.UUID; - -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_CENTER; - -@Service -@Transactional -@RequiredArgsConstructor -public class CenterSignService implements CenterSignUseCase { - - private final CenterRepository centerRepository; - - @Override - public UUID getIdByAccountId(String accountId) { - UUID centerId = centerRepository.findIdByAccountId(accountId); - if (centerId == null) { - throw new BadRequestException(NOT_EXISTS_CENTER); - } - - return centerId; - } - - @Override - public String getPasswordByAccountId(String accountId) { - String password = centerRepository.findPasswordByAccountId(accountId); - if (password == null) { - throw new BadRequestException(NOT_EXISTS_CENTER); - } - - return password; - } -} diff --git a/src/main/java/com/somemore/domains/center/service/query/PreferItemQueryService.java b/src/main/java/com/somemore/domains/center/service/query/PreferItemQueryService.java index 9c907cdee..e968ef097 100644 --- a/src/main/java/com/somemore/domains/center/service/query/PreferItemQueryService.java +++ b/src/main/java/com/somemore/domains/center/service/query/PreferItemQueryService.java @@ -27,7 +27,7 @@ public List getPreferItemDtosByCenterId(UUID centerId) { //프론트와 의논후 private으로 전환 예정 @Override public List getPreferItemsByCenterId(UUID centerId) { - return preferItemRepository.findByCenterId(centerId); + return preferItemRepository.findByCenterId(centerId); } private static List preferItemConvertToDtos(List preferItems) { diff --git a/src/main/java/com/somemore/domains/center/usecase/query/CenterQueryUseCase.java b/src/main/java/com/somemore/domains/center/usecase/query/CenterQueryUseCase.java index 598ef72e1..5176dc02c 100644 --- a/src/main/java/com/somemore/domains/center/usecase/query/CenterQueryUseCase.java +++ b/src/main/java/com/somemore/domains/center/usecase/query/CenterQueryUseCase.java @@ -1,13 +1,15 @@ package com.somemore.domains.center.usecase.query; -import com.somemore.domains.center.repository.mapper.CenterOverviewInfo; import com.somemore.domains.center.dto.response.CenterProfileResponseDto; +import com.somemore.domains.center.repository.mapper.CenterOverviewInfo; import java.util.List; import java.util.UUID; public interface CenterQueryUseCase { CenterProfileResponseDto getCenterProfileByCenterId(UUID centerId); + List getCenterOverviewsByIds(List centerIds); + void validateCenterExists(UUID centerId); } diff --git a/src/main/java/com/somemore/domains/center/usecase/query/CenterSignUseCase.java b/src/main/java/com/somemore/domains/center/usecase/query/CenterSignUseCase.java deleted file mode 100644 index d572cabe5..000000000 --- a/src/main/java/com/somemore/domains/center/usecase/query/CenterSignUseCase.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.somemore.domains.center.usecase.query; - -import java.util.UUID; - -public interface CenterSignUseCase { - - UUID getIdByAccountId(String accountId); - String getPasswordByAccountId(String accountId); -} diff --git a/src/main/java/com/somemore/domains/center/usecase/query/PreferItemQueryUseCase.java b/src/main/java/com/somemore/domains/center/usecase/query/PreferItemQueryUseCase.java index 64b09f3da..e38770f14 100644 --- a/src/main/java/com/somemore/domains/center/usecase/query/PreferItemQueryUseCase.java +++ b/src/main/java/com/somemore/domains/center/usecase/query/PreferItemQueryUseCase.java @@ -8,5 +8,6 @@ public interface PreferItemQueryUseCase { List getPreferItemDtosByCenterId(UUID centerId); + List getPreferItemsByCenterId(UUID centerId); } diff --git a/src/main/java/com/somemore/domains/community/controller/CommunityBoardCommandApiController.java b/src/main/java/com/somemore/domains/community/controller/CommunityBoardCommandApiController.java index 47bdd49d8..5bc77bc6b 100644 --- a/src/main/java/com/somemore/domains/community/controller/CommunityBoardCommandApiController.java +++ b/src/main/java/com/somemore/domains/community/controller/CommunityBoardCommandApiController.java @@ -1,11 +1,11 @@ package com.somemore.domains.community.controller; +import com.somemore.domains.community.dto.request.CommunityBoardCreateRequestDto; +import com.somemore.domains.community.dto.request.CommunityBoardUpdateRequestDto; import com.somemore.domains.community.usecase.board.CreateCommunityBoardUseCase; import com.somemore.domains.community.usecase.board.DeleteCommunityBoardUseCase; import com.somemore.domains.community.usecase.board.UpdateCommunityBoardUseCase; import com.somemore.global.auth.annotation.CurrentUser; -import com.somemore.domains.community.dto.request.CommunityBoardCreateRequestDto; -import com.somemore.domains.community.dto.request.CommunityBoardUpdateRequestDto; import com.somemore.global.common.response.ApiResponse; import com.somemore.global.imageupload.dto.ImageUploadRequestDto; import com.somemore.global.imageupload.usecase.ImageUploadUseCase; @@ -14,7 +14,13 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.security.access.annotation.Secured; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.util.UUID; diff --git a/src/main/java/com/somemore/domains/community/controller/CommunityBoardQueryApiController.java b/src/main/java/com/somemore/domains/community/controller/CommunityBoardQueryApiController.java index 2133d8530..e5198817b 100644 --- a/src/main/java/com/somemore/domains/community/controller/CommunityBoardQueryApiController.java +++ b/src/main/java/com/somemore/domains/community/controller/CommunityBoardQueryApiController.java @@ -2,7 +2,6 @@ import com.somemore.domains.community.dto.response.CommunityBoardDetailResponseDto; import com.somemore.domains.community.dto.response.CommunityBoardResponseDto; -//import com.somemore.community.usecase.board.CommunityBoardDocumentUseCase; import com.somemore.domains.community.usecase.board.CommunityBoardQueryUseCase; import com.somemore.global.common.response.ApiResponse; import io.swagger.v3.oas.annotations.Operation; @@ -10,7 +9,11 @@ import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.UUID; diff --git a/src/main/java/com/somemore/domains/community/controller/CommunityCommentCommandApiController.java b/src/main/java/com/somemore/domains/community/controller/CommunityCommentCommandApiController.java index a528d572f..772cc1634 100644 --- a/src/main/java/com/somemore/domains/community/controller/CommunityCommentCommandApiController.java +++ b/src/main/java/com/somemore/domains/community/controller/CommunityCommentCommandApiController.java @@ -1,18 +1,24 @@ package com.somemore.domains.community.controller; +import com.somemore.domains.community.dto.request.CommunityCommentCreateRequestDto; import com.somemore.domains.community.dto.request.CommunityCommentUpdateRequestDto; import com.somemore.domains.community.usecase.comment.CreateCommunityCommentUseCase; import com.somemore.domains.community.usecase.comment.DeleteCommunityCommentUseCase; import com.somemore.domains.community.usecase.comment.UpdateCommunityCommentUseCase; import com.somemore.global.auth.annotation.CurrentUser; -import com.somemore.domains.community.dto.request.CommunityCommentCreateRequestDto; import com.somemore.global.common.response.ApiResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.security.access.annotation.Secured; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.UUID; diff --git a/src/main/java/com/somemore/domains/community/domain/CommunityBoard.java b/src/main/java/com/somemore/domains/community/domain/CommunityBoard.java index 4a1f1c2a9..9e3ec612d 100644 --- a/src/main/java/com/somemore/domains/community/domain/CommunityBoard.java +++ b/src/main/java/com/somemore/domains/community/domain/CommunityBoard.java @@ -2,22 +2,21 @@ import com.somemore.domains.community.dto.request.CommunityBoardUpdateRequestDto; import com.somemore.global.common.entity.BaseEntity; -import static lombok.AccessLevel.PROTECTED; - import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; import jakarta.persistence.Lob; import jakarta.persistence.Table; - import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import java.util.UUID; +import static lombok.AccessLevel.PROTECTED; + @Getter @NoArgsConstructor(access = PROTECTED) @Entity diff --git a/src/main/java/com/somemore/domains/community/domain/CommunityComment.java b/src/main/java/com/somemore/domains/community/domain/CommunityComment.java index 0a4323a9a..bf9280b17 100644 --- a/src/main/java/com/somemore/domains/community/domain/CommunityComment.java +++ b/src/main/java/com/somemore/domains/community/domain/CommunityComment.java @@ -2,7 +2,13 @@ import com.somemore.domains.community.dto.request.CommunityCommentUpdateRequestDto; import com.somemore.global.common.entity.BaseEntity; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/somemore/domains/community/dto/request/CommunityBoardUpdateRequestDto.java b/src/main/java/com/somemore/domains/community/dto/request/CommunityBoardUpdateRequestDto.java index cba23e5b5..a6c3f48d4 100644 --- a/src/main/java/com/somemore/domains/community/dto/request/CommunityBoardUpdateRequestDto.java +++ b/src/main/java/com/somemore/domains/community/dto/request/CommunityBoardUpdateRequestDto.java @@ -15,4 +15,5 @@ public record CommunityBoardUpdateRequestDto( @Schema(description = "커뮤니티 게시글 내용", example = "저 포함 5명이 같이 가면 좋을 거 같아요") @NotBlank(message = "게시글 내용은 필수 값입니다.") String content -) {} \ No newline at end of file +) { +} \ No newline at end of file diff --git a/src/main/java/com/somemore/domains/community/dto/request/CommunityCommentUpdateRequestDto.java b/src/main/java/com/somemore/domains/community/dto/request/CommunityCommentUpdateRequestDto.java index 08bd105ff..990cf4cf1 100644 --- a/src/main/java/com/somemore/domains/community/dto/request/CommunityCommentUpdateRequestDto.java +++ b/src/main/java/com/somemore/domains/community/dto/request/CommunityCommentUpdateRequestDto.java @@ -8,8 +8,9 @@ @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) @Builder -public record CommunityCommentUpdateRequestDto ( +public record CommunityCommentUpdateRequestDto( @Schema(description = "커뮤니티 댓글 내용", example = "저도 함께 하고 싶습니다.") @NotBlank(message = "댓글 내용은 필수 값입니다.") String content -) {} +) { +} diff --git a/src/main/java/com/somemore/domains/community/dto/response/CommunityCommentResponseDto.java b/src/main/java/com/somemore/domains/community/dto/response/CommunityCommentResponseDto.java index 9e33779db..cb85b45a1 100644 --- a/src/main/java/com/somemore/domains/community/dto/response/CommunityCommentResponseDto.java +++ b/src/main/java/com/somemore/domains/community/dto/response/CommunityCommentResponseDto.java @@ -20,16 +20,16 @@ public record CommunityCommentResponseDto( @Schema(description = "커뮤니티 댓글 수정 일시", example = "2023-12-02T11:00:00") LocalDateTime updatedAt, @Schema(description = "대댓글 목록", example = """ - [ - { - "id": 3, - "content": "첫 번째 댓글의 답글입니다.", - "writerNickname": "사용자2", - "createdAt": "2023-12-02T11:00:00", - "replies": [] - } - ] -""") + [ + { + "id": 3, + "content": "첫 번째 댓글의 답글입니다.", + "writerNickname": "사용자2", + "createdAt": "2023-12-02T11:00:00", + "replies": [] + } + ] + """) List replies ) { public CommunityCommentResponseDto { diff --git a/src/main/java/com/somemore/domains/community/repository/board/CommunityBoardDocumentRepository.java b/src/main/java/com/somemore/domains/community/repository/board/CommunityBoardDocumentRepository.java index cc96869f5..574b3793e 100644 --- a/src/main/java/com/somemore/domains/community/repository/board/CommunityBoardDocumentRepository.java +++ b/src/main/java/com/somemore/domains/community/repository/board/CommunityBoardDocumentRepository.java @@ -4,7 +4,7 @@ //import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; // //public interface CommunityBoardDocumentRepository extends ElasticsearchRepository { -//// List findAll(); -//// @Query("{\"multi_match\": {\"query\": \"?0\", \"fields\": [\"title\", \"content\"]}}") -//// List findIdsByTitleOrContentContaining(String keyword); +/// / List findAll(); +/// / @Query("{\"multi_match\": {\"query\": \"?0\", \"fields\": [\"title\", \"content\"]}}") +/// / List findIdsByTitleOrContentContaining(String keyword); //} diff --git a/src/main/java/com/somemore/domains/community/repository/board/CommunityBoardRepository.java b/src/main/java/com/somemore/domains/community/repository/board/CommunityBoardRepository.java index 03d8ddb3f..d0e5bc988 100644 --- a/src/main/java/com/somemore/domains/community/repository/board/CommunityBoardRepository.java +++ b/src/main/java/com/somemore/domains/community/repository/board/CommunityBoardRepository.java @@ -11,16 +11,22 @@ public interface CommunityBoardRepository { CommunityBoard save(CommunityBoard communityBoard); + Optional findById(Long id); + Page findCommunityBoards(String keyword, Pageable pageable); + Page findByWriterId(UUID writerId, Pageable pageable); + boolean existsById(Long id); + default boolean doesNotExistById(Long id) { return !existsById(id); } + void deleteAllInBatch(); -// Page findByCommunityBoardsContaining(String keyword, Pageable pageable); + // Page findByCommunityBoardsContaining(String keyword, Pageable pageable); // void saveDocuments(List communityBoards); List findAll(); // void deleteDocument(Long id); diff --git a/src/main/java/com/somemore/domains/community/repository/board/CommunityBoardRepositoryImpl.java b/src/main/java/com/somemore/domains/community/repository/board/CommunityBoardRepositoryImpl.java index 902021d11..94a211706 100644 --- a/src/main/java/com/somemore/domains/community/repository/board/CommunityBoardRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/community/repository/board/CommunityBoardRepositoryImpl.java @@ -161,7 +161,9 @@ private BooleanExpression isNotDeleted() { return communityBoard.deleted.eq(false); } - private BooleanExpression isWriter(UUID writerId) {return communityBoard.writerId.eq(writerId); } + private BooleanExpression isWriter(UUID writerId) { + return communityBoard.writerId.eq(writerId); + } private BooleanExpression keywordEq(String keyword) { return StringUtils.isNotBlank(keyword) diff --git a/src/main/java/com/somemore/domains/community/repository/comment/CommunityCommentRepository.java b/src/main/java/com/somemore/domains/community/repository/comment/CommunityCommentRepository.java index fd4c285af..b125c6d14 100644 --- a/src/main/java/com/somemore/domains/community/repository/comment/CommunityCommentRepository.java +++ b/src/main/java/com/somemore/domains/community/repository/comment/CommunityCommentRepository.java @@ -9,11 +9,16 @@ public interface CommunityCommentRepository { CommunityComment save(CommunityComment communityComment); + Optional findById(Long id); + Page findCommentsByBoardId(Long boardId, Pageable pageable); + boolean existsById(Long id); + default boolean doesNotExistById(Long id) { return !existsById(id); } + void deleteAllInBatch(); } diff --git a/src/main/java/com/somemore/domains/community/repository/comment/CommunityCommentRepositoryImpl.java b/src/main/java/com/somemore/domains/community/repository/comment/CommunityCommentRepositoryImpl.java index f9d2ef604..654378cd2 100644 --- a/src/main/java/com/somemore/domains/community/repository/comment/CommunityCommentRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/community/repository/comment/CommunityCommentRepositoryImpl.java @@ -71,5 +71,7 @@ public boolean existsById(Long id) { } @Override - public void deleteAllInBatch() { communityCommentJpaRepository.deleteAllInBatch(); } + public void deleteAllInBatch() { + communityCommentJpaRepository.deleteAllInBatch(); + } } diff --git a/src/main/java/com/somemore/domains/community/service/board/CommunityBoardQueryService.java b/src/main/java/com/somemore/domains/community/service/board/CommunityBoardQueryService.java index 4d6d94387..eafa22319 100644 --- a/src/main/java/com/somemore/domains/community/service/board/CommunityBoardQueryService.java +++ b/src/main/java/com/somemore/domains/community/service/board/CommunityBoardQueryService.java @@ -1,10 +1,10 @@ package com.somemore.domains.community.service.board; import com.somemore.domains.community.domain.CommunityBoard; -import com.somemore.domains.community.repository.mapper.CommunityBoardView; import com.somemore.domains.community.dto.response.CommunityBoardDetailResponseDto; import com.somemore.domains.community.dto.response.CommunityBoardResponseDto; import com.somemore.domains.community.repository.board.CommunityBoardRepository; +import com.somemore.domains.community.repository.mapper.CommunityBoardView; import com.somemore.domains.community.usecase.board.CommunityBoardQueryUseCase; import com.somemore.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; @@ -37,7 +37,7 @@ public Page getCommunityBoards(String keyword, int pa @Override public Page getCommunityBoardsByWriterId(UUID writerId, int page) { Pageable pageable = PageRequest.of(page, PAGE_SIZE); - Page boards = communityBoardRepository.findByWriterId(writerId ,pageable); + Page boards = communityBoardRepository.findByWriterId(writerId, pageable); return boards.map(CommunityBoardResponseDto::from); } diff --git a/src/main/java/com/somemore/domains/community/service/board/UpdateCommunityBoardService.java b/src/main/java/com/somemore/domains/community/service/board/UpdateCommunityBoardService.java index 0b276d3dd..342a9aa70 100644 --- a/src/main/java/com/somemore/domains/community/service/board/UpdateCommunityBoardService.java +++ b/src/main/java/com/somemore/domains/community/service/board/UpdateCommunityBoardService.java @@ -5,13 +5,14 @@ import com.somemore.domains.community.repository.board.CommunityBoardRepository; import com.somemore.domains.community.usecase.board.UpdateCommunityBoardUseCase; import com.somemore.global.exception.BadRequestException; - -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.somemore.global.exception.ExceptionMessage.*; +import java.util.UUID; + +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_COMMUNITY_BOARD; +import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_COMMUNITY_BOARD; @RequiredArgsConstructor diff --git a/src/main/java/com/somemore/domains/community/service/comment/CommunityCommentQueryService.java b/src/main/java/com/somemore/domains/community/service/comment/CommunityCommentQueryService.java index 0eca5c4a3..2b3a20128 100644 --- a/src/main/java/com/somemore/domains/community/service/comment/CommunityCommentQueryService.java +++ b/src/main/java/com/somemore/domains/community/service/comment/CommunityCommentQueryService.java @@ -13,7 +13,12 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; @RequiredArgsConstructor @Transactional(readOnly = true) diff --git a/src/main/java/com/somemore/domains/community/service/comment/DeleteCommunityCommentService.java b/src/main/java/com/somemore/domains/community/service/comment/DeleteCommunityCommentService.java index 1cfeb938b..f9ce8cace 100644 --- a/src/main/java/com/somemore/domains/community/service/comment/DeleteCommunityCommentService.java +++ b/src/main/java/com/somemore/domains/community/service/comment/DeleteCommunityCommentService.java @@ -10,7 +10,8 @@ import java.util.UUID; -import static com.somemore.global.exception.ExceptionMessage.*; +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_COMMUNITY_COMMENT; +import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_COMMUNITY_COMMENT; @RequiredArgsConstructor @Transactional diff --git a/src/main/java/com/somemore/domains/community/service/comment/UpdateCommunityCommentService.java b/src/main/java/com/somemore/domains/community/service/comment/UpdateCommunityCommentService.java index adb3bcfa4..07138c08e 100644 --- a/src/main/java/com/somemore/domains/community/service/comment/UpdateCommunityCommentService.java +++ b/src/main/java/com/somemore/domains/community/service/comment/UpdateCommunityCommentService.java @@ -12,7 +12,9 @@ import java.util.UUID; -import static com.somemore.global.exception.ExceptionMessage.*; +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_COMMUNITY_BOARD; +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_COMMUNITY_COMMENT; +import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_COMMUNITY_COMMENT; @RequiredArgsConstructor @Transactional @@ -51,7 +53,7 @@ private void validateWriter(CommunityComment communityComment, UUID writerId) { if (communityComment.isWriter(writerId)) { return; } - + throw new BadRequestException(UNAUTHORIZED_COMMUNITY_COMMENT.getMessage()); } } diff --git a/src/main/java/com/somemore/domains/community/usecase/board/CommunityBoardQueryUseCase.java b/src/main/java/com/somemore/domains/community/usecase/board/CommunityBoardQueryUseCase.java index 0edbd8bde..abf6a1037 100644 --- a/src/main/java/com/somemore/domains/community/usecase/board/CommunityBoardQueryUseCase.java +++ b/src/main/java/com/somemore/domains/community/usecase/board/CommunityBoardQueryUseCase.java @@ -10,7 +10,10 @@ public interface CommunityBoardQueryUseCase { Page getCommunityBoards(String keyword, int page); + Page getCommunityBoardsByWriterId(UUID writerId, int page); + CommunityBoardDetailResponseDto getCommunityBoardDetail(Long id); + List getAllCommunityBoards(); } diff --git a/src/main/java/com/somemore/domains/community/usecase/board/CreateCommunityBoardUseCase.java b/src/main/java/com/somemore/domains/community/usecase/board/CreateCommunityBoardUseCase.java index c30fec825..41cfd1754 100644 --- a/src/main/java/com/somemore/domains/community/usecase/board/CreateCommunityBoardUseCase.java +++ b/src/main/java/com/somemore/domains/community/usecase/board/CreateCommunityBoardUseCase.java @@ -6,7 +6,7 @@ public interface CreateCommunityBoardUseCase { Long createCommunityBoard( - CommunityBoardCreateRequestDto requestDto, - UUID writerId, - String imgUrl); + CommunityBoardCreateRequestDto requestDto, + UUID writerId, + String imgUrl); } diff --git a/src/main/java/com/somemore/domains/interestcenter/controller/InterestCenterCommandApiController.java b/src/main/java/com/somemore/domains/interestcenter/controller/InterestCenterCommandApiController.java index c72ff2d5e..3e8fc83a2 100644 --- a/src/main/java/com/somemore/domains/interestcenter/controller/InterestCenterCommandApiController.java +++ b/src/main/java/com/somemore/domains/interestcenter/controller/InterestCenterCommandApiController.java @@ -1,15 +1,14 @@ package com.somemore.domains.interestcenter.controller; -import com.somemore.domains.interestcenter.usecase.CancelInterestCenterUseCase; -import com.somemore.global.auth.annotation.CurrentUser; -import com.somemore.global.common.response.ApiResponse; import com.somemore.domains.interestcenter.dto.request.RegisterInterestCenterRequestDto; import com.somemore.domains.interestcenter.dto.response.RegisterInterestCenterResponseDto; +import com.somemore.domains.interestcenter.usecase.CancelInterestCenterUseCase; import com.somemore.domains.interestcenter.usecase.RegisterInterestCenterUseCase; +import com.somemore.global.auth.annotation.CurrentUser; +import com.somemore.global.common.response.ApiResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.security.access.annotation.Secured; import org.springframework.web.bind.annotation.DeleteMapping; @@ -18,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import java.util.UUID; + @RequiredArgsConstructor @RestController @Tag(name = "Interest Center Command API", description = "관심 기관의 등록과 취소 API를 제공합니다") diff --git a/src/main/java/com/somemore/domains/interestcenter/controller/InterestCenterQueryApiController.java b/src/main/java/com/somemore/domains/interestcenter/controller/InterestCenterQueryApiController.java index 95479ab61..1ef1faea5 100644 --- a/src/main/java/com/somemore/domains/interestcenter/controller/InterestCenterQueryApiController.java +++ b/src/main/java/com/somemore/domains/interestcenter/controller/InterestCenterQueryApiController.java @@ -1,17 +1,18 @@ package com.somemore.domains.interestcenter.controller; +import com.somemore.domains.interestcenter.dto.response.InterestCentersResponseDto; import com.somemore.domains.interestcenter.usecase.InterestCenterQueryUseCase; import com.somemore.global.auth.annotation.CurrentUser; import com.somemore.global.common.response.ApiResponse; -import com.somemore.domains.interestcenter.dto.response.InterestCentersResponseDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import java.util.List; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; +import java.util.UUID; + @RequiredArgsConstructor @RestController @Tag(name = "Interest Center Query API", description = "관심 기관의 조회 API를 제공합니다") diff --git a/src/main/java/com/somemore/domains/interestcenter/domain/InterestCenter.java b/src/main/java/com/somemore/domains/interestcenter/domain/InterestCenter.java index 2ee2fc6d9..507d8af50 100644 --- a/src/main/java/com/somemore/domains/interestcenter/domain/InterestCenter.java +++ b/src/main/java/com/somemore/domains/interestcenter/domain/InterestCenter.java @@ -1,8 +1,15 @@ package com.somemore.domains.interestcenter.domain; import com.somemore.global.common.entity.BaseEntity; -import jakarta.persistence.*; -import lombok.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; import java.util.UUID; diff --git a/src/main/java/com/somemore/domains/interestcenter/dto/request/RegisterInterestCenterRequestDto.java b/src/main/java/com/somemore/domains/interestcenter/dto/request/RegisterInterestCenterRequestDto.java index 1cb6a9e0c..5c6309c5b 100644 --- a/src/main/java/com/somemore/domains/interestcenter/dto/request/RegisterInterestCenterRequestDto.java +++ b/src/main/java/com/somemore/domains/interestcenter/dto/request/RegisterInterestCenterRequestDto.java @@ -15,7 +15,7 @@ public record RegisterInterestCenterRequestDto( @NotNull(message = "기관 ID는 필수값입니다.") UUID centerId ) { - public InterestCenter toEntity(UUID volunteerId){ + public InterestCenter toEntity(UUID volunteerId) { return InterestCenter.create(volunteerId, centerId); } } diff --git a/src/main/java/com/somemore/domains/interestcenter/dto/response/RegisterInterestCenterResponseDto.java b/src/main/java/com/somemore/domains/interestcenter/dto/response/RegisterInterestCenterResponseDto.java index e6b0ff573..7bb99d30f 100644 --- a/src/main/java/com/somemore/domains/interestcenter/dto/response/RegisterInterestCenterResponseDto.java +++ b/src/main/java/com/somemore/domains/interestcenter/dto/response/RegisterInterestCenterResponseDto.java @@ -20,11 +20,11 @@ public record RegisterInterestCenterResponseDto( @Schema(description = "기관 ID", example = "123e4567-e89b-12d3-a456-426614174000") UUID centerId ) { - public static RegisterInterestCenterResponseDto from(InterestCenter interestCenter) { - return RegisterInterestCenterResponseDto.builder() - .id(interestCenter.getId()) - .volunteerId(interestCenter.getVolunteerId()) - .centerId(interestCenter.getCenterId()) - .build(); - } + public static RegisterInterestCenterResponseDto from(InterestCenter interestCenter) { + return RegisterInterestCenterResponseDto.builder() + .id(interestCenter.getId()) + .volunteerId(interestCenter.getVolunteerId()) + .centerId(interestCenter.getCenterId()) + .build(); + } } diff --git a/src/main/java/com/somemore/domains/interestcenter/repository/InterestCenterRepository.java b/src/main/java/com/somemore/domains/interestcenter/repository/InterestCenterRepository.java index 0eea76425..706ef082c 100644 --- a/src/main/java/com/somemore/domains/interestcenter/repository/InterestCenterRepository.java +++ b/src/main/java/com/somemore/domains/interestcenter/repository/InterestCenterRepository.java @@ -1,7 +1,7 @@ package com.somemore.domains.interestcenter.repository; -import com.somemore.domains.interestcenter.dto.response.RegisterInterestCenterResponseDto; import com.somemore.domains.interestcenter.domain.InterestCenter; +import com.somemore.domains.interestcenter.dto.response.RegisterInterestCenterResponseDto; import java.util.List; import java.util.Optional; @@ -9,10 +9,16 @@ public interface InterestCenterRepository { InterestCenter save(InterestCenter interestCenter); + Optional findById(Long id); + Optional findInterestCenterResponseById(Long id); + List findInterestCenterIdsByVolunteerId(UUID volunteerId); + List findVolunteerIdsByCenterId(UUID centerId); + boolean existsByVolunteerIdAndCenterId(UUID volunteerId, UUID centerId); + Optional findByVolunteerIdAndCenterId(UUID volunteerId, UUID centerId); } diff --git a/src/main/java/com/somemore/domains/interestcenter/repository/InterestCenterRepositoryImpl.java b/src/main/java/com/somemore/domains/interestcenter/repository/InterestCenterRepositoryImpl.java index 97e6d5bb1..319f835ca 100644 --- a/src/main/java/com/somemore/domains/interestcenter/repository/InterestCenterRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/interestcenter/repository/InterestCenterRepositoryImpl.java @@ -3,17 +3,16 @@ import com.querydsl.core.types.Projections; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.domains.interestcenter.domain.InterestCenter; import com.somemore.domains.interestcenter.domain.QInterestCenter; import com.somemore.domains.interestcenter.dto.response.RegisterInterestCenterResponseDto; -import com.somemore.domains.interestcenter.domain.InterestCenter; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; import java.util.List; import java.util.Optional; import java.util.UUID; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Repository; - @RequiredArgsConstructor @Repository public class InterestCenterRepositoryImpl implements InterestCenterRepository { diff --git a/src/main/java/com/somemore/domains/interestcenter/service/CancelInterestCenterService.java b/src/main/java/com/somemore/domains/interestcenter/service/CancelInterestCenterService.java index 54ee4b0e1..1b588557b 100644 --- a/src/main/java/com/somemore/domains/interestcenter/service/CancelInterestCenterService.java +++ b/src/main/java/com/somemore/domains/interestcenter/service/CancelInterestCenterService.java @@ -1,15 +1,15 @@ package com.somemore.domains.interestcenter.service; import com.somemore.domains.center.usecase.query.CenterQueryUseCase; -import com.somemore.domains.interestcenter.usecase.CancelInterestCenterUseCase; -import com.somemore.global.exception.BadRequestException; import com.somemore.domains.interestcenter.domain.InterestCenter; import com.somemore.domains.interestcenter.repository.InterestCenterRepository; - -import java.util.UUID; +import com.somemore.domains.interestcenter.usecase.CancelInterestCenterUseCase; +import com.somemore.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.UUID; + import static com.somemore.global.exception.ExceptionMessage.CANNOT_CANCEL_DELETED_INTEREST_CENTER; @RequiredArgsConstructor diff --git a/src/main/java/com/somemore/domains/interestcenter/service/InterestCenterQueryService.java b/src/main/java/com/somemore/domains/interestcenter/service/InterestCenterQueryService.java index a3fe9f0d8..dba205867 100644 --- a/src/main/java/com/somemore/domains/interestcenter/service/InterestCenterQueryService.java +++ b/src/main/java/com/somemore/domains/interestcenter/service/InterestCenterQueryService.java @@ -2,9 +2,9 @@ import com.somemore.domains.center.repository.mapper.CenterOverviewInfo; import com.somemore.domains.center.usecase.query.CenterQueryUseCase; -import com.somemore.domains.interestcenter.usecase.InterestCenterQueryUseCase; import com.somemore.domains.interestcenter.dto.response.InterestCentersResponseDto; import com.somemore.domains.interestcenter.repository.InterestCenterRepository; +import com.somemore.domains.interestcenter.usecase.InterestCenterQueryUseCase; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/somemore/domains/interestcenter/service/RegisterInterestCenterService.java b/src/main/java/com/somemore/domains/interestcenter/service/RegisterInterestCenterService.java index db389f846..302ed8e94 100644 --- a/src/main/java/com/somemore/domains/interestcenter/service/RegisterInterestCenterService.java +++ b/src/main/java/com/somemore/domains/interestcenter/service/RegisterInterestCenterService.java @@ -1,16 +1,17 @@ package com.somemore.domains.interestcenter.service; import com.somemore.domains.center.usecase.query.CenterQueryUseCase; -import com.somemore.global.exception.DuplicateException; import com.somemore.domains.interestcenter.domain.InterestCenter; import com.somemore.domains.interestcenter.dto.request.RegisterInterestCenterRequestDto; import com.somemore.domains.interestcenter.dto.response.RegisterInterestCenterResponseDto; import com.somemore.domains.interestcenter.repository.InterestCenterRepository; import com.somemore.domains.interestcenter.usecase.RegisterInterestCenterUseCase; -import java.util.UUID; +import com.somemore.global.exception.DuplicateException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.UUID; + import static com.somemore.global.exception.ExceptionMessage.DUPLICATE_INTEREST_CENTER; @RequiredArgsConstructor @@ -26,7 +27,7 @@ public RegisterInterestCenterResponseDto registerInterestCenter(UUID volunteerId centerQueryUseCase.validateCenterExists(requestDto.centerId()); boolean isDuplicate = repository.existsByVolunteerIdAndCenterId(volunteerId, requestDto.centerId()); - if(isDuplicate){ + if (isDuplicate) { throw new DuplicateException(DUPLICATE_INTEREST_CENTER.getMessage()); } diff --git a/src/main/java/com/somemore/domains/interestcenter/usecase/InterestCenterQueryUseCase.java b/src/main/java/com/somemore/domains/interestcenter/usecase/InterestCenterQueryUseCase.java index 6f242b61d..7f6d771de 100644 --- a/src/main/java/com/somemore/domains/interestcenter/usecase/InterestCenterQueryUseCase.java +++ b/src/main/java/com/somemore/domains/interestcenter/usecase/InterestCenterQueryUseCase.java @@ -7,5 +7,6 @@ public interface InterestCenterQueryUseCase { List getInterestCenters(UUID volunteerId); + List getVolunteerIdsByCenterId(UUID centerId); } diff --git a/src/main/java/com/somemore/domains/interestcenter/usecase/RegisterInterestCenterUseCase.java b/src/main/java/com/somemore/domains/interestcenter/usecase/RegisterInterestCenterUseCase.java index e28b7bc48..8c59bb77e 100644 --- a/src/main/java/com/somemore/domains/interestcenter/usecase/RegisterInterestCenterUseCase.java +++ b/src/main/java/com/somemore/domains/interestcenter/usecase/RegisterInterestCenterUseCase.java @@ -2,6 +2,7 @@ import com.somemore.domains.interestcenter.dto.request.RegisterInterestCenterRequestDto; import com.somemore.domains.interestcenter.dto.response.RegisterInterestCenterResponseDto; + import java.util.UUID; public interface RegisterInterestCenterUseCase { diff --git a/src/main/java/com/somemore/domains/location/domain/Location.java b/src/main/java/com/somemore/domains/location/domain/Location.java index 3ed0b8624..b3d37ce09 100644 --- a/src/main/java/com/somemore/domains/location/domain/Location.java +++ b/src/main/java/com/somemore/domains/location/domain/Location.java @@ -1,8 +1,5 @@ package com.somemore.domains.location.domain; -import static jakarta.persistence.GenerationType.IDENTITY; -import static lombok.AccessLevel.PROTECTED; - import com.somemore.domains.location.dto.request.LocationUpdateRequestDto; import com.somemore.global.common.entity.BaseEntity; import jakarta.persistence.Column; @@ -10,12 +7,16 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.Table; -import java.math.BigDecimal; -import java.math.RoundingMode; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import java.math.BigDecimal; +import java.math.RoundingMode; + +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + @Getter @NoArgsConstructor(access = PROTECTED) @Entity diff --git a/src/main/java/com/somemore/domains/location/dto/request/LocationCreateRequestDto.java b/src/main/java/com/somemore/domains/location/dto/request/LocationCreateRequestDto.java index cb6f2948a..af7ca6019 100644 --- a/src/main/java/com/somemore/domains/location/dto/request/LocationCreateRequestDto.java +++ b/src/main/java/com/somemore/domains/location/dto/request/LocationCreateRequestDto.java @@ -9,33 +9,34 @@ import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -import java.math.BigDecimal; import lombok.Builder; +import java.math.BigDecimal; + @JsonNaming(SnakeCaseStrategy.class) @Builder public record LocationCreateRequestDto( - @Schema(description = "도로명 주소", example = "서울특별시 서초구 반포대로 45, 4층(서초동, 명정빌딩)") - @NotBlank(message = "주소는 필수 입력 값입니다.") - String address, - @Schema(description = "주소에 해당하는 위도 정보", example = "37.4845373748015") - @NotNull(message = "위도는 필수 입력 값입니다.") - @DecimalMin(value = "33", message = "위도는 33도 이상이어야 합니다.") - @DecimalMax(value = "39", message = "위도는 38도 이하이어야 합니다.") - BigDecimal latitude, + @Schema(description = "도로명 주소", example = "서울특별시 서초구 반포대로 45, 4층(서초동, 명정빌딩)") + @NotBlank(message = "주소는 필수 입력 값입니다.") + String address, + @Schema(description = "주소에 해당하는 위도 정보", example = "37.4845373748015") + @NotNull(message = "위도는 필수 입력 값입니다.") + @DecimalMin(value = "33", message = "위도는 33도 이상이어야 합니다.") + @DecimalMax(value = "39", message = "위도는 38도 이하이어야 합니다.") + BigDecimal latitude, - @Schema(description = "주소에 해당하는 경도 정보", example = "127.010842267696") - @NotNull(message = "경도는 필수 입력 값입니다.") - @DecimalMin(value = "124", message = "경도는 124도 이상이어야 합니다.") - @DecimalMax(value = "132", message = "경도는 132도 이하이어야 합니다.") - BigDecimal longitude + @Schema(description = "주소에 해당하는 경도 정보", example = "127.010842267696") + @NotNull(message = "경도는 필수 입력 값입니다.") + @DecimalMin(value = "124", message = "경도는 124도 이상이어야 합니다.") + @DecimalMax(value = "132", message = "경도는 132도 이하이어야 합니다.") + BigDecimal longitude ) { public Location toEntity() { return Location.builder() - .address(address) - .latitude(latitude) - .longitude(longitude) - .build(); + .address(address) + .latitude(latitude) + .longitude(longitude) + .build(); } } diff --git a/src/main/java/com/somemore/domains/location/dto/request/LocationUpdateRequestDto.java b/src/main/java/com/somemore/domains/location/dto/request/LocationUpdateRequestDto.java index 9b23d7588..c0e336397 100644 --- a/src/main/java/com/somemore/domains/location/dto/request/LocationUpdateRequestDto.java +++ b/src/main/java/com/somemore/domains/location/dto/request/LocationUpdateRequestDto.java @@ -7,25 +7,26 @@ import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -import java.math.BigDecimal; import lombok.Builder; +import java.math.BigDecimal; + @JsonNaming(SnakeCaseStrategy.class) @Builder public record LocationUpdateRequestDto( - @Schema(description = "도로명 주소", example = "서울특별시 서초구 반포대로 45, 4층(서초동, 명정빌딩)") - @NotBlank(message = "주소는 필수 입력 값입니다.") - String address, - @Schema(description = "주소에 해당하는 위도 정보", example = "37.4845373748015") - @NotNull(message = "위도는 필수 입력 값입니다.") - @DecimalMin(value = "33", message = "위도는 33도 이상이어야 합니다.") - @DecimalMax(value = "39", message = "위도는 38도 이하이어야 합니다.") - BigDecimal latitude, - @Schema(description = "주소에 해당하는 경도 정보", example = "127.010842267696") - @NotNull(message = "경도는 필수 입력 값입니다.") - @DecimalMin(value = "124", message = "경도는 124도 이상이어야 합니다.") - @DecimalMax(value = "132", message = "경도는 132도 이하이어야 합니다.") - BigDecimal longitude + @Schema(description = "도로명 주소", example = "서울특별시 서초구 반포대로 45, 4층(서초동, 명정빌딩)") + @NotBlank(message = "주소는 필수 입력 값입니다.") + String address, + @Schema(description = "주소에 해당하는 위도 정보", example = "37.4845373748015") + @NotNull(message = "위도는 필수 입력 값입니다.") + @DecimalMin(value = "33", message = "위도는 33도 이상이어야 합니다.") + @DecimalMax(value = "39", message = "위도는 38도 이하이어야 합니다.") + BigDecimal latitude, + @Schema(description = "주소에 해당하는 경도 정보", example = "127.010842267696") + @NotNull(message = "경도는 필수 입력 값입니다.") + @DecimalMin(value = "124", message = "경도는 124도 이상이어야 합니다.") + @DecimalMax(value = "132", message = "경도는 132도 이하이어야 합니다.") + BigDecimal longitude ) { } diff --git a/src/main/java/com/somemore/domains/location/dto/response/LocationResponseDto.java b/src/main/java/com/somemore/domains/location/dto/response/LocationResponseDto.java index 8e0e416d2..ad2dd04b9 100644 --- a/src/main/java/com/somemore/domains/location/dto/response/LocationResponseDto.java +++ b/src/main/java/com/somemore/domains/location/dto/response/LocationResponseDto.java @@ -4,35 +4,36 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.somemore.domains.location.domain.Location; import io.swagger.v3.oas.annotations.media.Schema; -import java.math.BigDecimal; import lombok.Builder; +import java.math.BigDecimal; + @Builder @JsonNaming(SnakeCaseStrategy.class) @Schema(description = "위치 조회 응답 DTO") public record LocationResponseDto( - @Schema(description = "주소", example = "서울특별시 강남구 테헤란로 123") - String address, - @Schema(description = "위도", example = "37.5665") - BigDecimal latitude, - @Schema(description = "경도", example = "126.9780") - BigDecimal longitude + @Schema(description = "주소", example = "서울특별시 강남구 테헤란로 123") + String address, + @Schema(description = "위도", example = "37.5665") + BigDecimal latitude, + @Schema(description = "경도", example = "126.9780") + BigDecimal longitude ) { public static LocationResponseDto from(Location location) { return LocationResponseDto.builder() - .address(location.getAddress()) - .latitude(location.getLatitude()) - .longitude(location.getLongitude()) - .build(); + .address(location.getAddress()) + .latitude(location.getLatitude()) + .longitude(location.getLongitude()) + .build(); } public static LocationResponseDto of(String address, BigDecimal latitude, - BigDecimal longitude) { + BigDecimal longitude) { return LocationResponseDto.builder() - .address(address) - .latitude(latitude) - .longitude(longitude) - .build(); + .address(address) + .latitude(latitude) + .longitude(longitude) + .build(); } } diff --git a/src/main/java/com/somemore/domains/location/repository/LocationRepository.java b/src/main/java/com/somemore/domains/location/repository/LocationRepository.java index ebc203332..99e586f03 100644 --- a/src/main/java/com/somemore/domains/location/repository/LocationRepository.java +++ b/src/main/java/com/somemore/domains/location/repository/LocationRepository.java @@ -1,6 +1,7 @@ package com.somemore.domains.location.repository; import com.somemore.domains.location.domain.Location; + import java.util.Optional; public interface LocationRepository { diff --git a/src/main/java/com/somemore/domains/location/repository/LocationRepositoryImpl.java b/src/main/java/com/somemore/domains/location/repository/LocationRepositoryImpl.java index ba97a849c..014d1aa80 100644 --- a/src/main/java/com/somemore/domains/location/repository/LocationRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/location/repository/LocationRepositoryImpl.java @@ -2,10 +2,11 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import com.somemore.domains.location.domain.Location; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; +import java.util.Optional; + @RequiredArgsConstructor @Repository public class LocationRepositoryImpl implements LocationRepository { diff --git a/src/main/java/com/somemore/domains/location/service/command/CreateLocationService.java b/src/main/java/com/somemore/domains/location/service/command/CreateLocationService.java index 2fe03308d..74f598ab0 100644 --- a/src/main/java/com/somemore/domains/location/service/command/CreateLocationService.java +++ b/src/main/java/com/somemore/domains/location/service/command/CreateLocationService.java @@ -1,9 +1,9 @@ package com.somemore.domains.location.service.command; +import com.somemore.domains.location.domain.Location; import com.somemore.domains.location.dto.request.LocationCreateRequestDto; import com.somemore.domains.location.repository.LocationRepository; import com.somemore.domains.location.usecase.command.CreateLocationUseCase; -import com.somemore.domains.location.domain.Location; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/somemore/domains/location/service/command/UpdateLocationService.java b/src/main/java/com/somemore/domains/location/service/command/UpdateLocationService.java index dcb2e9acc..abab0320f 100644 --- a/src/main/java/com/somemore/domains/location/service/command/UpdateLocationService.java +++ b/src/main/java/com/somemore/domains/location/service/command/UpdateLocationService.java @@ -1,16 +1,16 @@ package com.somemore.domains.location.service.command; -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_LOCATION; - +import com.somemore.domains.location.domain.Location; import com.somemore.domains.location.dto.request.LocationUpdateRequestDto; import com.somemore.domains.location.repository.LocationRepository; import com.somemore.domains.location.usecase.command.UpdateLocationUseCase; import com.somemore.global.exception.BadRequestException; -import com.somemore.domains.location.domain.Location; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_LOCATION; + @RequiredArgsConstructor @Transactional @Service @@ -27,6 +27,6 @@ public void updateLocation(LocationUpdateRequestDto requestDto, Long locationId) private Location getLocation(Long locationId) { return locationRepository.findById(locationId) - .orElseThrow(() -> new BadRequestException(NOT_EXISTS_LOCATION.getMessage())); + .orElseThrow(() -> new BadRequestException(NOT_EXISTS_LOCATION.getMessage())); } } diff --git a/src/main/java/com/somemore/domains/location/service/query/LocationQueryService.java b/src/main/java/com/somemore/domains/location/service/query/LocationQueryService.java index cdbb5ec91..b42a92875 100644 --- a/src/main/java/com/somemore/domains/location/service/query/LocationQueryService.java +++ b/src/main/java/com/somemore/domains/location/service/query/LocationQueryService.java @@ -1,15 +1,15 @@ package com.somemore.domains.location.service.query; -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_LOCATION; - +import com.somemore.domains.location.domain.Location; import com.somemore.domains.location.repository.LocationRepository; import com.somemore.domains.location.usecase.query.LocationQueryUseCase; import com.somemore.global.exception.BadRequestException; -import com.somemore.domains.location.domain.Location; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_LOCATION; + @RequiredArgsConstructor @Transactional(readOnly = true) @Service @@ -24,7 +24,7 @@ public Location getById(Long id) { private Location getLocation(Long id) { return locationRepository.findById(id).orElseThrow( - () -> new BadRequestException(NOT_EXISTS_LOCATION.getMessage()) + () -> new BadRequestException(NOT_EXISTS_LOCATION.getMessage()) ); } diff --git a/src/main/java/com/somemore/domains/location/utils/GeoUtils.java b/src/main/java/com/somemore/domains/location/utils/GeoUtils.java index eb93b54dc..0454c56fb 100644 --- a/src/main/java/com/somemore/domains/location/utils/GeoUtils.java +++ b/src/main/java/com/somemore/domains/location/utils/GeoUtils.java @@ -1,16 +1,16 @@ package com.somemore.domains.location.utils; -import static lombok.AccessLevel.PRIVATE; - import lombok.NoArgsConstructor; +import static lombok.AccessLevel.PRIVATE; + @NoArgsConstructor(access = PRIVATE) public class GeoUtils { private static final double EARTH_RADIUS = 6371.0; public static double[] calculateMaxMinCoordinates(double latitude, double longitude, - double radius) { + double radius) { double latRad = Math.toRadians(latitude); double latDiff = radius / EARTH_RADIUS; double maxLatRad = latRad + latDiff; diff --git a/src/main/java/com/somemore/domains/note/controller/NoteCommandApiController.java b/src/main/java/com/somemore/domains/note/controller/NoteCommandApiController.java index a7af6a569..f3700f811 100644 --- a/src/main/java/com/somemore/domains/note/controller/NoteCommandApiController.java +++ b/src/main/java/com/somemore/domains/note/controller/NoteCommandApiController.java @@ -1,11 +1,11 @@ package com.somemore.domains.note.controller; -import com.somemore.global.auth.annotation.CurrentUser; -import com.somemore.global.common.response.ApiResponse; import com.somemore.domains.note.dto.SendNoteToCenterRequestDto; import com.somemore.domains.note.dto.SendNoteToVolunteerRequestDto; import com.somemore.domains.note.usecase.SendNoteToCenterUseCase; import com.somemore.domains.note.usecase.SendNoteToVolunteerUseCase; +import com.somemore.global.auth.annotation.CurrentUser; +import com.somemore.global.common.response.ApiResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; diff --git a/src/main/java/com/somemore/domains/note/controller/NoteQueryApiController.java b/src/main/java/com/somemore/domains/note/controller/NoteQueryApiController.java index 04435b7dd..dce7bd806 100644 --- a/src/main/java/com/somemore/domains/note/controller/NoteQueryApiController.java +++ b/src/main/java/com/somemore/domains/note/controller/NoteQueryApiController.java @@ -1,19 +1,22 @@ package com.somemore.domains.note.controller; -import com.somemore.global.auth.annotation.CurrentUser; -import com.somemore.global.common.response.ApiResponse; import com.somemore.domains.note.repository.mapper.NoteDetailViewForCenter; import com.somemore.domains.note.repository.mapper.NoteDetailViewForVolunteer; import com.somemore.domains.note.repository.mapper.NoteReceiverViewForCenter; import com.somemore.domains.note.repository.mapper.NoteReceiverViewForVolunteer; import com.somemore.domains.note.usecase.NoteQueryUseCase; +import com.somemore.global.auth.annotation.CurrentUser; +import com.somemore.global.common.response.ApiResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.security.access.annotation.Secured; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.UUID; diff --git a/src/main/java/com/somemore/domains/note/domain/Note.java b/src/main/java/com/somemore/domains/note/domain/Note.java index 42bee7aef..4f93fccf1 100644 --- a/src/main/java/com/somemore/domains/note/domain/Note.java +++ b/src/main/java/com/somemore/domains/note/domain/Note.java @@ -1,7 +1,12 @@ package com.somemore.domains.note.domain; import com.somemore.global.common.entity.BaseEntity; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/somemore/domains/note/dto/SendNoteToCenterRequestDto.java b/src/main/java/com/somemore/domains/note/dto/SendNoteToCenterRequestDto.java index 0145cb272..8579cfc1b 100644 --- a/src/main/java/com/somemore/domains/note/dto/SendNoteToCenterRequestDto.java +++ b/src/main/java/com/somemore/domains/note/dto/SendNoteToCenterRequestDto.java @@ -23,7 +23,7 @@ public record SendNoteToCenterRequestDto( @NotNull(message = "쪽지 내용은 필수 값입니다.") String content ) { - public Note toEntity(UUID senderId){ - return Note.create(senderId, receiverId, title, content); - } + public Note toEntity(UUID senderId) { + return Note.create(senderId, receiverId, title, content); + } } diff --git a/src/main/java/com/somemore/domains/note/dto/SendNoteToVolunteerRequestDto.java b/src/main/java/com/somemore/domains/note/dto/SendNoteToVolunteerRequestDto.java index 3876b5e98..10eff7089 100644 --- a/src/main/java/com/somemore/domains/note/dto/SendNoteToVolunteerRequestDto.java +++ b/src/main/java/com/somemore/domains/note/dto/SendNoteToVolunteerRequestDto.java @@ -23,7 +23,7 @@ public record SendNoteToVolunteerRequestDto( @NotNull(message = "쪽지 내용은 필수 값입니다.") String content ) { - public Note toEntity(UUID senderId){ + public Note toEntity(UUID senderId) { return Note.create(senderId, receiverId, title, content); } } \ No newline at end of file diff --git a/src/main/java/com/somemore/domains/note/repository/NoteRepository.java b/src/main/java/com/somemore/domains/note/repository/NoteRepository.java index 63f27565c..a435e49ed 100644 --- a/src/main/java/com/somemore/domains/note/repository/NoteRepository.java +++ b/src/main/java/com/somemore/domains/note/repository/NoteRepository.java @@ -1,10 +1,10 @@ package com.somemore.domains.note.repository; -import com.somemore.domains.note.repository.mapper.NoteDetailViewForCenter; -import com.somemore.domains.note.repository.mapper.NoteReceiverViewForVolunteer; import com.somemore.domains.note.domain.Note; +import com.somemore.domains.note.repository.mapper.NoteDetailViewForCenter; import com.somemore.domains.note.repository.mapper.NoteDetailViewForVolunteer; import com.somemore.domains.note.repository.mapper.NoteReceiverViewForCenter; +import com.somemore.domains.note.repository.mapper.NoteReceiverViewForVolunteer; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -13,9 +13,14 @@ public interface NoteRepository { Note save(Note note); + Optional findById(Long noteId); + Page findNotesByReceiverIsCenter(UUID centerId, Pageable pageable); + Page findNotesByReceiverIsVolunteer(UUID volunteerId, Pageable pageable); + Optional findNoteDetailViewReceiverIsCenter(Long noteId); + Optional findNoteDetailViewReceiverIsVolunteer(Long noteId); } diff --git a/src/main/java/com/somemore/domains/note/service/NoteMarkAsReadService.java b/src/main/java/com/somemore/domains/note/service/NoteMarkAsReadService.java index 885c7e89c..da3afcda3 100644 --- a/src/main/java/com/somemore/domains/note/service/NoteMarkAsReadService.java +++ b/src/main/java/com/somemore/domains/note/service/NoteMarkAsReadService.java @@ -1,9 +1,9 @@ package com.somemore.domains.note.service; +import com.somemore.domains.note.domain.Note; import com.somemore.domains.note.repository.NoteRepository; import com.somemore.domains.note.usecase.NoteMarkAsReadUseCase; import com.somemore.global.exception.NoSuchElementException; -import com.somemore.domains.note.domain.Note; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/somemore/domains/note/service/SendNoteToCenterService.java b/src/main/java/com/somemore/domains/note/service/SendNoteToCenterService.java index 2cef38f6f..0451e76c7 100644 --- a/src/main/java/com/somemore/domains/note/service/SendNoteToCenterService.java +++ b/src/main/java/com/somemore/domains/note/service/SendNoteToCenterService.java @@ -1,10 +1,10 @@ package com.somemore.domains.note.service; import com.somemore.domains.center.usecase.query.CenterQueryUseCase; -import com.somemore.domains.note.repository.NoteRepository; -import com.somemore.domains.note.usecase.SendNoteToCenterUseCase; import com.somemore.domains.note.domain.Note; import com.somemore.domains.note.dto.SendNoteToCenterRequestDto; +import com.somemore.domains.note.repository.NoteRepository; +import com.somemore.domains.note.usecase.SendNoteToCenterUseCase; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/somemore/domains/note/service/SendNoteToVolunteerService.java b/src/main/java/com/somemore/domains/note/service/SendNoteToVolunteerService.java index 9295c75ca..058cdac18 100644 --- a/src/main/java/com/somemore/domains/note/service/SendNoteToVolunteerService.java +++ b/src/main/java/com/somemore/domains/note/service/SendNoteToVolunteerService.java @@ -1,10 +1,10 @@ package com.somemore.domains.note.service; +import com.somemore.domains.note.domain.Note; +import com.somemore.domains.note.dto.SendNoteToVolunteerRequestDto; import com.somemore.domains.note.repository.NoteRepository; import com.somemore.domains.note.usecase.SendNoteToVolunteerUseCase; import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; -import com.somemore.domains.note.domain.Note; -import com.somemore.domains.note.dto.SendNoteToVolunteerRequestDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/somemore/domains/note/usecase/NoteQueryUseCase.java b/src/main/java/com/somemore/domains/note/usecase/NoteQueryUseCase.java index fe0e7d52f..17eb6e898 100644 --- a/src/main/java/com/somemore/domains/note/usecase/NoteQueryUseCase.java +++ b/src/main/java/com/somemore/domains/note/usecase/NoteQueryUseCase.java @@ -11,7 +11,10 @@ public interface NoteQueryUseCase { Page getNotesForCenter(UUID centerId, Pageable pageable); + Page getNotesForVolunteer(UUID volunteerId, Pageable pageable); + NoteDetailViewForCenter getNoteDetailForCenter(Long noteId); + NoteDetailViewForVolunteer getNoteDetailForVolunteer(Long noteId); } diff --git a/src/main/java/com/somemore/domains/notification/controller/NotificationCommandController.java b/src/main/java/com/somemore/domains/notification/controller/NotificationCommandController.java index 6bcad999e..2a3029372 100644 --- a/src/main/java/com/somemore/domains/notification/controller/NotificationCommandController.java +++ b/src/main/java/com/somemore/domains/notification/controller/NotificationCommandController.java @@ -1,9 +1,9 @@ package com.somemore.domains.notification.controller; +import com.somemore.domains.notification.dto.NotificationIdsRequestDto; import com.somemore.domains.notification.usecase.NotificationCommandUseCase; import com.somemore.global.auth.annotation.CurrentUser; import com.somemore.global.common.response.ApiResponse; -import com.somemore.domains.notification.dto.NotificationIdsRequestDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/somemore/domains/notification/controller/NotificationQueryController.java b/src/main/java/com/somemore/domains/notification/controller/NotificationQueryController.java index 2b7439b19..f9e6ffecd 100644 --- a/src/main/java/com/somemore/domains/notification/controller/NotificationQueryController.java +++ b/src/main/java/com/somemore/domains/notification/controller/NotificationQueryController.java @@ -1,9 +1,9 @@ package com.somemore.domains.notification.controller; -import com.somemore.global.auth.annotation.CurrentUser; -import com.somemore.global.common.response.ApiResponse; import com.somemore.domains.notification.dto.NotificationResponseDto; import com.somemore.domains.notification.usecase.NotificationQueryUseCase; +import com.somemore.global.auth.annotation.CurrentUser; +import com.somemore.global.common.response.ApiResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/somemore/domains/notification/domain/Notification.java b/src/main/java/com/somemore/domains/notification/domain/Notification.java index 59f3f6727..e0d82ca6e 100644 --- a/src/main/java/com/somemore/domains/notification/domain/Notification.java +++ b/src/main/java/com/somemore/domains/notification/domain/Notification.java @@ -1,6 +1,14 @@ package com.somemore.domains.notification.domain; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/somemore/domains/notification/event/converter/NotificationMessageConverter.java b/src/main/java/com/somemore/domains/notification/event/converter/NotificationMessageConverter.java index 8c4f0f3f2..1d5b6efe5 100644 --- a/src/main/java/com/somemore/domains/notification/event/converter/NotificationMessageConverter.java +++ b/src/main/java/com/somemore/domains/notification/event/converter/NotificationMessageConverter.java @@ -4,13 +4,13 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.somemore.domains.community.event.CommentAddedEvent; -import com.somemore.domains.volunteerapply.event.VolunteerReviewRequestEvent; import com.somemore.domains.interestcenter.event.domain.InterestCenterCreateRecruitBoardEvent; import com.somemore.domains.notification.domain.Notification; import com.somemore.domains.notification.domain.NotificationSubType; import com.somemore.domains.volunteerapply.domain.ApplyStatus; import com.somemore.domains.volunteerapply.event.VolunteerApplyEvent; import com.somemore.domains.volunteerapply.event.VolunteerApplyStatusChangeEvent; +import com.somemore.domains.volunteerapply.event.VolunteerReviewRequestEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/somemore/domains/notification/event/subscriber/RedisNotificationSubscriber.java b/src/main/java/com/somemore/domains/notification/event/subscriber/RedisNotificationSubscriber.java index c11621ccd..db6bff1f8 100644 --- a/src/main/java/com/somemore/domains/notification/event/subscriber/RedisNotificationSubscriber.java +++ b/src/main/java/com/somemore/domains/notification/event/subscriber/RedisNotificationSubscriber.java @@ -1,8 +1,8 @@ package com.somemore.domains.notification.event.subscriber; +import com.somemore.domains.notification.domain.Notification; import com.somemore.domains.notification.event.converter.NotificationMessageConverter; import com.somemore.domains.notification.event.handler.NotificationHandler; -import com.somemore.domains.notification.domain.Notification; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.connection.Message; import org.springframework.data.redis.connection.MessageListener; diff --git a/src/main/java/com/somemore/domains/notification/repository/NotificationRepository.java b/src/main/java/com/somemore/domains/notification/repository/NotificationRepository.java index 81c1b5aeb..813a232ac 100644 --- a/src/main/java/com/somemore/domains/notification/repository/NotificationRepository.java +++ b/src/main/java/com/somemore/domains/notification/repository/NotificationRepository.java @@ -17,6 +17,7 @@ public interface NotificationRepository { List findAllByIds(List ids); List findByReceiverIdAndUnread(UUID userId); + List findByReceiverIdAndRead(UUID userId); void deleteAllInBatch(); diff --git a/src/main/java/com/somemore/domains/notification/usecase/NotificationCommandUseCase.java b/src/main/java/com/somemore/domains/notification/usecase/NotificationCommandUseCase.java index fba6dd544..edd381e25 100644 --- a/src/main/java/com/somemore/domains/notification/usecase/NotificationCommandUseCase.java +++ b/src/main/java/com/somemore/domains/notification/usecase/NotificationCommandUseCase.java @@ -7,5 +7,6 @@ public interface NotificationCommandUseCase { void markSingleNotificationAsRead(UUID userId, Long notificationId); + void markMultipleNotificationsAsRead(UUID userId, NotificationIdsRequestDto notificationIds); } diff --git a/src/main/java/com/somemore/domains/notification/usecase/NotificationQueryUseCase.java b/src/main/java/com/somemore/domains/notification/usecase/NotificationQueryUseCase.java index f6ee649b5..186bf9b41 100644 --- a/src/main/java/com/somemore/domains/notification/usecase/NotificationQueryUseCase.java +++ b/src/main/java/com/somemore/domains/notification/usecase/NotificationQueryUseCase.java @@ -8,5 +8,6 @@ public interface NotificationQueryUseCase { List getUnreadNotifications(UUID userId); + List getReadNotifications(UUID userId); } diff --git a/src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardQueryApiController.java b/src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardQueryApiController.java index d39ff1d84..cc6dd4cd1 100644 --- a/src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardQueryApiController.java +++ b/src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardQueryApiController.java @@ -16,7 +16,11 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.UUID; diff --git a/src/main/java/com/somemore/domains/recruitboard/dto/condition/RecruitBoardNearByCondition.java b/src/main/java/com/somemore/domains/recruitboard/dto/condition/RecruitBoardNearByCondition.java index c16ea4298..84a0504dd 100644 --- a/src/main/java/com/somemore/domains/recruitboard/dto/condition/RecruitBoardNearByCondition.java +++ b/src/main/java/com/somemore/domains/recruitboard/dto/condition/RecruitBoardNearByCondition.java @@ -6,12 +6,12 @@ @Builder public record RecruitBoardNearByCondition( - Double latitude, - Double longitude, - Double radius, - String keyword, - RecruitStatus status, - Pageable pageable + Double latitude, + Double longitude, + Double radius, + String keyword, + RecruitStatus status, + Pageable pageable ) { } diff --git a/src/main/java/com/somemore/domains/recruitboard/dto/condition/RecruitBoardSearchCondition.java b/src/main/java/com/somemore/domains/recruitboard/dto/condition/RecruitBoardSearchCondition.java index 94b04c9ff..22325df44 100644 --- a/src/main/java/com/somemore/domains/recruitboard/dto/condition/RecruitBoardSearchCondition.java +++ b/src/main/java/com/somemore/domains/recruitboard/dto/condition/RecruitBoardSearchCondition.java @@ -7,12 +7,12 @@ @Builder public record RecruitBoardSearchCondition( - String keyword, - VolunteerCategory category, - String region, - Boolean admitted, - RecruitStatus status, - Pageable pageable + String keyword, + VolunteerCategory category, + String region, + Boolean admitted, + RecruitStatus status, + Pageable pageable ) { } diff --git a/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardLocationUpdateRequestDto.java b/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardLocationUpdateRequestDto.java index 153cb2e7b..d0618b2f8 100644 --- a/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardLocationUpdateRequestDto.java +++ b/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardLocationUpdateRequestDto.java @@ -8,35 +8,36 @@ import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -import java.math.BigDecimal; import lombok.Builder; +import java.math.BigDecimal; + @JsonNaming(SnakeCaseStrategy.class) @Builder public record RecruitBoardLocationUpdateRequestDto( - @Schema(description = "지역", example = "서울특별시") - @NotBlank(message = "지역은 필수 입력 값입니다.") - String region, - @Schema(description = "도로명 주소", example = "서울특별시 서초구 반포대로 45, 4층(서초동, 명정빌딩)") - @NotBlank(message = "주소는 필수 입력 값입니다.") - String address, - @Schema(description = "주소에 해당하는 위도 정보", example = "37.4845373748015") - @NotNull(message = "위도는 필수 입력 값입니다.") - @DecimalMin(value = "33", message = "위도는 33도 이상이어야 합니다.") - @DecimalMax(value = "39", message = "위도는 38도 이하이어야 합니다.") - BigDecimal latitude, - @Schema(description = "주소에 해당하는 경도 정보", example = "127.010842267696") - @NotNull(message = "경도는 필수 입력 값입니다.") - @DecimalMin(value = "124", message = "경도는 124도 이상이어야 합니다.") - @DecimalMax(value = "132", message = "경도는 132도 이하이어야 합니다.") - BigDecimal longitude + @Schema(description = "지역", example = "서울특별시") + @NotBlank(message = "지역은 필수 입력 값입니다.") + String region, + @Schema(description = "도로명 주소", example = "서울특별시 서초구 반포대로 45, 4층(서초동, 명정빌딩)") + @NotBlank(message = "주소는 필수 입력 값입니다.") + String address, + @Schema(description = "주소에 해당하는 위도 정보", example = "37.4845373748015") + @NotNull(message = "위도는 필수 입력 값입니다.") + @DecimalMin(value = "33", message = "위도는 33도 이상이어야 합니다.") + @DecimalMax(value = "39", message = "위도는 38도 이하이어야 합니다.") + BigDecimal latitude, + @Schema(description = "주소에 해당하는 경도 정보", example = "127.010842267696") + @NotNull(message = "경도는 필수 입력 값입니다.") + @DecimalMin(value = "124", message = "경도는 124도 이상이어야 합니다.") + @DecimalMax(value = "132", message = "경도는 132도 이하이어야 합니다.") + BigDecimal longitude ) { public LocationUpdateRequestDto toLocationUpdateRequestDto() { return LocationUpdateRequestDto.builder() - .address(address) - .latitude(latitude) - .longitude(longitude) - .build(); + .address(address) + .latitude(latitude) + .longitude(longitude) + .build(); } } diff --git a/src/main/java/com/somemore/domains/recruitboard/repository/mapper/RecruitBoardDetail.java b/src/main/java/com/somemore/domains/recruitboard/repository/mapper/RecruitBoardDetail.java index 452ba00d9..2afb71179 100644 --- a/src/main/java/com/somemore/domains/recruitboard/repository/mapper/RecruitBoardDetail.java +++ b/src/main/java/com/somemore/domains/recruitboard/repository/mapper/RecruitBoardDetail.java @@ -1,14 +1,15 @@ package com.somemore.domains.recruitboard.repository.mapper; import com.somemore.domains.recruitboard.domain.RecruitBoard; + import java.math.BigDecimal; public record RecruitBoardDetail( - RecruitBoard recruitBoard, - String address, - BigDecimal latitude, - BigDecimal longitude, - String centerName + RecruitBoard recruitBoard, + String address, + BigDecimal latitude, + BigDecimal longitude, + String centerName ) { } diff --git a/src/main/java/com/somemore/domains/recruitboard/repository/mapper/RecruitBoardWithCenter.java b/src/main/java/com/somemore/domains/recruitboard/repository/mapper/RecruitBoardWithCenter.java index d7e82e585..0462b5fa7 100644 --- a/src/main/java/com/somemore/domains/recruitboard/repository/mapper/RecruitBoardWithCenter.java +++ b/src/main/java/com/somemore/domains/recruitboard/repository/mapper/RecruitBoardWithCenter.java @@ -3,8 +3,8 @@ import com.somemore.domains.recruitboard.domain.RecruitBoard; public record RecruitBoardWithCenter( - RecruitBoard recruitBoard, - String centerName + RecruitBoard recruitBoard, + String centerName ) { } diff --git a/src/main/java/com/somemore/domains/recruitboard/repository/mapper/RecruitBoardWithLocation.java b/src/main/java/com/somemore/domains/recruitboard/repository/mapper/RecruitBoardWithLocation.java index c96907c46..9d8651e2e 100644 --- a/src/main/java/com/somemore/domains/recruitboard/repository/mapper/RecruitBoardWithLocation.java +++ b/src/main/java/com/somemore/domains/recruitboard/repository/mapper/RecruitBoardWithLocation.java @@ -1,13 +1,14 @@ package com.somemore.domains.recruitboard.repository.mapper; import com.somemore.domains.recruitboard.domain.RecruitBoard; + import java.math.BigDecimal; public record RecruitBoardWithLocation( - RecruitBoard recruitBoard, - String address, - BigDecimal latitude, - BigDecimal longitude + RecruitBoard recruitBoard, + String address, + BigDecimal latitude, + BigDecimal longitude ) { } diff --git a/src/main/java/com/somemore/domains/review/controller/ReviewCommandApiController.java b/src/main/java/com/somemore/domains/review/controller/ReviewCommandApiController.java index c8571f087..bd2f974b2 100644 --- a/src/main/java/com/somemore/domains/review/controller/ReviewCommandApiController.java +++ b/src/main/java/com/somemore/domains/review/controller/ReviewCommandApiController.java @@ -14,7 +14,14 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.security.access.annotation.Secured; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.util.UUID; diff --git a/src/main/java/com/somemore/domains/review/controller/ReviewQueryApiController.java b/src/main/java/com/somemore/domains/review/controller/ReviewQueryApiController.java index 5b35003b6..bd0ce88ba 100644 --- a/src/main/java/com/somemore/domains/review/controller/ReviewQueryApiController.java +++ b/src/main/java/com/somemore/domains/review/controller/ReviewQueryApiController.java @@ -1,16 +1,13 @@ package com.somemore.domains.review.controller; -import static org.springframework.data.domain.Sort.Direction.DESC; - import com.somemore.domains.recruitboard.domain.VolunteerCategory; -import com.somemore.global.common.response.ApiResponse; import com.somemore.domains.review.dto.condition.ReviewSearchCondition; import com.somemore.domains.review.dto.response.ReviewDetailResponseDto; import com.somemore.domains.review.dto.response.ReviewDetailWithNicknameResponseDto; import com.somemore.domains.review.usecase.ReviewQueryUseCase; +import com.somemore.global.common.response.ApiResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -21,6 +18,10 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.UUID; + +import static org.springframework.data.domain.Sort.Direction.DESC; + @Tag(name = "Review Query API", description = "리뷰 조회 API") @RequiredArgsConstructor @RequestMapping("/api") diff --git a/src/main/java/com/somemore/domains/review/domain/Review.java b/src/main/java/com/somemore/domains/review/domain/Review.java index 80cb5d89a..0e3bbb39b 100644 --- a/src/main/java/com/somemore/domains/review/domain/Review.java +++ b/src/main/java/com/somemore/domains/review/domain/Review.java @@ -1,8 +1,5 @@ package com.somemore.domains.review.domain; -import static jakarta.persistence.GenerationType.IDENTITY; -import static lombok.AccessLevel.PROTECTED; - import com.somemore.domains.review.dto.request.ReviewUpdateRequestDto; import com.somemore.global.common.entity.BaseEntity; import jakarta.persistence.Column; @@ -11,11 +8,15 @@ import jakarta.persistence.Id; import jakarta.persistence.Lob; import jakarta.persistence.Table; -import java.util.UUID; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.UUID; + +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + @Getter @NoArgsConstructor(access = PROTECTED) @Entity @@ -44,7 +45,7 @@ public class Review extends BaseEntity { @Builder public Review(Long volunteerApplyId, UUID volunteerId, String title, - String content, String imgUrl) { + String content, String imgUrl) { this.volunteerApplyId = volunteerApplyId; this.volunteerId = volunteerId; this.title = title; diff --git a/src/main/java/com/somemore/domains/review/dto/response/ReviewDetailResponseDto.java b/src/main/java/com/somemore/domains/review/dto/response/ReviewDetailResponseDto.java index a94b6bc7e..8ed2903ad 100644 --- a/src/main/java/com/somemore/domains/review/dto/response/ReviewDetailResponseDto.java +++ b/src/main/java/com/somemore/domains/review/dto/response/ReviewDetailResponseDto.java @@ -4,9 +4,10 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.somemore.domains.review.domain.Review; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; + import java.time.LocalDateTime; import java.util.UUID; -import lombok.Builder; @Builder @JsonNaming(SnakeCaseStrategy.class) diff --git a/src/main/java/com/somemore/domains/review/dto/response/ReviewDetailWithNicknameResponseDto.java b/src/main/java/com/somemore/domains/review/dto/response/ReviewDetailWithNicknameResponseDto.java index 155eb4194..cb759d83c 100644 --- a/src/main/java/com/somemore/domains/review/dto/response/ReviewDetailWithNicknameResponseDto.java +++ b/src/main/java/com/somemore/domains/review/dto/response/ReviewDetailWithNicknameResponseDto.java @@ -4,9 +4,10 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.somemore.domains.review.domain.Review; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; + import java.time.LocalDateTime; import java.util.UUID; -import lombok.Builder; @Builder @JsonNaming(SnakeCaseStrategy.class) diff --git a/src/main/java/com/somemore/domains/review/repository/ReviewJpaRepository.java b/src/main/java/com/somemore/domains/review/repository/ReviewJpaRepository.java index bc61db0c3..f778cb7a3 100644 --- a/src/main/java/com/somemore/domains/review/repository/ReviewJpaRepository.java +++ b/src/main/java/com/somemore/domains/review/repository/ReviewJpaRepository.java @@ -1,10 +1,11 @@ package com.somemore.domains.review.repository; import com.somemore.domains.review.domain.Review; -import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import java.util.Optional; + public interface ReviewJpaRepository extends JpaRepository { Optional findByIdAndDeletedFalse(Long id); diff --git a/src/main/java/com/somemore/domains/review/repository/ReviewRepository.java b/src/main/java/com/somemore/domains/review/repository/ReviewRepository.java index 8b0d10c1a..8af7fec6d 100644 --- a/src/main/java/com/somemore/domains/review/repository/ReviewRepository.java +++ b/src/main/java/com/somemore/domains/review/repository/ReviewRepository.java @@ -2,10 +2,11 @@ import com.somemore.domains.review.domain.Review; import com.somemore.domains.review.dto.condition.ReviewSearchCondition; +import org.springframework.data.domain.Page; + import java.util.List; import java.util.Optional; import java.util.UUID; -import org.springframework.data.domain.Page; public interface ReviewRepository { diff --git a/src/main/java/com/somemore/domains/review/repository/ReviewRepositoryImpl.java b/src/main/java/com/somemore/domains/review/repository/ReviewRepositoryImpl.java index eab2d2a89..75ff3d64e 100644 --- a/src/main/java/com/somemore/domains/review/repository/ReviewRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/review/repository/ReviewRepositoryImpl.java @@ -11,15 +11,16 @@ import com.somemore.domains.review.dto.condition.ReviewSearchCondition; import com.somemore.domains.volunteerapply.domain.QVolunteerApply; import jakarta.validation.constraints.NotNull; -import java.util.List; -import java.util.Optional; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; import org.springframework.data.support.PageableExecutionUtils; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + @RequiredArgsConstructor @Repository public class ReviewRepositoryImpl implements ReviewRepository { @@ -53,7 +54,7 @@ public boolean existsByVolunteerApplyId(Long volunteerApplyId) { @Override public Page findAllByVolunteerIdAndSearch(UUID volunteerId, - ReviewSearchCondition condition) { + ReviewSearchCondition condition) { BooleanExpression exp = volunteerIdEq(volunteerId) .and(volunteerCategoryEq(condition.category())) diff --git a/src/main/java/com/somemore/domains/review/service/CreateReviewService.java b/src/main/java/com/somemore/domains/review/service/CreateReviewService.java index 5f8ae85ed..1fd846fd9 100644 --- a/src/main/java/com/somemore/domains/review/service/CreateReviewService.java +++ b/src/main/java/com/somemore/domains/review/service/CreateReviewService.java @@ -1,23 +1,23 @@ package com.somemore.domains.review.service; -import static com.somemore.global.exception.ExceptionMessage.REVIEW_ALREADY_EXISTS; -import static com.somemore.global.exception.ExceptionMessage.REVIEW_RESTRICTED_TO_ATTENDED; - +import com.somemore.domains.review.domain.Review; +import com.somemore.domains.review.dto.request.ReviewCreateRequestDto; import com.somemore.domains.review.repository.ReviewRepository; +import com.somemore.domains.review.usecase.CreateReviewUseCase; import com.somemore.domains.review.usecase.ReviewQueryUseCase; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase; import com.somemore.global.exception.BadRequestException; -import com.somemore.domains.review.domain.Review; -import com.somemore.domains.review.dto.request.ReviewCreateRequestDto; -import com.somemore.domains.review.usecase.CreateReviewUseCase; - import com.somemore.global.exception.DuplicateException; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.UUID; + +import static com.somemore.global.exception.ExceptionMessage.REVIEW_ALREADY_EXISTS; +import static com.somemore.global.exception.ExceptionMessage.REVIEW_RESTRICTED_TO_ATTENDED; + @RequiredArgsConstructor @Transactional @Service diff --git a/src/main/java/com/somemore/domains/review/usecase/CreateReviewUseCase.java b/src/main/java/com/somemore/domains/review/usecase/CreateReviewUseCase.java index dfac7b11c..89c7f3401 100644 --- a/src/main/java/com/somemore/domains/review/usecase/CreateReviewUseCase.java +++ b/src/main/java/com/somemore/domains/review/usecase/CreateReviewUseCase.java @@ -1,6 +1,7 @@ package com.somemore.domains.review.usecase; import com.somemore.domains.review.dto.request.ReviewCreateRequestDto; + import java.util.UUID; public interface CreateReviewUseCase { diff --git a/src/main/java/com/somemore/domains/volunteer/controller/VolunteerProfileCommandController.java b/src/main/java/com/somemore/domains/volunteer/controller/VolunteerProfileCommandController.java index c61c42397..3cde64980 100644 --- a/src/main/java/com/somemore/domains/volunteer/controller/VolunteerProfileCommandController.java +++ b/src/main/java/com/somemore/domains/volunteer/controller/VolunteerProfileCommandController.java @@ -1,17 +1,14 @@ package com.somemore.domains.volunteer.controller; -import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; - +import com.somemore.domains.volunteer.dto.request.VolunteerProfileUpdateRequestDto; import com.somemore.domains.volunteer.usecase.UpdateVolunteerProfileUseCase; import com.somemore.global.auth.annotation.CurrentUser; import com.somemore.global.common.response.ApiResponse; import com.somemore.global.imageupload.dto.ImageUploadRequestDto; import com.somemore.global.imageupload.usecase.ImageUploadUseCase; -import com.somemore.domains.volunteer.dto.request.VolunteerProfileUpdateRequestDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; -import java.util.UUID; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.annotation.Secured; @@ -21,6 +18,10 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import java.util.UUID; + +import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; + @RestController @Slf4j @RequiredArgsConstructor diff --git a/src/main/java/com/somemore/domains/volunteer/controller/VolunteerProfileQueryController.java b/src/main/java/com/somemore/domains/volunteer/controller/VolunteerProfileQueryController.java index 1b564ef65..1fdad7ed5 100644 --- a/src/main/java/com/somemore/domains/volunteer/controller/VolunteerProfileQueryController.java +++ b/src/main/java/com/somemore/domains/volunteer/controller/VolunteerProfileQueryController.java @@ -6,7 +6,6 @@ import com.somemore.global.common.response.ApiResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import java.util.UUID; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.annotation.Secured; @@ -15,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.UUID; + @RestController @Slf4j @RequiredArgsConstructor diff --git a/src/main/java/com/somemore/domains/volunteer/controller/VolunteerSignController.java b/src/main/java/com/somemore/domains/volunteer/controller/VolunteerSignController.java deleted file mode 100644 index 0373acc2b..000000000 --- a/src/main/java/com/somemore/domains/volunteer/controller/VolunteerSignController.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.somemore.domains.volunteer.controller; - -import com.somemore.domains.volunteer.usecase.GenerateOAuthUrlUseCase; -import com.somemore.global.auth.signout.usecase.SignOutUseCase; -import com.somemore.global.common.response.ApiResponse; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.view.RedirectView; - -@RestController -@Slf4j -@RequiredArgsConstructor -@RequestMapping("/api/volunteer") -@Tag(name = "Volunteer Sign API", description = "봉사자 로그인, 로그아웃") -public class VolunteerSignController { - - private final GenerateOAuthUrlUseCase generateOAuthUrlUseCase; - private final SignOutUseCase signOutUseCase; - - @PostMapping("/sign-in/oauth/{oauthProvider}") - public RedirectView signIn( - @Parameter(name = "oauthProvider", description = "OAuth 제공자 선택", example = "naver", required = true, schema = @Schema(allowableValues = {"naver"})) - @PathVariable("oauthProvider") String oauthProvider) { - - String redirectUrl = generateOAuthUrlUseCase.generateUrl(oauthProvider); - - return new RedirectView(redirectUrl); - } - - @PostMapping("/sign-out") - public ApiResponse signOut( - HttpServletResponse response, - @AuthenticationPrincipal String userId) { - - signOutUseCase.signOut(response, userId); - - return ApiResponse.ok("로그아웃되었습니다"); - } -} diff --git a/src/main/java/com/somemore/domains/volunteer/domain/Gender.java b/src/main/java/com/somemore/domains/volunteer/domain/Gender.java index 8b7f81b66..de8889065 100644 --- a/src/main/java/com/somemore/domains/volunteer/domain/Gender.java +++ b/src/main/java/com/somemore/domains/volunteer/domain/Gender.java @@ -14,6 +14,10 @@ public enum Gender { this.code = code; } + public static Gender getDefault() { + return UNDEFINED; + } + public static Gender from(String code) { for (Gender gender : Gender.values()) { if (gender.code.equalsIgnoreCase(code)) { diff --git a/src/main/java/com/somemore/domains/volunteer/domain/Tier.java b/src/main/java/com/somemore/domains/volunteer/domain/Tier.java index 6af0204d0..0e3c5ce78 100644 --- a/src/main/java/com/somemore/domains/volunteer/domain/Tier.java +++ b/src/main/java/com/somemore/domains/volunteer/domain/Tier.java @@ -11,5 +11,9 @@ public enum Tier { BLUE, INDIGO, VIOLET, - RAINBOW + RAINBOW; + + public static Tier getDefault() { + return RED; + } } diff --git a/src/main/java/com/somemore/domains/volunteer/domain/Volunteer.java b/src/main/java/com/somemore/domains/volunteer/domain/Volunteer.java index dea62c453..52bc55497 100644 --- a/src/main/java/com/somemore/domains/volunteer/domain/Volunteer.java +++ b/src/main/java/com/somemore/domains/volunteer/domain/Volunteer.java @@ -1,17 +1,28 @@ package com.somemore.domains.volunteer.domain; +import com.somemore.domains.volunteer.dto.request.VolunteerProfileUpdateRequestDto; import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.global.common.entity.BaseEntity; -import com.somemore.domains.volunteer.dto.request.VolunteerProfileUpdateRequestDto; -import jakarta.persistence.*; -import lombok.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; import java.util.UUID; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "volunteer") +@Table(name = "volunteer_old") // TODO 삭제될 엔티티(테이블) public class Volunteer extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.UUID) diff --git a/src/main/java/com/somemore/domains/volunteer/domain/VolunteerDetail.java b/src/main/java/com/somemore/domains/volunteer/domain/VolunteerDetail.java index d85dae750..fcd1f22f0 100644 --- a/src/main/java/com/somemore/domains/volunteer/domain/VolunteerDetail.java +++ b/src/main/java/com/somemore/domains/volunteer/domain/VolunteerDetail.java @@ -1,8 +1,15 @@ package com.somemore.domains.volunteer.domain; -import com.somemore.global.common.entity.BaseEntity; import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto; -import jakarta.persistence.*; +import com.somemore.global.common.entity.BaseEntity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -13,7 +20,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "volunteer_detail") +@Table(name = "volunteer_detail_old") // TODO 삭제될 엔티티(테이블) public class VolunteerDetail extends BaseEntity { @Id diff --git a/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerRankingResponseDto.java b/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerRankingResponseDto.java index 56bd31741..6bff12738 100644 --- a/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerRankingResponseDto.java +++ b/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerRankingResponseDto.java @@ -50,8 +50,8 @@ private static VolunteerOverview from(VolunteerOverviewForRankingByHours source) public static VolunteerRankingResponseDto from(List sources) { return VolunteerRankingResponseDto.builder() .rankings(sources.stream() - .map(VolunteerOverview::from) - .toList()) + .map(VolunteerOverview::from) + .toList()) .build(); } } diff --git a/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerSimpleInfoResponseDto.java b/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerSimpleInfoResponseDto.java index fe1340067..07b12ca14 100644 --- a/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerSimpleInfoResponseDto.java +++ b/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerSimpleInfoResponseDto.java @@ -4,9 +4,10 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import io.swagger.v3.oas.annotations.media.Schema; -import java.util.UUID; import lombok.Builder; +import java.util.UUID; + @Schema(description = "봉사자 간단 정보 응답 DTO") @JsonNaming(SnakeCaseStrategy.class) @Builder diff --git a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerDetailRepository.java b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerDetailRepository.java index 2d795f43d..736ed76a6 100644 --- a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerDetailRepository.java +++ b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerDetailRepository.java @@ -9,5 +9,6 @@ @Repository public interface VolunteerDetailRepository { VolunteerDetail save(VolunteerDetail volunteerDetail); + Optional findByVolunteerId(UUID volunteerId); } diff --git a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerJpaRepository.java b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerJpaRepository.java index 621a9b503..d35bc9c08 100644 --- a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerJpaRepository.java +++ b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerJpaRepository.java @@ -1,13 +1,16 @@ package com.somemore.domains.volunteer.repository; import com.somemore.domains.volunteer.domain.Volunteer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; import java.util.List; import java.util.UUID; -import org.springframework.data.jpa.repository.JpaRepository; +@Repository("oldVolunteerJpaRepository") public interface VolunteerJpaRepository extends JpaRepository { List findAllByIdInAndDeletedFalse(List ids); + boolean existsByIdAndDeletedIsFalse(UUID id); } diff --git a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepository.java b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepository.java index ee6ac42a8..35b7e24b4 100644 --- a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepository.java +++ b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepository.java @@ -7,9 +7,7 @@ import java.util.List; import java.util.Optional; import java.util.UUID; -import org.springframework.stereotype.Repository; -@Repository public interface VolunteerRepository { Volunteer save(Volunteer volunteer); @@ -30,5 +28,7 @@ public interface VolunteerRepository { boolean existsByVolunteerId(UUID volunteerId); - default boolean doesNotExistsByVolunteerId(UUID volunteerId) { return !existsByVolunteerId(volunteerId); } + default boolean doesNotExistsByVolunteerId(UUID volunteerId) { + return !existsByVolunteerId(volunteerId); + } } diff --git a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java index a7a301f06..bf32f15c8 100644 --- a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java @@ -9,15 +9,15 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours; import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; import java.util.List; import java.util.Optional; import java.util.UUID; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Repository; @RequiredArgsConstructor -@Repository +@Repository("oldVolunteerRepository") public class VolunteerRepositoryImpl implements VolunteerRepository { private final VolunteerJpaRepository volunteerJpaRepository; diff --git a/src/main/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlService.java b/src/main/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlService.java deleted file mode 100644 index ffb0dd755..000000000 --- a/src/main/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlService.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.somemore.domains.volunteer.service; - -import com.somemore.domains.volunteer.usecase.GenerateOAuthUrlUseCase; -import com.somemore.global.auth.oauth.domain.OAuthProvider; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.springframework.web.util.UriComponentsBuilder; - -@Slf4j -@Service -@RequiredArgsConstructor -public class GenerateOAuthUrlService implements GenerateOAuthUrlUseCase { - - @Value("${app.back-url}") - private String backendRootUrl; - - @Override - public String generateUrl(String oAuthProvider) { - return UriComponentsBuilder.fromHttpUrl(generateBaseUrl()) - .pathSegment(OAuthProvider.from(oAuthProvider).getProviderName()) - .build() - .toUriString(); - } - - private String generateBaseUrl() { - return UriComponentsBuilder.fromHttpUrl(backendRootUrl) - .path("/oauth2/authorization") - .build() - .toUriString(); - } -} diff --git a/src/main/java/com/somemore/domains/volunteer/service/RegisterVolunteerService.java b/src/main/java/com/somemore/domains/volunteer/service/RegisterVolunteerService.java index fe0948a53..587a6d33d 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/RegisterVolunteerService.java +++ b/src/main/java/com/somemore/domains/volunteer/service/RegisterVolunteerService.java @@ -2,10 +2,10 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.domain.VolunteerDetail; -import com.somemore.domains.volunteer.usecase.RegisterVolunteerUseCase; import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto; import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; import com.somemore.domains.volunteer.repository.VolunteerRepository; +import com.somemore.domains.volunteer.usecase.RegisterVolunteerUseCase; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockService.java b/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockService.java index 33d130b4e..fd19a3434 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockService.java +++ b/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockService.java @@ -1,20 +1,20 @@ package com.somemore.domains.volunteer.service; -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER; - import com.somemore.domains.volunteer.domain.Volunteer; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.domains.volunteer.usecase.UpdateVolunteerUseCase; import com.somemore.global.exception.BadRequestException; -import com.somemore.domains.volunteer.repository.VolunteerRepository; - -import java.util.UUID; -import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.redisson.api.RLock; import org.redisson.api.RedissonClient; import org.springframework.stereotype.Service; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER; + @Slf4j @RequiredArgsConstructor @Service diff --git a/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileService.java b/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileService.java index c9ca42897..eede06c32 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileService.java +++ b/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileService.java @@ -1,10 +1,10 @@ package com.somemore.domains.volunteer.service; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.global.exception.BadRequestException; import com.somemore.domains.volunteer.dto.request.VolunteerProfileUpdateRequestDto; import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.domains.volunteer.usecase.UpdateVolunteerProfileUseCase; +import com.somemore.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/somemore/domains/volunteer/service/VolunteerQueryService.java b/src/main/java/com/somemore/domains/volunteer/service/VolunteerQueryService.java index 7ece3691e..36ef44f17 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/VolunteerQueryService.java +++ b/src/main/java/com/somemore/domains/volunteer/service/VolunteerQueryService.java @@ -1,25 +1,26 @@ package com.somemore.domains.volunteer.service; -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER; - import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.domain.VolunteerDetail; -import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; -import com.somemore.global.exception.BadRequestException; import com.somemore.domains.volunteer.dto.response.VolunteerProfileResponseDto; import com.somemore.domains.volunteer.dto.response.VolunteerRankingResponseDto; import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours; import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; +import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; import com.somemore.domains.volunteer.validator.VolunteerDetailAccessValidator; -import java.util.List; -import java.util.UUID; +import com.somemore.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.UUID; + +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER; + @Slf4j @Service @RequiredArgsConstructor @@ -49,7 +50,7 @@ public VolunteerProfileResponseDto getVolunteerProfile(UUID volunteerId) { @Override public VolunteerProfileResponseDto getVolunteerDetailedProfile(UUID volunteerId, - UUID centerId) { + UUID centerId) { volunteerDetailAccessValidator.validateByCenterId(centerId, volunteerId); return VolunteerProfileResponseDto.from( diff --git a/src/main/java/com/somemore/domains/volunteer/usecase/GenerateOAuthUrlUseCase.java b/src/main/java/com/somemore/domains/volunteer/usecase/GenerateOAuthUrlUseCase.java deleted file mode 100644 index a9b3db0f1..000000000 --- a/src/main/java/com/somemore/domains/volunteer/usecase/GenerateOAuthUrlUseCase.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.somemore.domains.volunteer.usecase; - -public interface GenerateOAuthUrlUseCase { - String generateUrl(String oAuthProvider); -} diff --git a/src/main/java/com/somemore/domains/volunteer/usecase/RegisterVolunteerUseCase.java b/src/main/java/com/somemore/domains/volunteer/usecase/RegisterVolunteerUseCase.java index 75d0028eb..3cf9236e1 100644 --- a/src/main/java/com/somemore/domains/volunteer/usecase/RegisterVolunteerUseCase.java +++ b/src/main/java/com/somemore/domains/volunteer/usecase/RegisterVolunteerUseCase.java @@ -3,5 +3,5 @@ import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto; public interface RegisterVolunteerUseCase { - void registerVolunteer(VolunteerRegisterRequestDto dto); + void registerVolunteer(VolunteerRegisterRequestDto userId); } diff --git a/src/main/java/com/somemore/domains/volunteer/usecase/VolunteerQueryUseCase.java b/src/main/java/com/somemore/domains/volunteer/usecase/VolunteerQueryUseCase.java index b1f165c31..d23ad6ffb 100644 --- a/src/main/java/com/somemore/domains/volunteer/usecase/VolunteerQueryUseCase.java +++ b/src/main/java/com/somemore/domains/volunteer/usecase/VolunteerQueryUseCase.java @@ -4,6 +4,7 @@ import com.somemore.domains.volunteer.dto.response.VolunteerProfileResponseDto; import com.somemore.domains.volunteer.dto.response.VolunteerRankingResponseDto; import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; + import java.util.List; import java.util.UUID; diff --git a/src/main/java/com/somemore/domains/volunteerapply/controller/CenterVolunteerApplyCommandApiController.java b/src/main/java/com/somemore/domains/volunteerapply/controller/CenterVolunteerApplyCommandApiController.java index 3eb4d8033..1f3e97441 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/controller/CenterVolunteerApplyCommandApiController.java +++ b/src/main/java/com/somemore/domains/volunteerapply/controller/CenterVolunteerApplyCommandApiController.java @@ -9,7 +9,6 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.security.access.annotation.Secured; import org.springframework.web.bind.annotation.PatchMapping; @@ -19,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.UUID; + @Tag(name = "Center Volunteer Apply Command API", description = "봉사 활동 지원 승인, 거절, 정산 API") @RequiredArgsConstructor @RequestMapping("/api") diff --git a/src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyCommandApiController.java b/src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyCommandApiController.java index 0a651bea1..a98ada482 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyCommandApiController.java +++ b/src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyCommandApiController.java @@ -8,7 +8,6 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.security.access.annotation.Secured; import org.springframework.web.bind.annotation.DeleteMapping; @@ -18,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.UUID; + @Tag(name = "Volunteer Apply Command API", description = "봉사 활동 지원, 철회 관련 API") @RequiredArgsConstructor @RequestMapping("/api") diff --git a/src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiController.java b/src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiController.java index 506d941a2..80df236dd 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiController.java +++ b/src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiController.java @@ -18,7 +18,11 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.security.access.annotation.Secured; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.UUID; diff --git a/src/main/java/com/somemore/domains/volunteerapply/domain/VolunteerApply.java b/src/main/java/com/somemore/domains/volunteerapply/domain/VolunteerApply.java index 10bc29c1b..324705a6c 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/domain/VolunteerApply.java +++ b/src/main/java/com/somemore/domains/volunteerapply/domain/VolunteerApply.java @@ -9,12 +9,13 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; -import java.util.UUID; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.UUID; + @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @@ -40,7 +41,7 @@ public class VolunteerApply extends BaseEntity { @Builder public VolunteerApply(UUID volunteerId, Long recruitBoardId, ApplyStatus status, - Boolean attended) { + Boolean attended) { this.volunteerId = volunteerId; this.recruitBoardId = recruitBoardId; this.status = status; diff --git a/src/main/java/com/somemore/domains/volunteerapply/dto/request/VolunteerApplyCreateRequestDto.java b/src/main/java/com/somemore/domains/volunteerapply/dto/request/VolunteerApplyCreateRequestDto.java index b2f04d1ee..71a2d71a6 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/dto/request/VolunteerApplyCreateRequestDto.java +++ b/src/main/java/com/somemore/domains/volunteerapply/dto/request/VolunteerApplyCreateRequestDto.java @@ -1,15 +1,16 @@ package com.somemore.domains.volunteerapply.dto.request; -import static com.somemore.domains.volunteerapply.domain.ApplyStatus.WAITING; - import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; -import java.util.UUID; import lombok.Builder; +import java.util.UUID; + +import static com.somemore.domains.volunteerapply.domain.ApplyStatus.WAITING; + @JsonNaming(SnakeCaseStrategy.class) @Builder public record VolunteerApplyCreateRequestDto( diff --git a/src/main/java/com/somemore/domains/volunteerapply/dto/request/VolunteerApplySettleRequestDto.java b/src/main/java/com/somemore/domains/volunteerapply/dto/request/VolunteerApplySettleRequestDto.java index 65388b5f4..af59c7b3f 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/dto/request/VolunteerApplySettleRequestDto.java +++ b/src/main/java/com/somemore/domains/volunteerapply/dto/request/VolunteerApplySettleRequestDto.java @@ -4,9 +4,10 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; -import java.util.List; import lombok.Builder; +import java.util.List; + @JsonNaming(SnakeCaseStrategy.class) @Builder public record VolunteerApplySettleRequestDto( diff --git a/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyRecruitInfoResponseDto.java b/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyRecruitInfoResponseDto.java index 1d02e646c..72353bfcb 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyRecruitInfoResponseDto.java +++ b/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyRecruitInfoResponseDto.java @@ -7,9 +7,10 @@ import com.somemore.domains.volunteerapply.domain.ApplyStatus; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; + import java.time.LocalDateTime; import java.util.UUID; -import lombok.Builder; @JsonNaming(SnakeCaseStrategy.class) @Builder @@ -32,7 +33,7 @@ public record VolunteerApplyRecruitInfoResponseDto( ) { public static VolunteerApplyRecruitInfoResponseDto of(VolunteerApply apply, - RecruitBoard board) { + RecruitBoard board) { RecruitBoardOverViewResponseDto recruitBoard = RecruitBoardOverViewResponseDto.from(board); return VolunteerApplyRecruitInfoResponseDto.builder() .id(apply.getId()) diff --git a/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplySummaryResponseDto.java b/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplySummaryResponseDto.java index c52d26425..d9a8969d3 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplySummaryResponseDto.java +++ b/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplySummaryResponseDto.java @@ -1,18 +1,19 @@ package com.somemore.domains.volunteerapply.dto.response; -import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED; -import static com.somemore.domains.volunteerapply.domain.ApplyStatus.REJECTED; -import static com.somemore.domains.volunteerapply.domain.ApplyStatus.WAITING; - import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.somemore.domains.volunteerapply.domain.ApplyStatus; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; + import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import lombok.Builder; + +import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED; +import static com.somemore.domains.volunteerapply.domain.ApplyStatus.REJECTED; +import static com.somemore.domains.volunteerapply.domain.ApplyStatus.WAITING; @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) @Builder diff --git a/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyVolunteerInfoResponseDto.java b/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyVolunteerInfoResponseDto.java index bd7809c43..7275b70cd 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyVolunteerInfoResponseDto.java +++ b/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyVolunteerInfoResponseDto.java @@ -7,9 +7,10 @@ import com.somemore.domains.volunteerapply.domain.ApplyStatus; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import io.swagger.v3.oas.annotations.media.Schema; -import java.time.LocalDateTime; import lombok.Builder; +import java.time.LocalDateTime; + @Schema(description = "봉사 지원자 상세 정보 응답 DTO") @JsonNaming(SnakeCaseStrategy.class) @Builder diff --git a/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyWithReviewStatusResponseDto.java b/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyWithReviewStatusResponseDto.java index fe77034b7..381869b49 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyWithReviewStatusResponseDto.java +++ b/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyWithReviewStatusResponseDto.java @@ -5,9 +5,10 @@ import com.somemore.domains.volunteerapply.domain.ApplyStatus; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; + import java.time.LocalDateTime; import java.util.UUID; -import lombok.Builder; @JsonNaming(SnakeCaseStrategy.class) @Builder diff --git a/src/main/java/com/somemore/domains/volunteerapply/event/VolunteerApplyStatusChangeEvent.java b/src/main/java/com/somemore/domains/volunteerapply/event/VolunteerApplyStatusChangeEvent.java index b166abc76..4c240bac8 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/event/VolunteerApplyStatusChangeEvent.java +++ b/src/main/java/com/somemore/domains/volunteerapply/event/VolunteerApplyStatusChangeEvent.java @@ -4,10 +4,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.somemore.domains.notification.domain.NotificationSubType; import com.somemore.domains.recruitboard.domain.RecruitBoard; -import com.somemore.global.common.event.ServerEvent; -import com.somemore.global.common.event.ServerEventType; import com.somemore.domains.volunteerapply.domain.ApplyStatus; import com.somemore.domains.volunteerapply.domain.VolunteerApply; +import com.somemore.global.common.event.ServerEvent; +import com.somemore.global.common.event.ServerEventType; import lombok.Getter; import lombok.experimental.SuperBuilder; diff --git a/src/main/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepository.java b/src/main/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepository.java index 314528566..2761b6229 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepository.java +++ b/src/main/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepository.java @@ -1,13 +1,13 @@ package com.somemore.domains.volunteerapply.repository; -import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition; import com.somemore.domains.volunteerapply.domain.VolunteerApply; +import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import java.util.List; import java.util.Optional; import java.util.UUID; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; public interface VolunteerApplyRepository { @@ -28,10 +28,10 @@ public interface VolunteerApplyRepository { List findAllByRecruitId(Long recruitId); Page findAllByRecruitId(Long recruitId, - VolunteerApplySearchCondition condition); + VolunteerApplySearchCondition condition); Page findAllByVolunteerId(UUID volunteerId, - VolunteerApplySearchCondition condition); + VolunteerApplySearchCondition condition); List findAllByIds(List ids); } diff --git a/src/main/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepositoryImpl.java b/src/main/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepositoryImpl.java index 0ed6b2823..6e58bf563 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepositoryImpl.java @@ -3,14 +3,10 @@ import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; -import com.somemore.domains.volunteerapply.domain.QVolunteerApply; -import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition; import com.somemore.domains.volunteerapply.domain.ApplyStatus; +import com.somemore.domains.volunteerapply.domain.QVolunteerApply; import com.somemore.domains.volunteerapply.domain.VolunteerApply; - -import java.util.List; -import java.util.Optional; -import java.util.UUID; +import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -18,6 +14,10 @@ import org.springframework.data.domain.Sort; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + @RequiredArgsConstructor @Repository public class VolunteerApplyRepositoryImpl implements VolunteerApplyRepository { @@ -91,7 +91,7 @@ public List findAllByRecruitId(Long recruitId) { @Override public Page findAllByRecruitId(Long recruitId, - VolunteerApplySearchCondition condition) { + VolunteerApplySearchCondition condition) { BooleanExpression exp = recruitIdEq(recruitId) .and(attendedEq(condition.attended())) @@ -117,7 +117,7 @@ public Page findAllByRecruitId(Long recruitId, @Override public Page findAllByVolunteerId(UUID volunteerId, - VolunteerApplySearchCondition condition) { + VolunteerApplySearchCondition condition) { BooleanExpression exp = volunteerIdEq(volunteerId) .and(attendedEq(condition.attended())) @@ -154,7 +154,7 @@ public List findAllByIds(List ids) { @Override public Optional findByRecruitIdAndVolunteerId(Long recruitId, - UUID volunteerId) { + UUID volunteerId) { BooleanExpression exp = recruitIdEq(recruitId) .and(volunteerApply.volunteerId.eq(volunteerId)); return findOne(exp); diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java index 93a213fd6..75aa0389d 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java @@ -20,7 +20,9 @@ import java.util.List; import java.util.UUID; -import static com.somemore.global.exception.ExceptionMessage.*; +import static com.somemore.global.exception.ExceptionMessage.RECRUIT_BOARD_ID_MISMATCH; +import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; +import static com.somemore.global.exception.ExceptionMessage.VOLUNTEER_APPLY_LIST_MISMATCH; @RequiredArgsConstructor @Transactional diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java index 80e9eea25..6647b231a 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java @@ -9,8 +9,8 @@ import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition; import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto; -import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyWithReviewStatusResponseDto; import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyVolunteerInfoResponseDto; +import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyWithReviewStatusResponseDto; import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryFacadeUseCase; import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java index 6530b4c41..008e8a061 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java @@ -18,7 +18,9 @@ import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED; import static com.somemore.domains.volunteerapply.domain.ApplyStatus.REJECTED; -import static com.somemore.global.exception.ExceptionMessage.*; +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER_APPLY; +import static com.somemore.global.exception.ExceptionMessage.RECRUIT_BOARD_ALREADY_COMPLETED; +import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; @RequiredArgsConstructor @Transactional diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/WithdrawVolunteerApplyService.java b/src/main/java/com/somemore/domains/volunteerapply/service/WithdrawVolunteerApplyService.java index 8ba5144a9..82e5ff770 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/WithdrawVolunteerApplyService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/WithdrawVolunteerApplyService.java @@ -1,18 +1,18 @@ package com.somemore.domains.volunteerapply.service; -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER_APPLY; -import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_VOLUNTEER_APPLY; - +import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository; import com.somemore.domains.volunteerapply.usecase.WithdrawVolunteerApplyUseCase; import com.somemore.global.exception.BadRequestException; -import com.somemore.domains.volunteerapply.domain.VolunteerApply; - -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.UUID; + +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER_APPLY; +import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_VOLUNTEER_APPLY; + @RequiredArgsConstructor @Transactional @Service diff --git a/src/main/java/com/somemore/domains/volunteerapply/usecase/ApplyVolunteerApplyUseCase.java b/src/main/java/com/somemore/domains/volunteerapply/usecase/ApplyVolunteerApplyUseCase.java index f225f81a5..0ea4ab6f0 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/usecase/ApplyVolunteerApplyUseCase.java +++ b/src/main/java/com/somemore/domains/volunteerapply/usecase/ApplyVolunteerApplyUseCase.java @@ -1,6 +1,7 @@ package com.somemore.domains.volunteerapply.usecase; import com.somemore.domains.volunteerapply.dto.request.VolunteerApplyCreateRequestDto; + import java.util.UUID; public interface ApplyVolunteerApplyUseCase { diff --git a/src/main/java/com/somemore/domains/volunteerapply/usecase/SettleVolunteerApplyFacadeUseCase.java b/src/main/java/com/somemore/domains/volunteerapply/usecase/SettleVolunteerApplyFacadeUseCase.java index a548a00be..36c914127 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/usecase/SettleVolunteerApplyFacadeUseCase.java +++ b/src/main/java/com/somemore/domains/volunteerapply/usecase/SettleVolunteerApplyFacadeUseCase.java @@ -1,6 +1,7 @@ package com.somemore.domains.volunteerapply.usecase; import com.somemore.domains.volunteerapply.dto.request.VolunteerApplySettleRequestDto; + import java.util.UUID; public interface SettleVolunteerApplyFacadeUseCase { diff --git a/src/main/java/com/somemore/domains/volunteerapply/usecase/VolunteerApplyQueryFacadeUseCase.java b/src/main/java/com/somemore/domains/volunteerapply/usecase/VolunteerApplyQueryFacadeUseCase.java index 1412c0954..f2b6689eb 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/usecase/VolunteerApplyQueryFacadeUseCase.java +++ b/src/main/java/com/somemore/domains/volunteerapply/usecase/VolunteerApplyQueryFacadeUseCase.java @@ -2,8 +2,8 @@ import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition; import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto; -import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyWithReviewStatusResponseDto; import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyVolunteerInfoResponseDto; +import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyWithReviewStatusResponseDto; import org.springframework.data.domain.Page; import java.util.UUID; diff --git a/src/main/java/com/somemore/domains/volunteerrecord/domain/VolunteerRecord.java b/src/main/java/com/somemore/domains/volunteerrecord/domain/VolunteerRecord.java index 6174bb91d..7b90018f0 100644 --- a/src/main/java/com/somemore/domains/volunteerrecord/domain/VolunteerRecord.java +++ b/src/main/java/com/somemore/domains/volunteerrecord/domain/VolunteerRecord.java @@ -1,7 +1,11 @@ package com.somemore.domains.volunteerrecord.domain; import com.somemore.global.common.entity.BaseEntity; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/somemore/global/aspect/log/LoggingAspect.java b/src/main/java/com/somemore/global/aspect/log/LoggingAspect.java index 95f4fed07..91fa2ff06 100644 --- a/src/main/java/com/somemore/global/aspect/log/LoggingAspect.java +++ b/src/main/java/com/somemore/global/aspect/log/LoggingAspect.java @@ -15,7 +15,6 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; - import java.util.UUID; @RequiredArgsConstructor @@ -29,7 +28,8 @@ public class LoggingAspect { private final ParameterExtractor parameterExtractor; @Pointcut("execution(* com.somemore.domains.*.controller..*.*(..))") - private void controllerPointCut() {} + private void controllerPointCut() { + } @Around("controllerPointCut()") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { diff --git a/src/main/java/com/somemore/global/aspect/log/extractor/ResponseExtractor.java b/src/main/java/com/somemore/global/aspect/log/extractor/ResponseExtractor.java index 3433ffcba..487685650 100644 --- a/src/main/java/com/somemore/global/aspect/log/extractor/ResponseExtractor.java +++ b/src/main/java/com/somemore/global/aspect/log/extractor/ResponseExtractor.java @@ -2,9 +2,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.somemore.global.common.response.LoggedResponse; +import com.somemore.global.exception.BadRequestException; import com.somemore.global.exception.DuplicateException; import com.somemore.global.exception.ImageUploadException; -import com.somemore.global.exception.BadRequestException; import com.somemore.global.exception.NoSuchElementException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/somemore/global/aspect/log/utils/SensitiveDataMasker.java b/src/main/java/com/somemore/global/aspect/log/utils/SensitiveDataMasker.java index 9b8b870d0..1b7dbccf0 100644 --- a/src/main/java/com/somemore/global/aspect/log/utils/SensitiveDataMasker.java +++ b/src/main/java/com/somemore/global/aspect/log/utils/SensitiveDataMasker.java @@ -6,7 +6,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.util.*; +import java.util.Arrays; +import java.util.Date; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; @Slf4j @Component @@ -57,7 +62,8 @@ private Map maskSensitiveDataInMap(Map map) { private String maskSensitiveDataInJson(String json, ObjectMapper objectMapper) { try { - Map jsonMap = objectMapper.readValue(json, new TypeReference<>() {}); + Map jsonMap = objectMapper.readValue(json, new TypeReference<>() { + }); Map maskedMap = maskSensitiveDataInMap(jsonMap); return objectMapper.writeValueAsString(maskedMap); } catch (Exception e) { diff --git a/src/main/java/com/somemore/global/auth/annotation/CurrentUser.java b/src/main/java/com/somemore/global/auth/annotation/CurrentUser.java index 922575ae1..e292ec999 100644 --- a/src/main/java/com/somemore/global/auth/annotation/CurrentUser.java +++ b/src/main/java/com/somemore/global/auth/annotation/CurrentUser.java @@ -1,10 +1,11 @@ package com.somemore.global.auth.annotation; +import org.springframework.security.core.annotation.AuthenticationPrincipal; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.springframework.security.core.annotation.AuthenticationPrincipal; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) diff --git a/src/main/java/com/somemore/global/auth/controller/AuthController.java b/src/main/java/com/somemore/global/auth/controller/AuthController.java deleted file mode 100644 index f5fdeccde..000000000 --- a/src/main/java/com/somemore/global/auth/controller/AuthController.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.somemore.global.auth.controller; - -import com.somemore.global.auth.annotation.CurrentUser; -import com.somemore.global.auth.dto.UserInfoResponseDto; -import com.somemore.global.auth.jwt.domain.EncodedToken; -import com.somemore.global.auth.usecase.AuthQueryUseCase; -import com.somemore.global.common.response.ApiResponse; -import com.somemore.user.domain.UserRole; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.UUID; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/auth") -public class AuthController { - - private final AuthQueryUseCase authQueryUseCase; - - @GetMapping("/user-info") - public ApiResponse getUserInfo( - @CurrentUser UUID userId - ) { - UserRole role = authQueryUseCase.getRoleByUserId(userId); - - return ApiResponse.ok(HttpStatus.OK.value(), - UserInfoResponseDto.of(userId, role), - "유저 정보 응답 성공"); - } - - @GetMapping("/token") - public ApiResponse getToken( - @CurrentUser UUID userId - ) { - EncodedToken accessToken = authQueryUseCase.getAccessTokenByUserId(userId); - - return ApiResponse.ok(HttpStatus.OK.value(), - accessToken.getValueWithPrefix(), - "액세스 토큰 응답 성공"); - } -} diff --git a/src/main/java/com/somemore/global/auth/controller/SignController.java b/src/main/java/com/somemore/global/auth/controller/SignController.java deleted file mode 100644 index 151acbafa..000000000 --- a/src/main/java/com/somemore/global/auth/controller/SignController.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.somemore.global.auth.controller; - -import com.somemore.global.auth.dto.SignRequestDto; -import com.somemore.global.auth.signout.usecase.SignOutUseCase; -import com.somemore.global.common.response.ApiResponse; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/api") -@Tag(name = "Sign API", description = "ID,PW 로그인, 로그아웃") -public class SignController { - - private final SignOutUseCase signOutUseCase; - - /* - * ID 및 PW 기반 로그인 엔드포인트 (Swagger 문서화를 위한 엔드포인트) - * - * 이 엔드포인트는 실제로 작동하지 않으며, Spring Security 필터 체인에 의해 요청이 처리됩니다. - * 로그인 요청은 필터에서 가로채어 인증 절차를 수행하며, 이 엔드포인트로 전달되지 않습니다. - * 따라서 이 엔드포인트는 로그인 요청의 처리를 위한 진입점이 아니라, - * Swagger API 문서화를 위해 정의된 엔드포인트입니다. - * - * 실제 로그인 절차는 필터에서 처리됩니다. - */ - @PostMapping("/sign-in/id-pw") - public ApiResponse signIn( - @RequestParam SignRequestDto signRequestDto - ) { - return ApiResponse.ok("로그인되었습니다."); - } - - @PostMapping("/sign-out") - public ApiResponse signOut( - HttpServletResponse response, - @AuthenticationPrincipal String userId) { - - signOutUseCase.signOut(response, userId); - - return ApiResponse.ok("로그아웃되었습니다"); - } -} diff --git a/src/main/java/com/somemore/global/auth/dto/UserInfoResponseDto.java b/src/main/java/com/somemore/global/auth/dto/UserInfoResponseDto.java deleted file mode 100644 index 3e2ccbd81..000000000 --- a/src/main/java/com/somemore/global/auth/dto/UserInfoResponseDto.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.somemore.global.auth.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.somemore.user.domain.UserRole; -import io.swagger.v3.oas.annotations.media.Schema; - -import java.util.UUID; - -@Schema(description = "유저 정보 DTO") -public record UserInfoResponseDto( - @JsonProperty("USER_ID") - @Schema(description = "유저 ID") - String userId, - - @JsonProperty("ROLE") - @Schema(description = "유저 ROLE") - String role -) { - public static UserInfoResponseDto of(UUID userId, UserRole role) { - return new UserInfoResponseDto(userId.toString(), role.getAuthority()); - } -} diff --git a/src/main/java/com/somemore/global/auth/idpw/filter/IdPwAuthFilter.java b/src/main/java/com/somemore/global/auth/idpw/filter/IdPwAuthFilter.java index 0e58e7790..ebbbf798d 100644 --- a/src/main/java/com/somemore/global/auth/idpw/filter/IdPwAuthFilter.java +++ b/src/main/java/com/somemore/global/auth/idpw/filter/IdPwAuthFilter.java @@ -28,7 +28,7 @@ public class IdPwAuthFilter extends UsernamePasswordAuthenticationFilter { private final AuthenticationManager authenticationManager; private final GenerateTokensOnLoginUseCase generateTokensOnLoginUseCase; -// private final CookieUseCase cookieUseCase; + // private final CookieUseCase cookieUseCase; private final ObjectMapper objectMapper; @Override diff --git a/src/main/java/com/somemore/global/auth/idpw/provider/CustomAuthenticationProvider.java b/src/main/java/com/somemore/global/auth/idpw/provider/CustomAuthenticationProvider.java index 9720a703e..d81f9031b 100644 --- a/src/main/java/com/somemore/global/auth/idpw/provider/CustomAuthenticationProvider.java +++ b/src/main/java/com/somemore/global/auth/idpw/provider/CustomAuthenticationProvider.java @@ -32,7 +32,7 @@ public Authentication authenticate(Authentication authentication) throws Authent User user = userQueryUseCase.getByAccountId(accountId); - validatePassword(rawAccountPassword, user.getPassword()); + validatePassword(rawAccountPassword, user.getAccountPassword()); EncodedToken accessToken = generateAccessToken(user); diff --git a/src/main/java/com/somemore/global/auth/jwt/controller/TokenExchangeController.java b/src/main/java/com/somemore/global/auth/jwt/controller/TokenExchangeController.java new file mode 100644 index 000000000..1adc89f43 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/jwt/controller/TokenExchangeController.java @@ -0,0 +1,34 @@ +package com.somemore.global.auth.jwt.controller; + +import com.somemore.global.auth.annotation.CurrentUser; +import com.somemore.global.auth.jwt.domain.EncodedToken; +import com.somemore.global.auth.jwt.manager.TokenManager; +import com.somemore.global.common.response.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.UUID; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/auth/token") +@Tag(name = "Token Exchange API", description = "SignInToken을 AccessToken으로 교환하는 API") +public class TokenExchangeController { + + private final TokenManager tokenManager; + + @GetMapping("/exchange") + public ApiResponse exchangeToken( + @CurrentUser UUID userId + ) { + EncodedToken accessToken = tokenManager.getAccessTokenByUserId(userId); + + return ApiResponse.ok(HttpStatus.OK.value(), + accessToken.getValueWithPrefix(), + "액세스 토큰 응답 성공"); + } +} diff --git a/src/main/java/com/somemore/global/auth/jwt/domain/EncodedToken.java b/src/main/java/com/somemore/global/auth/jwt/domain/EncodedToken.java index 311d37170..beeda1f09 100644 --- a/src/main/java/com/somemore/global/auth/jwt/domain/EncodedToken.java +++ b/src/main/java/com/somemore/global/auth/jwt/domain/EncodedToken.java @@ -5,6 +5,10 @@ public record EncodedToken(String value) { private static final String UNINITIALIZED = "UNINITIALIZED"; private static final String PREFIX = "Bearer "; + public static EncodedToken from(String value) { + return new EncodedToken(value); + } + public String getValueWithPrefix() { return PREFIX + this.value; } diff --git a/src/main/java/com/somemore/global/auth/jwt/refresh/domain/RefreshToken.java b/src/main/java/com/somemore/global/auth/jwt/domain/RefreshToken.java similarity index 89% rename from src/main/java/com/somemore/global/auth/jwt/refresh/domain/RefreshToken.java rename to src/main/java/com/somemore/global/auth/jwt/domain/RefreshToken.java index e1368c9d9..fcc436a07 100644 --- a/src/main/java/com/somemore/global/auth/jwt/refresh/domain/RefreshToken.java +++ b/src/main/java/com/somemore/global/auth/jwt/domain/RefreshToken.java @@ -1,6 +1,5 @@ -package com.somemore.global.auth.jwt.refresh.domain; +package com.somemore.global.auth.jwt.domain; -import com.somemore.global.auth.jwt.domain.EncodedToken; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/somemore/global/auth/jwt/filter/JwtAuthFilter.java b/src/main/java/com/somemore/global/auth/jwt/filter/JwtAuthFilter.java index 18f0ce917..8bd75bf94 100644 --- a/src/main/java/com/somemore/global/auth/jwt/filter/JwtAuthFilter.java +++ b/src/main/java/com/somemore/global/auth/jwt/filter/JwtAuthFilter.java @@ -76,7 +76,7 @@ private static EncodedToken findAccessTokenFromHeader(HttpServletRequest request return EncodedToken.createUninitialized(); } - return new EncodedToken(authorizationHeader); + return EncodedToken.from(authorizationHeader); } private EncodedToken findAccessTokenFromCookie(HttpServletRequest request) { diff --git a/src/main/java/com/somemore/global/auth/jwt/generator/HmacJwtGenerator.java b/src/main/java/com/somemore/global/auth/jwt/generator/HmacJwtGenerator.java index 6d00476c4..a1ecf53f1 100644 --- a/src/main/java/com/somemore/global/auth/jwt/generator/HmacJwtGenerator.java +++ b/src/main/java/com/somemore/global/auth/jwt/generator/HmacJwtGenerator.java @@ -26,13 +26,15 @@ public EncodedToken generateToken(String userId, String role, TokenType tokenTyp Instant expiration = now.plusMillis(tokenType.getPeriodInMillis()); String uniqueId = UUID.randomUUID().toString(); // JTI - return new EncodedToken(Jwts.builder() - .claims(claims) - .id(uniqueId) - .issuedAt(Date.from(now)) - .expiration(Date.from(expiration)) - .signWith(secretKey, ALGORITHM) - .compact()); + return EncodedToken.from( + Jwts.builder() + .claims(claims) + .id(uniqueId) + .issuedAt(Date.from(now)) + .expiration(Date.from(expiration)) + .signWith(secretKey, ALGORITHM) + .compact() + ); } private static Claims buildClaims(String userId, String role) { diff --git a/src/main/java/com/somemore/global/auth/jwt/refresh/manager/RedisRefreshTokenManager.java b/src/main/java/com/somemore/global/auth/jwt/manager/RedisTokenManager.java similarity index 64% rename from src/main/java/com/somemore/global/auth/jwt/refresh/manager/RedisRefreshTokenManager.java rename to src/main/java/com/somemore/global/auth/jwt/manager/RedisTokenManager.java index 1185a3fde..a07bda5a1 100644 --- a/src/main/java/com/somemore/global/auth/jwt/refresh/manager/RedisRefreshTokenManager.java +++ b/src/main/java/com/somemore/global/auth/jwt/manager/RedisTokenManager.java @@ -1,10 +1,10 @@ -package com.somemore.global.auth.jwt.refresh.manager; +package com.somemore.global.auth.jwt.manager; import com.somemore.global.auth.jwt.domain.EncodedToken; +import com.somemore.global.auth.jwt.domain.RefreshToken; import com.somemore.global.auth.jwt.exception.JwtErrorType; import com.somemore.global.auth.jwt.exception.JwtException; -import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; -import com.somemore.global.auth.jwt.refresh.repository.RefreshTokenRepository; +import com.somemore.global.auth.jwt.repository.RefreshTokenRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -12,20 +12,22 @@ @Service @RequiredArgsConstructor -public class RedisRefreshTokenManager implements RefreshTokenManager { +public class RedisTokenManager implements TokenManager { private final RefreshTokenRepository refreshTokenRepository; @Override - public RefreshToken findRefreshTokenByAccessToken(EncodedToken accessToken) { + public RefreshToken getRefreshTokenByAccessToken(EncodedToken accessToken) { return refreshTokenRepository.findByAccessToken(accessToken.value()) .orElseThrow(() -> new JwtException(JwtErrorType.EXPIRED_TOKEN)); } @Override - public RefreshToken findRefreshTokenByUserId(UUID userId) { - return refreshTokenRepository.findByUserId(userId.toString()) + public EncodedToken getAccessTokenByUserId(UUID userId) { + RefreshToken refreshToken = refreshTokenRepository.findByUserId(userId.toString()) .orElseThrow(() -> new JwtException(JwtErrorType.EXPIRED_TOKEN)); + + return EncodedToken.from(refreshToken.getAccessToken()); } @Override diff --git a/src/main/java/com/somemore/global/auth/jwt/manager/TokenManager.java b/src/main/java/com/somemore/global/auth/jwt/manager/TokenManager.java new file mode 100644 index 000000000..edec9be15 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/jwt/manager/TokenManager.java @@ -0,0 +1,16 @@ +package com.somemore.global.auth.jwt.manager; + +import com.somemore.global.auth.jwt.domain.EncodedToken; +import com.somemore.global.auth.jwt.domain.RefreshToken; + +import java.util.UUID; + +public interface TokenManager { + RefreshToken getRefreshTokenByAccessToken(EncodedToken accessToken); + + EncodedToken getAccessTokenByUserId(UUID userId); + + void save(RefreshToken refreshToken); + + void removeRefreshToken(String userId); +} diff --git a/src/main/java/com/somemore/global/auth/jwt/refresh/manager/RefreshTokenManager.java b/src/main/java/com/somemore/global/auth/jwt/refresh/manager/RefreshTokenManager.java deleted file mode 100644 index d4598d14c..000000000 --- a/src/main/java/com/somemore/global/auth/jwt/refresh/manager/RefreshTokenManager.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.somemore.global.auth.jwt.refresh.manager; - -import com.somemore.global.auth.jwt.domain.EncodedToken; -import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; - -import java.util.UUID; - -public interface RefreshTokenManager { - RefreshToken findRefreshTokenByAccessToken(EncodedToken accessToken); - - RefreshToken findRefreshTokenByUserId(UUID userId); - - void save(RefreshToken refreshToken); - - void removeRefreshToken(String userId); -} diff --git a/src/main/java/com/somemore/global/auth/jwt/refresh/refresher/DefaultJwtRefresher.java b/src/main/java/com/somemore/global/auth/jwt/refresher/DefaultJwtRefresher.java similarity index 68% rename from src/main/java/com/somemore/global/auth/jwt/refresh/refresher/DefaultJwtRefresher.java rename to src/main/java/com/somemore/global/auth/jwt/refresher/DefaultJwtRefresher.java index 86430634e..9a1eaa2cc 100644 --- a/src/main/java/com/somemore/global/auth/jwt/refresh/refresher/DefaultJwtRefresher.java +++ b/src/main/java/com/somemore/global/auth/jwt/refresher/DefaultJwtRefresher.java @@ -1,11 +1,11 @@ -package com.somemore.global.auth.jwt.refresh.refresher; +package com.somemore.global.auth.jwt.refresher; import com.somemore.global.auth.jwt.domain.EncodedToken; +import com.somemore.global.auth.jwt.domain.RefreshToken; import com.somemore.global.auth.jwt.domain.TokenType; import com.somemore.global.auth.jwt.generator.JwtGenerator; +import com.somemore.global.auth.jwt.manager.TokenManager; import com.somemore.global.auth.jwt.parser.JwtParser; -import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; -import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; import com.somemore.global.auth.jwt.validator.JwtValidator; import io.jsonwebtoken.Claims; import lombok.RequiredArgsConstructor; @@ -17,22 +17,22 @@ @Slf4j public class DefaultJwtRefresher implements JwtRefresher { - private final RefreshTokenManager refreshTokenManager; + private final TokenManager tokenManager; private final JwtValidator jwtValidator; private final JwtParser jwtParser; private final JwtGenerator jwtGenerator; @Override public EncodedToken refreshAccessToken(EncodedToken accessToken) { - RefreshToken refreshToken = refreshTokenManager.findRefreshTokenByAccessToken(accessToken); - EncodedToken refreshTokenValue = new EncodedToken(refreshToken.getRefreshToken()); + RefreshToken refreshToken = tokenManager.getRefreshTokenByAccessToken(accessToken); + EncodedToken refreshTokenValue = EncodedToken.from(refreshToken.getRefreshToken()); jwtValidator.validateToken(refreshTokenValue); Claims claims = jwtParser.parseToken(refreshTokenValue); refreshToken.updateAccessToken(generateAccessToken(claims)); - refreshTokenManager.save(refreshToken); + tokenManager.save(refreshToken); - return new EncodedToken(refreshToken.getAccessToken()); + return EncodedToken.from(refreshToken.getAccessToken()); } private EncodedToken generateAccessToken(Claims claims) { diff --git a/src/main/java/com/somemore/global/auth/jwt/refresh/refresher/JwtRefresher.java b/src/main/java/com/somemore/global/auth/jwt/refresher/JwtRefresher.java similarity index 73% rename from src/main/java/com/somemore/global/auth/jwt/refresh/refresher/JwtRefresher.java rename to src/main/java/com/somemore/global/auth/jwt/refresher/JwtRefresher.java index 962deb2a9..cc3e4cec2 100644 --- a/src/main/java/com/somemore/global/auth/jwt/refresh/refresher/JwtRefresher.java +++ b/src/main/java/com/somemore/global/auth/jwt/refresher/JwtRefresher.java @@ -1,4 +1,4 @@ -package com.somemore.global.auth.jwt.refresh.refresher; +package com.somemore.global.auth.jwt.refresher; import com.somemore.global.auth.jwt.domain.EncodedToken; diff --git a/src/main/java/com/somemore/global/auth/jwt/refresh/repository/RefreshTokenRepository.java b/src/main/java/com/somemore/global/auth/jwt/repository/RefreshTokenRepository.java similarity index 74% rename from src/main/java/com/somemore/global/auth/jwt/refresh/repository/RefreshTokenRepository.java rename to src/main/java/com/somemore/global/auth/jwt/repository/RefreshTokenRepository.java index 289ac501b..562778aae 100644 --- a/src/main/java/com/somemore/global/auth/jwt/refresh/repository/RefreshTokenRepository.java +++ b/src/main/java/com/somemore/global/auth/jwt/repository/RefreshTokenRepository.java @@ -1,6 +1,6 @@ -package com.somemore.global.auth.jwt.refresh.repository; +package com.somemore.global.auth.jwt.repository; -import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; +import com.somemore.global.auth.jwt.domain.RefreshToken; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/com/somemore/global/auth/jwt/service/GenerateTokensOnLoginService.java b/src/main/java/com/somemore/global/auth/jwt/service/GenerateTokensOnLoginService.java index fc62ddc4d..5197d0b79 100644 --- a/src/main/java/com/somemore/global/auth/jwt/service/GenerateTokensOnLoginService.java +++ b/src/main/java/com/somemore/global/auth/jwt/service/GenerateTokensOnLoginService.java @@ -1,12 +1,12 @@ package com.somemore.global.auth.jwt.service; -import com.somemore.user.domain.UserRole; import com.somemore.global.auth.jwt.domain.EncodedToken; +import com.somemore.global.auth.jwt.domain.RefreshToken; import com.somemore.global.auth.jwt.domain.TokenType; import com.somemore.global.auth.jwt.generator.JwtGenerator; -import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; -import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; +import com.somemore.global.auth.jwt.manager.TokenManager; import com.somemore.global.auth.jwt.usecase.GenerateTokensOnLoginUseCase; +import com.somemore.user.domain.UserRole; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -21,7 +21,7 @@ public class GenerateTokensOnLoginService implements GenerateTokensOnLoginUseCase { private final JwtGenerator jwtGenerator; - private final RefreshTokenManager refreshTokenManager; + private final TokenManager tokenManager; @Override public EncodedToken generateLoginToken(UUID userId, UserRole role) { @@ -54,6 +54,6 @@ private RefreshToken generateRefreshTokenWithAccessToken(UUID userId, UserRole r } private void saveRefreshToken(RefreshToken refreshToken) { - refreshTokenManager.save(refreshToken); + tokenManager.save(refreshToken); } } diff --git a/src/main/java/com/somemore/global/auth/jwt/service/JwtService.java b/src/main/java/com/somemore/global/auth/jwt/service/JwtService.java index 43600e8d3..9c7ce62d0 100644 --- a/src/main/java/com/somemore/global/auth/jwt/service/JwtService.java +++ b/src/main/java/com/somemore/global/auth/jwt/service/JwtService.java @@ -1,13 +1,12 @@ package com.somemore.global.auth.jwt.service; -import com.somemore.global.auth.cookie.CookieUseCase; import com.somemore.global.auth.jwt.domain.EncodedToken; import com.somemore.global.auth.jwt.domain.TokenType; import com.somemore.global.auth.jwt.exception.JwtErrorType; import com.somemore.global.auth.jwt.exception.JwtException; import com.somemore.global.auth.jwt.generator.JwtGenerator; import com.somemore.global.auth.jwt.parser.JwtParser; -import com.somemore.global.auth.jwt.refresh.refresher.JwtRefresher; +import com.somemore.global.auth.jwt.refresher.JwtRefresher; import com.somemore.global.auth.jwt.usecase.JwtUseCase; import com.somemore.global.auth.jwt.validator.JwtValidator; import io.jsonwebtoken.Claims; @@ -24,7 +23,6 @@ public class JwtService implements JwtUseCase { private final JwtParser jwtParser; private final JwtValidator jwtValidator; private final JwtRefresher jwtRefresher; - private final CookieUseCase cookieUseCase; @Override public EncodedToken generateToken(String userId, String role, TokenType tokenType) { @@ -48,7 +46,7 @@ public Claims getClaims(EncodedToken token) { private void handleJwtExpiredException(JwtException e, EncodedToken accessToken, HttpServletResponse response) { if (e.getErrorType() == JwtErrorType.EXPIRED_TOKEN) { EncodedToken refreshedToken = jwtRefresher.refreshAccessToken(accessToken); - cookieUseCase.setToken(response, refreshedToken.value(), TokenType.ACCESS); + // TODO 프론트엔드와 협의 : 만료된 액세스 토큰 관리 방법 return; } throw e; diff --git a/src/main/java/com/somemore/global/auth/jwt/usecase/GenerateTokensOnLoginUseCase.java b/src/main/java/com/somemore/global/auth/jwt/usecase/GenerateTokensOnLoginUseCase.java index 4c7c74828..3bdf560a3 100644 --- a/src/main/java/com/somemore/global/auth/jwt/usecase/GenerateTokensOnLoginUseCase.java +++ b/src/main/java/com/somemore/global/auth/jwt/usecase/GenerateTokensOnLoginUseCase.java @@ -7,5 +7,6 @@ public interface GenerateTokensOnLoginUseCase { EncodedToken generateLoginToken(UUID userId, UserRole role); + EncodedToken generateAuthTokensAndReturnAccessToken(UUID userId, UserRole role); } diff --git a/src/main/java/com/somemore/global/auth/oauth/converter/OAuthResponseConverterImpl.java b/src/main/java/com/somemore/global/auth/oauth/converter/OAuthResponseConverterImpl.java index a5cb8bb35..8d08f2c40 100644 --- a/src/main/java/com/somemore/global/auth/oauth/converter/OAuthResponseConverterImpl.java +++ b/src/main/java/com/somemore/global/auth/oauth/converter/OAuthResponseConverterImpl.java @@ -18,27 +18,28 @@ public class OAuthResponseConverterImpl implements OAuthResponseConverter { @Override public CommonOAuthInfo convert(CustomOAuth2User oAuth2User) { OAuthProvider provider = oAuth2User.getProvider(); - switch (provider) { - case KAKAO: + return switch (provider) { + case KAKAO -> { KakaoUserProfileResponseDto kakaoUserProfile = objectMapper.convertValue( oAuth2User.getAttributes(), KakaoUserProfileResponseDto.class ); - return CommonOAuthInfo.of( + yield CommonOAuthInfo.of( OAuthProvider.KAKAO, kakaoUserProfile.id() ); - case NAVER: + } + case NAVER -> { NaverUserProfileResponseDto naverUserProfile = objectMapper.convertValue( oAuth2User.getAttributes(), NaverUserProfileResponseDto.class ); - return CommonOAuthInfo.of( + yield CommonOAuthInfo.of( OAuthProvider.NAVER, naverUserProfile.response().id() ); - default: - throw new IllegalArgumentException("지원하지 않는 OAuth Provider입니다."); - } + } + default -> throw new IllegalArgumentException("지원하지 않는 OAuth Provider입니다."); + }; } } diff --git a/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepository.java b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepository.java index db1982211..6986266f7 100644 --- a/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepository.java +++ b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepository.java @@ -8,6 +8,8 @@ public interface OAuthInfoRepository { Optional findUserIdByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId); + boolean existsByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId); + OAuthInfo save(OAuthInfo oauthInfo); } diff --git a/src/main/java/com/somemore/global/auth/sign/in/SignInController.java b/src/main/java/com/somemore/global/auth/sign/in/SignInController.java new file mode 100644 index 000000000..822b4665e --- /dev/null +++ b/src/main/java/com/somemore/global/auth/sign/in/SignInController.java @@ -0,0 +1,57 @@ +package com.somemore.global.auth.sign.in; + +import com.somemore.global.common.response.ApiResponse; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +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; + +@RestController +@RequiredArgsConstructor +@RequestMapping() +@Tag(name = "SignIn API", description = "유저 로그인") +public class SignInController { + + /** + * ID 및 PW 기반 로그인 엔드포인트 (Swagger 문서화를 위한 더미 엔드포인트) + *

+ * 이 엔드포인트는 실제로 동작하지 않으며, Spring Security의 필터 체인에 의해 요청이 처리됩니다. + * 사용자가 ID/PW로 로그인을 시도하면, 해당 요청은 Spring Security 필터 체인에서 가로채어 인증 절차를 수행하며, + * 이 엔드포인트로 전달되지 않습니다. + *

+ * 따라서 이 엔드포인트는 실제 인증 로직과는 무관하며, Swagger API 문서화를 위해 정의된 것입니다. + *

+ * 실제 인증 절차는 Spring Security의 필터에서 처리됩니다. + */ + @PostMapping("/api/sign-in/id-pw") + public ApiResponse signIn( + @RequestBody SignInRequestDto signInRequestDto) { + return ApiResponse.ok("로그인되었습니다."); + } + + /** + * OAuth2 소셜 로그인 엔드포인트 (Swagger 문서화를 위한 더미 엔드포인트) + *

+ * 이 엔드포인트는 실제로 동작하지 않으며, Spring Security가 제공하는 OAuth2 클라이언트 기능에 의해 처리됩니다. + * 클라이언트가 특정 OAuth 제공자(Naver, Kakao 등)로 로그인 요청을 보내면, + * 요청은 Spring Security의 OAuth2 필터 체인에 의해 가로채어 처리되며, 이 엔드포인트로 전달되지 않습니다. + *

+ * 따라서 이 엔드포인트는 실제 소셜 로그인 처리를 위한 진입점이 아니라, + * Swagger API 문서화를 위해 정의된 것입니다. + *

+ * 실제 OAuth2 로그인 절차는 Spring Security가 처리합니다. + */ + @GetMapping("oauth2/authorization/{oauthProvider}") + public ApiResponse signIn( + @Parameter(name = "oauthProvider", description = "OAuth 제공자 선택", example = "naver", required = true, schema = @Schema(allowableValues = {"naver, kakao"})) + @PathVariable("oauthProvider") String oauthProvider) { + + return ApiResponse.ok("로그인되었습니다."); + } +} diff --git a/src/main/java/com/somemore/global/auth/dto/SignRequestDto.java b/src/main/java/com/somemore/global/auth/sign/in/SignInRequestDto.java similarity index 84% rename from src/main/java/com/somemore/global/auth/dto/SignRequestDto.java rename to src/main/java/com/somemore/global/auth/sign/in/SignInRequestDto.java index dca6711c1..462171e35 100644 --- a/src/main/java/com/somemore/global/auth/dto/SignRequestDto.java +++ b/src/main/java/com/somemore/global/auth/sign/in/SignInRequestDto.java @@ -1,11 +1,11 @@ -package com.somemore.global.auth.dto; +package com.somemore.global.auth.sign.in; import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; import io.swagger.v3.oas.annotations.media.Schema; @JsonNaming(SnakeCaseStrategy.class) -public record SignRequestDto( +public record SignInRequestDto( @Schema(description = "ID", example = "somemore") String accountId, @Schema(description = "PW", example = "password1234") diff --git a/src/main/java/com/somemore/global/auth/sign/out/SignOutController.java b/src/main/java/com/somemore/global/auth/sign/out/SignOutController.java new file mode 100644 index 000000000..b7a07c45f --- /dev/null +++ b/src/main/java/com/somemore/global/auth/sign/out/SignOutController.java @@ -0,0 +1,31 @@ +package com.somemore.global.auth.sign.out; + +import com.somemore.global.auth.annotation.CurrentUser; +import com.somemore.global.common.response.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.UUID; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api") +@Tag(name = "SignOut API", description = "유저 로그아웃") +public class SignOutController { + + private final SignOutUseCase signOutUseCase; + + @PostMapping("/sign-out") + public ApiResponse signOut( + HttpServletResponse response, + @CurrentUser UUID userId) { + + signOutUseCase.signOut(response, userId); + + return ApiResponse.ok("로그아웃되었습니다"); + } +} diff --git a/src/main/java/com/somemore/global/auth/sign/out/SignOutService.java b/src/main/java/com/somemore/global/auth/sign/out/SignOutService.java new file mode 100644 index 000000000..1a12ec668 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/sign/out/SignOutService.java @@ -0,0 +1,27 @@ +package com.somemore.global.auth.sign.out; + +import com.somemore.global.auth.jwt.manager.TokenManager; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Slf4j +@Service +@RequiredArgsConstructor +@Transactional +public class SignOutService implements SignOutUseCase { + + private final TokenManager tokenManager; + + @Override + public void signOut( + HttpServletResponse response, + UUID userId) { + + tokenManager.removeRefreshToken(userId.toString()); + } +} diff --git a/src/main/java/com/somemore/global/auth/sign/out/SignOutUseCase.java b/src/main/java/com/somemore/global/auth/sign/out/SignOutUseCase.java new file mode 100644 index 000000000..4a5ca4821 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/sign/out/SignOutUseCase.java @@ -0,0 +1,10 @@ +package com.somemore.global.auth.sign.out; + +import jakarta.servlet.http.HttpServletResponse; + +import java.util.UUID; + +public interface SignOutUseCase { + + void signOut(HttpServletResponse response, UUID userId); +} diff --git a/src/main/java/com/somemore/global/auth/sign/up/SignUpController.java b/src/main/java/com/somemore/global/auth/sign/up/SignUpController.java new file mode 100644 index 000000000..0b278ba2a --- /dev/null +++ b/src/main/java/com/somemore/global/auth/sign/up/SignUpController.java @@ -0,0 +1,27 @@ +package com.somemore.global.auth.sign.up; + +import com.somemore.global.common.response.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +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; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api") +@Tag(name = "SignUp API", description = "유저 회원가입") +public class SignUpController { + + private final SignUpUseCase signUpUseCase; + + @PostMapping("/sign-up") + public ApiResponse signUp( + @RequestBody SignUpRequestDto signUpRequestDto + ) { + signUpUseCase.signUp(signUpRequestDto); + + return ApiResponse.ok("회원가입 되었습니다"); + } +} diff --git a/src/main/java/com/somemore/global/auth/sign/up/SignUpRequestDto.java b/src/main/java/com/somemore/global/auth/sign/up/SignUpRequestDto.java new file mode 100644 index 000000000..34c8f2460 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/sign/up/SignUpRequestDto.java @@ -0,0 +1,23 @@ +package com.somemore.global.auth.sign.up; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; + +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public record SignUpRequestDto( + + @Schema(description = "계정 ID", example = "making") + @NotBlank(message = "계정 ID는 필수 값이며 비어 있을 수 없습니다.") + String accountId, + + @Schema(description = "계정 비밀번호", example = "password") + @NotBlank(message = "계정 비밀번호는 필수 값이며 비어 있을 수 없습니다.") + String accountPassword, + + @Schema(description = "유저 역할", example = "VOLUNTEER", allowableValues = {"VOLUNTEER", "CENTER"}) + @NotBlank(message = "유저 역할은 필수 값이며 비어 있을 수 없습니다.") + String userRole +) { +} \ No newline at end of file diff --git a/src/main/java/com/somemore/global/auth/sign/up/SignUpService.java b/src/main/java/com/somemore/global/auth/sign/up/SignUpService.java new file mode 100644 index 000000000..89c276842 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/sign/up/SignUpService.java @@ -0,0 +1,46 @@ +package com.somemore.global.auth.sign.up; + +import com.somemore.center.usecase.NEWRegisterCenterUseCase; +import com.somemore.user.domain.User; +import com.somemore.user.domain.UserRole; +import com.somemore.user.dto.UserAuthInfo; +import com.somemore.user.service.RegisterUserService; +import com.somemore.volunteer.usecase.NEWRegisterVolunteerUseCase; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +@Transactional +public class SignUpService implements SignUpUseCase { + + private final RegisterUserService registerUserUseCase; + private final NEWRegisterVolunteerUseCase NEWRegisterVolunteerUseCase; + private final NEWRegisterCenterUseCase NEWRegisterCenterUseCase; + + @Override + public void signUp(SignUpRequestDto signUpRequestDto) { + User user = registerUserUseCase.registerLocalUser( + UserAuthInfo.of(signUpRequestDto.accountId(), signUpRequestDto.accountPassword()), + UserRole.from(signUpRequestDto.userRole())); + + // TODO 회원가입 이벤트 발행으로 변경 (봉사자 혹은 기관 등록) + // 임시 로직 + registerVolunteerOrCenter(user); + } + + private void registerVolunteerOrCenter(User user) { + UUID userId = user.getId(); + UserRole role = user.getRole(); + + if (role == UserRole.VOLUNTEER) { + NEWRegisterVolunteerUseCase.register(userId); + return; + } + + NEWRegisterCenterUseCase.register(userId); + } +} diff --git a/src/main/java/com/somemore/global/auth/sign/up/SignUpUseCase.java b/src/main/java/com/somemore/global/auth/sign/up/SignUpUseCase.java new file mode 100644 index 000000000..44e71b39e --- /dev/null +++ b/src/main/java/com/somemore/global/auth/sign/up/SignUpUseCase.java @@ -0,0 +1,6 @@ +package com.somemore.global.auth.sign.up; + +public interface SignUpUseCase { + + void signUp(SignUpRequestDto signUpRequestDto); +} diff --git a/src/main/java/com/somemore/global/auth/signout/service/SignOutService.java b/src/main/java/com/somemore/global/auth/signout/service/SignOutService.java deleted file mode 100644 index 0172f03b7..000000000 --- a/src/main/java/com/somemore/global/auth/signout/service/SignOutService.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.somemore.global.auth.signout.service; - -import com.somemore.global.auth.cookie.CookieUseCase; -import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; -import com.somemore.global.auth.signout.usecase.SignOutUseCase; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Slf4j -@Service -@RequiredArgsConstructor -@Transactional -public class SignOutService implements SignOutUseCase { - - private final CookieUseCase cookieUseCase; - private final RefreshTokenManager refreshTokenManager; - - @Override - public void signOut( - HttpServletResponse response, - String volunteerId) { - - cookieUseCase.deleteAccessToken(response); - refreshTokenManager.removeRefreshToken(volunteerId); - } -} diff --git a/src/main/java/com/somemore/global/auth/signout/usecase/SignOutUseCase.java b/src/main/java/com/somemore/global/auth/signout/usecase/SignOutUseCase.java deleted file mode 100644 index 480d9abe4..000000000 --- a/src/main/java/com/somemore/global/auth/signout/usecase/SignOutUseCase.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.somemore.global.auth.signout.usecase; - -import jakarta.servlet.http.HttpServletResponse; - -public interface SignOutUseCase { - - void signOut(HttpServletResponse response, String volunteerId); -} diff --git a/src/main/java/com/somemore/global/auth/usecase/AuthQueryService.java b/src/main/java/com/somemore/global/auth/usecase/AuthQueryService.java deleted file mode 100644 index 9da0b7180..000000000 --- a/src/main/java/com/somemore/global/auth/usecase/AuthQueryService.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.somemore.global.auth.usecase; - -import com.somemore.global.auth.jwt.domain.EncodedToken; -import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; -import com.somemore.user.domain.UserRole; -import com.somemore.user.usecase.UserQueryUseCase; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.UUID; - -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -public class AuthQueryService implements AuthQueryUseCase { - - private final UserQueryUseCase userQueryUseCase; - private final RefreshTokenManager refreshTokenManager; - - @Override - public UserRole getRoleByUserId(UUID userId) { - return userQueryUseCase.getRoleById(userId); - } - - @Override - public EncodedToken getAccessTokenByUserId(UUID userId) { - return new EncodedToken( - refreshTokenManager.findRefreshTokenByUserId(userId) - .getAccessToken()); - } -} diff --git a/src/main/java/com/somemore/global/auth/usecase/AuthQueryUseCase.java b/src/main/java/com/somemore/global/auth/usecase/AuthQueryUseCase.java deleted file mode 100644 index 74caed416..000000000 --- a/src/main/java/com/somemore/global/auth/usecase/AuthQueryUseCase.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.somemore.global.auth.usecase; - -import com.somemore.global.auth.jwt.domain.EncodedToken; -import com.somemore.user.domain.UserRole; - -import java.util.UUID; - -public interface AuthQueryUseCase { - UserRole getRoleByUserId(UUID userId); - EncodedToken getAccessTokenByUserId(UUID userId); -} diff --git a/src/main/java/com/somemore/global/common/entity/BaseEntity.java b/src/main/java/com/somemore/global/common/entity/BaseEntity.java index 4c2b09468..73594e2d9 100644 --- a/src/main/java/com/somemore/global/common/entity/BaseEntity.java +++ b/src/main/java/com/somemore/global/common/entity/BaseEntity.java @@ -17,7 +17,7 @@ public class BaseEntity { @CreatedDate - @Column(name = "created_at" ,nullable = false, updatable = false) + @Column(name = "created_at", nullable = false, updatable = false) private LocalDateTime createdAt; @LastModifiedDate diff --git a/src/main/java/com/somemore/global/common/event/DomainEventSubType.java b/src/main/java/com/somemore/global/common/event/DomainEventSubType.java index c16328807..175941425 100644 --- a/src/main/java/com/somemore/global/common/event/DomainEventSubType.java +++ b/src/main/java/com/somemore/global/common/event/DomainEventSubType.java @@ -7,8 +7,7 @@ @RequiredArgsConstructor public enum DomainEventSubType { CREATE_RECRUIT_BOARD("모집 글 등록"), - VOLUNTEER_HOURS_SETTLE("봉사 시간 정산") - ; + VOLUNTEER_HOURS_SETTLE("봉사 시간 정산"); private final String description; diff --git a/src/main/java/com/somemore/global/common/response/ApiResponse.java b/src/main/java/com/somemore/global/common/response/ApiResponse.java index c88f32b39..427ddf281 100644 --- a/src/main/java/com/somemore/global/common/response/ApiResponse.java +++ b/src/main/java/com/somemore/global/common/response/ApiResponse.java @@ -3,11 +3,14 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.http.HttpStatus; @NoArgsConstructor @Getter public class ApiResponse { + public static final String EMPTY = ""; + @Schema(description = "응답 상태 코드. 성공 시 200, 실패 시 오류 코드", example = "200") private int code; @Schema(description = "응답에 대한 메시지. 요청 성공/실패에 대한 설명", example = "요청 성공") @@ -15,16 +18,20 @@ public class ApiResponse { @Schema(description = "API 요청 처리 결과로 반환되는 데이터") private T data; - public static ApiResponse ok(int status, T data, String message) { - return new ApiResponse<>(status, message, data); + public static ApiResponse ok(String message) { + return new ApiResponse<>(HttpStatus.OK.value(), message, ""); + } + + public static ApiResponse ok(T data, String message) { + return new ApiResponse<>(HttpStatus.OK.value(), message, data); } public static ApiResponse ok(int status, String message) { - return new ApiResponse<>(status, message, ""); + return new ApiResponse<>(status, message, EMPTY); } - public static ApiResponse ok(String message) { - return new ApiResponse<>(200, message, ""); + public static ApiResponse ok(int status, T data, String message) { + return new ApiResponse<>(status, message, data); } public ApiResponse(int code, String message, T data) { diff --git a/src/main/java/com/somemore/global/exception/BadRequestException.java b/src/main/java/com/somemore/global/exception/BadRequestException.java index 1f0d08221..953bd7357 100644 --- a/src/main/java/com/somemore/global/exception/BadRequestException.java +++ b/src/main/java/com/somemore/global/exception/BadRequestException.java @@ -1,8 +1,6 @@ package com.somemore.global.exception; - - -public class BadRequestException extends RuntimeException{ +public class BadRequestException extends RuntimeException { public BadRequestException(final String message) { super(message); diff --git a/src/main/java/com/somemore/global/exception/DuplicateException.java b/src/main/java/com/somemore/global/exception/DuplicateException.java index f9ae30685..580e3f960 100644 --- a/src/main/java/com/somemore/global/exception/DuplicateException.java +++ b/src/main/java/com/somemore/global/exception/DuplicateException.java @@ -1,10 +1,11 @@ package com.somemore.global.exception; -public class DuplicateException extends RuntimeException{ +public class DuplicateException extends RuntimeException { public DuplicateException(final ExceptionMessage message) { super(message.getMessage()); } + public DuplicateException(final String message) { super(message); } diff --git a/src/main/java/com/somemore/global/exception/ImageUploadException.java b/src/main/java/com/somemore/global/exception/ImageUploadException.java index d314407ea..c91ba4b40 100644 --- a/src/main/java/com/somemore/global/exception/ImageUploadException.java +++ b/src/main/java/com/somemore/global/exception/ImageUploadException.java @@ -1,6 +1,6 @@ package com.somemore.global.exception; -public class ImageUploadException extends RuntimeException{ +public class ImageUploadException extends RuntimeException { public ImageUploadException(String message) { super(message); diff --git a/src/main/java/com/somemore/global/exception/NoSuchElementException.java b/src/main/java/com/somemore/global/exception/NoSuchElementException.java index 579c7c5f7..8d7c46ce1 100644 --- a/src/main/java/com/somemore/global/exception/NoSuchElementException.java +++ b/src/main/java/com/somemore/global/exception/NoSuchElementException.java @@ -1,6 +1,6 @@ package com.somemore.global.exception; -public class NoSuchElementException extends RuntimeException{ +public class NoSuchElementException extends RuntimeException { public NoSuchElementException(final ExceptionMessage message) { super(message.getMessage()); } diff --git a/src/main/java/com/somemore/global/imageupload/converter/MultipartJackson2HttpMessageConverter.java b/src/main/java/com/somemore/global/imageupload/converter/MultipartJackson2HttpMessageConverter.java index 2472cfef8..e468258a0 100644 --- a/src/main/java/com/somemore/global/imageupload/converter/MultipartJackson2HttpMessageConverter.java +++ b/src/main/java/com/somemore/global/imageupload/converter/MultipartJackson2HttpMessageConverter.java @@ -1,11 +1,12 @@ package com.somemore.global.imageupload.converter; import com.fasterxml.jackson.databind.ObjectMapper; -import java.lang.reflect.Type; import org.springframework.http.MediaType; import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; import org.springframework.stereotype.Component; +import java.lang.reflect.Type; + @Component public class MultipartJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter { diff --git a/src/main/java/com/somemore/global/imageupload/service/ImageUploadService.java b/src/main/java/com/somemore/global/imageupload/service/ImageUploadService.java index 1352cc65f..cc0deb65d 100644 --- a/src/main/java/com/somemore/global/imageupload/service/ImageUploadService.java +++ b/src/main/java/com/somemore/global/imageupload/service/ImageUploadService.java @@ -2,9 +2,9 @@ import com.somemore.global.exception.ImageUploadException; import com.somemore.global.imageupload.dto.ImageUploadRequestDto; +import com.somemore.global.imageupload.usecase.ImageUploadUseCase; import com.somemore.global.imageupload.util.ImageUploadUtils; import com.somemore.global.imageupload.validator.ImageUploadValidator; -import com.somemore.global.imageupload.usecase.ImageUploadUseCase; import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/com/somemore/global/imageupload/validator/DefaultImageUploadValidator.java b/src/main/java/com/somemore/global/imageupload/validator/DefaultImageUploadValidator.java index cef7eb57b..6e623d672 100644 --- a/src/main/java/com/somemore/global/imageupload/validator/DefaultImageUploadValidator.java +++ b/src/main/java/com/somemore/global/imageupload/validator/DefaultImageUploadValidator.java @@ -4,7 +4,8 @@ import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; -import static com.somemore.global.exception.ExceptionMessage.*; +import static com.somemore.global.exception.ExceptionMessage.FILE_SIZE_EXCEEDED; +import static com.somemore.global.exception.ExceptionMessage.INVALID_FILE_TYPE; @Component public class DefaultImageUploadValidator implements ImageUploadValidator { diff --git a/src/main/java/com/somemore/global/imageupload/validator/ImageUploadValidator.java b/src/main/java/com/somemore/global/imageupload/validator/ImageUploadValidator.java index 928727d6f..a8f9f8742 100644 --- a/src/main/java/com/somemore/global/imageupload/validator/ImageUploadValidator.java +++ b/src/main/java/com/somemore/global/imageupload/validator/ImageUploadValidator.java @@ -5,6 +5,8 @@ public interface ImageUploadValidator { void validateFileSize(MultipartFile file); + void validateFileType(MultipartFile file); + boolean isEmptyFile(MultipartFile file); } diff --git a/src/main/java/com/somemore/global/sse/domain/SseEventType.java b/src/main/java/com/somemore/global/sse/domain/SseEventType.java index dedd1c1a3..df14c12a1 100644 --- a/src/main/java/com/somemore/global/sse/domain/SseEventType.java +++ b/src/main/java/com/somemore/global/sse/domain/SseEventType.java @@ -7,8 +7,7 @@ @RequiredArgsConstructor public enum SseEventType { INITIALIZATION("초기화"), - NOTIFICATION("알림") - ; + NOTIFICATION("알림"); private final String description; } diff --git a/src/main/java/com/somemore/global/sse/repository/EmitterRepository.java b/src/main/java/com/somemore/global/sse/repository/EmitterRepository.java index af712de3d..2bb1c81dd 100644 --- a/src/main/java/com/somemore/global/sse/repository/EmitterRepository.java +++ b/src/main/java/com/somemore/global/sse/repository/EmitterRepository.java @@ -1,10 +1,10 @@ package com.somemore.global.sse.repository; +import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; + import java.util.Map; import java.util.UUID; -import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; - public interface EmitterRepository { SseEmitter save(String emitterId, SseEmitter sseEmitter); diff --git a/src/main/java/com/somemore/user/controller/UserQueryController.java b/src/main/java/com/somemore/user/controller/UserQueryController.java new file mode 100644 index 000000000..e72c2d18f --- /dev/null +++ b/src/main/java/com/somemore/user/controller/UserQueryController.java @@ -0,0 +1,31 @@ +package com.somemore.user.controller; + +import com.somemore.global.common.response.ApiResponse; +import com.somemore.user.usecase.UserQueryUseCase; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "User Query API", description = "유저 조회 관련 API") +@RestController +@Slf4j +@RequiredArgsConstructor +@RequestMapping("/api/user") +public class UserQueryController { + + private final UserQueryUseCase userQueryUseCase; + + @GetMapping("/exists/") + @Operation(summary = "아이디 중복 확인", description = "입력한 아이디가 중복되었는지 확인합니다.") + public ApiResponse checkUserExists( + @RequestParam String accountId + ) { + boolean isAccountIdDuplicate = userQueryUseCase.isDuplicateAccountId(accountId); + return ApiResponse.ok(isAccountIdDuplicate, "중복 조회 완료"); + } +} diff --git a/src/main/java/com/somemore/user/domain/User.java b/src/main/java/com/somemore/user/domain/User.java index 2746f5702..acebfaa13 100644 --- a/src/main/java/com/somemore/user/domain/User.java +++ b/src/main/java/com/somemore/user/domain/User.java @@ -31,26 +31,26 @@ public class User extends BaseEntity { @Column(name = "account_id", nullable = false) private String accountId; - @Column(name = "password", nullable = false) - private String password; + @Column(name = "account_password", nullable = false) + private String accountPassword; @Enumerated(EnumType.STRING) @Column(name = "role", nullable = false) private UserRole role; - public static User from(UserAuthInfo userAuthInfo, UserRole role) { + public static User of(UserAuthInfo userAuthInfo, UserRole role) { return User.builder() .accountId(userAuthInfo.accountId()) - .password(userAuthInfo.password()) + .accountPassword(userAuthInfo.accountPassword()) .role(role) .build(); } @Builder - private User(String accountId, String password, UserRole role) { + private User(String accountId, String accountPassword, UserRole role) { this.accountId = accountId; - this.password = password; + this.accountPassword = accountPassword; this.role = role; } } diff --git a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java index b23e49a44..101f8e87d 100644 --- a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java +++ b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java @@ -12,7 +12,6 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import org.apache.commons.lang3.StringUtils; import java.util.UUID; @@ -30,8 +29,11 @@ public class UserCommonAttribute extends BaseEntity { @Column(name = "user_id", nullable = false) private UUID userId; - @Column(name = "nickname", nullable = false) - private String nickname; + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "contact_number", nullable = false) + private String contactNumber; @Column(name = "img_url", nullable = false) private String imgUrl; @@ -47,10 +49,11 @@ public void customize() { this.isCustomized = true; } - public static UserCommonAttribute createDefault(UUID userId) { + public static UserCommonAttribute createDefault(UUID userId, UserRole role) { return UserCommonAttribute.builder() .userId(userId) - .nickname(String.valueOf(UUID.randomUUID()).substring(0, 8)) + .name(role.getDescription() + UUID.randomUUID().toString().substring(0, 8)) + .contactNumber("") .imgUrl(ImageUploadService.DEFAULT_IMAGE_URL) .introduce("") .isCustomized(false) @@ -58,9 +61,10 @@ public static UserCommonAttribute createDefault(UUID userId) { } @Builder - private UserCommonAttribute(UUID userId, String nickname, String imgUrl, String introduce, boolean isCustomized) { + private UserCommonAttribute(UUID userId, String name, String contactNumber, String imgUrl, String introduce, boolean isCustomized) { this.userId = userId; - this.nickname = nickname; + this.name = name; + this.contactNumber = contactNumber; this.imgUrl = imgUrl; this.introduce = introduce; this.isCustomized = isCustomized; diff --git a/src/main/java/com/somemore/user/domain/UserRole.java b/src/main/java/com/somemore/user/domain/UserRole.java index 642a92c56..b3897e4df 100644 --- a/src/main/java/com/somemore/user/domain/UserRole.java +++ b/src/main/java/com/somemore/user/domain/UserRole.java @@ -2,17 +2,21 @@ import com.somemore.global.auth.jwt.exception.JwtErrorType; import com.somemore.global.auth.jwt.exception.JwtException; +import lombok.Getter; import lombok.RequiredArgsConstructor; import org.springframework.security.core.GrantedAuthority; @RequiredArgsConstructor public enum UserRole implements GrantedAuthority { - VOLUNTEER("ROLE_VOLUNTEER"), - CENTER("ROLE_CENTER"), - ADMIN("ROLE_ADMIN"); + VOLUNTEER("ROLE_VOLUNTEER", "봉사자"), + CENTER("ROLE_CENTER", "기관"), + ADMIN("ROLE_ADMIN", "관리자"); private final String authority; + @Getter + private final String description; + @Override public String getAuthority() { return this.authority; @@ -30,4 +34,6 @@ public static UserRole from(String role) { } throw new JwtException(JwtErrorType.UNKNOWN_ERROR); } + + } diff --git a/src/main/java/com/somemore/user/dto/UserAuthInfo.java b/src/main/java/com/somemore/user/dto/UserAuthInfo.java index b210496f0..674dc26a6 100644 --- a/src/main/java/com/somemore/user/dto/UserAuthInfo.java +++ b/src/main/java/com/somemore/user/dto/UserAuthInfo.java @@ -5,11 +5,15 @@ import java.util.UUID; public record UserAuthInfo(String accountId, - String password) { + String accountPassword) { + + public static UserAuthInfo of(String accountId, String accountPassword) { + return new UserAuthInfo(accountId, accountPassword); + } public static UserAuthInfo createForOAuth(OAuthProvider provider) { String accountId = provider.getProviderName() + UUID.randomUUID(); - String password = String.valueOf(UUID.randomUUID()); - return new UserAuthInfo(accountId, password); + String accountPassword = String.valueOf(UUID.randomUUID()); + return new UserAuthInfo(accountId, accountPassword); } } diff --git a/src/main/java/com/somemore/user/repository/user/UserRepository.java b/src/main/java/com/somemore/user/repository/user/UserRepository.java index 238ffddb1..a9b6b5a7e 100644 --- a/src/main/java/com/somemore/user/repository/user/UserRepository.java +++ b/src/main/java/com/somemore/user/repository/user/UserRepository.java @@ -15,4 +15,6 @@ public interface UserRepository { Optional findByAccountId(String accountId); User save(User user); + + boolean existsByAccountId(String accountId); } diff --git a/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java b/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java index f08d4e3e2..1f56208de 100644 --- a/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java +++ b/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java @@ -56,6 +56,16 @@ public User save(User user) { return userJpaRepository.save(user); } + @Override + public boolean existsByAccountId(String accountId) { + return queryFactory.select(user.accountId) + .from(user) + .where( + user.accountId.eq(accountId), + isNotDeleted()) + .fetchFirst() != null; + } + private static BooleanExpression isNotDeleted() { return user.deleted.eq(false); } diff --git a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java index 3b802fe5a..ec73318f1 100644 --- a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java +++ b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java @@ -8,6 +8,8 @@ public interface UserCommonAttributeRepository { Optional findByUserId(UUID userId); + UserCommonAttribute save(UserCommonAttribute userCommonAttribute); + Optional findIsCustomizedByUserId(UUID userId); } diff --git a/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepository.java b/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepository.java index 45bae3d88..03d93ba6f 100644 --- a/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepository.java +++ b/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepository.java @@ -8,5 +8,6 @@ public interface UserSettingRepository { Optional findByUserId(UUID userId); + UserSetting save(UserSetting userSetting); } diff --git a/src/main/java/com/somemore/user/service/RegisterUserService.java b/src/main/java/com/somemore/user/service/RegisterUserService.java index 18b988194..fa44e3c34 100644 --- a/src/main/java/com/somemore/user/service/RegisterUserService.java +++ b/src/main/java/com/somemore/user/service/RegisterUserService.java @@ -1,9 +1,9 @@ package com.somemore.user.service; -import com.somemore.user.domain.UserRole; import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; import com.somemore.user.domain.User; import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.user.domain.UserRole; import com.somemore.user.domain.UserSetting; import com.somemore.user.dto.UserAuthInfo; import com.somemore.user.repository.user.UserRepository; @@ -39,14 +39,14 @@ public User registerLocalUser(UserAuthInfo userAuthInfo, UserRole role) { } private User createAndRegisterUser(UserRole role, UserAuthInfo userAuthInfo) { - User user = User.from(userAuthInfo, role); + User user = User.of(userAuthInfo, role); userRepository.save(user); UUID userId = user.getId(); UserSetting userSetting = UserSetting.from(userId); userSettingRepository.save(userSetting); - UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId); + UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId, role); userCommonAttributeRepository.save(userCommonAttribute); return user; diff --git a/src/main/java/com/somemore/user/service/UserQueryService.java b/src/main/java/com/somemore/user/service/UserQueryService.java index 9f026c420..2ce9ebf30 100644 --- a/src/main/java/com/somemore/user/service/UserQueryService.java +++ b/src/main/java/com/somemore/user/service/UserQueryService.java @@ -55,4 +55,9 @@ public boolean getIsCustomizedByUserId(UUID userId) { .orElseThrow(() -> new NoSuchElementException(NOT_EXIST_USER)); } + @Override + public boolean isDuplicateAccountId(String accountId) { + return userRepository.existsByAccountId(accountId); + } + } diff --git a/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java b/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java index c34994ada..081eecaff 100644 --- a/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java +++ b/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java @@ -1,11 +1,12 @@ package com.somemore.user.usecase; -import com.somemore.user.domain.UserRole; import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; import com.somemore.user.domain.User; +import com.somemore.user.domain.UserRole; import com.somemore.user.dto.UserAuthInfo; public interface RegisterUserUseCase { User registerOAuthUser(CommonOAuthInfo commonOAuthInfo, UserRole role); + User registerLocalUser(UserAuthInfo userAuthInfo, UserRole role); } diff --git a/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java b/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java index 75339fab1..f41056b07 100644 --- a/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java +++ b/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java @@ -9,8 +9,14 @@ public interface UserQueryUseCase { User getById(UUID id); + UserRole getRoleById(UUID userId); + User getByAccountId(String accountId); + UserCommonAttribute getCommonAttributeByUserId(UUID userId); + boolean getIsCustomizedByUserId(UUID userId); + + boolean isDuplicateAccountId(String accountId); } diff --git a/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java b/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java new file mode 100644 index 000000000..0a178c674 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java @@ -0,0 +1,67 @@ +package com.somemore.volunteer.domain; + +import com.somemore.domains.volunteer.domain.Gender; +import com.somemore.domains.volunteer.domain.Tier; +import com.somemore.global.common.entity.BaseEntity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "new_volunteer") // TODO prefix 삭제 +public class NEWVolunteer extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + @Column(name = "id", nullable = false, columnDefinition = "BINARY(16)") + private UUID id; + + @Column(name = "user_id", nullable = false, columnDefinition = "BINARY(16)") + private UUID userId; + + @Column(name = "nickname", nullable = false) + private String nickname; + + @Enumerated(EnumType.STRING) + @Column(name = "gender", nullable = false, length = 10) + private Gender gender; + + @Enumerated(EnumType.STRING) + @Column(name = "tier", nullable = false, length = 20) + private Tier tier; + + @Builder + private NEWVolunteer( + UUID userId, + String nickname, + Gender gender, + Tier tier + ) { + this.userId = userId; + this.nickname = nickname; + this.gender = gender; + this.tier = tier; + } + + public static NEWVolunteer createDefault(UUID userId) { + return NEWVolunteer.builder() + .userId(userId) + .nickname(userId.toString().substring(0, 8)) + .gender(Gender.getDefault()) + .tier(Tier.getDefault()) + .build(); + } +} diff --git a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerJpaRepository.java b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerJpaRepository.java new file mode 100644 index 000000000..b5f5ae4ad --- /dev/null +++ b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerJpaRepository.java @@ -0,0 +1,11 @@ +package com.somemore.volunteer.repository; + +import com.somemore.volunteer.domain.NEWVolunteer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.UUID; + +@Repository("newVolunteerJpaRepository") +public interface NEWVolunteerJpaRepository extends JpaRepository { +} diff --git a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java new file mode 100644 index 000000000..4189070f0 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java @@ -0,0 +1,15 @@ +package com.somemore.volunteer.repository; + +import com.somemore.volunteer.domain.NEWVolunteer; + +import java.util.Optional; +import java.util.UUID; + +public interface NEWVolunteerRepository { + + NEWVolunteer save(NEWVolunteer volunteer); + + Optional findById(UUID id); + + Optional findByUserId(UUID userId); +} diff --git a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java new file mode 100644 index 000000000..f64a15791 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java @@ -0,0 +1,54 @@ +package com.somemore.volunteer.repository; + +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.volunteer.domain.NEWVolunteer; +import com.somemore.volunteer.domain.QNEWVolunteer; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +import java.util.Optional; +import java.util.UUID; + +@Repository("newVolunteerRepository") +@RequiredArgsConstructor +public class NEWVolunteerRepositoryImpl implements NEWVolunteerRepository { + + private final NEWVolunteerJpaRepository NEWVolunteerJpaRepository; + private final JPAQueryFactory queryFactory; + + private static final QNEWVolunteer volunteer = QNEWVolunteer.nEWVolunteer; + + @Override + public NEWVolunteer save(NEWVolunteer volunteer) { + return NEWVolunteerJpaRepository.save(volunteer); + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable( + queryFactory.selectFrom(volunteer) + .where( + volunteer.id.eq(id), + isNotDeleted() + ) + .fetchOne() + ); + } + + @Override + public Optional findByUserId(UUID userId) { + return Optional.ofNullable( + queryFactory.selectFrom(volunteer) + .where( + volunteer.userId.eq(userId), + isNotDeleted() + ) + .fetchOne() + ); + } + + private static BooleanExpression isNotDeleted() { + return volunteer.deleted.eq(false); + } +} diff --git a/src/main/java/com/somemore/volunteer/service/NEWRegisterVolunteerService.java b/src/main/java/com/somemore/volunteer/service/NEWRegisterVolunteerService.java new file mode 100644 index 000000000..b6cfd061e --- /dev/null +++ b/src/main/java/com/somemore/volunteer/service/NEWRegisterVolunteerService.java @@ -0,0 +1,25 @@ +package com.somemore.volunteer.service; + +import com.somemore.volunteer.domain.NEWVolunteer; +import com.somemore.volunteer.repository.NEWVolunteerRepository; +import com.somemore.volunteer.usecase.NEWRegisterVolunteerUseCase; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +@Transactional +public class NEWRegisterVolunteerService implements NEWRegisterVolunteerUseCase { + + private final NEWVolunteerRepository NEWVolunteerRepository; + + @Override + public void register(UUID userId) { + NEWVolunteer volunteer = NEWVolunteer.createDefault(userId); + + NEWVolunteerRepository.save(volunteer); + } +} diff --git a/src/main/java/com/somemore/volunteer/usecase/NEWRegisterVolunteerUseCase.java b/src/main/java/com/somemore/volunteer/usecase/NEWRegisterVolunteerUseCase.java new file mode 100644 index 000000000..14b665609 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/usecase/NEWRegisterVolunteerUseCase.java @@ -0,0 +1,8 @@ +package com.somemore.volunteer.usecase; + +import java.util.UUID; + +public interface NEWRegisterVolunteerUseCase { + + void register(UUID userId); +} diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 3f246af78..6e29d61de 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -1,8 +1,8 @@ - - + + @@ -45,7 +45,8 @@ true @@ -67,17 +68,17 @@ - - - + + + - - + + - - - + + + diff --git a/src/test/java/com/somemore/center/repository/NEWCenterRepositoryImplTest.java b/src/test/java/com/somemore/center/repository/NEWCenterRepositoryImplTest.java new file mode 100644 index 000000000..e18244c5d --- /dev/null +++ b/src/test/java/com/somemore/center/repository/NEWCenterRepositoryImplTest.java @@ -0,0 +1,39 @@ +package com.somemore.center.repository; + +import com.somemore.center.domain.NEWCenter; +import com.somemore.support.IntegrationTestSupport; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +@Transactional +class NEWCenterRepositoryImplTest extends IntegrationTestSupport { + + @Autowired + private NEWCenterRepositoryImpl centerRepository; + + @DisplayName("유저 아이디로 기관을 등록할 수 있다.") + @Test + void saveVolunteerByUserId() { + // given + UUID userId = UUID.randomUUID(); + NEWCenter center = NEWCenter.createDefault(userId); + + // when + centerRepository.save(center); + + // then + NEWCenter centerByUserId = centerRepository.findByUserId(userId).orElseThrow(); + NEWCenter centerById = centerRepository.findById(center.getId()).orElseThrow(); + + assertThat(center) + .isEqualTo(centerByUserId) + .isEqualTo(centerById); + + } +} diff --git a/src/test/java/com/somemore/center/service/NEWRegisterCenterServiceTest.java b/src/test/java/com/somemore/center/service/NEWRegisterCenterServiceTest.java new file mode 100644 index 000000000..8293a18b7 --- /dev/null +++ b/src/test/java/com/somemore/center/service/NEWRegisterCenterServiceTest.java @@ -0,0 +1,39 @@ +package com.somemore.center.service; + +import com.somemore.center.domain.NEWCenter; +import com.somemore.center.repository.NEWCenterRepository; +import com.somemore.support.IntegrationTestSupport; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +@Transactional +class NEWRegisterCenterServiceTest extends IntegrationTestSupport { + + @Autowired + private NEWRegisterCenterService registerCenterService; + + @Autowired + private NEWCenterRepository centerRepository; + + @Test + @DisplayName("유저 아이디로 센터가 등록될 수 있다.") + void registerByUserId() { + // given + UUID userId = UUID.randomUUID(); + + // when + registerCenterService.register(userId); + + // then + Optional foundCenter = centerRepository.findByUserId(userId); + assertThat(foundCenter).isNotEmpty(); + } + +} \ No newline at end of file diff --git a/src/test/java/com/somemore/domains/center/domain/CenterTest.java b/src/test/java/com/somemore/domains/center/domain/CenterTest.java index b7b9bf808..6a9f84d53 100644 --- a/src/test/java/com/somemore/domains/center/domain/CenterTest.java +++ b/src/test/java/com/somemore/domains/center/domain/CenterTest.java @@ -13,8 +13,6 @@ class CenterTest { private static final String IMG_URL = "http://example.com/image.jpg"; private static final String INTRODUCE = "우리는 서울 도서관입니다."; private static final String HOMEPAGE_LINK = "http://testcenter.com"; - private static final String ACCOUNT_ID = "testId"; - private static final String ACCOUNT_PW = "testPw"; @DisplayName("Center 엔티티를 생성할 수 있다.") @Test @@ -25,9 +23,7 @@ void create() { CONTACT_NUMBER, IMG_URL, INTRODUCE, - HOMEPAGE_LINK, - ACCOUNT_ID, - ACCOUNT_PW + HOMEPAGE_LINK ); //then @@ -36,9 +32,7 @@ void create() { () -> assertThat(center.getContactNumber()).isEqualTo(CONTACT_NUMBER), () -> assertThat(center.getImgUrl()).isEqualTo(IMG_URL), () -> assertThat(center.getIntroduce()).isEqualTo(INTRODUCE), - () -> assertThat(center.getHomepageLink()).isEqualTo(HOMEPAGE_LINK), - () -> assertThat(center.getAccountId()).isEqualTo(ACCOUNT_ID), - () -> assertThat(center.getAccountPw()).isEqualTo(ACCOUNT_PW) + () -> assertThat(center.getHomepageLink()).isEqualTo(HOMEPAGE_LINK) ); } diff --git a/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java b/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java index 557f8520c..5bc879a2b 100644 --- a/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java +++ b/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java @@ -36,8 +36,6 @@ void findById() { assertThat(foundCenter.get().getImgUrl()).isEqualTo("http://example.com/image.jpg"); assertThat(foundCenter.get().getIntroduce()).isEqualTo("기관 소개 내용"); assertThat(foundCenter.get().getHomepageLink()).isEqualTo("http://example.com"); - assertThat(foundCenter.get().getAccountId()).isEqualTo("account123"); - assertThat(foundCenter.get().getAccountPw()).isEqualTo("password123"); } @DisplayName("기관 id로 기관이 존재하는지 확인할 수 있다.") @@ -67,71 +65,13 @@ void notExistsById() { assertThat(isExist).isFalse(); } - @DisplayName("기관 계정 ID로 기관 ID를 조회할 수 있다.") - @Test - void findIdByAccountId() { - //given - Center center = createCenter(); - centerRepository.save(center); - - //when - UUID foundId = centerRepository.findIdByAccountId("account123"); - - //then - assertThat(foundId).isNotNull(); - assertThat(foundId).isEqualTo(center.getId()); - } - - @DisplayName("기관 계정 ID로 비밀번호를 조회할 수 있다.") - @Test - void findPasswordByAccountId() { - //given - Center center = createCenter(); - centerRepository.save(center); - - //when - String foundPassword = centerRepository.findPasswordByAccountId("account123"); - - //then - assertThat(foundPassword).isNotNull(); - assertThat(foundPassword).isEqualTo("password123"); - } - - @DisplayName("존재하지 않는 계정 ID로 기관 ID 조회 시 null을 반환한다.") - @Test - void findIdByNonExistentAccountId() { - //given - String nonExistentAccountId = "nonExistentAccount123"; - - //when - UUID foundId = centerRepository.findIdByAccountId(nonExistentAccountId); - - //then - assertThat(foundId).isNull(); - } - - @DisplayName("존재하지 않는 계정 ID로 비밀번호 조회 시 null을 반환한다.") - @Test - void findPasswordByNonExistentAccountId() { - //given - String nonExistentAccountId = "nonExistentAccount123"; - - //when - String foundPassword = centerRepository.findPasswordByAccountId(nonExistentAccountId); - - //then - assertThat(foundPassword).isNull(); - } - private static Center createCenter() { return Center.create( "기본 기관 이름", "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); } } diff --git a/src/test/java/com/somemore/domains/center/service/command/CreatePreferItemServiceTest.java b/src/test/java/com/somemore/domains/center/service/command/CreatePreferItemServiceTest.java index f8bcef244..fb949e9b0 100644 --- a/src/test/java/com/somemore/domains/center/service/command/CreatePreferItemServiceTest.java +++ b/src/test/java/com/somemore/domains/center/service/command/CreatePreferItemServiceTest.java @@ -82,9 +82,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerRepository.save(center); diff --git a/src/test/java/com/somemore/domains/center/service/command/DeletePreferItemServiceTest.java b/src/test/java/com/somemore/domains/center/service/command/DeletePreferItemServiceTest.java index dc427f1d7..7148f09e0 100644 --- a/src/test/java/com/somemore/domains/center/service/command/DeletePreferItemServiceTest.java +++ b/src/test/java/com/somemore/domains/center/service/command/DeletePreferItemServiceTest.java @@ -92,9 +92,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerRepository.save(center); diff --git a/src/test/java/com/somemore/domains/center/service/query/CenterQueryServiceTest.java b/src/test/java/com/somemore/domains/center/service/query/CenterQueryServiceTest.java index 4b8c509f0..058077268 100644 --- a/src/test/java/com/somemore/domains/center/service/query/CenterQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/center/service/query/CenterQueryServiceTest.java @@ -125,9 +125,7 @@ void validateExistingCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); Center savedCenter = centerRepository.save(center); @@ -144,9 +142,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); } } diff --git a/src/test/java/com/somemore/domains/center/service/query/CenterSignServiceTest.java b/src/test/java/com/somemore/domains/center/service/query/CenterSignServiceTest.java deleted file mode 100644 index cd3b3342c..000000000 --- a/src/test/java/com/somemore/domains/center/service/query/CenterSignServiceTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.somemore.domains.center.service.query; - -import com.somemore.domains.center.domain.Center; -import com.somemore.domains.center.repository.center.CenterJpaRepository; -import com.somemore.domains.center.repository.center.CenterRepository; -import com.somemore.global.exception.BadRequestException; -import com.somemore.support.IntegrationTestSupport; -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.transaction.annotation.Transactional; - -import java.util.UUID; - -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_CENTER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -@Transactional -class CenterSignServiceTest extends IntegrationTestSupport { - - @Autowired - private CenterSignService centerSignService; - - @Autowired - private CenterRepository centerRepository; - - @Autowired - private CenterJpaRepository centerJpaRepository; - - @BeforeEach - void cleanUp() { - centerJpaRepository.deleteAll(); - } - - @DisplayName("계정 ID로 센터 ID를 조회할 수 있다.") - @Test - void getIdByAccountId() { - //given - Center center = createCenter(); - centerRepository.save(center); - - //when - UUID centerId = centerSignService.getIdByAccountId("account123"); - - //then - assertThat(centerId) - .isNotNull() - .isEqualTo(center.getId()); - } - - @DisplayName("존재하지 않는 계정 ID로 센터 ID를 조회하면 예외가 발생한다.") - @Test - void getIdByNonExistentAccountId() { - //given - String nonExistentAccountId = "nonExistentAccount123"; - - //when - //then - assertThatThrownBy(() -> centerSignService.getIdByAccountId(nonExistentAccountId)) - .isInstanceOf(BadRequestException.class) - .hasMessage(NOT_EXISTS_CENTER.getMessage()); - } - - @DisplayName("계정 ID로 비밀번호를 조회할 수 있다.") - @Test - void getPasswordByAccountId() { - //given - Center center = createCenter(); - centerRepository.save(center); - - //when - String password = centerSignService.getPasswordByAccountId("account123"); - - //then - assertThat(password) - .isNotNull() - .isEqualTo("password123"); - } - - @DisplayName("존재하지 않는 계정 ID로 비밀번호를 조회하면 예외가 발생한다.") - @Test - void getPasswordByNonExistentAccountId() { - //given - String nonExistentAccountId = "nonExistentAccount123"; - - //when - //then - assertThatThrownBy(() -> centerSignService.getPasswordByAccountId(nonExistentAccountId)) - .isInstanceOf(BadRequestException.class) - .hasMessage(NOT_EXISTS_CENTER.getMessage()); - } - - private static Center createCenter() { - return Center.create( - "기본 기관 이름", - "010-1234-5678", - "http://example.com/image.jpg", - "기관 소개 내용", - "http://example.com", - "account123", - "password123" - ); - } -} diff --git a/src/test/java/com/somemore/domains/interestcenter/repository/InterestCenterRepositoryImplTest.java b/src/test/java/com/somemore/domains/interestcenter/repository/InterestNEWCenterRepositoryImplTest.java similarity index 94% rename from src/test/java/com/somemore/domains/interestcenter/repository/InterestCenterRepositoryImplTest.java rename to src/test/java/com/somemore/domains/interestcenter/repository/InterestNEWCenterRepositoryImplTest.java index 9b38dbaac..bc139697a 100644 --- a/src/test/java/com/somemore/domains/interestcenter/repository/InterestCenterRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/interestcenter/repository/InterestNEWCenterRepositoryImplTest.java @@ -13,7 +13,7 @@ import static org.assertj.core.api.Assertions.assertThat; @Transactional -class InterestCenterRepositoryImplTest extends IntegrationTestSupport { +class InterestNEWCenterRepositoryImplTest extends IntegrationTestSupport { @Autowired private InterestCenterRepository interestCenterRepository; diff --git a/src/test/java/com/somemore/domains/interestcenter/service/CancelInterestCenterServiceTest.java b/src/test/java/com/somemore/domains/interestcenter/service/CancelInterestCenterServiceTest.java index 7f3b56d00..61b9c3b94 100644 --- a/src/test/java/com/somemore/domains/interestcenter/service/CancelInterestCenterServiceTest.java +++ b/src/test/java/com/somemore/domains/interestcenter/service/CancelInterestCenterServiceTest.java @@ -84,9 +84,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerRepository.save(center); diff --git a/src/test/java/com/somemore/domains/interestcenter/service/InterestCenterQueryServiceTest.java b/src/test/java/com/somemore/domains/interestcenter/service/InterestCenterQueryServiceTest.java index ebba619b9..2bde83904 100644 --- a/src/test/java/com/somemore/domains/interestcenter/service/InterestCenterQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/interestcenter/service/InterestCenterQueryServiceTest.java @@ -125,18 +125,13 @@ void getVolunteerIdsByCenterId_ReturnsEmptyList_WhenNoVolunteers() { assertThat(result).isEmpty(); } - - - private Center createCenter() { return Center.create( "기본 기관 이름", "010-1234-5678", "http://image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); } diff --git a/src/test/java/com/somemore/domains/interestcenter/service/RegisterInterestCenterServiceTest.java b/src/test/java/com/somemore/domains/interestcenter/service/RegisterInterestCenterServiceTest.java index 2c84a7246..611b8b640 100644 --- a/src/test/java/com/somemore/domains/interestcenter/service/RegisterInterestCenterServiceTest.java +++ b/src/test/java/com/somemore/domains/interestcenter/service/RegisterInterestCenterServiceTest.java @@ -96,9 +96,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerRepository.save(center); diff --git a/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java b/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java index 64bd9cb50..6a1085d2c 100644 --- a/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java @@ -143,9 +143,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerJpaRepository.save(center); diff --git a/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java b/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java index e1cbb26a6..059d42bea 100644 --- a/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java @@ -181,9 +181,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerJpaRepository.save(center); diff --git a/src/test/java/com/somemore/domains/note/service/SendNoteToCenterServiceTest.java b/src/test/java/com/somemore/domains/note/service/SendNoteToCenterServiceTest.java index 23ab4a795..0d6445159 100644 --- a/src/test/java/com/somemore/domains/note/service/SendNoteToCenterServiceTest.java +++ b/src/test/java/com/somemore/domains/note/service/SendNoteToCenterServiceTest.java @@ -80,9 +80,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerRepository.save(center); diff --git a/src/test/java/com/somemore/domains/volunteer/repository/VolunteerDetailRepositoryImplTest.java b/src/test/java/com/somemore/domains/volunteer/repository/VolunteerDetailRepositoryImplTest.java index a98ad50eb..e26e63492 100644 --- a/src/test/java/com/somemore/domains/volunteer/repository/VolunteerDetailRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/volunteer/repository/VolunteerDetailRepositoryImplTest.java @@ -2,6 +2,7 @@ import com.somemore.domains.volunteer.domain.Gender; import com.somemore.domains.volunteer.domain.VolunteerDetail; +import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -14,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat; @Transactional -class VolunteerDetailRepositoryTest extends IntegrationTestSupport { +class VolunteerDetailRepositoryImplTest extends IntegrationTestSupport { @Autowired private VolunteerDetailRepository volunteerDetailRepository; diff --git a/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryTest.java b/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImplTest.java similarity index 95% rename from src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryTest.java rename to src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImplTest.java index f68277087..831d369c6 100644 --- a/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryTest.java +++ b/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImplTest.java @@ -3,6 +3,7 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.domain.VolunteerDetail; import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto; +import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours; import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import com.somemore.support.IntegrationTestSupport; @@ -22,7 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat; @Transactional -class VolunteerRepositoryTest extends IntegrationTestSupport { +class VolunteerRepositoryImplTest extends IntegrationTestSupport { @Autowired private VolunteerRepository volunteerRepository; @@ -210,9 +211,9 @@ void notExistsVolunteerById() { } private void createVolunteerAndUpdateVolunteerStats(int i) { - Volunteer newVolunteer = Volunteer.createDefault(NAVER, "oauth-id-" + i); - newVolunteer.updateVolunteerStats(i * 10, i); - volunteerRepository.save(newVolunteer); + Volunteer Volunteer = com.somemore.domains.volunteer.domain.Volunteer.createDefault(NAVER, "oauth-id-" + i); + Volunteer.updateVolunteerStats(i * 10, i); + volunteerRepository.save(Volunteer); } private static VolunteerRegisterRequestDto createVolunteerRegisterRequestDto(String name) { diff --git a/src/test/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlServiceTest.java b/src/test/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlServiceTest.java deleted file mode 100644 index 92d6aebfe..000000000 --- a/src/test/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlServiceTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.somemore.domains.volunteer.service; - -import com.somemore.global.auth.oauth.domain.OAuthProvider; -import com.somemore.support.IntegrationTestSupport; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; - -import static org.assertj.core.api.Assertions.assertThat; - -class GenerateOAuthUrlServiceTest extends IntegrationTestSupport { - - @Autowired - private GenerateOAuthUrlService generateOAuthUrlService; - - @Value("${app.back-url}") - private String backendRootUrl; - - - @Test - @DisplayName("Naver 제공자를 위한 OAuth URL이 올바르게 생성되는지 검증") - void generateUrl_ShouldReturnCorrectUrl_ForNaver() { - // Given - String oAuthProvider = OAuthProvider.NAVER.getProviderName(); - - // When - String result = generateOAuthUrlService.generateUrl(oAuthProvider); - - // Then - String expectedUrl = backendRootUrl + "/oauth2/authorization/naver"; - - assertThat(result).isEqualTo(expectedUrl); - } - - @Test - @DisplayName("Kakao 제공자를 위한 OAuth URL이 올바르게 생성되는지 검증") - void generateUrl_ShouldReturnCorrectUrl_ForKakao() { - // Given - String oAuthProvider = OAuthProvider.KAKAO.getProviderName(); - - // When - String result = generateOAuthUrlService.generateUrl(oAuthProvider); - - // Then - String expectedUrl = backendRootUrl + "/oauth2/authorization/kakao"; - - assertThat(result).isEqualTo(expectedUrl); - } -} diff --git a/src/test/java/com/somemore/global/auth/jwt/service/JwtServiceTest.java b/src/test/java/com/somemore/global/auth/jwt/service/JwtServiceTest.java index 568f3aa16..393bc3e13 100644 --- a/src/test/java/com/somemore/global/auth/jwt/service/JwtServiceTest.java +++ b/src/test/java/com/somemore/global/auth/jwt/service/JwtServiceTest.java @@ -1,14 +1,14 @@ package com.somemore.global.auth.jwt.service; -import com.somemore.support.IntegrationTestSupport; import com.somemore.global.auth.jwt.domain.EncodedToken; +import com.somemore.global.auth.jwt.domain.RefreshToken; import com.somemore.global.auth.jwt.domain.TokenType; -import com.somemore.user.domain.UserRole; import com.somemore.global.auth.jwt.exception.JwtErrorType; import com.somemore.global.auth.jwt.exception.JwtException; -import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; -import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; +import com.somemore.global.auth.jwt.manager.TokenManager; import com.somemore.global.auth.jwt.validator.JwtValidator; +import com.somemore.support.IntegrationTestSupport; +import com.somemore.user.domain.UserRole; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import org.junit.jupiter.api.AfterEach; @@ -23,7 +23,8 @@ import java.util.Date; import java.util.UUID; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; class JwtServiceTest extends IntegrationTestSupport { @@ -35,7 +36,7 @@ class JwtServiceTest extends IntegrationTestSupport { @Autowired private SecretKey secretKey; @Autowired - private RefreshTokenManager refreshTokenManager; + private TokenManager tokenManager; @Autowired private RedisTemplate redisTemplate; @@ -128,7 +129,7 @@ void throwExceptionWhenRefreshTokenIsInvalid() { EncodedToken expiredRefreshToken = createExpiredToken(userId, role); RefreshToken refreshToken = new RefreshToken(userId, expiredAccessToken, expiredRefreshToken); - refreshTokenManager.save(refreshToken); + tokenManager.save(refreshToken); // when // then @@ -156,28 +157,6 @@ void throwExceptionWhenRefreshTokenIsMissing() { .hasMessage(JwtErrorType.EXPIRED_TOKEN.getMessage()); } - @DisplayName("리프레시된 AccessToken은 쿠키에 올바르게 저장된다") - @Test - void refreshedAccessTokenIsSetInCookie() { - // given - String userId = UUID.randomUUID().toString(); - UserRole role = UserRole.VOLUNTEER; - - EncodedToken expiredAccessToken = createExpiredToken(userId, role); - createAndSaveRefreshToken(userId, expiredAccessToken, Instant.now().plusMillis(TokenType.REFRESH.getPeriodInMillis())); - - MockHttpServletResponse mockResponse = new MockHttpServletResponse(); - - // when - jwtService.processAccessToken(expiredAccessToken, mockResponse); - - // then - String cookieHeader = mockResponse.getHeader("Set-Cookie"); - assertThat(cookieHeader).contains("ACCESS_TOKEN="); - assertThat(cookieHeader).contains("HttpOnly"); - assertThat(cookieHeader).contains("Secure"); - } - @DisplayName("기존 RefreshToken이 갱신된다") @Test void refreshTokenIsUpdated() { @@ -193,7 +172,7 @@ void refreshTokenIsUpdated() { // when // then - assertThatThrownBy(() -> refreshTokenManager.findRefreshTokenByAccessToken(expiredAccessToken)) + assertThatThrownBy(() -> tokenManager.getRefreshTokenByAccessToken(expiredAccessToken)) .isInstanceOf(JwtException.class) .hasMessage(JwtErrorType.EXPIRED_TOKEN.getMessage()); @@ -207,7 +186,7 @@ void refreshTokenIsUpdated() { void invalidTokenThrowsJwtException() { // given String invalidToken = "invalid.token.value"; - EncodedToken encodedToken = new EncodedToken(invalidToken); + EncodedToken encodedToken = EncodedToken.from(invalidToken); // when // then @@ -252,7 +231,7 @@ private EncodedToken createExpiredToken(String userId, UserRole role) { Instant now = Instant.now(); Instant expiration = now.plusMillis(-1); // 과거 - return new EncodedToken(Jwts.builder() + return EncodedToken.from(Jwts.builder() .claims(claims) .issuedAt(Date.from(now)) .expiration(Date.from(expiration)) @@ -268,7 +247,7 @@ private RefreshToken createAndSaveRefreshToken(String userId, EncodedToken acces RefreshToken refreshToken = new RefreshToken( userId, accessToken, - new EncodedToken(Jwts.builder() + EncodedToken.from(Jwts.builder() .claims(claims) .id(uniqueId) .issuedAt(Date.from(now)) @@ -276,7 +255,7 @@ private RefreshToken createAndSaveRefreshToken(String userId, EncodedToken acces .signWith(secretKey, Jwts.SIG.HS256) .compact())); - refreshTokenManager.save(refreshToken); + tokenManager.save(refreshToken); return refreshToken; } diff --git a/src/test/java/com/somemore/domains/volunteer/service/SignOutVolunteerServiceTest.java b/src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java similarity index 57% rename from src/test/java/com/somemore/domains/volunteer/service/SignOutVolunteerServiceTest.java rename to src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java index 23b4e5e76..625291c77 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/SignOutVolunteerServiceTest.java +++ b/src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java @@ -1,16 +1,15 @@ -package com.somemore.domains.volunteer.service; +package com.somemore.global.auth.sign; -import com.somemore.global.auth.cookie.CookieUseCase; import com.somemore.global.auth.jwt.domain.EncodedToken; import com.somemore.global.auth.jwt.domain.TokenType; -import com.somemore.user.domain.UserRole; import com.somemore.global.auth.jwt.exception.JwtErrorType; import com.somemore.global.auth.jwt.exception.JwtException; import com.somemore.global.auth.jwt.generator.JwtGenerator; -import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; -import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; -import com.somemore.global.auth.signout.service.SignOutService; +import com.somemore.global.auth.jwt.domain.RefreshToken; +import com.somemore.global.auth.jwt.manager.TokenManager; +import com.somemore.global.auth.sign.out.SignOutService; import com.somemore.support.IntegrationTestSupport; +import com.somemore.user.domain.UserRole; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -19,32 +18,31 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.mock.web.MockHttpServletResponse; -import java.util.Arrays; +import java.util.UUID; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.assertj.core.api.Assertions.assertThatThrownBy; -class SignOutVolunteerServiceTest extends IntegrationTestSupport { +class SignOutServiceTest extends IntegrationTestSupport { @Autowired private SignOutService signOutVolunteerService; @Autowired - private CookieUseCase cookieUseCase; - @Autowired - private RefreshTokenManager refreshTokenManager; + private TokenManager tokenManager; @Autowired private JwtGenerator jwtGenerator; @Autowired private RedisTemplate redisTemplate; private MockHttpServletResponse response; - private String volunteerId; + private UUID userId; private UserRole role; @BeforeEach void setUp() { response = new MockHttpServletResponse(); - volunteerId = "test-volunteer"; + userId = UUID.randomUUID(); role = UserRole.VOLUNTEER; } @@ -58,35 +56,31 @@ void tearDown() { @DisplayName("로그아웃 시 액세스 토큰 쿠키를 삭제하고 리프레시 토큰을 제거해야 한다.") void signOutDeletesTokens() { // Given - EncodedToken accessToken = jwtGenerator.generateToken(volunteerId, role.getAuthority(), TokenType.ACCESS); + EncodedToken accessToken = jwtGenerator.generateToken(userId.toString(), role.getAuthority(), TokenType.ACCESS); RefreshToken refreshToken = new RefreshToken( - volunteerId, + userId.toString(), accessToken, - jwtGenerator.generateToken(volunteerId, role.getAuthority(), TokenType.REFRESH)); + jwtGenerator.generateToken(userId.toString(), role.getAuthority(), TokenType.REFRESH)); - refreshTokenManager.save(refreshToken); - cookieUseCase.setToken(response, accessToken.value(), TokenType.ACCESS); + tokenManager.save(refreshToken); // When - signOutVolunteerService.signOut(response, volunteerId); + signOutVolunteerService.signOut(response, userId); // Then - assertThatThrownBy(() -> refreshTokenManager.findRefreshTokenByAccessToken(accessToken)) + assertThatThrownBy(() -> tokenManager.getRefreshTokenByAccessToken(accessToken)) .isInstanceOf(JwtException.class) .hasMessage(JwtErrorType.EXPIRED_TOKEN.getMessage()); - - assertThat(Arrays.toString(response.getCookies())).contains(TokenType.SIGN_OUT.name()); } @Test @DisplayName("로그아웃 시 리프레시 토큰이 없어도 예외가 발생하지 않는다.") void signOutWithoutRefreshToken() { // When - signOutVolunteerService.signOut(response, volunteerId); + signOutVolunteerService.signOut(response, userId); // Then - assertThatNoException().isThrownBy(() -> signOutVolunteerService.signOut(response, volunteerId)); - assertThat(Arrays.toString(response.getCookies())).contains(TokenType.SIGN_OUT.name()); + assertThatNoException().isThrownBy(() -> signOutVolunteerService.signOut(response, userId)); } } diff --git a/src/test/java/com/somemore/support/fixture/CenterFixture.java b/src/test/java/com/somemore/support/fixture/CenterFixture.java index 4be307ac1..a28af198e 100644 --- a/src/test/java/com/somemore/support/fixture/CenterFixture.java +++ b/src/test/java/com/somemore/support/fixture/CenterFixture.java @@ -14,8 +14,6 @@ public static Center createCenter() { .imgUrl("https://image.domain.com/center-img") .introduce("센터 소개") .homepageLink("https://www.centerhomepage.com") - .accountId("center_account") - .accountPw("password123") .build(); } @@ -26,8 +24,6 @@ public static Center createCenter(String name) { .imgUrl("https://image.domain.com/center-img") .introduce("센터 소개") .homepageLink("https://www.centerhomepage.com") - .accountId("center_account") - .accountPw("password123") .build(); } diff --git a/src/test/java/com/somemore/user/repository/user/UserRepositoryImplTest.java b/src/test/java/com/somemore/user/repository/user/UserRepositoryImplTest.java index 40d44270b..2cc00310d 100644 --- a/src/test/java/com/somemore/user/repository/user/UserRepositoryImplTest.java +++ b/src/test/java/com/somemore/user/repository/user/UserRepositoryImplTest.java @@ -26,7 +26,7 @@ class UserRepositoryImplTest extends IntegrationTestSupport { void saveOAuthVolunteerUser() { // given UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(OAuthProvider.NAVER); - User user = User.from(userAuthInfo, UserRole.VOLUNTEER); + User user = User.of(userAuthInfo, UserRole.VOLUNTEER); // when User savedUser = userRepository.save(user); @@ -42,7 +42,7 @@ void saveOAuthVolunteerUser() { void saveOAuthCenterUser() { // given UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(OAuthProvider.NAVER); - User user = User.from(userAuthInfo, UserRole.CENTER); + User user = User.of(userAuthInfo, UserRole.CENTER); // when User savedUser = userRepository.save(user); @@ -58,7 +58,7 @@ void saveOAuthCenterUser() { void saveLocalCenterUser() { // given UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); - User user = User.from(userAuthInfo, UserRole.CENTER); + User user = User.of(userAuthInfo, UserRole.CENTER); // when User savedUser = userRepository.save(user); @@ -74,7 +74,7 @@ void saveLocalCenterUser() { void findById() { // given UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); - User user = User.from(userAuthInfo, UserRole.CENTER); + User user = User.of(userAuthInfo, UserRole.CENTER); User savedUser = userRepository.save(user); // when @@ -90,7 +90,7 @@ void findById() { void findByInvalidId() { // given UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); - User user = User.from(userAuthInfo, UserRole.CENTER); + User user = User.of(userAuthInfo, UserRole.CENTER); userRepository.save(user); UUID invalidUserId = UUID.randomUUID(); @@ -106,7 +106,7 @@ void findByInvalidId() { void findRoleById() { // given UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); - User user = User.from(userAuthInfo, UserRole.CENTER); + User user = User.of(userAuthInfo, UserRole.CENTER); User savedUser = userRepository.save(user); // when @@ -122,7 +122,7 @@ void findRoleById() { void findByAccountId() { // given UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); - User user = User.from(userAuthInfo, UserRole.CENTER); + User user = User.of(userAuthInfo, UserRole.CENTER); User savedUser = userRepository.save(user); // when diff --git a/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java b/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java index d286fcabf..8293a11e3 100644 --- a/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java +++ b/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java @@ -3,6 +3,7 @@ import com.somemore.global.imageupload.service.ImageUploadService; import com.somemore.support.IntegrationTestSupport; import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.user.domain.UserRole; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -23,7 +24,7 @@ class UserCommonAttributeRepositoryImplTest extends IntegrationTestSupport { void saveUserCommonAttribute() { // given UUID userId = UUID.randomUUID(); - UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId); + UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId, UserRole.VOLUNTEER); // when UserCommonAttribute savedUserCommonAttribute = userCommonAttributeRepository.save(userCommonAttribute); diff --git a/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java b/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java index 7e6eb7cb4..5bad35984 100644 --- a/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java +++ b/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java @@ -12,7 +12,6 @@ import com.somemore.user.repository.user.UserRepository; import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; import com.somemore.user.repository.usersetting.UserSettingRepository; -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; @@ -64,7 +63,7 @@ void registerOAuthUser() { assertThat(savedCommonAttribute).isNotNull(); assertThat(savedCommonAttribute.getUserId()).isEqualTo(savedUser.getId()); - assertThat(savedCommonAttribute.getNickname()).hasSize(8); + assertThat(savedCommonAttribute.getName()).contains(UserRole.getOAuthUserDefaultRole().getDescription()); assertThat(savedCommonAttribute.getIntroduce()).isEqualTo(""); assertThat(savedCommonAttribute.getImgUrl()).isEqualTo(ImageUploadService.DEFAULT_IMAGE_URL); assertThat(savedCommonAttribute.isCustomized()).isEqualTo(userDefaultSetting); @@ -98,7 +97,7 @@ void registerLocalUser() { assertThat(savedCommonAttribute).isNotNull(); assertThat(savedCommonAttribute.getUserId()).isEqualTo(savedUser.getId()); - assertThat(savedCommonAttribute.getNickname()).hasSize(8); + assertThat(savedCommonAttribute.getName()).contains(role.getDescription()); assertThat(savedCommonAttribute.getIntroduce()).isEqualTo(""); assertThat(savedCommonAttribute.getImgUrl()).isEqualTo(ImageUploadService.DEFAULT_IMAGE_URL); assertThat(savedCommonAttribute.isCustomized()).isEqualTo(userDefaultSetting); diff --git a/src/test/java/com/somemore/user/service/UserQueryServiceTest.java b/src/test/java/com/somemore/user/service/UserQueryServiceTest.java index 87c39279d..11c3aa0cc 100644 --- a/src/test/java/com/somemore/user/service/UserQueryServiceTest.java +++ b/src/test/java/com/somemore/user/service/UserQueryServiceTest.java @@ -35,8 +35,8 @@ class UserQueryServiceTest extends IntegrationTestSupport { void setup() { UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(OAuthProvider.NAVER); - user = userRepository.save(User.from(userAuthInfo, UserRole.VOLUNTEER)); - userCommonAttribute = userCommonAttributeRepository.save(UserCommonAttribute.createDefault(user.getId())); + user = userRepository.save(User.of(userAuthInfo, UserRole.VOLUNTEER)); + userCommonAttribute = userCommonAttributeRepository.save(UserCommonAttribute.createDefault(user.getId(),UserRole.VOLUNTEER)); } diff --git a/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java b/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java index a4e76036b..ccae9e666 100644 --- a/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java +++ b/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java @@ -32,14 +32,14 @@ class ValidateBasicInfoServiceTest extends IntegrationTestSupport { @BeforeEach void setup() { UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.com", "Test User"); - user = userRepository.save(User.from(userAuthInfo, UserRole.VOLUNTEER)); + user = userRepository.save(User.of(userAuthInfo, UserRole.VOLUNTEER)); } @DisplayName("필수 입력 정보가 입력되었다면, true를 반환한다.") @Test void isBasicInfoComplete_ReturnsTrue() { // given - UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(user.getId()); + UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(user.getId(), UserRole.VOLUNTEER); userCommonAttribute.customize(); userCommonAttributeRepository.save(userCommonAttribute); @@ -54,7 +54,7 @@ void isBasicInfoComplete_ReturnsTrue() { @Test void isNotBasicInfoComplete_ReturnsFalse() { // given - UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(user.getId()); + UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(user.getId(), UserRole.VOLUNTEER); userCommonAttributeRepository.save(userCommonAttribute); // when diff --git a/src/test/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImplTest.java b/src/test/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImplTest.java new file mode 100644 index 000000000..f4d49189d --- /dev/null +++ b/src/test/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImplTest.java @@ -0,0 +1,40 @@ +package com.somemore.volunteer.repository; + +import com.somemore.support.IntegrationTestSupport; +import com.somemore.volunteer.domain.NEWVolunteer; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +@Transactional +class NEWVolunteerRepositoryImplTest extends IntegrationTestSupport { + + @Autowired + private NEWVolunteerRepositoryImpl volunteerRepository; + + @DisplayName("유저 아이디로 봉사자를 등록할 수 있다.") + @Test + void saveVolunteerByUserId() { + // given + UUID userId = UUID.randomUUID(); + NEWVolunteer volunteer = NEWVolunteer.createDefault(userId); + + // when + volunteerRepository.save(volunteer); + + // then + NEWVolunteer volunteerByUserId = volunteerRepository.findByUserId(userId).orElseThrow(); + NEWVolunteer volunteerById = volunteerRepository.findById(volunteer.getId()).orElseThrow(); + + + assertThat(volunteer) + .isEqualTo(volunteerByUserId) + .isEqualTo(volunteerById); + + } +} diff --git a/src/test/java/com/somemore/volunteer/service/NEWRegisterVolunteerServiceTest.java b/src/test/java/com/somemore/volunteer/service/NEWRegisterVolunteerServiceTest.java new file mode 100644 index 000000000..49da8a8eb --- /dev/null +++ b/src/test/java/com/somemore/volunteer/service/NEWRegisterVolunteerServiceTest.java @@ -0,0 +1,38 @@ +package com.somemore.volunteer.service; + +import com.somemore.support.IntegrationTestSupport; +import com.somemore.volunteer.domain.NEWVolunteer; +import com.somemore.volunteer.repository.NEWVolunteerRepository; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +@Transactional +class NEWRegisterVolunteerServiceTest extends IntegrationTestSupport { + + @Autowired + private NEWRegisterVolunteerService registerVolunteerService; + + @Autowired + private NEWVolunteerRepository volunteerRepository; + + @Test + @DisplayName("유저 아이디로 봉사자가 등록될 수 있다.") + void registerByUserId() { + // given + UUID userId = UUID.randomUUID(); + + // when + registerVolunteerService.register(userId); + + // then + Optional foundVolunteer = volunteerRepository.findByUserId(userId); + assertThat(foundVolunteer).isNotEmpty(); + } +}