Skip to content

Commit

Permalink
Conflict Resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
HyoBN committed Sep 5, 2023
2 parents 6e95a6b + cf8fce1 commit 4e041c2
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public WebSecurityCustomizer webSecurityCustomizer(){
"/v3/api-docs/**",
"/swagger-ui/**",
"/docs/**","/members/oauth", "/members/oauth/info","/members/new-token","/members/terms","/categories","/members/exist-nickname",
"/members/phone/sms","/members/phone/auth","/members/temp-login"
"/members/phone/sms","/members/phone/auth","/members/temp-login","/auto-login"
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/zipdabang/server/base/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public enum Code {
NICKNAME_EXIST(HttpStatus.OK,2052, "닉네임이 이미 존재합니다."),
NICKNAME_OK(HttpStatus.OK,2053, "사용 가능한 닉네임 입니다."),
PHONE_NUMBER_EXIST(HttpStatus.OK, 2054, "이미 인증된 전화번호입니다."),
AUTO_LOGIN_MAIN(HttpStatus.OK, 2055, "홈 화면으로 이동하세요"),
AUTO_LOGIN_NOT_MAIN(HttpStatus.OK, 2056, "로그인 화면으로 이동하세요"),


//recipe response
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package zipdabang.server.base.exception.handler;

import zipdabang.server.base.Code;
import zipdabang.server.base.exception.GeneralException;

public class RootException extends GeneralException {
public RootException(Code errorCode) {
super(errorCode);
}
}
2 changes: 2 additions & 0 deletions src/main/java/zipdabang/server/service/RootService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
public interface RootService {

List<Category> getAllCategories();

Boolean autoLoginService(String authorizationHeader);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import zipdabang.server.auth.provider.TokenProvider;
import zipdabang.server.base.Code;
import zipdabang.server.base.exception.handler.RootException;
import zipdabang.server.domain.Category;
import zipdabang.server.domain.member.Member;
import zipdabang.server.repository.CategoryRepository;
import zipdabang.server.repository.memberRepositories.MemberRepository;
import zipdabang.server.service.RootService;
Expand All @@ -21,8 +25,33 @@ public class RootServiceImpl implements RootService {

private final MemberRepository memberRepository;

private final TokenProvider tokenProvider;

@Override
public List<Category> getAllCategories() {
return categoryRepository.findAll();
}

@Override
public Boolean autoLoginService(String authorizationHeader) {

Boolean result = null;
if(authorizationHeader == null)
result = false;
else{
String token = authorizationHeader.substring(7);
Long memberId = tokenProvider.validateAndReturnSubject(token);
if (memberId.equals(0L))
result = true;
else{
Member member = memberRepository.findById(memberId).orElseThrow(() -> new RootException(Code.MEMBER_NOT_FOUND));
if(member.getAge() == null || member.getNickname() == null || member.getName() == null || member.getGender() == null)
result = false;
else
result = true;
}
}

return result;
}
}
26 changes: 26 additions & 0 deletions src/main/java/zipdabang/server/web/controller/RootController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import zipdabang.server.base.Code;
import zipdabang.server.base.ResponseDto;
import zipdabang.server.converter.RootConverter;
import zipdabang.server.domain.Category;
import zipdabang.server.service.RootService;
import zipdabang.server.web.dto.common.BaseDto;
import zipdabang.server.web.dto.responseDto.RootResponseDto;

import java.util.List;
Expand Down Expand Up @@ -57,4 +60,27 @@ public ResponseDto<RootResponseDto.BeverageCategoryListDto> showCategoryList(){
public ResponseDto<RootResponseDto.BannerImageDto> showBanners() {
return null;
}


@Operation(summary = "자동 로그인 API ✔️", description = "자동 로그인 API 입니다. 스웨거에 authorizationHeader는 무시해주세요 스웨거에서는 옆 자물쇠에 토큰 넣어주세요! 평소대로 헤더에 토큰 넣어서 주시면 됩니다")
@ApiResponses({
@ApiResponse(responseCode = "2055",description = "OK , 홈 화면으로 이동해도 됨",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "2056",description = "OK , 로그인을 다시 진행 해야 함",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4000",description = "FORBIDDEN, 이미 로그아웃 한 토큰, 로그인 다시 하세요",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4003",description = "UNAUTHORIZED, 토큰 모양이 이상함, 토큰 제대로 주세요",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4005",description = "UNAUTHORIZED, 엑세스 토큰 만료, 리프레시 토큰 사용",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4052",description = "BAD_REQUEST, 사용자가 없습니다. 이 api에서 이거 생기면 백앤드 개발자 호출",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "5000",description = "SERVER ERROR, 백앤드 개발자에게 알려주세요",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
})
@Parameters({
@Parameter(name = "user", hidden = true)
})
@GetMapping("/auto-login")
public ResponseDto<BaseDto.BaseResponseDto> autoLogin(@RequestHeader(value = "Authorization", required = false) String authorizationHeader){
Boolean autoResult = rootService.autoLoginService(authorizationHeader);
if(autoResult)
return ResponseDto.of(Code.AUTO_LOGIN_MAIN,null);
else
return ResponseDto.of(Code.AUTO_LOGIN_NOT_MAIN,null);
}
}

0 comments on commit 4e041c2

Please sign in to comment.