Skip to content

Commit

Permalink
YEL-161 [deploy] v1.194
Browse files Browse the repository at this point in the history
YEL-161 [deploy] v1.194
  • Loading branch information
euije authored Sep 10, 2023
2 parents eba4961 + 67fb4c4 commit c46e4ea
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public AdminUserDetailResponse findUserDetail(Long adminId, Long userId) {
userAdminRepository.getByUser(admin);

// logic
final User user = userRepository.getById(userId);
final User user = userRepository.getByIdNotFiltered(userId);

return AdminUserDetailResponse.of(user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.yello.server.domain.authorization.service.AuthService;
import com.yello.server.global.common.annotation.ServiceToken;
import com.yello.server.global.common.dto.BaseResponse;
import com.yello.server.infrastructure.slack.annotation.SlackSignUpNotification;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -52,6 +53,7 @@ public BaseResponse<Boolean> getYelloIdValidation(@RequestParam("yelloId") Strin
}

@PostMapping("/signup")
@SlackSignUpNotification
public BaseResponse<SignUpResponse> postSignUp(@Valid @RequestBody SignUpRequest signUpRequest) {
val data = authService.signUp(signUpRequest);
return BaseResponse.success(SIGN_UP_SUCCESS, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public interface UserJpaRepository extends JpaRepository<User, Long> {
"and u.deletedAt is null")
Optional<User> findById(@Param("id") Long id);

@Query("select u from User u " +
"where u.id = :id")
Optional<User> findByIdNotFiltered(@Param("id") Long id);

@Query("select u from User u " +
"where u.uuid = :uuid")
Optional<User> findByUuid(@Param("uuid") String uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface UserRepository {

User getById(Long id);

User getByIdNotFiltered(Long id);

Optional<User> findByUuid(String uuid);

Optional<User> findByUuidNotFiltered(String uuid);
Expand Down Expand Up @@ -64,6 +66,6 @@ List<User> findAllByOtherGroupContainingYelloId(String groupName, String keyword
Page<User> findAllByYelloIdContaining(Pageable pageable, String yelloId);

Page<User> findAllByNameContaining(Pageable pageable, String name);

void delete(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public User getById(Long id) {
.orElseThrow(() -> new UserNotFoundException(USERID_NOT_FOUND_USER_EXCEPTION));
}

@Override
public User getByIdNotFiltered(Long id) {
return userJpaRepository.findByIdNotFiltered(id)
.orElseThrow(() -> new UserNotFoundException(USERID_NOT_FOUND_USER_EXCEPTION));
}

@Override
public Optional<User> findByUuid(String uuid) {
return userJpaRepository.findByUuid(uuid);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.yello.server.infrastructure.slack.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface SlackSignUpNotification {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.yello.server.infrastructure.slack.aspect;

import com.yello.server.infrastructure.slack.factory.SlackWebhookMessageFactory;
import javax.servlet.http.HttpServletRequest;
import net.gpedro.integrations.slack.SlackApi;
import net.gpedro.integrations.slack.SlackMessage;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Aspect
@Component
public class SlackSignUpNotificationAspect {

private final SlackApi slackSignUpApi;
private final SlackWebhookMessageFactory slackWebhookMessageFactory;
private final TaskExecutor taskExecutor;

public SlackSignUpNotificationAspect(
@Qualifier("slackSignUpApi") SlackApi slackSignUpApi,
SlackWebhookMessageFactory slackWebhookMessageFactory,
TaskExecutor taskExecutor) {
this.slackSignUpApi = slackSignUpApi;
this.slackWebhookMessageFactory = slackWebhookMessageFactory;
this.taskExecutor = taskExecutor;
}

@Around("@annotation(com.yello.server.infrastructure.slack.annotation.SlackSignUpNotification)")
Object signUpNotification(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
.getRequest();

SlackMessage slackMessage = slackWebhookMessageFactory.generateSlackSignUpMessage(
request
);

Runnable runnable = () -> slackSignUpApi.call(slackMessage);
taskExecutor.execute(runnable);

return proceedingJoinPoint.proceed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class SlackConfiguration {
@Value("${slack.token.bank}")
String slackTokenForPurchase;

@Value("${slack.token.sign-up}")
String slackTokenForSignUp;

@Bean
SlackApi slackErrorApi() {
return new SlackApi("https://hooks.slack.com/services/" + slackTokenForError);
Expand All @@ -23,4 +26,9 @@ SlackApi slackErrorApi() {
SlackApi slackPurchaseApi() {
return new SlackApi("https://hooks.slack.com/services/" + slackTokenForPurchase);
}

@Bean
SlackApi slackSignUpApi() {
return new SlackApi("https://hooks.slack.com/services/" + slackTokenForSignUp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class SlackWebhookMessageFactory {
private static final String PURCHASE_TITLE = "돈이 입금되었습니다.";
private static final String PURCHASE_USERNAME = "옐로 뱅크";

private static final String SIGNUP_TITLE = "신규 유저가 가입하였습니다. ";
private static final String SIGNUP_USERNAME = "옐로 온보딩";

private final UserRepository userRepository;
private final TokenProvider tokenProvider;

Expand Down Expand Up @@ -84,6 +87,15 @@ public SlackMessage generateSlackPurchaseMessage(
.setUsername(PURCHASE_USERNAME);
}

public SlackMessage generateSlackSignUpMessage(
HttpServletRequest request
) throws IOException {
return new SlackMessage()
.setAttachments(generateSlackSignUpAttachment(request))
.setText(SIGNUP_TITLE)
.setUsername(SIGNUP_USERNAME);
}

private List<SlackAttachment> generateSlackErrorAttachment(
HttpServletRequest request,
Exception exception
Expand Down Expand Up @@ -114,6 +126,19 @@ private List<SlackAttachment> generateSlackPurchaseAttachment(
return Collections.singletonList(slackAttachment);
}

private List<SlackAttachment> generateSlackSignUpAttachment(
HttpServletRequest request
) throws IOException {
final SlackAttachment slackAttachment = new SlackAttachment()
.setFallback("good")
.setColor("good")
.setTitle(SIGNUP_TITLE)
.setTitleLink(request.getContextPath())
.setText(SIGNUP_TITLE)
.setFields(generateSlackSimpleFieldList(request));
return Collections.singletonList(slackAttachment);
}

private List<SlackField> generateSlackFieldList(
HttpServletRequest request
) throws IOException {
Expand Down Expand Up @@ -143,4 +168,13 @@ private List<SlackField> generateSlackFieldList(
new SlackField().setTitle("인증/인가 정보 - 유저").setValue(userInfo)
);
}

private List<SlackField> generateSlackSimpleFieldList(
HttpServletRequest request
) throws IOException {
return Arrays.asList(
new SlackField().setTitle("Request Body")
.setValue(getRequestBody(request))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public Optional<User> findById(Long id) {

@Override
public User getById(Long id) {
return data.stream()
.filter(user -> user.getDeletedAt() == null)
.filter(user -> user.getId().equals(id))
.findFirst()
.orElseThrow(() -> new UserNotFoundException(USERID_NOT_FOUND_USER_EXCEPTION));
}

@Override
public User getByIdNotFiltered(Long id) {
return data.stream()
.filter(user -> user.getId().equals(id))
.findFirst()
Expand Down

0 comments on commit c46e4ea

Please sign in to comment.