Skip to content

Commit

Permalink
Merge pull request #91 from TeamSobokSobok/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
dev-Crayon authored Feb 22, 2024
2 parents f65525f + 3ada81f commit 2103955
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 161 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CD-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ jobs:
mkdir firebase
# firebase admin-sdk 파일 생성
touch ./firebase/sobok-76d0a-firebase-adminsdk-qb2ez-cedea5e056.json
touch ./firebase/soboksobok-564b3-firebase-adminsdk-l4k48-58b981ed69.json
# Github-Actions 에서 설정한 값을 json 파일에 입력
echo "${{ secrets.SOBOKSOBOK_FIREBASE }}" >> ./firebase/sobok-76d0a-firebase-adminsdk-qb2ez-cedea5e056.json
echo "${{ secrets.SOBOKSOBOK_FIREBASE }}" >> ./firebase/soboksobok-564b3-firebase-adminsdk-l4k48-58b981ed69.json
# GitHub-Actions 에서 설정한 값을 application.yml 파일에 쓰기
echo "${{ secrets.SOBOKSOBOK_DEPLOY }}" >> ./application.yml
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,4 @@ application-dev.yml
application-prod.yml

# firebase admin sdk
sobok-76d0a-firebase-adminsdk-qb2ez-cedea5e056.json
soboksobok-564b3-firebase-adminsdk-l4k48-58b981ed69.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sobok.SobokSobok.auth.application;

import io.sobok.SobokSobok.auth.application.util.UserServiceUtil;
import io.sobok.SobokSobok.auth.domain.User;
import io.sobok.SobokSobok.auth.infrastructure.UserRepository;
import io.sobok.SobokSobok.auth.ui.dto.JwtTokenResponse;
Expand All @@ -26,8 +27,7 @@ public class AuthService {
@Transactional
public void logout(Long userId) {

User user = userRepository.findById(userId)
.orElseThrow(() -> new NotFoundException(ErrorCode.UNREGISTERED_USER));
User user = UserServiceUtil.findUserById(userRepository, userId);

ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
if (valueOperations.get(user.getSocialInfo().getSocialId()) == null) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,78 @@
package io.sobok.SobokSobok.auth.application;

import io.sobok.SobokSobok.auth.ui.dto.*;
import io.sobok.SobokSobok.auth.domain.Role;
import io.sobok.SobokSobok.auth.domain.SocialInfo;
import io.sobok.SobokSobok.auth.domain.SocialType;
import io.sobok.SobokSobok.auth.domain.User;
import io.sobok.SobokSobok.auth.infrastructure.UserRepository;
import io.sobok.SobokSobok.auth.ui.dto.SocialLoginRequest;
import io.sobok.SobokSobok.auth.ui.dto.SocialLoginResponse;
import io.sobok.SobokSobok.auth.ui.dto.SocialSignupRequest;
import io.sobok.SobokSobok.auth.ui.dto.SocialSignupResponse;
import io.sobok.SobokSobok.exception.ErrorCode;
import io.sobok.SobokSobok.exception.model.ConflictException;
import io.sobok.SobokSobok.exception.model.NotFoundException;
import io.sobok.SobokSobok.external.kakao.KakaoService;
import io.sobok.SobokSobok.security.jwt.Jwt;
import io.sobok.SobokSobok.security.jwt.JwtProvider;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

public abstract class SocialService {
@Service
@RequiredArgsConstructor
public class SocialService {

public abstract SocialSignupResponse signup(SocialSignupRequest request);
private final KakaoService kakaoService;

public abstract SocialLoginResponse login(SocialLoginRequest request);
private final UserRepository userRepository;

private final JwtProvider jwtProvider;

@Transactional
public SocialSignupResponse signup(SocialSignupRequest request) {
if (userRepository.existsBySocialInfoSocialId(request.socialId())) {
throw new ConflictException(ErrorCode.ALREADY_EXISTS_USER);
}

if (userRepository.existsByUsername(request.username())) {
throw new ConflictException(ErrorCode.ALREADY_USING_USERNAME);
}

User signupUser = userRepository.save(User.builder()
.username(request.username())
.socialInfo(SocialInfo.builder()
.socialId(request.socialId())
.build())
.deviceToken(request.deviceToken())
.roles(Role.USER.name())
.build());

Jwt jwt = jwtProvider.getUserJwt(signupUser.getSocialInfo().getSocialId());

return SocialSignupResponse.builder()
.id(signupUser.getId())
.username(signupUser.getUsername())
.socialId(signupUser.getSocialInfo().getSocialId())
.accessToken(jwt.accessToken())
.refreshToken(jwt.refreshToken())
.build();
}

@Transactional
public SocialLoginResponse login(SocialLoginRequest request) {
User loginUser = userRepository.findBySocialInfoSocialId(request.socialId())
.orElseThrow(() -> new NotFoundException(ErrorCode.UNREGISTERED_USER));

if (!request.deviceToken().equals(loginUser.getDeviceToken())) {
loginUser.updateDeviceToken(request.deviceToken());
}

Jwt jwt = jwtProvider.getUserJwt(loginUser.getSocialInfo().getSocialId());

return SocialLoginResponse.builder()
.accessToken(jwt.accessToken())
.refreshToken(jwt.refreshToken())
.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public List<UsernameResponse> getUsername(Long userId, String username) {
member -> result.add(UsernameResponse.builder()
.memberId(member.getId())
.memberName(member.getUsername())
.deviceOS(member.getSocialInfo().getSocialType())
.selfCheck(member.getId().equals(userId))
.build())
);
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/io/sobok/SobokSobok/auth/domain/SocialInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,15 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class SocialInfo {

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private SocialType socialType;

@Column(nullable = false)
private String socialId;

@Column
private String socialProfileImage;

public void removeSocialInfo() {
this.socialId = "";
this.socialProfileImage = "";
}

@Builder
public SocialInfo(SocialType socialType, String socialId, String socialProfileImage) {
this.socialType = socialType;
public SocialInfo(String socialId) {
this.socialId = socialId;
this.socialProfileImage = socialProfileImage;
}
}
12 changes: 3 additions & 9 deletions src/main/java/io/sobok/SobokSobok/auth/ui/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import io.sobok.SobokSobok.auth.application.AuthService;
import io.sobok.SobokSobok.auth.application.SocialService;
import io.sobok.SobokSobok.auth.application.SocialServiceProvider;
import io.sobok.SobokSobok.auth.domain.SocialType;
import io.sobok.SobokSobok.auth.domain.User;
import io.sobok.SobokSobok.auth.ui.dto.*;
import io.sobok.SobokSobok.common.dto.ApiResponse;
Expand All @@ -24,7 +22,7 @@
public class AuthController {

private final AuthService authService;
private final SocialServiceProvider socialServiceProvider;
private final SocialService socialService;

@PostMapping("/signup")
@Operation(
Expand All @@ -33,7 +31,6 @@ public class AuthController {
)
public ResponseEntity<ApiResponse<SocialSignupResponse>> signup(@RequestBody @Valid final SocialSignupRequest request) {

SocialService socialService = socialServiceProvider.getSocialService(request.socialType());
return ResponseEntity
.status(HttpStatus.CREATED)
.body(ApiResponse.success(
Expand All @@ -48,19 +45,16 @@ public ResponseEntity<ApiResponse<SocialSignupResponse>> signup(@RequestBody @Va
description = "사용자의 소셜 정보로 소복소복에 로그인하는 API 입니다."
)
public ResponseEntity<ApiResponse<SocialLoginResponse>> login(
@RequestParam final String code,
@RequestParam final SocialType socialType,
@RequestParam final String socialId,
@RequestParam final String deviceToken
) {

SocialService socialService = socialServiceProvider.getSocialService(socialType);
return ResponseEntity
.status(HttpStatus.OK)
.body(ApiResponse.success(
SuccessCode.SOCIAL_LOGIN_SUCCESS,
socialService.login(SocialLoginRequest.builder()
.code(code)
.socialType(socialType)
.socialId(socialId)
.deviceToken(deviceToken)
.build())
));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package io.sobok.SobokSobok.auth.ui.dto;

import io.sobok.SobokSobok.auth.domain.SocialType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

@Builder
public record SocialLoginRequest(

@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
String code,

@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull
SocialType socialType,
String socialId,

@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
String deviceToken
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package io.sobok.SobokSobok.auth.ui.dto;

import io.sobok.SobokSobok.auth.domain.SocialType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

public record SocialSignupRequest(

@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank
String code,

@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull
SocialType socialType,
String socialId,

@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package io.sobok.SobokSobok.auth.ui.dto;

import io.sobok.SobokSobok.auth.domain.SocialType;
import lombok.Builder;

@Builder
public record UsernameResponse(
Long memberId,
String memberName,
SocialType deviceOS,
Boolean selfCheck
) {

Expand Down

0 comments on commit 2103955

Please sign in to comment.