Skip to content

Commit

Permalink
Merge pull request #141 from kakao-tech-campus-2nd-step3/week10
Browse files Browse the repository at this point in the history
Week10 merge
  • Loading branch information
amm0124 authored Nov 11, 2024
2 parents e7013cc + 0362e8c commit 8021bea
Show file tree
Hide file tree
Showing 142 changed files with 3,512 additions and 1,008 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Run Tests on PR

on:
pull_request:
types: [ opened, synchronize, reopened ]

permissions:
contents: write
pull-requests: write
checks: write

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'adopt'

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Run tests
run: ./gradlew test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: 테스트 결과를 PR에 코멘트로 등록합니다
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
files: '**/build/test-results/test/TEST-*.xml'
github_token: ${{ secrets.GITHUB_TOKEN }}
seconds_between_github_reads: 5
seconds_between_github_writes: 5
6 changes: 3 additions & 3 deletions .github/workflows/deploy-ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
ECR_REPOSITORY: poomasi-server
ECS_SERVICE: poomasi-server
ECS_CLUSTER: poomasi
ECS_TASK_DEFINITION: tf-staging.json
ECS_TASK_DEFINITION: tf-prod.json
CONTAINER_NAME: spring
PROGRESS_SLACK_CHANNEL: C080DMAE7MX
permissions:
Expand Down Expand Up @@ -64,10 +64,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 22
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '22'
java-version: '21'
distribution: 'adopt'

- name: Grant execute permission for gradlew
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.3.1'
id 'io.spring.dependency-management' version '1.1.5'
id 'com.apollographql.apollo3' version '4.0.0-beta.7'

}

group = 'camp.nextstep.edu'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
@Configuration
public class SecurityBeanGenerator {

private final TokenStorageService tokenStorageService;
private final MemberService memberService;
private final TokenBlacklistService tokenBlacklistService;

@Bean
@Description("AuthenticationProvider를 위한 Spring bean")
Expand All @@ -37,11 +34,5 @@ MvcRequestMatcher.Builder mvc(HandlerMappingIntrospector introspector) {
return new MvcRequestMatcher.Builder(introspector);
}

@Bean
JwtUtil jwtUtil(){
return new JwtUtil(tokenBlacklistService,
tokenStorageService,
memberService);
}

}
4 changes: 2 additions & 2 deletions src/main/java/poomasi/domain/auth/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class SecurityConfig {
private final CustomSuccessHandler customSuccessHandler;
private final UserDetailsServiceImpl userDetailsService;


@Autowired
private OAuth2UserDetailServiceImpl oAuth2UserDetailServiceImpl;

Expand Down Expand Up @@ -74,10 +73,11 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti

// 기본 경로 및 테스트 경로
http.authorizeHttpRequests((authorize) -> authorize
.requestMatchers(HttpMethod.GET, "/api/farm/**").permitAll()
.requestMatchers(HttpMethod.POST, "/api/farm/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/product/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/review/**").permitAll()
.requestMatchers(HttpMethod.GET, "/health").permitAll()
.requestMatchers(HttpMethod.GET, "/api/image/**").permitAll()
.requestMatchers("/api/sign-up", "/api/login", "api/reissue", "api/payment/**", "api/order/**", "api/reservation/**", "/api/v1/farmer/reservations").permitAll()
.requestMatchers("/api/need-auth/**").authenticated()
.anyRequest().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import poomasi.domain.auth.security.oauth2.dto.response.OAuth2Response;
import poomasi.domain.member.entity.LoginType;
import poomasi.domain.member.entity.Member;
import poomasi.domain.member.entity.MemberProfile;
import poomasi.domain.member._profile.entity.MemberProfile;
import poomasi.domain.member.entity.Role;
import poomasi.domain.member.repository.MemberRepository;

Expand Down Expand Up @@ -52,7 +52,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic


//일단 없으면 가입시키는 쪽으로 구현ㄴ
Member member = memberRepository.findByEmail(email).orElse(null);
Member member = memberRepository.findByEmailAndDeletedAtIsNull(email).orElse(null);
if(member == null) {
member = Member.builder()
.email(email)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public UserDetailsServiceImpl(MemberRepository memberRepository) {

@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
Member member = memberRepository.findByEmail(email)
Member member = memberRepository.findByEmailAndDeletedAtIsNull(email)
.orElseThrow(() -> new BusinessException(BusinessError.MEMBER_NOT_FOUND));
return new UserDetailsImpl(member);
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package poomasi.domain.auth.token.refreshtoken.service;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package poomasi.domain.auth.token.reissue.controller;


import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import poomasi.domain.auth.token.reissue.dto.ReissueRequest;
import poomasi.domain.auth.token.reissue.dto.ReissueResponse;
import poomasi.domain.auth.token.reissue.service.ReissueTokenService;

@RestController
@RequiredArgsConstructor
public class ReissueTokenController {

@Autowired
private ReissueTokenService reissueTokenService;
private final ReissueTokenService reissueTokenService;

@PostMapping("/api/reissue")
public ResponseEntity<ReissueResponse> reissue(@RequestHeader(HttpHeaders.AUTHORIZATION) String authorizationHeader,
@RequestBody ReissueRequest reissueRequest){

@GetMapping("/api/reissue")
public ResponseEntity<ReissueResponse> reissue(@RequestBody ReissueRequest reissueRequest){
return ResponseEntity.ok(reissueTokenService.reissueToken(reissueRequest));
String accessToken = authorizationHeader.replace("Bearer ", "");

return ResponseEntity.ok(reissueTokenService.reissueToken(accessToken, reissueRequest));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ public class ReissueTokenService {
private final RefreshTokenService refreshTokenService;

// 토큰 재발급
public ReissueResponse reissueToken(ReissueRequest reissueRequest) {
public ReissueResponse reissueToken(String accessToken, ReissueRequest reissueRequest) {
Long memberId = jwtUtil.getIdFromToken(accessToken);

String refreshToken = reissueRequest.refreshToken();
Long memberId = jwtUtil.getIdFromToken(refreshToken);
Long requestMemberId = jwtUtil.getIdFromToken(refreshToken);

if (!requestMemberId.equals(memberId)) {
throw new BusinessException(REFRESH_TOKEN_NOT_VALID);
}

checkRefreshToken(refreshToken, memberId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public record FarmRegisterRequest(
Double longitude,
String phoneNumber,
String description,
Long experiencePrice,
int experiencePrice,
Integer maxCapacity,
Integer maxReservation
) {
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/poomasi/domain/farm/dto/FarmResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import poomasi.domain.farm.entity.Farm;


public record FarmResponse( // FIXME: 사용자 정보 추가 및 설명/전화번호 추가
Long id,
String name,
String address,
String addressDetail,
Double latitude,
Double longitude,
String description,
Long experiencePrice
public record FarmResponse(
Long id,
String name,
String address,
String addressDetail,
Double latitude,
Double longitude,
String description,
int experiencePrice
) {
public static FarmResponse fromEntity(Farm farm) {
return new FarmResponse(
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/poomasi/domain/farm/entity/Farm.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.time.LocalDateTime;

import poomasi.domain.order.entity._farm.OrderedFarm;
import poomasi.domain.review.entity.Review;

@Entity
Expand Down Expand Up @@ -56,7 +57,7 @@ public class Farm {
private FarmStatus status = FarmStatus.OPEN;

@Comment("체험 비용")
private Long experiencePrice;
private int experiencePrice;

@Comment("팀 최대 인원")
private Integer maxCapacity;
Expand All @@ -77,10 +78,14 @@ public class Farm {

@OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true)
@JoinColumn(name = "entityId")
List<Review> reviewList = new ArrayList<>();
private List<Review> reviewList = new ArrayList<>();

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ordered_farm_id")
private OrderedFarm orderedFarm;

@Builder
public Farm(Long id, String name, Long ownerId, String address, String addressDetail, Double latitude, Double longitude, String description, Long experiencePrice, Integer maxCapacity, Integer maxReservation) {
public Farm(Long id, String name, Long ownerId, String address, String addressDetail, Double latitude, Double longitude, String description, int experiencePrice, Integer maxCapacity, Integer maxReservation) {
this.id = id;
this.name = name;
this.ownerId = ownerId;
Expand All @@ -104,7 +109,7 @@ public Farm updateFarm(FarmUpdateRequest farmUpdateRequest) {
return this;
}

public void updateExpPrice(Long expPrice) {
public void updateExpPrice(int expPrice) {
this.experiencePrice = expPrice;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private Farm getFarmByFarmId(Long farmId) {
return farmRepository.findByIdAndDeletedAtIsNull(farmId).orElseThrow(() -> new BusinessException(FARM_NOT_FOUND));
}

public void updateFarmExpPrice(Long farmerId, Long farmId, Long expPrice) {
public void updateFarmExpPrice(Long farmerId, Long farmId, int expPrice) {
Farm farm = this.getFarmByFarmId(farmId);
if (!farm.getOwnerId().equals(farmerId)) {
throw new BusinessException(FARM_OWNER_MISMATCH);
Expand Down
Loading

0 comments on commit 8021bea

Please sign in to comment.