Skip to content

Commit

Permalink
Merge pull request #26 from Central-MakeUs/fix/screeningReview
Browse files Browse the repository at this point in the history
[Fix]screening review
  • Loading branch information
AlmondBreez3 authored Jan 27, 2024
2 parents aec79d8 + 25bdc8a commit 0f00cd7
Show file tree
Hide file tree
Showing 29 changed files with 520 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ jobs:
- name: 환경 변수를 세팅합니다.
run: |
cd ./Infra/src/main/resources
sudo touch ./popcornmate-d7ca1-firebase-adminsdk-svbpw-fce737e873.json
echo "$FIREBASE_JSON" | sudo tee ./popcornmate-d7ca1-firebase-adminsdk-svbpw-fce737e873.json > /dev/null
sed -i 's/#/"/g' ./popcornmate-d7ca1-firebase-adminsdk-svbpw-fce737e873.json
sudo touch ./popcornmateprod-firebase-adminsdk-yvb81-02b4302a03.json
echo "$FIREBASE_JSON" | sudo tee ./popcornmateprod-firebase-adminsdk-yvb81-02b4302a03.json > /dev/null
sed -i 's/#/"/g' ./popcornmateprod-firebase-adminsdk-yvb81-02b4302a03.json
env:
FIREBASE_JSON: ${{ secrets.FCM_SECRET }}

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ out/
.env

Domain/src/main/generated/**/*.java
Infra/src/main/resources/popcornmate-d7ca1-firebase-adminsdk-svbpw-fce737e873.json
Infra/src/main/resources/popcornmate-d7ca1-firebase-adminsdk-svbpw-343677f710.json
22 changes: 18 additions & 4 deletions Api/src/main/java/com/example/api/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.api.config;


import com.example.api.config.security.AccessDeniedFilter;
import com.example.api.config.security.FilterConfig;
import com.example.api.config.security.JwtExceptionFilter;
import com.example.api.config.security.JwtTokenFilter;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -10,7 +13,10 @@
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler;
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;

@Configuration
@RequiredArgsConstructor
Expand All @@ -22,6 +28,9 @@
public class SecurityConfig {

private final FilterConfig filterConfig;
private final JwtTokenFilter jwtTokenFilter;
private final JwtExceptionFilter jwtExceptionFilter;
private final AccessDeniedFilter accessDeniedFilter;


@Bean
Expand All @@ -41,18 +50,23 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti

.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.authorizeRequests().expressionHandler(expressionHandler());

http.authorizeRequests()
.requestMatchers("/api/auth/**").permitAll()
.requestMatchers( "/","/api/swagger-ui/**", "/api/v3/api-docs/**").permitAll()
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() // Preflight Request 허용해주기
.requestMatchers( "/api/swagger-ui/**", "/api/v3/api-docs/**").permitAll()
.requestMatchers("/api/**").authenticated();

http.apply(filterConfig);




return http.build();
}

@Bean
public DefaultWebSecurityExpressionHandler expressionHandler() {
DefaultWebSecurityExpressionHandler expressionHandler =
new DefaultWebSecurityExpressionHandler();
return expressionHandler;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.http.MediaType;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Component;
import org.springframework.util.PatternMatchUtils;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.example.api.fcm.controller;

import com.example.api.config.security.SecurityUtil;
import com.example.fcm.request.FcmRegistrationRequest;
import com.example.fcm.service.FcmService;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthException;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static io.netty.handler.codec.http.HttpResponseStatus.CREATED;

@Slf4j
@RestController
@RequestMapping("/fcm")
@RequiredArgsConstructor
public class FcmController {

private final FcmService fcmService;

@PostMapping("/{userId}")
public ResponseEntity<Void> fcmTokenRegistration(
@PathVariable("userId") Long userId,
@RequestBody FcmRegistrationRequest request) {
// Long userId = SecurityUtil.getCurrentUserId();
fcmService.registerFCMToken(userId, request);
return ResponseEntity
.status(CREATED.code())
.build();
}

@GetMapping
public void fcmToken() throws FirebaseAuthException {
String uid = "some-uid";

String customToken = FirebaseAuth.getInstance().createCustomToken(uid);
System.out.println(customToken);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class ScreeningController {
private final ScreeningAdaptor screeningAdaptor;
private final ReviewAdaptor reviewAdaptor;
private final GetBookMarkedScreeningsUseCase getBookMarkedScreeningUseCase;
private final GetPastScreeningListUseCase getPastScreeningListUseCase;


@Operation(description = "모임 대표 이미지")
Expand All @@ -80,8 +81,8 @@ public Screening uploadScreening(@RequestBody PostScreeningRequest request){
}

@Operation(summary = "스크리닝 id별로 가져오기", description = "screening id가져와서 요청하기")
@PostMapping("/{screeningId}")
public Screening getScreening(@PathVariable("screeningId") Long screeningId) {
@GetMapping("/{screeningId}")
public ScreeningInfoResponse getScreening(@PathVariable("screeningId") Long screeningId) {
return getScreeningUseCase.execute(screeningId);
}

Expand Down Expand Up @@ -201,8 +202,7 @@ public List<ScreeningResponseDto> getRecentScreening() {
//TODO 관람예정(찜하기 한 것 중에서 날짜 지난거) - private 0
@GetMapping("/screenings/past")
public List<Screening> getPassedScreenings() {
Long userId = SecurityUtil.getCurrentUserId();
return screeningAdaptor.getBookmarkedScreenings(userId);
return getPastScreeningListUseCase.execute();
}

//TODO 관람예정(찜하기 한 것 중에서 날짜 안지난거) -> try해봐야함() - private 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.example.api.screening.dto.response;

import com.example.domains.screening.entity.Screening;
import com.example.domains.screening.enums.Category;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
public class ScreeningInfoResponse {
@Schema(defaultValue = "1", description = "스크리닝 id")
private Long screeningId;

@Schema(defaultValue = "https://jgjfhdjghsdkjhgkjd", description = "상영회 대표 이미지")
private String posterImgUrl;

@Schema(defaultValue = "홍익대학교 졸업전시회", description = "상영회 제목")
private String screeningTitle;

@Schema(defaultValue = "이한비", description = "주최자명")
private String hostName;

@Schema(defaultValue = "졸업상영", description = "카테고리(\"졸업상영\"/\"과제상영\"/\"정기상영\"/\"특별상영\"/\"기타\")")
private Category category;

@Schema(defaultValue = "2023-02-13", description = "시작 날짜")
private LocalDateTime screeningStartDate;

@Schema(defaultValue = "2023-02-14", description = "종료 날짜")
private LocalDateTime screeningEndDate;

@Schema(defaultValue = "13:00", description = "시작 시간")
private LocalDateTime screeningStartTime;

@Schema(defaultValue = "홍익대학교", description = "주최 장소")
private String location;

@Schema(defaultValue = "졸업 작품보러오세요", description = "상영회 정보")
private String information;

@Schema(defaultValue = "https://sdhgfhsdjkfsjjgsh.com", description = "신청 폼 링크")
private String formUrl;

@Schema(defaultValue = "010-0000-0000", description = "주최자 전화번호")
private String hostPhoneNumber;

@Schema(defaultValue = "[email protected]", description = "주최자 이메일")
private String hostEmail;
@Schema(defaultValue = "true", description = "정책 동의 여부")
private boolean hasAgreed;

@Schema(defaultValue = "false", description = "정책 동의 여부")
private boolean isPrivate;

@Schema(defaultValue = "false", description = "찜하기 여부")
private boolean isBookmarked;

@Schema(defaultValue = "false", description = "리뷰 여부")
private boolean isReviewed;


@Builder
public ScreeningInfoResponse(Long screeningId,
String screeningTitle, String posterImgUrl, String hostName, String hostEmail, String hostPhoneNumber , String location, String formUrl,
String information, boolean hasAgreed, Category category, LocalDateTime screeningStartDate, LocalDateTime screeningEndDate, LocalDateTime screeningStartTime,
boolean isPrivate, boolean isBookmarked, boolean isReviewed
) {
this.screeningId = screeningId;
this.screeningTitle = screeningTitle;
this.posterImgUrl = posterImgUrl;
this.hostName = hostName;
this.location = location;
this.formUrl = formUrl;
this.information = information;
this.hasAgreed = hasAgreed;
this.screeningStartDate = screeningStartDate;
this.screeningEndDate = screeningEndDate;
this.screeningStartTime = screeningStartTime;
this.category = category;
this.hostEmail = hostEmail;
this.hostPhoneNumber = hostPhoneNumber;
this.isPrivate = isPrivate;
this.isBookmarked = isBookmarked;
this.isReviewed = isReviewed;
}

public static ScreeningInfoResponse from(Screening screening,boolean isBookmarked, boolean isReviewed) {
return ScreeningInfoResponse .builder()
.screeningId(screening.getId())
.screeningTitle(screening.getTitle())
.posterImgUrl(screening.getPosterImgUrl())
.hostName(screening.getHostInfo().getHostName())
.location(screening.getLocation())
.formUrl(screening.getParticipationUrl())
.information(screening.getInformation())
.hasAgreed(screening.isHasAgreed())
.screeningStartDate(screening.getScreeningStartDate())
.screeningEndDate(screening.getScreeningEndDate())
.screeningStartTime(screening.getScreeningStartTime())
.category(screening.getCategory())
.hostEmail(screening.getHostInfo().getHostEmail())
.isPrivate(screening.isPrivate())
.isBookmarked(isBookmarked)
.isReviewed(isReviewed)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.api.screening.service;

import com.example.adaptor.UseCase;
import com.example.api.config.security.SecurityUtil;
import com.example.domains.screening.adaptor.ScreeningAdaptor;
import com.example.domains.screening.entity.Screening;
import com.example.domains.userscreening.adaptor.UserScreeningAdaptor;
import lombok.RequiredArgsConstructor;

import java.util.List;

@UseCase
@RequiredArgsConstructor
public class GetPastScreeningListUseCase {
private final ScreeningAdaptor screeningAdaptor;
public List<Screening> execute() {
Long userId = SecurityUtil.getCurrentUserId();

List<Screening> screenings = screeningAdaptor.getBookmarkedScreenings(userId);
return screenings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import com.example.adaptor.UseCase;
import com.example.api.config.security.SecurityUtil;
import com.example.api.screening.dto.response.ScreeningInfoResponse;
import com.example.api.screening.dto.response.ScreeningResponse;
import com.example.api.screening.dto.response.ScreeningUploadResponse;
import com.example.domains.screening.adaptor.ScreeningAdaptor;
import com.example.domains.screening.entity.Screening;
import com.example.domains.screeningReview.adaptor.ReviewAdaptor;
import com.example.domains.screeningReview.entity.ScreeningReview;
import com.example.domains.user.entity.User;
import com.example.domains.user.validator.UserValidator;
import com.example.domains.userscreening.adaptor.UserScreeningAdaptor;
import com.example.domains.userscreening.entity.UserScreening;
Expand All @@ -19,12 +23,34 @@ public class GetScreeningUseCase {
private final UserValidator userValidator;
private final ScreeningAdaptor screeningAdaptor;
private final UserScreeningAdaptor userScreeningAdaptor;
private final ReviewAdaptor screeningReviewAdaptor;
boolean isReviewed = false;
boolean isBookMarked = false;

public Screening execute(Long screeningId) {
public ScreeningInfoResponse execute(Long screeningId) {
Long userId = SecurityUtil.getCurrentUserId();
validateExecution(userId);
Screening screening = screeningAdaptor.findById(screeningId);
return screening;

if(!validateUserScreening(userId,screeningId)){
isReviewed = false;
isBookMarked = false;
} else {
UserScreening userScreening = userScreeningAdaptor.findByUserAndScreening(userId,screeningId);
isReviewed = validateScreeningReview(userScreening.getId());
isBookMarked = userScreening.isBookmarked();
};


return ScreeningInfoResponse.from(screening,isReviewed,isBookMarked);
}

private boolean validateUserScreening(Long userId, Long screeningId) {
return userScreeningAdaptor.existsByUserAndScreening(userId,screeningId);
}

private boolean validateScreeningReview(Long id) {
return screeningReviewAdaptor.checkIfExists(id);
}

private void validateExecution(Long userId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.example.api.user.controller;

import com.example.api.config.security.SecurityUtil;
import com.example.api.user.model.dto.DuplicateCheckResponse;
import com.example.api.user.model.dto.GetUserInfoResponse;
import com.example.api.user.model.dto.UpdateUserInfoRequest;
import com.example.api.user.service.CheckDuplicateUseCase;
import com.example.api.user.service.GetUserInfoUseCase;
import com.example.api.user.service.PatchUserInfoUseCase;
import com.example.domains.user.enums.Genre;
import com.example.domains.user.exception.exceptions.UserNotFoundException;
import com.example.domains.user.service.UserService;
Expand All @@ -12,10 +16,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

Expand All @@ -27,6 +28,8 @@
public class UserController {
private final GetUserInfoUseCase getUserInfoUseCase;
private final UserService userService;
private final PatchUserInfoUseCase patchUserInfoUseCase;
private final CheckDuplicateUseCase checkDuplicateUseCase;

@Operation(summary = "내 정보를 가져옵니다.")
@GetMapping(value = "/info")
Expand All @@ -46,4 +49,14 @@ public ResponseEntity<List<Genre>> getUserGenres() {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}
}

@PatchMapping
public void updateUserNickname(@RequestBody UpdateUserInfoRequest request) {
patchUserInfoUseCase.execute(request);
}

@PostMapping("/check")
public DuplicateCheckResponse checkDuplicate(@RequestBody UpdateUserInfoRequest request) {
return checkDuplicateUseCase.execute(request);
}
}
Loading

0 comments on commit 0f00cd7

Please sign in to comment.