Skip to content

Commit

Permalink
Merge pull request #151 from BudgetBuddiesTeam/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ggamD00 authored Aug 20, 2024
2 parents dcfcabe + 3dec4b1 commit 9a5516a
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 90 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.bbteam.budgetbuddies.domain.category.entity.Category;

public interface CategoryRepository extends JpaRepository<Category, Long> {
@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<Category> findUserCategoryByUserId(@Param("id") Long id);

@Query("SELECT c FROM Category c WHERE c.isDefault = true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,55 +61,48 @@ ApiResponse<DiscountResponseDto> registerDiscountInfo(
@Parameter(name = "discountInfoId", description = "좋아요를 누를 할인정보의 id입니다."),
})
ApiResponse<DiscountResponseDto> 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))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @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<DiscountResponseDto> 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))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @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<String> 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))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @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<DiscountResponseDto> getDiscountInfo(
@RequestParam Long userId,
@PathVariable Long discountInfoId
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,19 @@ public ApiResponse<DiscountResponseDto> likeDiscountInfo(
@Override
@PutMapping("")
public ApiResponse<DiscountResponseDto> updateDiscountInfo(
@RequestParam @ExistUser Long userId,
@RequestBody DiscountRequest.UpdateDiscountDto discountRequestDto
) {
DiscountResponseDto discountResponseDto = discountInfoService.updateDiscountInfo(userId, discountRequestDto);
DiscountResponseDto discountResponseDto = discountInfoService.updateDiscountInfo(discountRequestDto);

return ApiResponse.onSuccess(discountResponseDto);
}

@Override
@DeleteMapping("/{discountInfoId}")
public ApiResponse<String> deleteDiscountInfo(
@RequestParam @ExistUser Long userId,
@PathVariable Long discountInfoId
) {
String message = discountInfoService.deleteDiscountInfo(userId, discountInfoId);
String message = discountInfoService.deleteDiscountInfo(discountInfoId);

return ApiResponse.onSuccess(message);
}
Expand All @@ -76,10 +74,9 @@ public ApiResponse<String> deleteDiscountInfo(
@Override
@GetMapping("/{discountInfoId}")
public ApiResponse<DiscountResponseDto> getDiscountInfo(
@RequestParam @ExistUser Long userId,
@PathVariable Long discountInfoId
) {
DiscountResponseDto discountResponseDto = discountInfoService.getDiscountInfoById(userId, discountInfoId);
DiscountResponseDto discountResponseDto = discountInfoService.getDiscountInfoById(discountInfoId);

return ApiResponse.onSuccess(discountResponseDto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Page<DiscountResponseDto> 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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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"));

Expand All @@ -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"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,54 +58,48 @@ ApiResponse<SupportResponseDto> registerSupportInfo(
@Parameter(name = "supportInfoId", description = "좋아요를 누를 지원정보의 id입니다."),
})
ApiResponse<SupportResponseDto> 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))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @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<SupportResponseDto> 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))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @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<String> 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))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @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<SupportResponseDto> getSupportInfo(
@RequestParam Long userId,
@PathVariable Long supportInfoId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,29 @@ public ApiResponse<SupportResponseDto> likeSupportInfo(
@Override
@PutMapping("")
public ApiResponse<SupportResponseDto> updateSupportInfo(
@RequestParam @ExistUser Long userId,
@RequestBody SupportRequest.UpdateSupportDto supportRequestDto
) {
SupportResponseDto supportResponseDto = supportInfoService.updateSupportInfo(userId, supportRequestDto);
SupportResponseDto supportResponseDto = supportInfoService.updateSupportInfo(supportRequestDto);

return ApiResponse.onSuccess(supportResponseDto);
}

@Override
@DeleteMapping("/{supportInfoId}")
public ApiResponse<String> deleteSupportInfo(
@RequestParam @ExistUser Long userId,
@PathVariable Long supportInfoId
) {
String message = supportInfoService.deleteSupportInfo(userId, supportInfoId);
String message = supportInfoService.deleteSupportInfo(supportInfoId);

return ApiResponse.onSuccess(message);
}

@Override
@GetMapping("/{supportInfoId}")
public ApiResponse<SupportResponseDto> getSupportInfo(
@RequestParam @ExistUser Long userId,
@PathVariable Long supportInfoId
) {
SupportResponseDto supportResponseDto = supportInfoService.getSupportInfoById(userId, supportInfoId);
SupportResponseDto supportResponseDto = supportInfoService.getSupportInfoById(supportInfoId);

return ApiResponse.onSuccess(supportResponseDto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Page<SupportResponseDto> 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);

}
Loading

0 comments on commit 9a5516a

Please sign in to comment.