Skip to content

Commit

Permalink
Merge pull request #688 from woowacourse-teams/develop
Browse files Browse the repository at this point in the history
v1.2.2 배포
  • Loading branch information
moonheekim0118 authored Oct 28, 2022
2 parents c2cc7fe + fb6db92 commit c68e30a
Show file tree
Hide file tree
Showing 50 changed files with 29,726 additions and 39,692 deletions.
2 changes: 0 additions & 2 deletions backend/src/main/java/com/pickpick/PickpickApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@EnableJpaAuditing
@ConfigurationPropertiesScan
@SpringBootApplication
public class PickpickApplication {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
package com.pickpick.auth.application;

import com.pickpick.auth.application.dto.WorkspaceInfoDto;
import com.pickpick.auth.application.dto.MemberInfoDto;
import com.pickpick.auth.application.dto.OAuthAccessInfoDto;
import com.pickpick.auth.support.JwtTokenProvider;
import com.pickpick.auth.ui.dto.LoginResponse;
import com.pickpick.channel.domain.Channel;
import com.pickpick.channel.domain.ChannelRepository;
import com.pickpick.exception.workspace.WorkspaceDuplicateException;
import com.pickpick.member.domain.Member;
import com.pickpick.member.domain.MemberRepository;
import com.pickpick.support.ExternalClient;
import com.pickpick.workspace.domain.Workspace;
import com.pickpick.workspace.domain.WorkspaceRepository;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@Transactional(readOnly = true)
public class AuthService {

private final MemberRepository members;
private final WorkspaceRepository workspaces;
private final ChannelRepository channels;
private final ExternalClient externalClient;
private final JwtTokenProvider jwtTokenProvider;

public AuthService(final MemberRepository members, final WorkspaceRepository workspaces,
final ChannelRepository channels, final ExternalClient externalClient,
public AuthService(final MemberRepository members, final ExternalClient externalClient,
final JwtTokenProvider jwtTokenProvider) {
this.members = members;
this.workspaces = workspaces;
this.channels = channels;
this.externalClient = externalClient;
this.jwtTokenProvider = jwtTokenProvider;
}
Expand All @@ -42,39 +30,21 @@ public void verifyToken(final String token) {
}

@Transactional
public void registerWorkspace(final String code) {
WorkspaceInfoDto workspaceInfoDto = externalClient.callWorkspaceInfo(code);

validateExistWorkspace(workspaceInfoDto.getWorkspaceSlackId());

Workspace workspace = workspaces.save(workspaceInfoDto.toEntity());

List<Member> allWorkspaceMembers = externalClient.findMembersByWorkspace(workspace);
members.saveAll(allWorkspaceMembers);

List<Channel> allWorkspaceChannels = externalClient.findChannelsByWorkspace(workspace);
channels.saveAll(allWorkspaceChannels);
}

private void validateExistWorkspace(final String workspaceSlackId) {
if (workspaces.existsBySlackId(workspaceSlackId)) {
throw new WorkspaceDuplicateException(workspaceSlackId);
}
public LoginResponse login(final String code) {
MemberInfoDto memberInfoDto = externalClient.callMemberInfo(code);
return login(memberInfoDto.getSlackId(), memberInfoDto.getUserToken());
}

@Transactional
public LoginResponse login(final String code) {
String userToken = externalClient.callUserToken(code);
return loginByToken(userToken);
public LoginResponse login(final OAuthAccessInfoDto oAuthAccessInfoDto) {
return login(oAuthAccessInfoDto.getUserSlackId(), oAuthAccessInfoDto.getUserToken());
}

private LoginResponse loginByToken(final String userSlackToken) {
String memberSlackId = externalClient.callMemberSlackId(userSlackToken);

private LoginResponse login(final String memberSlackId, final String memberToken) {
Member member = members.getBySlackId(memberSlackId);

boolean isFirstLogin = member.isFirstLogin();
member.firstLogin(userSlackToken);
member.firstLogin(memberToken);

return LoginResponse.builder()
.token(jwtTokenProvider.createToken(String.valueOf(member.getId())))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.pickpick.auth.application.dto;

import lombok.Getter;

@Getter
public class MemberInfoDto {

private final String slackId;
private final String userToken;

public MemberInfoDto(final String slackId, final String userToken) {
this.slackId = slackId;
this.userToken = userToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@
import lombok.Getter;

@Getter
public class WorkspaceInfoDto {
public class OAuthAccessInfoDto {

private final String workspaceSlackId;
private final String botToken;
private final String botSlackId;
private final String userToken;
private final String userSlackId;

public WorkspaceInfoDto(final String workspaceSlackId, final String botToken, final String botSlackId,
final String userToken) {
public OAuthAccessInfoDto(final String workspaceSlackId, final String botToken, final String botSlackId,
final String userToken, final String userSlackId) {
this.workspaceSlackId = workspaceSlackId;
this.botToken = botToken;
this.botSlackId = botSlackId;
this.userToken = userToken;
this.userSlackId = userSlackId;
}

public Workspace toEntity() {
public Workspace toWorkspace() {
return new Workspace(workspaceSlackId, botToken, botSlackId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,4 @@ public void verifyToken(final HttpServletRequest request) {
public LoginResponse login(@RequestParam @NotEmpty final String code) {
return authService.login(code);
}

@GetMapping("/slack-workspace")
public void registerWorkspace(@RequestParam @NotEmpty final String code) {
authService.registerWorkspace(code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pickpick.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@Configuration
@EnableJpaAuditing
public class JpaAuditingConfig {
}
Loading

0 comments on commit c68e30a

Please sign in to comment.