Skip to content

Commit

Permalink
[Fix] Conflict 해결#113
Browse files Browse the repository at this point in the history
  • Loading branch information
parseyong committed Jul 20, 2024
2 parents 852fe61 + 58ad252 commit 99711d6
Show file tree
Hide file tree
Showing 46 changed files with 323 additions and 176 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ dependencies {
// Jsoup
implementation 'org.jsoup:jsoup:1.17.2'

//redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'


}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public class QProfilePhoto extends EntityPathBase<ProfilePhoto> {
//inherited
public final DateTimePath<java.time.LocalDateTime> createdDate = _super.createdDate;

public final NumberPath<Long> id = createNumber("id", Long.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> lastModifiedDate = _super.lastModifiedDate;

public final NumberPath<Long> profilePhotoId = createNumber("profilePhotoId", Long.class);

public final StringPath profilePhotoName = createString("profilePhotoName");

public final StringPath profilePhotoPath = createString("profilePhotoPath");
Expand Down
4 changes: 2 additions & 2 deletions src/main/generated/me/snaptime/user/domain/QUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public class QUser extends EntityPathBase<User> {

public final StringPath email = createString("email");

public final NumberPath<Long> id = createNumber("id", Long.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> lastModifiedDate = _super.lastModifiedDate;

Expand All @@ -46,6 +44,8 @@ public class QUser extends EntityPathBase<User> {

public final ListPath<String, StringPath> roles = this.<String, StringPath>createList("roles", String.class, StringPath.class, PathInits.DIRECT2);

public final NumberPath<Long> userId = createNumber("userId", Long.class);

public QUser(String variable) {
this(User.class, forVariable(variable), INITS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public FindAlbumResDto findAlbum(String uId, Long album_id) {
FindSnapResDto.entityToResDto(
snap,
urlComponent.makePhotoURL(snap.getFileName(), false),
urlComponent.makeProfileURL(snap.getUser().getProfilePhoto().getId())
urlComponent.makeProfileURL(snap.getUser().getProfilePhoto().getProfilePhotoId())
)
)
.collect(Collectors.toList()))
Expand All @@ -90,7 +90,7 @@ public FindAlbumResDto findAlbum(String uId, Long album_id) {
FindSnapResDto.entityToResDto(
snap,
urlComponent.makePhotoURL(snap.getFileName(), snap.isPrivate()),
urlComponent.makeProfileURL(snap.getUser().getProfilePhoto().getId())
urlComponent.makeProfileURL(snap.getUser().getProfilePhoto().getProfilePhotoId())
)
)
.collect(Collectors.toList()))
Expand Down Expand Up @@ -169,7 +169,7 @@ public void removeAlbum(String uId, Long album_id) {
@Override
public void isUserHavePermission(User user, Long album_id) {
Album foundAlbum = albumRepository.findById(album_id).orElseThrow(() -> new CustomException(ExceptionCode.ALBUM_NOT_EXIST));
if(!(Objects.equals(foundAlbum.getUser().getId(), user.getId()))){
if(!(Objects.equals(foundAlbum.getUser().getUserId(), user.getUserId()))){
throw new CustomException(ExceptionCode.ALBUM_USER_NOT_MATCH);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/me/snaptime/exception/ExceptionCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public enum ExceptionCode {
TOKEN_UNAUTHENTICATED(HttpStatus.UNAUTHORIZED, "인증되지 않은 토큰입니다."),
TOKEN_INVALID_FORMAT(HttpStatus.UNAUTHORIZED, "잘못된 형식의 토큰입니다."),
TOKEN_NOT_FOUND(HttpStatus.BAD_REQUEST, "토큰이 비었거나 null입니다"),
INVALID_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED,"리프레시 토큰이 유효하지 않습니다"),

// Jsoup Action
URL_HAVING_PROBLEM(HttpStatus.BAD_REQUEST, "문제가 있는 URL입니다.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public List<Tuple> findFriendList(User targetUser, FriendSearchType searchType,
Pageable pageable= PageRequest.of((int) (pageNum-1),20);

List<Tuple> tuples = jpaQueryFactory.select(
user.loginId, user.profilePhoto.id, user.name, friend.friendId
user.loginId, user.profilePhoto.profilePhotoId, user.name, friend.friendId
)
.from(friend)
.join(user).on(getJoinBuilder(searchType))
Expand All @@ -50,18 +50,18 @@ public List<Tuple> findFriendList(User targetUser, FriendSearchType searchType,
}

private OrderSpecifier createOrderSpecifier() {
return new OrderSpecifier(Order.ASC, user.id);
return new OrderSpecifier(Order.ASC, user.userId);
}

// WHERE절을 동적으로 만들기 위한 메소드
private BooleanBuilder getWhereBuilder(User targetUser, FriendSearchType friendSearchType, String searchKeyword){
BooleanBuilder builder = new BooleanBuilder();

if(friendSearchType == FriendSearchType.FOLLOWING){
builder.and(friend.sender.id.eq(targetUser.getId()));
builder.and(friend.sender.userId.eq(targetUser.getUserId()));
}
else{
builder.and(friend.receiver.id.eq(targetUser.getId()));
builder.and(friend.receiver.userId.eq(targetUser.getUserId()));
}

if(searchKeyword !=null){
Expand All @@ -75,10 +75,10 @@ private BooleanBuilder getWhereBuilder(User targetUser, FriendSearchType friendS
private BooleanBuilder getJoinBuilder(FriendSearchType friendSearchType){
BooleanBuilder builder = new BooleanBuilder();
if(friendSearchType == FriendSearchType.FOLLOWING){
return builder.and(friend.receiver.id.eq(user.id));
return builder.and(friend.receiver.userId.eq(user.userId));
}
else{
return builder.and(friend.sender.id.eq(user.id));
return builder.and(friend.sender.userId.eq(user.userId));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void sendFollow(String senderLoginId, String receiverLoginId){
throw new CustomException(ExceptionCode.ALREADY_FOLLOW);

// 자기자신에게 팔로우요청을 했다면
if (receiver.getId() == sender.getId())
if (receiver.getUserId() == sender.getUserId())
throw new CustomException(ExceptionCode.SELF_FRIEND_REQ);

friendRepository.save(Friend.builder()
Expand Down Expand Up @@ -111,7 +111,7 @@ public FindFriendResDto findFriends(String reqLoginId, String targetLoginId, Lon
List<FriendInfo> friendInfos = tuples.stream().map(tuple ->
{
boolean isMyFriend = checkIsFollow(reqUser ,findUserByLoginId(tuple.get(user.loginId)));
String profilePhotoURL = urlComponent.makeProfileURL(tuple.get(user.profilePhoto.id));
String profilePhotoURL = urlComponent.makeProfileURL(tuple.get(user.profilePhoto.profilePhotoId));
return FriendInfo.toDto(tuple,profilePhotoURL,isMyFriend);
}).collect(Collectors.toList());

Expand Down
40 changes: 29 additions & 11 deletions src/main/java/me/snaptime/jwt/JwtProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
Expand All @@ -24,19 +25,20 @@ public class JwtProvider {

private Key secretKey;

private Long accessTokenValidTime= 1000L * 60 * 60*24;
@Value("${accessTokenValidTime}")
private Long accessTokenValidTime;

@Value("${refreshTokenValidTime}")
private Long refreshTokenValidTime;

@PostConstruct
protected void init(){
log.info("[init] JwtTokenProvide 내 secretKey 초기화 시작");
secretKey = Keys.secretKeyFor(SignatureAlgorithm.HS256);
log.info("[init] JwtTokenProvider 내 secretKey 초기화 완료");
}

public String createAccessToken(String loginId, List<String> roles){
log.info("[createAccessToken] 엑세스 토큰 생성 시작");

public String createAccessToken(Long userId, String loginId, List<String> roles){
Claims claims = Jwts.claims().setSubject(loginId);
claims.put("userId",userId);
claims.put("type","access");
claims.put("roles",roles);
Date now = new Date();
Expand All @@ -47,14 +49,33 @@ public String createAccessToken(String loginId, List<String> roles){
.signWith(secretKey)
.compact();

log.info("[createAccessToken] 엑세스 토큰 생성 완료");
return token;
}

public String createRefreshToken(Long id, String loginId, List<String> roles){
Claims claims = Jwts.claims().setSubject(loginId);
claims.put("userId", id);
claims.put("type", "refresh");
claims.put("roles", roles);
Date now = new Date();
String token = Jwts.builder()
.setClaims(claims)
.setIssuedAt(now)
.setExpiration(new Date(now.getTime() + refreshTokenValidTime))
.signWith(secretKey)
.compact();
return token;
}

public Long getUserId(String token) {
Long userId = Long.valueOf(Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token).getBody().get("userId").toString());
log.info("[getUserId] 토큰 기반 회원 구별 정보 추출 완료, userId : {}", userId);
return userId;
}

// 필터에서 인증 성공 후, SecurityContextHolder 에 저장할 Authentication 을 생성
//UsernamePasswordAuthenticationToken 클래스를 사용
public Authentication getAuthentication(String token){
log.info("[getAuthentication] 토큰 인증 정보 조회 시작");
UserDetails userDetails = userDetailsService.loadUserByUsername(this.getUsername(token));
log.info("[getAuthentication] 토큰 인증 정보 조회 완료, UserDetails loginId : {}",userDetails.getUsername());

Expand All @@ -65,7 +86,6 @@ public Authentication getAuthentication(String token){
//Jwts.parser()를 통해 secretKey를 설정하고 클레임을 추출해서 토큰을 생성할 때 넣었던 sub값을 추출합니다.
public String getUsername(String token)
{
log.info("[getUsername] 토큰 기반 회원 구별 정보 추출");
String loginId = Jwts.parserBuilder()
.setSigningKey(secretKey)
.build()
Expand All @@ -77,7 +97,6 @@ public String getUsername(String token)
}

public String getAuthorizationToken(HttpServletRequest request){
log.info("[getAuthorizationToken] HTTP 헤더에서 Token 값 추출");
String token = request.getHeader("Authorization");
try{
if(!token.substring(0,"BEARER ".length()).equalsIgnoreCase("Bearer ")){
Expand All @@ -94,7 +113,6 @@ public String getAuthorizationToken(HttpServletRequest request){
이 메소드는 토큰을 전달 받아 클레임의 유효기간을 체크하고 boolean 타입 값을 리턴하는 역할을 한다.
*/
public boolean validateToken(String token) {
log.info("[validateToken] 토큰 유효 체크 시작");
try{
//복잡한 설정일 떈, Jwts.parserBuilder()를 이용
Jws<Claims> claims = Jwts.parser()
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/me/snaptime/profile/controller/ProfileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,30 @@ public class ProfileController {
@Operation(summary = "유저 앨범, 스냅 조회", description = "유저의 앨범들과, 각 앨범의 스냅들을 조회합니다." +
"<br> 자신의 프로필 조회 -> 앨범 당 private, public 관계 없이 최근 snap 2개 리턴" +
"<br> 다른 사람의 프로필 조회 -> snap이 전부 private이거나 없는 경우 앨범 리턴 x 그리고 private 인 snap 리턴 x")
@Parameter(name = "loginId", description = "앨범과 사진들을 가져오기 위한 loginId", required = true)
@Parameter(name = "targetLoginId", description = "앨범과 사진들을 가져오기 위한 loginId", required = true)
@GetMapping("/album-snap")
public ResponseEntity<CommonResponseDto<List<AlbumSnapResDto>>> getAlbumSnap(@AuthenticationPrincipal UserDetails principal,
@RequestParam("loginId")
public ResponseEntity<CommonResponseDto<List<AlbumSnapResDto>>> getAlbumSnap(@AuthenticationPrincipal UserDetails userDetails,
@RequestParam("targetLoginId")
@NotBlank(message = "로그인 아이디 입력은 필수입니다.") String targetLoginId){
String yourLoginId = principal.getUsername();
List<AlbumSnapResDto> albumSnapResDtoList = profileService.getAlbumSnap(yourLoginId, targetLoginId);
String reqLoginId = userDetails.getUsername();
List<AlbumSnapResDto> albumSnapResDtos = profileService.getAlbumSnap(reqLoginId, targetLoginId);
return ResponseEntity.status(HttpStatus.OK).body(
new CommonResponseDto<>(
"유저 앨범과 스냅 조회를 성공적으로 완료하였습니다.",
albumSnapResDtoList
albumSnapResDtos
));
}

@Operation(summary = "유저 이름, 프로필 사진 조회", description = "유저의 이름과, 프로필 사진을 조회합니다." +
"<br> 유저 번호, 유저 이름, 프로필 사진 url 리턴(토큰 없이 url 접근 가능)" +
"<br> 토큰이 없어도 해당 Api 엔드포인트를 요청할 수 있습니다.")
@Parameter(name = "loginId", description = "이름과 프로필 사진을 가져오기 위한 loginId", required = true)
@Parameter(name = "targetLoginId", description = "이름과 프로필 사진을 가져오기 위한 loginId", required = true)
@GetMapping("/profile")
public ResponseEntity<CommonResponseDto<UserProfileResDto>> getUserProfile(@AuthenticationPrincipal UserDetails principal,
@RequestParam("loginId")
@NotBlank(message = "로그인 아이디 입력은 필수입니다.") String loginId){
UserProfileResDto userProfileResDto = profileService.getUserProfile(principal.getUsername(),loginId);
public ResponseEntity<CommonResponseDto<UserProfileResDto>> getUserProfile(@AuthenticationPrincipal UserDetails userDetails,
@RequestParam("targetLoginId")
@NotBlank(message = "로그인 아이디 입력은 필수입니다.") String targetLoginId){
String reqLoginId = userDetails.getUsername();
UserProfileResDto userProfileResDto = profileService.getUserProfile(reqLoginId, targetLoginId);
return ResponseEntity.status(HttpStatus.OK).body(
new CommonResponseDto<>(
"유저 이름과, 프로필 사진 조회를 성공적으로 완료하였습니다.",
Expand All @@ -87,7 +88,6 @@ public ResponseEntity<CommonResponseDto<ProfileCntResDto>> getProfileCnt(@Reques
@GetMapping("/tag-snap")
public ResponseEntity<CommonResponseDto<List<ProfileTagSnapResDto>>> getTagSnap(@RequestParam("loginId")
@NotBlank(message = "로그인 아이디 입력은 필수입니다.") String loginId){

List<ProfileTagSnapResDto> profileTagSnapResDto = profileService.getTagSnap(loginId);
return ResponseEntity.status(HttpStatus.OK).body(
new CommonResponseDto<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public record UserProfileResDto(
public static UserProfileResDto toDto(User user, String profileURL , Boolean isFollow)
{
return UserProfileResDto.builder()
.userId(user.getId())
.userId(user.getUserId())
.userName(user.getName())
.profileURL(profileURL)
.isFollow(isFollow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
public interface ProfileRepository{

List<AlbumSnapResDto> findAlbumSnap(User targetUser, Boolean checkPermission);
List<ProfileTagSnapResDto> findTagSnap(User reqUser);
List<ProfileTagSnapResDto> findTagSnap(User targetUser);
}
Loading

0 comments on commit 99711d6

Please sign in to comment.