diff --git a/build.gradle b/build.gradle index f2596c13..dc9cb11d 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-validation' - implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' //Swagger + implementation 'org.springframework.boot:spring-boot-starter-security' // security + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0' //Swagger compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java index 5bc49395..e07fcba9 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java @@ -10,7 +10,7 @@ import com.bbteam.budgetbuddies.domain.category.entity.Category; public interface CategoryRepository extends JpaRepository { - @Query(value = "SELECT c FROM Category AS c WHERE c.isDefault=TRUE OR c.user.id=:id") + @Query("SELECT c FROM Category c WHERE (c.isDefault = TRUE OR c.user.id = :id) AND c.deleted = FALSE") List findUserCategoryByUserId(@Param("id") Long id); @Query("SELECT c FROM Category c WHERE c.isDefault = true") diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java index 3ceb2112..bf3445b6 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java @@ -3,6 +3,7 @@ import com.bbteam.budgetbuddies.apiPayload.ApiResponse; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; +import com.bbteam.budgetbuddies.domain.user.validation.ExistUser; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -60,11 +61,11 @@ ApiResponse registerDiscountInfo( @Parameter(name = "discountInfoId", description = "좋아요를 누를 할인정보의 id입니다."), }) ApiResponse likeDiscountInfo( - @RequestParam Long userId, + @RequestParam @ExistUser Long userId, @PathVariable Long discountInfoId ); - @Operation(summary = "[ADMIN] 특정 할인정보 수정하기 API", description = "특정 할인정보를 수정하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)") + @Operation(summary = "[ADMIN] 특정 할인정보 수정하기 API", description = "특정 할인정보를 수정하는 API입니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), // @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), @@ -72,15 +73,12 @@ ApiResponse likeDiscountInfo( // @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) @Parameters({ - @Parameter(name = "userId", description = "수정할 사용자의 id입니다."), -// @Parameter(name = "discountRequestDto", description = "수정할 할인 정보의 전체 내용입니다."), }) ApiResponse updateDiscountInfo( - @RequestParam Long userId, @RequestBody DiscountRequest.UpdateDiscountDto discountRequestDto ); - @Operation(summary = "[ADMIN] 특정 할인정보 삭제하기 API", description = "특정 할인정보를 삭제하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)") + @Operation(summary = "[ADMIN] 특정 할인정보 삭제하기 API", description = "ID를 통해 특정 할인정보를 삭제하는 API입니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), // @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), @@ -88,15 +86,13 @@ ApiResponse updateDiscountInfo( // @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) @Parameters({ - @Parameter(name = "userId", description = "삭제할 사용자의 id입니다."), @Parameter(name = "discountInfoId", description = "삭제할 할인 정보의 id입니다."), }) ApiResponse deleteDiscountInfo( - @RequestParam Long userId, @PathVariable Long discountInfoId ); - @Operation(summary = "[ADMIN] 특정 할인정보 가져오기 API", description = "ID를 통해 특정 할인정보를 가져오는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)") + @Operation(summary = "[ADMIN] 특정 할인정보 가져오기 API", description = "ID를 통해 특정 할인정보를 가져오는 API입니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), // @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), @@ -104,11 +100,9 @@ ApiResponse deleteDiscountInfo( // @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) @Parameters({ - @Parameter(name = "userId", description = "조회할 사용자의 id입니다."), @Parameter(name = "discountInfoId", description = "조회할 할인 정보의 id입니다."), }) ApiResponse getDiscountInfo( - @RequestParam Long userId, @PathVariable Long discountInfoId ); diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java index c17af639..a70a3bf4 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java @@ -53,10 +53,9 @@ public ApiResponse likeDiscountInfo( @Override @PutMapping("") public ApiResponse updateDiscountInfo( - @RequestParam @ExistUser Long userId, @RequestBody DiscountRequest.UpdateDiscountDto discountRequestDto ) { - DiscountResponseDto discountResponseDto = discountInfoService.updateDiscountInfo(userId, discountRequestDto); + DiscountResponseDto discountResponseDto = discountInfoService.updateDiscountInfo(discountRequestDto); return ApiResponse.onSuccess(discountResponseDto); } @@ -64,10 +63,9 @@ public ApiResponse updateDiscountInfo( @Override @DeleteMapping("/{discountInfoId}") public ApiResponse deleteDiscountInfo( - @RequestParam @ExistUser Long userId, @PathVariable Long discountInfoId ) { - String message = discountInfoService.deleteDiscountInfo(userId, discountInfoId); + String message = discountInfoService.deleteDiscountInfo(discountInfoId); return ApiResponse.onSuccess(message); } @@ -76,10 +74,9 @@ public ApiResponse deleteDiscountInfo( @Override @GetMapping("/{discountInfoId}") public ApiResponse getDiscountInfo( - @RequestParam @ExistUser Long userId, @PathVariable Long discountInfoId ) { - DiscountResponseDto discountResponseDto = discountInfoService.getDiscountInfoById(userId, discountInfoId); + DiscountResponseDto discountResponseDto = discountInfoService.getDiscountInfoById(discountInfoId); return ApiResponse.onSuccess(discountResponseDto); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java index ba77217d..3b2aee74 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java @@ -16,10 +16,10 @@ Page getDiscountsByYearAndMonth( DiscountResponseDto toggleLike(Long userId, Long discountInfoId); - DiscountResponseDto updateDiscountInfo(Long userId, DiscountRequest.UpdateDiscountDto discountRequestDto); + DiscountResponseDto updateDiscountInfo(DiscountRequest.UpdateDiscountDto discountRequestDto); - String deleteDiscountInfo(Long userId, Long discountInfoId); + String deleteDiscountInfo(Long discountInfoId); - DiscountResponseDto getDiscountInfoById(Long userId, Long discountInfoId); + DiscountResponseDto getDiscountInfoById(Long discountInfoId); } \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java index 8e472080..54051dca 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java @@ -117,17 +117,14 @@ public DiscountResponseDto toggleLike(Long userId, Long discountInfoId) { @Transactional @Override - public DiscountResponseDto updateDiscountInfo(Long userId, DiscountRequest.UpdateDiscountDto discountRequestDto) { + public DiscountResponseDto updateDiscountInfo(DiscountRequest.UpdateDiscountDto discountRequestDto) { /** - * 1. 사용자 조회 -> 없으면 에러 - * 2. 할인정보 조회 -> 없으면 에러 - * 3. 변경사항 업데이트 - * 4. 변경사항 저장 - * 5. Entity -> ResponseDto로 변환 후 리턴 + * 1. 할인정보 조회 -> 없으면 에러 + * 2. 변경사항 업데이트 + * 3. 변경사항 저장 + * 4. Entity -> ResponseDto로 변환 후 리턴 */ - User user = userRepository.findById(userId) - .orElseThrow(() -> new IllegalArgumentException("User not found")); DiscountInfo discountInfo = discountInfoRepository.findById(discountRequestDto.getId()) .orElseThrow(() -> new IllegalArgumentException("DiscountInfo not found")); @@ -141,17 +138,13 @@ public DiscountResponseDto updateDiscountInfo(Long userId, DiscountRequest.Updat @Transactional @Override - public String deleteDiscountInfo(Long userId, Long discountInfoId) { + public String deleteDiscountInfo(Long discountInfoId) { /** - * 1. 사용자 조회 -> 없으면 에러 - * 2. 할인정보 조회 -> 없으면 에러 - * 3. Entity 삭제 - * 4. 성공여부 반환 + * 1. 할인정보 조회 -> 없으면 에러 + * 2. Entity 삭제 + * 3. 성공여부 반환 */ - User user = userRepository.findById(userId) - .orElseThrow(() -> new IllegalArgumentException("User not found")); - DiscountInfo discountInfo = discountInfoRepository.findById(discountInfoId) .orElseThrow(() -> new IllegalArgumentException("DiscountInfo not found")); @@ -163,17 +156,13 @@ public String deleteDiscountInfo(Long userId, Long discountInfoId) { @Transactional @Override - public DiscountResponseDto getDiscountInfoById(Long userId, Long discountInfoId) { + public DiscountResponseDto getDiscountInfoById(Long discountInfoId) { /** - * 1. 사용자 조회 -> 없으면 에러 - * 2. 할인정보 조회 -> 없으면 에러 - * 3. Entity 조회 - * 4. Entity -> ResponseDto로 변환 후 리턴 + * 1. 할인정보 조회 -> 없으면 에러 + * 2. Entity 조회 + * 3. Entity -> ResponseDto로 변환 후 리턴 */ - User user = userRepository.findById(userId) - .orElseThrow(() -> new IllegalArgumentException("User not found")); - DiscountInfo discountInfo = discountInfoRepository.findById(discountInfoId) .orElseThrow(() -> new IllegalArgumentException("DiscountInfo not found")); diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java index 8fbc3a83..2e87c495 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java @@ -3,6 +3,7 @@ import com.bbteam.budgetbuddies.apiPayload.ApiResponse; import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest; import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; +import com.bbteam.budgetbuddies.domain.user.validation.ExistUser; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -57,11 +58,11 @@ ApiResponse registerSupportInfo( @Parameter(name = "supportInfoId", description = "좋아요를 누를 지원정보의 id입니다."), }) ApiResponse likeSupportInfo( - @RequestParam Long userId, + @RequestParam @ExistUser Long userId, @PathVariable Long supportInfoId ); - @Operation(summary = "[ADMIN] 특정 지원정보 수정하기 API", description = "특정 지원정보를 수정하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)") + @Operation(summary = "[ADMIN] 특정 지원정보 수정하기 API", description = "ID를 통해 특정 지원정보를 수정하는 API입니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), // @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), @@ -69,14 +70,12 @@ ApiResponse likeSupportInfo( // @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) @Parameters({ - @Parameter(name = "userId", description = "수정할 사용자의 id입니다."), }) ApiResponse updateSupportInfo( - @RequestParam Long userId, @RequestBody SupportRequest.UpdateSupportDto supportRequestDto ); - @Operation(summary = "[ADMIN] 특정 지원정보 삭제하기 API", description = "특정 지원정보를 삭제하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)") + @Operation(summary = "[ADMIN] 특정 지원정보 삭제하기 API", description = "ID를 통해 특정 지원정보를 삭제하는 API입니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), // @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), @@ -84,15 +83,13 @@ ApiResponse updateSupportInfo( // @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) @Parameters({ - @Parameter(name = "userId", description = "삭제할 사용자의 id입니다."), @Parameter(name = "supportInfoId", description = "삭제할 지원 정보의 id입니다."), }) ApiResponse deleteSupportInfo( - @RequestParam Long userId, @PathVariable Long supportInfoId ); - @Operation(summary = "[ADMIN] 특정 지원정보 가져오기 API", description = "ID를 통해 특정 지원정보를 가져오는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)") + @Operation(summary = "[ADMIN] 특정 지원정보 가져오기 API", description = "ID를 통해 특정 지원정보를 가져오는 API입니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), // @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), @@ -100,11 +97,9 @@ ApiResponse deleteSupportInfo( // @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) @Parameters({ - @Parameter(name = "userId", description = "조회할 사용자의 id입니다."), @Parameter(name = "supportInfoId", description = "조회할 지원 정보의 id입니다."), }) ApiResponse getSupportInfo( - @RequestParam Long userId, @PathVariable Long supportInfoId ); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java index 44eb81d4..bbac6fb9 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java @@ -53,10 +53,9 @@ public ApiResponse likeSupportInfo( @Override @PutMapping("") public ApiResponse updateSupportInfo( - @RequestParam @ExistUser Long userId, @RequestBody SupportRequest.UpdateSupportDto supportRequestDto ) { - SupportResponseDto supportResponseDto = supportInfoService.updateSupportInfo(userId, supportRequestDto); + SupportResponseDto supportResponseDto = supportInfoService.updateSupportInfo(supportRequestDto); return ApiResponse.onSuccess(supportResponseDto); } @@ -64,10 +63,9 @@ public ApiResponse updateSupportInfo( @Override @DeleteMapping("/{supportInfoId}") public ApiResponse deleteSupportInfo( - @RequestParam @ExistUser Long userId, @PathVariable Long supportInfoId ) { - String message = supportInfoService.deleteSupportInfo(userId, supportInfoId); + String message = supportInfoService.deleteSupportInfo(supportInfoId); return ApiResponse.onSuccess(message); } @@ -75,10 +73,9 @@ public ApiResponse deleteSupportInfo( @Override @GetMapping("/{supportInfoId}") public ApiResponse getSupportInfo( - @RequestParam @ExistUser Long userId, @PathVariable Long supportInfoId ) { - SupportResponseDto supportResponseDto = supportInfoService.getSupportInfoById(userId, supportInfoId); + SupportResponseDto supportResponseDto = supportInfoService.getSupportInfoById(supportInfoId); return ApiResponse.onSuccess(supportResponseDto); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoService.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoService.java index 9f87b268..c9ef7783 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoService.java @@ -16,10 +16,10 @@ Page getSupportsByYearAndMonth( SupportResponseDto toggleLike(Long userId, Long supportInfoId); - SupportResponseDto updateSupportInfo(Long userId, SupportRequest.UpdateSupportDto supportRequestDto); + SupportResponseDto updateSupportInfo(SupportRequest.UpdateSupportDto supportRequestDto); - String deleteSupportInfo(Long userId, Long supportInfoId); + String deleteSupportInfo(Long supportInfoId); - SupportResponseDto getSupportInfoById(Long userId, Long supportInfoId); + SupportResponseDto getSupportInfoById(Long supportInfoId); } \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java index b3f37f31..f5ca3f7e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java @@ -117,18 +117,14 @@ public SupportResponseDto toggleLike(Long userId, Long supportInfoId) { @Transactional @Override - public SupportResponseDto updateSupportInfo(Long userId, SupportRequest.UpdateSupportDto supportRequestDto) { + public SupportResponseDto updateSupportInfo(SupportRequest.UpdateSupportDto supportRequestDto) { /** - * 1. 사용자 조회 -> 없으면 에러 - * 2. 지원정보 조회 -> 없으면 에러 - * 3. 변경사항 업데이트 - * 4. 변경사항 저장 - * 5. Entity -> ResponseDto로 변환 후 리턴 + * 1. 지원정보 조회 -> 없으면 에러 + * 2. 변경사항 업데이트 + * 3. 변경사항 저장 + * 4. Entity -> ResponseDto로 변환 후 리턴 */ - User user = userRepository.findById(userId) - .orElseThrow(() -> new IllegalArgumentException("User not found")); - SupportInfo supportInfo = supportInfoRepository.findById(supportRequestDto.getId()) .orElseThrow(() -> new IllegalArgumentException("SupportInfo not found")); @@ -141,17 +137,13 @@ public SupportResponseDto updateSupportInfo(Long userId, SupportRequest.UpdateSu @Transactional @Override - public String deleteSupportInfo(Long userId, Long supportInfoId) { + public String deleteSupportInfo(Long supportInfoId) { /** - * 1. 사용자 조회 -> 없으면 에러 - * 2. 지원정보 조회 -> 없으면 에러 - * 3. Entity 삭제 - * 4. 성공여부 반환 + * 1. 지원정보 조회 -> 없으면 에러 + * 2. Entity 삭제 + * 3. 성공여부 반환 */ - User user = userRepository.findById(userId) - .orElseThrow(() -> new IllegalArgumentException("User not found")); - SupportInfo supportInfo = supportInfoRepository.findById(supportInfoId) .orElseThrow(() -> new IllegalArgumentException("SupportInfo not found")); @@ -163,17 +155,13 @@ public String deleteSupportInfo(Long userId, Long supportInfoId) { @Transactional @Override - public SupportResponseDto getSupportInfoById(Long userId, Long supportInfoId) { + public SupportResponseDto getSupportInfoById(Long supportInfoId) { /** - * 1. 사용자 조회 -> 없으면 에러 - * 2. 지원정보 조회 -> 없으면 에러 - * 3. Entity 조회 - * 4. Entity -> ResponseDto로 변환 후 리턴 + * 1. 지원정보 조회 -> 없으면 에러 + * 2. Entity 조회 + * 3. Entity -> ResponseDto로 변환 후 리턴 */ - User user = userRepository.findById(userId) - .orElseThrow(() -> new IllegalArgumentException("User not found")); - SupportInfo supportInfo = supportInfoRepository.findById(supportInfoId) .orElseThrow(() -> new IllegalArgumentException("SupportInfo not found")); diff --git a/src/main/java/com/bbteam/budgetbuddies/global/config/SecurityConfig.java b/src/main/java/com/bbteam/budgetbuddies/global/config/SecurityConfig.java new file mode 100644 index 00000000..dc28772d --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/global/config/SecurityConfig.java @@ -0,0 +1,61 @@ +package com.bbteam.budgetbuddies.global.config; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; +import org.springframework.security.web.SecurityFilterChain; + +import java.util.Objects; + +import static org.springframework.security.config.Customizer.withDefaults; + +@Configuration +@EnableWebSecurity +@Slf4j +public class SecurityConfig { + + private final Environment env; + + public SecurityConfig(Environment env) { + this.env = env; + } + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http + .authorizeHttpRequests(authorizeRequests -> + authorizeRequests + .requestMatchers("/swagger-ui/**", "/v3/api-docs/**").hasRole("ADMIN") + .anyRequest().permitAll() + ) + .formLogin(withDefaults()) + .httpBasic(withDefaults()); + + return http.build(); + } + + @Bean + public InMemoryUserDetailsManager userDetailsService() { + String username = env.getProperty("spring.security.user.name"); + String password = env.getProperty("spring.security.user.password"); + + log.info("username : {}", username); + log.info("password : {}", password); + + UserDetails user = User.withDefaultPasswordEncoder() + .username(Objects.requireNonNull(username)) + .password(Objects.requireNonNull(password)) + .roles("ADMIN") + .build(); + + return new InMemoryUserDetailsManager(user); + } + + +} \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/global/config/SwaggerConfig.java b/src/main/java/com/bbteam/budgetbuddies/global/config/SwaggerConfig.java index 36a72988..f529ae35 100644 --- a/src/main/java/com/bbteam/budgetbuddies/global/config/SwaggerConfig.java +++ b/src/main/java/com/bbteam/budgetbuddies/global/config/SwaggerConfig.java @@ -13,6 +13,7 @@ public class SwaggerConfig { @Bean public OpenAPI openAPI() { return new OpenAPI() + .openapi("3.0.0") .components(new Components()) .info(apiInfo()); }