Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.List;

@RestController
@RequestMapping("/api/chatbot")
@RequestMapping("/chatbot")
@RequiredArgsConstructor
@Slf4j
public class ChatbotController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.List;

@RestController
@RequestMapping("/api/cocktails/{cocktailId}/comments")
@RequestMapping("/cocktails/{cocktailId}/comments")
@Tag(name = "ApiCocktailCommentController", description = "API 칵테일댓글 컨트롤러")
@RequiredArgsConstructor
public class CocktailCommentController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.List;

@RestController
@RequestMapping("api/cocktails")
@RequestMapping("cocktails")
@Tag(name = "ApiCocktailController", description = "API 칵테일 컨트롤러")
@RequiredArgsConstructor
public class CocktailController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.Map;

@RestController
@RequestMapping("/api/cocktails")
@RequestMapping("/cocktails")
@RequiredArgsConstructor
public class CocktailShareController {
private final CocktailRepository cocktailRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.time.LocalDateTime;

@RestController
@RequestMapping("/api/me/bar")
@RequestMapping("/me/bar")
@RequiredArgsConstructor
@Validated
public class MyBarController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.time.LocalDateTime;

@RestController
@RequestMapping("/api/me")
@RequestMapping("/me")
@RequiredArgsConstructor
@Validated
public class MyHistoryController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public MyHistoryCommentGoResponseDto getPostLinkFromMyComment(Long userId, Long
throw new ServiceException(410, "삭제된 게시글입니다.");
}
Long postId = post.getId();
String apiUrl = "/api/posts/" + postId;
String apiUrl = "/posts/" + postId;
return new MyHistoryCommentGoResponseDto(postId, apiUrl);
}

Expand All @@ -116,7 +116,7 @@ public MyHistoryPostGoResponseDto getPostLinkFromMyPost(Long userId, Long postId
if (p.getStatus() == PostStatus.DELETED) {
throw new ServiceException(410, "삭제된 게시글입니다.");
}
String apiUrl = "/api/posts/" + p.getId();
String apiUrl = "/posts/" + p.getId();
return new MyHistoryPostGoResponseDto(p.getId(), apiUrl);
}

Expand Down Expand Up @@ -177,7 +177,7 @@ public MyHistoryPostGoResponseDto getPostLinkFromMyLikedPost(Long userId, Long p
if (post.getStatus() == PostStatus.DELETED) {
throw new ServiceException(410, "삭제된 게시글입니다.");
}
String apiUrl = "/api/posts/" + post.getId();
String apiUrl = "/posts/" + post.getId();
return new MyHistoryPostGoResponseDto(post.getId(), apiUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,21 @@
import com.back.domain.notification.service.NotificationService;
import com.back.domain.notification.service.NotificationSettingService;
import com.back.global.rsData.RsData;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import io.swagger.v3.oas.annotations.Operation;
import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/api/me")
@RequestMapping("/me")
@RequiredArgsConstructor
@Validated
public class NotificationController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
import com.back.domain.user.entity.User;
import com.back.global.exception.ServiceException;
import com.back.global.rq.Rq;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Service
@RequiredArgsConstructor
public class NotificationService {
Expand Down Expand Up @@ -85,7 +86,7 @@ public NotificationGoResponseDto markAsReadAndGetPostLink(Long userId, Long noti
notification.markRead();
}
Long postId = notification.getPost().getId();
String apiUrl = "/api/posts/" + postId;
String apiUrl = "/posts/" + postId;
return new NotificationGoResponseDto(postId, apiUrl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/posts/{postId}/comments")
@RequestMapping("/posts/{postId}/comments")
@Tag(name = "ApiCommentController", description = "API 댓글 컨트롤러")
@RequiredArgsConstructor
public class CommentController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/posts")
@RequestMapping("/posts")
@Tag(name = "ApiPostController", description = "API 게시글 컨트롤러")
@RequiredArgsConstructor
public class PostController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/me/profile")
@RequestMapping("/me/profile")
@RequiredArgsConstructor
public class ProfileController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,26 @@ private void work(HttpServletRequest request, HttpServletResponse response, Filt
String uri = request.getRequestURI();
String method = request.getMethod();

// SecurityConfig에서 permitAll()로 설정된 경로들은 필터를 통과시키기
// 개발 편의성을 위해 모든 요청 통과 (SecurityConfig에서 모든 요청 permitAll)
/*
if (
//추후 로그인 필요한 api 추가 설정
uri.startsWith("/h2-console") ||
uri.startsWith("/login/oauth2/") ||
(method.equals("GET") && uri.equals("/api/~~")) ||
(method.equals("POST") && uri.equals("/api/~"))

uri.startsWith("/login/oauth2/") ||
uri.startsWith("/oauth2/") ||
uri.startsWith("/actuator/") ||
uri.startsWith("/swagger-ui/") ||
uri.startsWith("/api-docs/") ||
uri.equals("/") ||
// 조회 API들 - 권한 불필요
(method.equals("GET") && uri.startsWith("/cocktails")) ||
(method.equals("POST") && uri.equals("/cocktails/search")) ||
(method.equals("GET") && uri.startsWith("/posts")) ||
(method.equals("GET") && uri.contains("/comments"))
) {
filterChain.doFilter(request, response);
return;
}

// 인증 필수 URL 확인
boolean requiresAuth = uri.startsWith("/api/");

// 인증이 필요하지 않은 URL이면 그냥 통과
if (!requiresAuth) {
filterChain.doFilter(request, response);
return;
}
*/

// 쿠키에서 accessToken 가져오기
String accessToken = rq.getCookieValue("accessToken", "");
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/back/global/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,33 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
) // OAuth 인증시 필요할때만 세션 사용

.authorizeHttpRequests(auth -> auth
// 개발 편의성을 위해 모든 요청 허용
.anyRequest().permitAll()

/*
.requestMatchers("/").permitAll()
.requestMatchers("/h2-console/**").permitAll()
.requestMatchers("/actuator/**").permitAll()
.requestMatchers("/oauth2/**").permitAll()
.requestMatchers("/login/oauth2/**").permitAll()
.requestMatchers("/swagger-ui/**", "/api-docs/**").permitAll()
.requestMatchers("/user/**").permitAll()
.requestMatchers("/cocktails/**").permitAll()
.requestMatchers("/chatbot/**").permitAll()

// 권한 불필요 - 조회 API
.requestMatchers(GET, "/cocktails/**").permitAll()
.requestMatchers(POST, "/cocktails/search").permitAll()
.requestMatchers(GET, "/posts").permitAll()
.requestMatchers(GET, "/posts/{postId}").permitAll()
.requestMatchers(GET, "/posts/{postId}/comments").permitAll()
.requestMatchers(GET, "/posts/{postId}/comments/{commentId}").permitAll()
.requestMatchers(GET, "/cocktails/{cocktailId}/comments").permitAll()
.requestMatchers(GET, "/cocktails/{cocktailId}/comments/{cocktailCommentId}").permitAll()

// 회원 or 인증된 사용자만 가능
.requestMatchers("/admin/**").hasRole("ADMIN")

//그 외에는 인증해야함
// 나머지 모든 API는 인증 필요
.anyRequest().authenticated()
*/
)
.formLogin(AbstractHttpConfigurer::disable)
.httpBasic(AbstractHttpConfigurer::disable)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: create-drop
ddl-auto: create # 삭제 재성성 과정에서 외래키 제약발생. create 변경 후 배포 테스트
properties:
hibernate:
show_sql: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void t1() throws Exception {

// when: GET 요청
ResultActions resultActions = mvc.perform(
get("/api/cocktails/{id}", savedCocktail.getId())
get("/cocktails/{id}", savedCocktail.getId())
.contentType(MediaType.APPLICATION_JSON)
).andDo(print());

Expand All @@ -80,7 +80,7 @@ void t2() throws Exception {
long nonExistentId = 9999L;

ResultActions resultActions = mvc.perform(
get("/api/cocktails/{id}", nonExistentId)
get("/cocktails/{id}", nonExistentId)
.contentType(MediaType.APPLICATION_JSON)
).andDo(print());

Expand All @@ -96,7 +96,7 @@ void t2() throws Exception {
void t3() throws Exception {
// when
ResultActions resultActions = mvc.perform(
get("/api/cocktails")
get("/cocktails")
.contentType(MediaType.APPLICATION_JSON)
).andDo(print());

Expand All @@ -117,7 +117,7 @@ void t4() throws Exception {

// when
ResultActions resultActions = mvc.perform(
get("/api/cocktails")
get("/cocktails")
.param("lastId", lastId.toString())
.param("size", String.valueOf(size))
.contentType(MediaType.APPLICATION_JSON)
Expand Down