-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Team-Shaka/feat/19
Feat/19 시큐리티 세팅 및 Invitation 관련 로직 추가, 초대장 조회 API 구현
- Loading branch information
Showing
16 changed files
with
388 additions
and
2 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/java/treehouse/server/api/invitation/business/InvitationMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package treehouse.server.api.invitation.business; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import treehouse.server.api.invitation.presentation.dto.InvitationResponseDTO; | ||
import treehouse.server.global.entity.Invitation.Invitation; | ||
import treehouse.server.global.entity.User.User; | ||
import treehouse.server.global.entity.User.UserRole; | ||
import treehouse.server.global.entity.User.UserStatus; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class InvitationMapper { | ||
|
||
public InvitationResponseDTO.getInvitation toGetInvitation (Invitation invitation, List<String> treeMemberProfileImages) { | ||
return InvitationResponseDTO.getInvitation.builder() | ||
.invitationId(invitation.getId()) | ||
.treehouseName(invitation.getTreeHouse().getName()) | ||
.senderName(invitation.getSender().getName()) | ||
.senderProfileImageUrl(invitation.getSender().getProfileImageUrl()) | ||
.treehouseSize(invitation.getTreeHouse().getMemberList().size()) | ||
.treehouseMemberProfileImages(treeMemberProfileImages) | ||
.build(); | ||
} | ||
public InvitationResponseDTO.getInvitations toGetInvitations(List<InvitationResponseDTO.getInvitation> invitationDtos) { | ||
return InvitationResponseDTO.getInvitations.builder() | ||
.invitations(invitationDtos) | ||
.build(); | ||
} | ||
} | ||
|
60 changes: 60 additions & 0 deletions
60
src/main/java/treehouse/server/api/invitation/business/InvitationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package treehouse.server.api.invitation.business; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import treehouse.server.api.invitation.implement.InvitationCommandAdapter; | ||
import treehouse.server.api.invitation.implement.InvitationQueryAdapter; | ||
import treehouse.server.api.invitation.presentation.dto.InvitationRequestDTO; | ||
import treehouse.server.api.invitation.presentation.dto.InvitationResponseDTO; | ||
import treehouse.server.global.entity.Invitation.Invitation; | ||
import treehouse.server.global.entity.User.User; | ||
import treehouse.server.global.entity.member.Member; | ||
import treehouse.server.global.entity.redis.RefreshToken; | ||
import treehouse.server.global.entity.treeHouse.TreeHouse; | ||
import treehouse.server.global.exception.GlobalErrorCode; | ||
import treehouse.server.global.exception.ThrowClass.AuthException; | ||
import treehouse.server.global.exception.ThrowClass.GeneralException; | ||
import treehouse.server.global.redis.service.RedisService; | ||
import treehouse.server.global.security.jwt.dto.TokenDTO; | ||
import treehouse.server.global.security.provider.TokenProvider; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@AllArgsConstructor | ||
@Slf4j | ||
public class InvitationService { | ||
|
||
|
||
private final InvitationQueryAdapter invitationQueryAdapter; | ||
|
||
private final InvitationCommandAdapter invitationCommandAdapter; | ||
private final InvitationMapper invitationMapper; | ||
private static final Integer treeMemberRandomProfileSize = 3; | ||
|
||
|
||
@Transactional | ||
public InvitationResponseDTO.getInvitations getInvitations(User user) { | ||
|
||
log.error("User name : ", user.getName()); | ||
log.error("User id : ", user.getId()); | ||
List<Invitation> invitations = invitationQueryAdapter.findAllByPhone(user.getPhone()); | ||
log.error("size : ", invitations.size()); | ||
|
||
List<InvitationResponseDTO.getInvitation> invitationDtos = invitations.stream() | ||
.map(invitation -> { | ||
TreeHouse treeHouse = invitation.getTreeHouse(); | ||
List<Member> treeMembers = treeHouse.getMemberList(); | ||
List<String> randomProfileImages = treeMembers.stream() | ||
.map(Member::getProfileImageUrl) | ||
.limit(treeMemberRandomProfileSize) | ||
.toList(); | ||
return invitationMapper.toGetInvitation(invitation, randomProfileImages); | ||
}) | ||
.collect(Collectors.toList()); | ||
return invitationMapper.toGetInvitations(invitationDtos); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/treehouse/server/api/invitation/implement/InvitationCommandAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package treehouse.server.api.invitation.implement; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
import treehouse.server.api.invitation.persistence.InvitationRepository; | ||
import treehouse.server.global.annotations.Adapter; | ||
import treehouse.server.global.entity.User.User; | ||
import treehouse.server.global.entity.User.UserRole; | ||
import treehouse.server.global.entity.redis.RefreshToken; | ||
import treehouse.server.global.redis.service.RedisService; | ||
import treehouse.server.global.security.jwt.dto.TokenDTO; | ||
import treehouse.server.global.security.provider.TokenProvider; | ||
|
||
import java.util.List; | ||
|
||
@Adapter | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class InvitationCommandAdapter { | ||
|
||
private final InvitationRepository invitationRepository; | ||
|
||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/treehouse/server/api/invitation/implement/InvitationQueryAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package treehouse.server.api.invitation.implement; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import treehouse.server.api.invitation.persistence.InvitationRepository; | ||
import treehouse.server.api.invitation.presentation.dto.InvitationRequestDTO; | ||
import treehouse.server.global.annotations.Adapter; | ||
import treehouse.server.global.entity.Invitation.Invitation; | ||
import treehouse.server.global.entity.User.User; | ||
import treehouse.server.global.exception.GlobalErrorCode; | ||
import treehouse.server.global.exception.ThrowClass.UserException; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Adapter | ||
@RequiredArgsConstructor | ||
public class InvitationQueryAdapter { | ||
|
||
private final InvitationRepository invitationRepository; | ||
|
||
public List<Invitation> findAllByPhone(String phone) { | ||
return invitationRepository.findAllByPhone(phone); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/treehouse/server/api/invitation/persistence/InvitationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package treehouse.server.api.invitation.persistence; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import treehouse.server.global.entity.Invitation.Invitation; | ||
import treehouse.server.global.entity.User.User; | ||
import treehouse.server.global.entity.treeHouse.TreeHouse; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface InvitationRepository extends JpaRepository<Invitation, Long> { | ||
|
||
List<Invitation> findAllByPhone(String phone); | ||
|
||
Invitation findByPhoneAndTreeHouse(String phone, TreeHouse treeHouse); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/treehouse/server/api/invitation/presentation/InvitationApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package treehouse.server.api.invitation.presentation; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
import treehouse.server.api.invitation.business.InvitationService; | ||
import treehouse.server.api.invitation.presentation.dto.InvitationRequestDTO; | ||
import treehouse.server.api.invitation.presentation.dto.InvitationResponseDTO; | ||
import treehouse.server.global.common.CommonResponse; | ||
import treehouse.server.global.entity.User.User; | ||
import treehouse.server.global.security.handler.annotation.AuthMember; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Validated | ||
@Tag(name = "😎 Invitation API", description = "초대장 관련 API 입니다. 초대장 조회, 전송 등의 API가 포함됩니다.") | ||
@RequestMapping("/invi") | ||
public class InvitationApi { | ||
|
||
private final InvitationService invitationService; | ||
|
||
@GetMapping("/invitation") | ||
@Operation(summary = "초대장 조회", description = "내가 받은 초대장을 조회합니다.") | ||
public CommonResponse<InvitationResponseDTO.getInvitations> getInvitations( | ||
@AuthMember @Parameter(hidden = true) User user | ||
) { | ||
return CommonResponse.onSuccess(invitationService.getInvitations(user)); | ||
} | ||
|
||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/treehouse/server/api/invitation/presentation/dto/InvitationRequestDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package treehouse.server.api.invitation.presentation.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
|
||
public class InvitationRequestDTO { | ||
|
||
|
||
|
||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/treehouse/server/api/invitation/presentation/dto/InvitationResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package treehouse.server.api.invitation.presentation.dto; | ||
|
||
import lombok.*; | ||
|
||
import java.util.List; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class InvitationResponseDTO { | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class getInvitation { | ||
private Long invitationId; | ||
private String treehouseName; | ||
private String senderName; | ||
private String senderProfileImageUrl; | ||
private Integer treehouseSize; | ||
private List<String> treehouseMemberProfileImages; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class getInvitations { | ||
List<InvitationResponseDTO.getInvitation> invitations; | ||
} | ||
|
||
} |
16 changes: 15 additions & 1 deletion
16
src/main/java/treehouse/server/api/user/business/UserMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/treehouse/server/global/config/GlobalWebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package treehouse.server.global.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import treehouse.server.global.security.handler.annotation.resolver.AuthMemberArgumentResolver; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class GlobalWebConfig implements WebMvcConfigurer { | ||
|
||
private final AuthMemberArgumentResolver authMemberArgumentResolver; | ||
|
||
/** | ||
* 컨트롤러 메서드의 특정 파라미터를 지원하는 커스텀한 ArgumentResolver를 추가 | ||
* @param resolverList | ||
*/ | ||
@Override | ||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolverList) { | ||
resolverList.add(authMemberArgumentResolver); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/treehouse/server/global/security/handler/annotation/AuthMember.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
package treehouse.server.global.security.handler.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) // 런타임 중에 어노테이션 정보를 조회하고 처리할 수 있도록 설정 | ||
@Target(ElementType.PARAMETER) // 어노테이션을 파라미터에만 적용 | ||
public @interface AuthMember { | ||
} |
Oops, something went wrong.