Skip to content

Commit

Permalink
Merge pull request #109 from gague-jinsim-in-jadeul/refact/108_jpa_to…
Browse files Browse the repository at this point in the history
…_querydsl

♻️ Refactoring Auth / ⚡ Change chatting payload
  • Loading branch information
MinkeySon authored Jan 10, 2025
2 parents f31c632 + 712b81d commit bbcd149
Show file tree
Hide file tree
Showing 20 changed files with 553 additions and 370 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.amazonaws.Response;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.PostConstruct;
import jakarta.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -56,14 +57,14 @@ public void init() {

@Operation(summary = "구글 소셜 로그인 콜백 컨트롤러 입니다.")
@GetMapping("/google/callback")
public ResponseEntity<?> getGoogleAuthorizeCode(@RequestParam("code") String authorizeCode, String type){
public ResponseEntity<?> getGoogleAuthorizeCode(@RequestParam("code") String authorizeCode, String type) throws JsonProcessingException {
type = "google";
log.info("[google login] authorizeCode : {}", authorizeCode);
return authService.signIn(authorizeCode, type);
}
@Operation(summary = "카카오 소셜 로그인 콜백 컨트롤러 입니다.")
@GetMapping("/kakao/callback")
public ResponseEntity<?> getKaKaoAuthorizeCode(@RequestParam("code") String authorizeCode, String type){
public ResponseEntity<?> getKaKaoAuthorizeCode(@RequestParam("code") String authorizeCode, String type) throws JsonProcessingException {
type = "kakao";
log.info("[kakao login] authorizeCode : {}", authorizeCode);
return authService.signIn(authorizeCode, type);
Expand All @@ -72,28 +73,42 @@ public ResponseEntity<?> getKaKaoAuthorizeCode(@RequestParam("code") String auth
@PostMapping("/google/sign")
public ResponseEntity<?> googleSign(@RequestBody RequestOauthSignDto requestOauthSignDto){
String type = "google";

if(requestOauthSignDto.getProfileUrl().length() > 8000){
return ResultCode.TOO_LONG_FILENAME.toResponseEntity();
}

return authService.normalSignIn(requestOauthSignDto, type);
}
@Operation(summary = "카카오 소셜 로그인 컨트롤러 입니다.")
@PostMapping("/kakao/sign")
public ResponseEntity<?> kaKaoSign(@RequestBody RequestOauthSignDto requestOauthSignDto){
log.info("[kakao login] dto : {}", requestOauthSignDto);
String type = "kakao";

if(requestOauthSignDto.getProfileUrl().length() > 8000){
return ResultCode.TOO_LONG_FILENAME.toResponseEntity();
}

return authService.normalSignIn(requestOauthSignDto, type);
}
@Operation(summary = "일반 회원가입 컨트롤러 입니다.")
@PostMapping("/general/sign-up")
public ResponseEntity<?> generalSignUp(@RequestBody RequestGeneralSignUpDto requestGeneralSignUpDto){
String type = "general";
String type = "GENERAL";

if(requestGeneralSignUpDto.getProfileUrl().length() > 8000){
return ResultCode.TOO_LONG_FILENAME.toResponseEntity();
}
return authService.generalSingUp(requestGeneralSignUpDto, type);
}
@Operation(summary = "일반 로그인 컨트롤러 입니다.")
@PostMapping("/general/sign-in")
public ResponseEntity<?> generalSignIn(@RequestBody RequestGeneralSignDto requestGeneralSignDto){
String type = "general";
String type = "GENERAL";
return authService.generalSignIn(requestGeneralSignDto, type);
}
@Operation(summary = "사용자 프로필 사진 업로드", description = "사용자가 회원가입 시 프로필을 업로드합니다.")
@Operation(summary = "공방 관계자 프로필 업로드", description = "회원가입 시 사용자 프로필을 업로드합니다.")
@PostMapping("/profile-upload")
public ResponseEntity<?> uploadFile(
@RequestParam("file") MultipartFile file){
Expand Down Expand Up @@ -146,7 +161,6 @@ public ResponseEntity<?> sendOne(@RequestBody RequestPhoneNumber requestPhoneNum
return ResultCode.BAD_REQUEST.toResponseEntity();
}


Message message = new Message();

message.setFrom(MESSAGE_SENDER);
Expand Down
555 changes: 241 additions & 314 deletions src/main/java/org/gagu/gagubackend/auth/dao/impl/AuthDAOImpl.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.persistence.*;
import lombok.*;
import org.gagu.gagubackend.auth.dto.request.RequestSaveUserDto;
import org.gagu.gagubackend.global.domain.BaseTimeEntity;

import java.math.BigDecimal;
Expand Down Expand Up @@ -35,4 +36,12 @@ public class StarReview extends BaseTimeEntity {
@OneToOne
@JoinColumn
private User workshop; // 공방 일대일 대응

public StarReview(RequestSaveUserDto dto, User user){
this.workshopName = dto.getNickName();
this.starsAverage = BigDecimal.valueOf(0.0);
this.sum = new BigDecimal(0);
this.count = BigInteger.valueOf(0);
this.workshop = user;
}
}
51 changes: 50 additions & 1 deletion src/main/java/org/gagu/gagubackend/auth/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.persistence.*;
import lombok.*;
import org.gagu.gagubackend.auth.dto.request.RequestSaveUserDto;
import org.gagu.gagubackend.chat.domain.ChatRoomMember;
import org.gagu.gagubackend.global.domain.BaseTimeEntity;
import org.hibernate.annotations.ColumnDefault;
Expand All @@ -13,6 +14,7 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -49,7 +51,7 @@ public class User extends BaseTimeEntity implements UserDetails {
@Column(nullable = false)
private String email;

@Column(nullable = false)
@Column(nullable = false, length = 8000)
private String profileUrl;

@Column(nullable = false)
Expand Down Expand Up @@ -106,4 +108,51 @@ public boolean isCredentialsNonExpired() {
public boolean isEnabled() {
return true;
}

public void regularUpdate(String email, String resourceId, String fcm){
this.email = email;
this.resourceId = resourceId;
this.FCMToken = fcm;
}
public void profileUpdate(String fileUrl){
this.profileUrl = fileUrl;
}
public void infoUpdate(String address, String nickname){
this.address = address;
this.nickName = nickname;
}
public void addressUpdate(String address){
this.address = address;
}
public void workshopFCMUpdate(String fcm){
this.FCMToken = fcm;
}

public User(RequestSaveUserDto dto, String role){
this.name = dto.getName();
this.nickName = dto.getNickName();
this.password = dto.getPassword();
this.phoneNumber = dto.getPhoneNumber();
this.email = dto.getEmail();
this.profileUrl = dto.getProfileUrl();
this.loginType = dto.getLoginType();
this.profileMessage = dto.getProfileMessage();
this.FCMToken = dto.getFCMToken();
this.useAble = dto.isUseAble();
this.roles = Collections.singletonList(role);
}
public User(RequestSaveUserDto dto, String nickname, String role){
this.name = dto.getName();
this.resourceId = dto.getResourceId();
this.nickName = nickname;
this.password = dto.getPassword();
this.phoneNumber = dto.getPhoneNumber();
this.email = dto.getEmail();
this.profileUrl = dto.getProfileUrl();
this.loginType = dto.getLoginType();
this.profileMessage = dto.getProfileMessage();
this.FCMToken = dto.getFCMToken();
this.useAble = dto.isUseAble();
this.roles = Collections.singletonList(role);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public class RequestSaveUserDto {
private String FCMToken;
private String resourceId;
private boolean useAble;

public void updateNickname(String nickname){
this.nickName = nickname;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package org.gagu.gagubackend.auth.dto.response;

import lombok.*;
import org.gagu.gagubackend.auth.domain.User;
import org.gagu.gagubackend.global.domain.CommonResponse;
import org.gagu.gagubackend.global.security.JwtTokenProvider;
import org.springframework.beans.factory.annotation.Autowired;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Builder
public class ResponseAuthDto {

private String accessToken;
private String nickname;
private String name;
private String resourceId;
private CommonResponse<?> status;

public ResponseAuthDto(User user, String accessToken){
this.accessToken = accessToken;
this.nickname = user.getNickName();
this.name = user.getName();
this.resourceId = user.getResourceId();
this.status = CommonResponse.success();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.gagu.gagubackend.auth.dto.response;

import lombok.*;
import org.gagu.gagubackend.auth.domain.User;

@Getter
@Setter
Expand All @@ -15,4 +16,12 @@ public class ResponseProfileDto {
private String loginTypeLogo;
private String profileUrl;
private String address;

public ResponseProfileDto(User user){
this.profileUrl = user.getProfileUrl();
this.name = user.getName();
this.email = user.getEmail();
this.address = user.getAddress();
this.nickname = user.getNickName();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.gagu.gagubackend.auth.dto.response;

import lombok.*;
import org.gagu.gagubackend.auth.domain.User;

@Getter
@Setter
Expand All @@ -12,4 +13,10 @@ public class ResponseWorkShopDetailsDto {
private String workshopName;
private String address;
private String description;

public ResponseWorkShopDetailsDto(User user){
this.workshopName = user.getNickName();
this.description = user.getProfileMessage();
this.address = user.getAddress();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
public interface UserRepository extends JpaRepository<User,Long>, UserRepositoryCustom {
User findByEmailAndLoginType(String name, String loginType);
User findByResourceIdAndLoginType(String resourceId, String loginType);
List<User> findAllByEmailAndLoginType(String email, String loginType);
User findByEmailAndNickName(String email, String nickName);
User findByNickName(String nickname);
boolean existsByNickName(String nickname);
boolean existsByNickNameAndLoginType(String nickname, String loginType);
boolean existsByResourceIdAndLoginType(String resourceId, String loginType);
boolean existsByEmailAndNickName(String email, String nickname);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,45 @@

import org.gagu.gagubackend.auth.domain.User;

import java.util.List;
import java.util.Optional;

public interface UserRepositoryCustom {
/**
* 닉네임으로 유저 조회
* @param nickname
* @return Optional
*/
Optional<User> findUserByNickname(String nickname);

/**
* 공방 회원가입 여부 확인
* @param nickname
* @param loginType
* @return Optional
*/
Optional<User> checkWorkshopExist(String nickname, String loginType);

/**
* 공방 조회 시 중복 된 이메일 존재하여 List 반환
* @param email
* @param type
* @return Optional
*/
Optional<List<User>> findWorkshops(String email, String type);

/**
* 소셜 로그인 유저 조회
* @param resourceId
* @param loginType
* @return user
*/
Optional<User> checkSocialUserExist(String resourceId, String loginType);

/**
* 페이지에서 공방 id 값으로 조회
* @param id
* @return user
*/
Optional<User> findWorkshopById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
Expand All @@ -29,4 +30,42 @@ public Optional<User> findUserByNickname(String nickname) {
.where(qUser.nickName.eq(nickname))
.fetchOne());
}

@Override
public Optional<User> checkWorkshopExist(String nickname, String loginType) {
QUser qUser = QUser.user;
return Optional.ofNullable(jpaQueryFactory.select(qUser)
.from(qUser)
.where(qUser.nickName.eq(nickname).and(qUser.loginType.eq(loginType)))
.fetchOne());
}

@Override
public Optional<List<User>> findWorkshops(String email, String type) {
QUser qUser = QUser.user;

return Optional.ofNullable(jpaQueryFactory.select(qUser)
.from(qUser)
.where(qUser.email.eq(email).and(qUser.loginType.eq(type)))
.fetch());
}

@Override
public Optional<User> checkSocialUserExist(String resourceId, String loginType) {
QUser qUser = QUser.user;
return Optional.ofNullable(jpaQueryFactory.select(qUser)
.from(qUser)
.where(qUser.resourceId.eq(resourceId).and(qUser.loginType.eq(loginType)))
.fetchOne());
}

@Override
public Optional<User> findWorkshopById(Long id) {
QUser qUser = QUser.user;

return Optional.ofNullable(jpaQueryFactory.select(qUser)
.from(qUser)
.where(qUser.id.eq(id))
.fetchOne());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.gagu.gagubackend.auth.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.gagu.gagubackend.auth.dto.request.*;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -11,7 +12,7 @@ public interface AuthService {
* @param type
* @return
*/
ResponseEntity<?> signIn(String authorizeCode, String type);
ResponseEntity<?> signIn(String authorizeCode, String type) throws JsonProcessingException;
/**
* 소셜 로그인 api 사용 x
* @param requestOauthSignDto
Expand Down
Loading

0 comments on commit bbcd149

Please sign in to comment.