Skip to content

Commit

Permalink
Merge pull request #99 from mju-likelion/feature/update-deprecated-co…
Browse files Browse the repository at this point in the history
…de-#98

Feature/#98 Deprecated된 코드 수정
  • Loading branch information
rnqhstmd authored Sep 10, 2024
2 parents 04596b2 + 5409f15 commit c13409e
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@Slf4j
@AllArgsConstructor
public class JwtEncoder {

public static final String TOKEN_TYPE = "Bearer ";

/**
Expand All @@ -22,7 +23,7 @@ public class JwtEncoder {
*/
public static String encode(String token) {
String cookieValue = TOKEN_TYPE + token;
return URLEncoder.encode(cookieValue, StandardCharsets.UTF_8).replaceAll("\\+", "%20");
return URLEncoder.encode(cookieValue, StandardCharsets.UTF_8).replace("+", "%20");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class CorsConfig implements WebMvcConfigurer {
private final long MAX_AGE_SECS = 3600L;
private static final long MAX_AGE_SECS = 3600L;
@Value("${client.host}")
private List<String> clientHosts;
private final List<String> allowedMethods = List.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.mutsideout_mju.config;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.mutsideout_mju.dto.request.auth;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.mutsideout_mju.dto.request.auth;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.mutsideout_mju.dto.request.planner;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.mutsideout_mju.dto.request.survey;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.springframework.data.domain.Page;

import java.util.List;
import java.util.stream.Collectors;

@Getter
@Builder
Expand All @@ -19,8 +18,8 @@ public static DiaryListResponseData from(Page<Diary> page){
return DiaryListResponseData.builder()
.diaryList(page.stream()
//DiaryDto 형식으로 변환
.map(diary -> DiaryResponseDto.fromDiary(diary))
.collect(Collectors.toList()))
.map(DiaryResponseDto::fromDiary)
.toList())
.pagination(PaginationData.paginationData(page))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class DiaryResponseData {

public static DiaryResponseData from(Diary diary) {
List<ImageData> images = diary.getImageFiles().stream()
.map(imageFile -> new ImageData(imageFile.getId(),imageFile.getImageUrl()))
.collect(Collectors.toList());
.map(imageFile -> new ImageData(imageFile.getId(), imageFile.getImageUrl()))
.toList();

return DiaryResponseData.builder()
.id(diary.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
Expand All @@ -14,7 +13,7 @@ public class DailyPlannerCompletionDataList {
public static DailyPlannerCompletionDataList from(Map<String, Long> dailyCounts) {
List<DailyPlannerCompletionData> dailyList = dailyCounts.entrySet().stream()
.map(entry -> DailyPlannerCompletionData.of(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
.toList();
return new DailyPlannerCompletionDataList(dailyList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.Builder;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.example.mutsideout_mju.dto.response.room;

import com.example.mutsideout_mju.dto.response.PaginationData;
import com.example.mutsideout_mju.entity.Room;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.springframework.data.domain.Page;

import java.util.List;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.example.mutsideout_mju.dto.response.token;

import com.example.mutsideout_mju.entity.RefreshToken;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class TokenResponseDto {
private String AccessToken;
private String RefreshToken;
private String accessToken;
private String refreshToken;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.mutsideout_mju.repository;

import com.example.mutsideout_mju.entity.Planner;
import com.example.mutsideout_mju.entity.Room;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.querydsl.core.Tuple;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;
Expand All @@ -13,7 +11,6 @@

import static com.example.mutsideout_mju.entity.QPlanner.planner;

@Repository
public class CustomPlannerRepositoryImpl implements CustomPlannerRepository {

private final JPAQueryFactory queryFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.example.mutsideout_mju.entity.SurveyOption;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;

Expand All @@ -19,13 +20,15 @@ public CustomUserSurveyRepositoryImpl(EntityManager entityManager) {

@Override
public long countValidSurveyResponse(UUID userId) {
return queryFactory
.selectFrom(userSurvey)
JPAQuery<Long> countQuery = queryFactory
.select(userSurvey.count())
.from(userSurvey)
.where(userSurvey.user.id.eq(userId),
userSurvey.survey.number.between(1, 3)
.and(userSurvey.surveyOption.in(SurveyOption.NORMAL, SurveyOption.YES))
.or(userSurvey.survey.number.between(4, 6)
.and(userSurvey.surveyOption.eq(SurveyOption.YES))))
.fetchCount();
.and(userSurvey.surveyOption.eq(SurveyOption.YES))));

return countQuery.fetchOne();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.example.mutsideout_mju.service;

import com.example.mutsideout_mju.dto.request.planner.CompletePlannerRequestDto;
import com.example.mutsideout_mju.dto.request.planner.PlannerDto;
import com.example.mutsideout_mju.dto.response.planner.*;
import com.example.mutsideout_mju.entity.Planner;
import com.example.mutsideout_mju.entity.User;
import com.example.mutsideout_mju.exception.ForbiddenException;
import com.example.mutsideout_mju.exception.NotFoundException;
import com.example.mutsideout_mju.exception.UnauthorizedException;
import com.example.mutsideout_mju.exception.errorCode.ErrorCode;
import com.example.mutsideout_mju.repository.planner.PlannerRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -34,7 +32,7 @@ public PlannerListResponseData getAllPlanners(User user) {
.filter(planner -> !planner.isCompleted())
.sorted(Comparator.comparing(Planner::getCreatedAt).reversed())
.map(PlannerResponseData::fromPlanner)
.collect(Collectors.toList());
.toList();

return new PlannerListResponseData(plannerResponseDataList);
}
Expand Down Expand Up @@ -83,7 +81,7 @@ public GroupedCompletedPlannerResponse getCompletedPlannersGroupedByDate(User us
List<CompletedPlannerResponseForClient> sortedPlanners = entry.getValue().stream()
.map(CompletedPlannerResponse::toClientResponse)
.sorted(Comparator.comparing(CompletedPlannerResponseForClient::getModifiedDate).reversed())
.collect(Collectors.toList());
.toList();
sortedGroupedPlanners.put(entry.getKey(), sortedPlanners);
});

Expand All @@ -97,7 +95,7 @@ private CompletedPlannerListResponseData getAllCompletedPlanners(User user) {
List<Planner> completedPlanners = plannerRepository.findByIsCompletedAndUser(true, user);
List<CompletedPlannerResponse> completedPlannerResponses = completedPlanners.stream()
.map(CompletedPlannerResponse::fromPlanner)
.collect(Collectors.toList());
.toList();

return new CompletedPlannerListResponseData(completedPlannerResponses);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -58,7 +57,7 @@ public RoomListResponseData getRoomList(PaginationDto paginationDto) {

List<RoomResponseDto> roomResponseList = roomPage.getContent().stream()
.map(room -> RoomResponseDto.fromRoom(room, s3Service.getRoomImageLink(room.getLink())))
.collect(Collectors.toList());
.toList();

PaginationData pagination = PaginationData.paginationData(roomPage);
return new RoomListResponseData(roomResponseList, pagination);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class SurveyService {

private final SurveyRepository surveyRepository;
private final UserSurveyRepository userSurveyRepository;

Expand All @@ -28,9 +28,10 @@ public class SurveyService {
*/
public SurveyQuestionListResponseDto getAllSurveyQuestions() {
List<SurveyQuestionData> surveyQuestionDataList = surveyRepository.findAll().stream()
.map(survey -> SurveyQuestionData.from(survey))
.map(SurveyQuestionData::from)
.sorted(Comparator.comparing(SurveyQuestionData::getNumber))
.collect(Collectors.toList());
.toList();

return SurveyQuestionListResponseDto.wrap(surveyQuestionDataList);
}

Expand All @@ -39,6 +40,7 @@ public SurveyQuestionListResponseDto getAllSurveyQuestions() {
*/
@Transactional
public void saveSurveyResults(User user, SurveyResultListDto surveyResultListDto) {

// 설문에 이미 응답했는지 검증
if (userSurveyRepository.existsByUserId(user.getId())) {
throw new ConflictException(ErrorCode.SURVEY_ALREADY_PARTICIPATED);
Expand All @@ -47,7 +49,7 @@ public void saveSurveyResults(User user, SurveyResultListDto surveyResultListDto
// 설문 ID들 추출
List<UUID> surveyIds = surveyResultListDto.getSurveyResultList().stream()
.map(result -> UUID.fromString(result.getSurveyId()))
.collect(Collectors.toList());
.toList();

// 해당 사용자가 제출한 설문 중복 검사
List<UserSurvey> existingSurveys = userSurveyRepository.findByUserIdAndSurveyIdIn(user.getId(), surveyIds);
Expand All @@ -66,7 +68,7 @@ public void saveSurveyResults(User user, SurveyResultListDto surveyResultListDto
.surveyOption(surveyResult.getOption())
.build();
})
.collect(Collectors.toList());
.toList();
userSurveyRepository.saveAll(userSurveys);
}

Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/example/mutsideout_mju/util/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,24 @@ private String getImagePath(String link) {
}

public List<String> uploadImage(List<MultipartFile> files) throws IOException {

List<String> imageUrls = new ArrayList<>();

for (MultipartFile file : files) {
String dateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
String extension = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
String filename = file.getOriginalFilename();
// 파일명이 null인 경우 예외 처리
if (filename == null) {
throw new IllegalStateException("파일명이 null입니다.");
}

int dotIndex = filename.lastIndexOf(".");
// 확장자가 없는 경우 예외 처리
if (dotIndex == -1) {
throw new IllegalArgumentException("파일에 적절한 확장자가 없습니다: " + filename);
}
String extension = filename.substring(dotIndex);

String dateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
String key = "diaries/" + UUID.randomUUID().toString() + "-" + dateTime + extension;
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(file.getSize());
Expand Down

0 comments on commit c13409e

Please sign in to comment.