Skip to content

Commit b99c83b

Browse files
authored
Merge branch 'main' into feature/79-add-review-create
2 parents 6fe2c08 + be132e1 commit b99c83b

File tree

38 files changed

+960
-105
lines changed

38 files changed

+960
-105
lines changed

.github/workflows/CD.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ jobs:
2323
NAVER_CLIENT_ID: ${{ secrets.NAVER_CLIENT_ID }}
2424
NAVER_CLIENT_SECRET: ${{ secrets.NAVER_CLIENT_SECRET }}
2525
NAVER_SCOPE: ${{ secrets.NAVER_SCOPE }}
26-
NAVER_REDIRECT_URL: ${{secrets.NAVER_REDIRECT_URL}}
26+
NAVER_REDIRECT_URL: ${{ secrets.NAVER_REDIRECT_URL }}
2727
JWT_SECRET: ${{ secrets.JWT_SECRET }}
28-
FRONT_URL: ${{secrets.FRONT_URL}}
29-
BACK_URL: ${{secrets.BACK_URL}}
30-
BUCKET_NAME: ${{secrets.BUCKET_NAME}}
31-
BUCKET_REGION: ${{secrets.BUCKET_REGION}}
32-
IMG_BASE_URL: ${{secrets.BASE_URL}}
33-
S3_ACCESS_KEY: ${{secrets.S3_ACCESS_KEY}}
34-
S3_SECRET_KEY: ${{secrets.S3_SECRET_KEY}}
28+
FRONT_URL: ${{ secrets.FRONT_URL }}
29+
BACK_URL: ${{ secrets.BACK_URL }}
30+
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
31+
BUCKET_REGION: ${{ secrets.BUCKET_REGION }}
32+
IMG_BASE_URL: ${{ secrets.BASE_URL }}
33+
S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }}
34+
S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }}
35+
DEFAULT_IMG_URL: ${{ secrets.DEFAULT_IMG_URL }}
36+
APP_DEVELOP_MODE: ${{ secrets.APP_DEVELOP_MODE }}
3537

3638
steps:
3739
- name: Github Repository 파일 불러오기

.github/workflows/CI.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ jobs:
3131
NAVER_CLIENT_ID: ${{ secrets.NAVER_CLIENT_ID }}
3232
NAVER_CLIENT_SECRET: ${{ secrets.NAVER_CLIENT_SECRET }}
3333
NAVER_SCOPE: ${{ secrets.NAVER_SCOPE }}
34-
NAVER_REDIRECT_URL: ${{secrets.NAVER_REDIRECT_URL}}
34+
NAVER_REDIRECT_URL: ${{ secrets.NAVER_REDIRECT_URL }}
3535
JWT_SECRET: ${{ secrets.JWT_SECRET }}
36-
FRONT_URL: ${{secrets.FRONT_URL}}
37-
BACK_URL: ${{secrets.BACK_URL}}
38-
BUCKET_NAME: ${{secrets.BUCKET_NAME}}
39-
BUCKET_REGION: ${{secrets.BUCKET_REGION}}
40-
IMG_BASE_URL: ${{secrets.BASE_URL}}
41-
S3_ACCESS_KEY: ${{secrets.S3_ACCESS_KEY}}
42-
S3_SECRET_KEY: ${{secrets.S3_SECRET_KEY}}
36+
FRONT_URL: ${{ secrets.FRONT_URL }}
37+
BACK_URL: ${{ secrets.BACK_URL }}
38+
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
39+
BUCKET_REGION: ${{ secrets.BUCKET_REGION }}
40+
IMG_BASE_URL: ${{ secrets.BASE_URL }}
41+
S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }}
42+
S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }}
43+
DEFAULT_IMG_URL: ${{ secrets.DEFAULT_IMG_URL }}
44+
APP_DEVELOP_MODE: ${{ secrets.APP_DEVELOP_MODE }}
4345

4446

4547
steps:

src/main/java/com/somemore/auth/jwt/filter/JwtAuthFilter.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import jakarta.servlet.ServletException;
1010
import jakarta.servlet.http.HttpServletRequest;
1111
import jakarta.servlet.http.HttpServletResponse;
12+
import java.io.IOException;
13+
import java.util.List;
1214
import lombok.RequiredArgsConstructor;
1315
import lombok.extern.slf4j.Slf4j;
1416
import org.springframework.security.core.Authentication;
@@ -17,9 +19,6 @@
1719
import org.springframework.stereotype.Component;
1820
import org.springframework.web.filter.OncePerRequestFilter;
1921

20-
import java.io.IOException;
21-
import java.util.List;
22-
2322
@RequiredArgsConstructor
2423
@Slf4j
2524
@Component
@@ -29,12 +28,13 @@ public class JwtAuthFilter extends OncePerRequestFilter {
2928

3029
@Override
3130
protected boolean shouldNotFilter(HttpServletRequest request) {
32-
return true; // 개발 중 모든 요청 허용
33-
// return httpServletRequest.getRequestURI().contains("token");
31+
String token = request.getHeader("Authorization");
32+
return token == null || token.isEmpty();
3433
}
3534

3635
@Override
37-
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
36+
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
37+
FilterChain filterChain) throws ServletException, IOException {
3838
EncodedToken accessToken = getAccessToken(request);
3939
jwtUseCase.processAccessToken(accessToken, response);
4040

@@ -47,15 +47,19 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
4747

4848
private EncodedToken getAccessToken(HttpServletRequest request) {
4949
String accessToken = request.getHeader("Authorization");
50-
if (accessToken == null || accessToken.isEmpty()) {
50+
if (!accessToken.startsWith("Bearer ")) {
5151
throw new JwtException(JwtErrorType.MISSING_TOKEN);
5252
}
53+
54+
accessToken = accessToken.substring(7);
55+
5356
return new EncodedToken(accessToken);
5457
}
5558

56-
private JwtAuthenticationToken createAuthenticationToken(Claims claims, EncodedToken accessToken) {
59+
private JwtAuthenticationToken createAuthenticationToken(Claims claims,
60+
EncodedToken accessToken) {
5761
String userId = claims.get("id", String.class);
58-
UserRole role = claims.get("role", UserRole.class);
62+
UserRole role = UserRole.valueOf(claims.get("role", String.class));
5963

6064
return new JwtAuthenticationToken(
6165
userId,
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.somemore.auth.util;
2+
3+
import static com.somemore.auth.oauth.OAuthProvider.NAVER;
4+
5+
import com.somemore.auth.jwt.domain.EncodedToken;
6+
import com.somemore.auth.jwt.domain.TokenType;
7+
import com.somemore.auth.jwt.domain.UserRole;
8+
import com.somemore.auth.jwt.generator.JwtGenerator;
9+
import com.somemore.auth.jwt.refresh.domain.RefreshToken;
10+
import com.somemore.auth.jwt.refresh.manager.RefreshTokenManager;
11+
import com.somemore.center.domain.Center;
12+
import com.somemore.center.repository.CenterJpaRepository;
13+
import com.somemore.volunteer.domain.Volunteer;
14+
import com.somemore.volunteer.repository.VolunteerJpaRepository;
15+
import jakarta.annotation.PostConstruct;
16+
import jakarta.annotation.PreDestroy;
17+
import java.util.UUID;
18+
import lombok.RequiredArgsConstructor;
19+
import lombok.extern.slf4j.Slf4j;
20+
import org.springframework.beans.factory.annotation.Value;
21+
import org.springframework.stereotype.Component;
22+
23+
@Slf4j
24+
@RequiredArgsConstructor
25+
@Component
26+
public class DevAccountSetUpConfig {
27+
28+
private final VolunteerJpaRepository volunteerRepository;
29+
private final CenterJpaRepository centerRepository;
30+
private final JwtGenerator jwtGenerator;
31+
private final RefreshTokenManager refreshTokenManager;
32+
33+
private Volunteer volunteer;
34+
private Center center;
35+
36+
@Value("${app.develop.mode}")
37+
private boolean developMode;
38+
39+
@PostConstruct
40+
public void generateAccessTokenForDev() {
41+
if (!developMode) {
42+
return; // 개발 모드에서만 실행
43+
}
44+
45+
volunteer = Volunteer.createDefault(NAVER, "bongdari");
46+
center = Center.create(
47+
"봉다리 자원봉사센터",
48+
"02-1234-5678",
49+
"",
50+
"봉다리 기관 테스트 계정입니다.",
51+
"https://somemore.bongdari.com",
52+
"bongdari",
53+
"1234"
54+
);
55+
56+
volunteer = volunteerRepository.findByOauthId(volunteer.getOauthId())
57+
.orElseGet(() -> volunteerRepository.save(volunteer));
58+
59+
center = centerRepository.findByName(center.getName())
60+
.orElseGet(() -> centerRepository.save(center));
61+
62+
EncodedToken volunteerToken = saveRefreshTokenAndReturnAccessToken(volunteer.getId(),
63+
UserRole.VOLUNTEER);
64+
EncodedToken centerToken = saveRefreshTokenAndReturnAccessToken(center.getId(),
65+
UserRole.CENTER);
66+
67+
log.info("테스트용 봉사자 AccessToken: {}", volunteerToken.value());
68+
log.info("테스트용 기관 AccessToken: {}", centerToken.value());
69+
}
70+
71+
@PreDestroy
72+
public void cleanup() {
73+
if (volunteer != null) {
74+
refreshTokenManager.removeRefreshToken(volunteer.getId().toString());
75+
log.info("테스트용 AccessToken 제거, 봉사자 ID: {}", volunteer.getId());
76+
}
77+
if (center != null) {
78+
refreshTokenManager.removeRefreshToken(center.getId().toString());
79+
log.info("테스트용 AccessToken 제거, 기관 ID: {}", center.getId());
80+
}
81+
}
82+
83+
private EncodedToken saveRefreshTokenAndReturnAccessToken(UUID id, UserRole role) {
84+
EncodedToken accessToken = generateToken(id, role, TokenType.ACCESS);
85+
RefreshToken refreshToken = generateRefreshToken(id, role, accessToken);
86+
refreshTokenManager.save(refreshToken);
87+
return accessToken;
88+
}
89+
90+
private EncodedToken generateToken(UUID id, UserRole role, TokenType tokenType) {
91+
return jwtGenerator.generateToken(id.toString(), role.name(), tokenType);
92+
}
93+
94+
private RefreshToken generateRefreshToken(UUID id, UserRole role, EncodedToken accessToken) {
95+
return new RefreshToken(id.toString(), accessToken,
96+
generateToken(id, role, TokenType.REFRESH));
97+
}
98+
}
99+

src/main/java/com/somemore/center/repository/CenterJpaRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
public interface CenterJpaRepository extends JpaRepository<Center, Long> {
1010
boolean existsById(UUID id);
1111
Optional<Center> findCenterById(UUID id);
12+
Optional<Center> findByName(String name);
1213
}

src/main/java/com/somemore/community/domain/CommunityComment.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public class CommunityComment extends BaseEntity {
2222
@Column(name = "id", nullable = false)
2323
private Long id;
2424

25+
@Column(name = "community_board_id", nullable = false)
26+
private Long communityBoardId;
27+
2528
@Column(name = "writer_id", nullable = false, length = 16)
2629
private UUID writerId;
2730

@@ -33,7 +36,8 @@ public class CommunityComment extends BaseEntity {
3336
private Long parentCommentId;
3437

3538
@Builder
36-
public CommunityComment(UUID writerId, String content, Long parentCommentId) {
39+
public CommunityComment(Long communityBoardId, UUID writerId, String content, Long parentCommentId) {
40+
this.communityBoardId = communityBoardId;
3741
this.writerId = writerId;
3842
this.content = content;
3943
this.parentCommentId = parentCommentId;

src/main/java/com/somemore/community/dto/request/CommunityCommentCreateRequestDto.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@
66
import io.swagger.v3.oas.annotations.media.Schema;
77
import jakarta.annotation.Nullable;
88
import jakarta.validation.constraints.NotBlank;
9+
import jakarta.validation.constraints.NotNull;
910
import lombok.Builder;
1011

1112
import java.util.UUID;
1213

1314
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
1415
@Builder
1516
public record CommunityCommentCreateRequestDto(
17+
@Schema(description = "커뮤니티 게시글 ID", example = "33")
18+
@NotNull(message = "게시글 ID는 필수 값입니다.")
19+
Long communityBoardId,
1620
@Schema(description = "커뮤니티 댓글 내용", example = "저도 함께 하고 싶습니다.")
1721
@NotBlank(message = "댓글 내용은 필수 값입니다.")
1822
String content,
19-
@Schema(description = "부모 댓글의 ID", example = "1234", nullable = true)
23+
@Schema(description = "부모 댓글 ID", example = "1234", nullable = true)
2024
@Nullable
2125
Long parentCommentId
2226
) {
2327
public CommunityComment toEntity(UUID writerId) {
2428
return CommunityComment.builder()
29+
.communityBoardId(communityBoardId)
2530
.writerId(writerId)
2631
.content(content)
2732
.parentCommentId(parentCommentId)

src/main/java/com/somemore/community/repository/board/CommunityBoardJpaRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
import org.springframework.data.jpa.repository.JpaRepository;
55

66
public interface CommunityBoardJpaRepository extends JpaRepository<CommunityBoard, Long> {
7+
boolean existsByIdAndDeletedFalse(Long id);
78
}

src/main/java/com/somemore/community/repository/board/CommunityBoardRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ public interface CommunityBoardRepository {
1212
Optional<CommunityBoard> findById(Long id);
1313
List<CommunityBoardView> getCommunityBoards();
1414
List<CommunityBoardView> findByWriterId(UUID writerId);
15+
boolean existsById(Long id);
16+
default boolean doesNotExistById(Long id) {
17+
return !existsById(id);
18+
}
1519
void deleteAllInBatch();
1620
}

src/main/java/com/somemore/community/repository/board/CommunityBoardRepositoryImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public List<CommunityBoardView> findByWriterId(UUID writerId) {
5252
.fetch();
5353
}
5454

55+
@Override
56+
public boolean existsById(Long id) {
57+
return communityBoardJpaRepository.existsByIdAndDeletedFalse(id);
58+
}
59+
5560
private JPAQuery<CommunityBoardView> getCommunityBoardsQuery() {
5661
QCommunityBoard communityBoard = QCommunityBoard.communityBoard;
5762
QVolunteer volunteer = QVolunteer.volunteer;

0 commit comments

Comments
 (0)