Skip to content

Commit

Permalink
Weekly 9 (#206)
Browse files Browse the repository at this point in the history
* Weekly/8/issue#144 동시성 제어 (#189)

* Feat: RedissonConfig 설정

* Feat: Redisson Lock 구현(임시)

* Fix: RaceCondition 테스트 오류 수정

1. RedissonLock의 value로 hostId만 넘기기
2. RaceConditionTest를 SpringBootTest로 테스트
3. BeforeEach로 Redis 초기화

* Refactor: GroupMember 조회 fetch join 적용

* Refactor: random GroupMember 조회 fetch join 적용

* Refactor: 방문자 조회수 비동기 로직 추가

* Feat: 질문 지목 시 count 증가 동시성 제어

* Refactor: merge weekly9

* Refactor: 누락된 코드 추가

* Refactor: 누락된 코드 추가

* Refactor: 코드 수정

* Refactor: redissonClient 제거

* Refactor: redis 설정 변경

* Refactor: redis 설정 변경

* HotFix: 이미지 파일 resize 비율 조정

* Refactor: RedissonClient 사용 테스트 ActiveProfile 설정

* Refactor: RedissonClient 사용 테스트 Profile 설정

* Fix: Profile() 메서드에 적용

* Fix: ProfileIntegrationTest, RaceConditionTest 주석처리

* Fix: 충돌 해결

* Refactor: Random Question Response 수정

* Chore: 불필요한 Import 제거

* Import: 충돌 해결

---------

Co-authored-by: hjinshin <gudwls818@gmail.com>
Co-authored-by: Kwon Da woon <82216606+momnpa333@users.noreply.github.com>

* Refactor: 알림 타임아웃 수정

* Refactor: 프로필 질문 createdAt 형식 변경

* Fix: 포인트 결제 method 변경

* Feat: 관리자 api 구현

* Feat: alarm 연결 시 로그

* Refactor: answer record desc로 정렬

* Refactor: 방문자 검증을 쿠키 확인을 변경

---------

Co-authored-by: yso8296 <66588512+yso8296@users.noreply.github.com>
Co-authored-by: Kwon Da woon <82216606+momnpa333@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 10, 2024
1 parent 84c49e0 commit a66c17f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import supernova.whokie.answer.controller.dto.AnswerRequest;
Expand Down Expand Up @@ -57,14 +57,15 @@ public AnswerResponse.Refresh refresh(

@GetMapping("/record")
public PagingResponse<AnswerResponse.Record> getAnswerRecord(
@PageableDefault(page = 0, size = 10, sort = "createdAt", direction = Sort.Direction.ASC) Pageable pageable,
@RequestParam(name = "page", defaultValue = "0") int page,
@RequestParam(name = "size", defaultValue = "10") int size,
@RequestParam(name = "date", required = false) LocalDate date,
@Authenticate Long userId
) {

Page<AnswerModel.Record> page = answerService.getAnswerRecord(pageable, userId,
Pageable pageable = PageRequest.of(page, size, Sort.unsorted());
Page<AnswerModel.Record> models = answerService.getAnswerRecord(pageable, userId,
date);
Page<AnswerResponse.Record> response = page.map(AnswerResponse.Record::from);
Page<AnswerResponse.Record> response = models.map(AnswerResponse.Record::from);
return PagingResponse.from(response);
}
@GetMapping("/record/days")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public interface AnswerRepository extends JpaRepository<Answer, Long> {
@EntityGraph(attributePaths = {"picked"})
@Query("SELECT p FROM Answer p WHERE p.picked = :user AND p.createdAt BETWEEN :startDate AND :endDate")
@Query("SELECT p FROM Answer p WHERE p.picked = :user AND p.createdAt BETWEEN :startDate AND :endDate ORDER BY p.createdAt DESC")
Page<Answer> findAllByPickedAndCreatedAtBetween(Pageable pageable, @Param("user") Users user, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);

@Query("SELECT DISTINCT FUNCTION('day', p.createdAt) FROM Answer p WHERE p.picked = :user AND p.createdAt BETWEEN :startDate AND :endDate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface VisitorIp {
public @interface VisitorUuid {
}
12 changes: 6 additions & 6 deletions src/main/java/supernova/whokie/global/config/WebMvcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import supernova.whokie.global.interceptor.IpInterceptor;
import supernova.whokie.global.interceptor.VisitorInterceptor;
import supernova.whokie.global.interceptor.JwtInterceptor;
import supernova.whokie.global.auth.JwtProvider;
import supernova.whokie.global.resolver.IpArgumentResolver;
import supernova.whokie.global.resolver.VisitorArgumentResolver;
import supernova.whokie.global.resolver.LoginAdminArgumentResolver;
import supernova.whokie.global.resolver.LoginUserArgumentResolver;

Expand All @@ -31,8 +31,8 @@ public JwtInterceptor jwtInterceptor() {

@Bean
@Order(2)
public IpInterceptor ipInterceptor() {
return new IpInterceptor();
public VisitorInterceptor ipInterceptor() {
return new VisitorInterceptor();
}

@Bean
Expand All @@ -46,8 +46,8 @@ public LoginAdminArgumentResolver loginAdminArgumentResolver() {
}

@Bean
public IpArgumentResolver ipArgumentResolver() {
return new IpArgumentResolver();
public VisitorArgumentResolver ipArgumentResolver() {
return new VisitorArgumentResolver();
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package supernova.whokie.global.interceptor;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;

import java.util.UUID;

public class VisitorInterceptor implements HandlerInterceptor {

private static final String COOKIE_NAME = "visitorUUID";

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

Cookie[] cookies = request.getCookies();
String cookieUuid = null;
if(cookies != null) {
for(Cookie cookie : cookies) {
if(cookie.getName().equals(COOKIE_NAME)) {
cookieUuid = cookie.getValue();
}
}
}

if(cookieUuid == null) {
cookieUuid = UUID.randomUUID().toString();
Cookie cookie = new Cookie(COOKIE_NAME, cookieUuid);
cookie.setPath("/");
response.addCookie(cookie);
}

request.setAttribute("visitorUuid", cookieUuid);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import supernova.whokie.global.annotation.VisitorIp;
import supernova.whokie.global.annotation.VisitorUuid;

public class IpArgumentResolver implements HandlerMethodArgumentResolver {
public class VisitorArgumentResolver implements HandlerMethodArgumentResolver {

@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.hasParameterAnnotation(VisitorIp.class);
return parameter.hasParameterAnnotation(VisitorUuid.class);
}

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();
return request.getAttribute("visitorIp");
return request.getAttribute("visitorUuid");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import supernova.whokie.global.annotation.Authenticate;
import supernova.whokie.global.annotation.VisitorIp;
import supernova.whokie.global.annotation.VisitorUuid;
import supernova.whokie.global.dto.GlobalResponse;
import supernova.whokie.profile.controller.dto.ProfileRequest;
import supernova.whokie.profile.controller.dto.ProfileResponse;
Expand All @@ -26,9 +26,9 @@ public class ProfileController {
@GetMapping("/{user-id}")
public ProfileResponse.Info getProfileInfo(
@PathVariable("user-id") @Valid @NotNull @Min(1) Long userId,
@VisitorIp String visitorIp
@VisitorUuid String visitorUuid
) {
ProfileModel.Info response = profileService.getProfile(userId, visitorIp);
ProfileModel.Info response = profileService.getProfile(userId, visitorUuid);
return ProfileResponse.Info.from(response);
}

Expand Down

0 comments on commit a66c17f

Please sign in to comment.