Skip to content

Commit

Permalink
Merge pull request #113 from BudgetBuddiesTeam/dev
Browse files Browse the repository at this point in the history
[v2] 사용자 미인증 버전
  • Loading branch information
SoulTree-Lovers authored Aug 14, 2024
2 parents 089e7fc + 2743541 commit 89022f9
Show file tree
Hide file tree
Showing 42 changed files with 808 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,9 @@ public enum ErrorStatus implements BaseErrorCode {


_INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "COMMON500", "서버에러"),
_BAD_REQUEST(HttpStatus.BAD_REQUEST, "COMMON400", "잘못된 요청입니다."),
_UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "COMMON401", "인증이 필요합니다"),
_FORBIDDEN(HttpStatus.FORBIDDEN, "COMMON403", "금지된 요청입니다."),
USER_NOT_FOUND(HttpStatus.BAD_REQUEST, "USER4001", "사용자가 없습니다."),
NICKNAME_NOT_EXIST(HttpStatus.BAD_REQUEST, "MEMBER4002", "닉네임은 필수입니다."),
COMMENT_NOT_FOUND(HttpStatus.BAD_REQUEST, "COMMENT4001", "해당 댓글이 없습니다.") ,
ARTICLE_NOT_FOUND(HttpStatus.NOT_FOUND, "ARTICLE4002", "게시글이 없습니다."),
TEMP_EXCEPTION(HttpStatus.BAD_REQUEST, "TEMP4001", "test"),
FOOD_CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, "FOOD_CATEGORY4004", "해당하는 음식 카테고리가 없습니다."),
STORE_NOT_FOUND(HttpStatus.NOT_FOUND, "STORE4004", "해당하는 가게는 존재하지 않습니다."),
MISSION_ALREADY_ACCEPT(HttpStatus.BAD_REQUEST, "MISSION4001", "해당 미션은 이미 수주되었습니다."),
REVIEW_ALREADY_EXIST(HttpStatus.BAD_REQUEST, "REVIEW4001","해당 가게에 리뷰를 이미 작성하셨습니다."),
PAGE_LOWER_ZERO(HttpStatus.BAD_REQUEST, "PAGE4001", "요청된 페이지가 0보다 작습니다."),
MISSION_NOT_FOUND(HttpStatus.NOT_FOUND, "MISSION4004", "해당 미션이 존재하지 않습니다."),
MISSION_ALREADY_COMPLETE(HttpStatus.BAD_REQUEST, "MISSION4001", "해당 미션은 이미 완료된 미션입니다.");
PAGE_LOWER_ZERO(HttpStatus.BAD_REQUEST, "PAGE4001", "요청된 페이지가 0보다 작습니다.");


private HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.bbteam.budgetbuddies.domain.calendar.controller;

import com.bbteam.budgetbuddies.apiPayload.ApiResponse;
import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

public interface CalendarApi {

@Operation(summary = "[User] 주머니 캘린더 API", description = "주머니 캘린더 화면에 필요한 API를 호출합니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
})
@Parameters({
@Parameter(name = "year", description = "호출할 연도입니다."),
@Parameter(name = "month", description = "호출할 연도의 월입니다."),
})
public ApiResponse<CalendarDto.CalendarMonthResponseDto> request(
@RequestParam("year") Integer year, @RequestParam("month") Integer month);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bbteam.budgetbuddies.domain.calendar.controller;

import com.bbteam.budgetbuddies.apiPayload.ApiResponse;
import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto;
import com.bbteam.budgetbuddies.domain.calendar.service.CalendarService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -16,9 +17,10 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/calendar")
public class CalendarController {
public class CalendarController implements CalendarApi{

private final CalendarService calendarService;

@Operation(summary = "[User] 주머니 캘린더 API", description = "주머니 캘린더 화면에 필요한 API를 호출합니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
Expand All @@ -27,11 +29,11 @@ public class CalendarController {
@Parameter(name = "year", description = "호출할 연도입니다."),
@Parameter(name = "month", description = "호출할 연도의 월입니다."),
})
@GetMapping("/")
public ResponseEntity<CalendarDto.CalendarMonthResponseDto> request(
@GetMapping
public ApiResponse<CalendarDto.CalendarMonthResponseDto> request(
@RequestParam("year") Integer year, @RequestParam("month") Integer month
) {
CalendarDto.CalendarMonthResponseDto result = calendarService.find(year, month);
return ResponseEntity.ok(result);
return ApiResponse.onSuccess(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo;
import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo;

import java.time.LocalDate;
import java.util.List;

public class CalendarConverter {
Expand All @@ -16,12 +17,13 @@ public static CalendarDto.CalendarMonthResponseDto toCalendarMonthResponseDto(Ca
}

public static CalendarDto.CalendarMonthInfoDto toCalendarMonthInfoDto(List<DiscountInfo> discountInfoList,
List<SupportInfo> supportInfoList) {
List<SupportInfo> supportInfoList,
LocalDate firstDay, LocalDate lastDay) {
List<CalendarDto.CalendarDiscountInfoDto> discountInfoDtoList = discountInfoList.stream()
.map(CalendarConverter::toCalendarDiscountInfoDto)
.map(discountInfo -> toCalendarDiscountInfoDto(discountInfo, firstDay, lastDay))
.toList();
List<CalendarDto.CalendarSupportInfoDto> supportInfoDtoList = supportInfoList.stream()
.map(CalendarConverter::toCalendarSupportInfoDto)
.map(supportInfo -> toCalendarSupportInfoDto(supportInfo, firstDay, lastDay))
.toList();

return CalendarDto.CalendarMonthInfoDto.builder()
Expand All @@ -30,26 +32,62 @@ public static CalendarDto.CalendarMonthInfoDto toCalendarMonthInfoDto(List<Disco
.build();
}

public static CalendarDto.CalendarDiscountInfoDto toCalendarDiscountInfoDto(DiscountInfo discountInfo) {
public static CalendarDto.CalendarDiscountInfoDto toCalendarDiscountInfoDto(DiscountInfo discountInfo,
LocalDate firstDay, LocalDate lastDay) {
LocalDate startDate = null;
LocalDate endDate = null;

if(discountInfo.getStartDate().isBefore(firstDay)) {
startDate = firstDay;
} else {
startDate = discountInfo.getStartDate();
}

if(discountInfo.getEndDate().isAfter(lastDay)) {
endDate = lastDay;
} else {
endDate = discountInfo.getEndDate();
}


return CalendarDto.CalendarDiscountInfoDto.builder()
.id(discountInfo.getId())
.title(discountInfo.getTitle())
.likeCount(discountInfo.getLikeCount())
.startDate(discountInfo.getStartDate())
.endDate(discountInfo.getEndDate())
.startDate(startDate)
.endDate(endDate)
.discountRate(discountInfo.getDiscountRate())
.siteUrl(discountInfo.getSiteUrl())
.thumbnailURL(discountInfo.getThumbnailUrl())
.build();
}

public static CalendarDto.CalendarSupportInfoDto toCalendarSupportInfoDto(SupportInfo supportInfo) {
public static CalendarDto.CalendarSupportInfoDto toCalendarSupportInfoDto(SupportInfo supportInfo,
LocalDate firstDay, LocalDate lastDay) {

LocalDate startDate = null;
LocalDate endDate = null;

if(supportInfo.getStartDate().isBefore(firstDay)) {
startDate = firstDay;
} else {
startDate = supportInfo.getStartDate();
}

if(supportInfo.getEndDate().isAfter(lastDay)) {
endDate = lastDay;
} else {
endDate = supportInfo.getEndDate();
}

return CalendarDto.CalendarSupportInfoDto.builder()
.id(supportInfo.getId())
.title(supportInfo.getTitle())
.likeCount(supportInfo.getLikeCount())
.startDate(supportInfo.getStartDate())
.endDate(supportInfo.getEndDate())
.startDate(startDate)
.endDate(endDate)
.siteUrl(supportInfo.getSiteUrl())
.thumbnailURL(supportInfo.getThumbnailUrl())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static class CalendarDiscountInfoDto {
private Integer likeCount;
private Integer discountRate;
private String siteUrl;
private String thumbnailURL;
}

@Getter
Expand All @@ -46,5 +47,6 @@ public static class CalendarSupportInfoDto {
private LocalDate endDate;
private Integer likeCount;
private String siteUrl;
private String thumbnailURL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ private CalendarDto.CalendarMonthResponseDto getCalendarMonthResponseDto(LocalDa
private CalendarDto.CalendarMonthInfoDto getCalendarMonthInfoDto(LocalDate firstDay, LocalDate lastDay) {
List<DiscountInfo> monthDiscountInfoList = discountInfoRepository.findByMonth(firstDay, lastDay);
List<SupportInfo> monthSupportInfoList = supportInfoRepository.findByMonth(firstDay, lastDay);
return CalendarConverter.toCalendarMonthInfoDto(monthDiscountInfoList, monthSupportInfoList);
return CalendarConverter.toCalendarMonthInfoDto(monthDiscountInfoList, monthSupportInfoList, firstDay, lastDay);
}

private CalendarDto.CalendarMonthInfoDto getRecommendMonthInfoDto(LocalDate firstDay, LocalDate lastDay) {
List<DiscountInfo> recommendDiscountInfoList = discountInfoRepository.findRecommendInfoByMonth(firstDay, lastDay);
List<SupportInfo> recommendSupportInfoList = supportInfoRepository.findRecommendInfoByMonth(firstDay, lastDay);
return CalendarConverter.toCalendarMonthInfoDto(recommendDiscountInfoList, recommendSupportInfoList);
return CalendarConverter.toCalendarMonthInfoDto(recommendDiscountInfoList, recommendSupportInfoList, firstDay, lastDay);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public interface CategoryApi {
@ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class)))
})
@PostMapping("/add")
@PostMapping("/add/{userId}")
ResponseEntity<CategoryResponseDTO> createCategory(
@PathVariable Long userId,
@Parameter(description = "user_id, name(사용자가 입력한 카테고리명), is_default(default 카테고리 여부)로 request")
@RequestBody CategoryRequestDTO categoryRequestDTO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public class CategoryController implements CategoryApi {
private final CategoryService categoryService;

@Override
@PostMapping("/add")
public ResponseEntity<CategoryResponseDTO> createCategory(@RequestBody CategoryRequestDTO categoryRequestDTO) {
CategoryResponseDTO response = categoryService.createCategory(categoryRequestDTO);
@PostMapping("/add/{userId}")
public ResponseEntity<CategoryResponseDTO> createCategory(
@PathVariable Long userId,
@RequestBody CategoryRequestDTO categoryRequestDTO) {
CategoryResponseDTO response = categoryService.createCategory(userId, categoryRequestDTO);
return ResponseEntity.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
@Getter
@Setter
public class CategoryRequestDTO {
private Long userId;
private String name;
private Boolean isDefault;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bbteam.budgetbuddies.domain.category.dto;

import com.bbteam.budgetbuddies.domain.user.entity.User;
import lombok.Builder;
import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.bbteam.budgetbuddies.domain.user.entity.User;

public interface CategoryService {
CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO);
CategoryResponseDTO createCategory(Long userId, CategoryRequestDTO categoryRequestDTO);

List<CategoryResponseDTO> getUserCategories(Long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public class CategoryServiceImpl implements CategoryService {
private final ConsumptionGoalRepository consumptionGoalRepository;

@Override
public CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO) {
User user = userRepository.findById(categoryRequestDTO.getUserId())
.orElseThrow(() -> new IllegalArgumentException("cannot find user"));
public CategoryResponseDTO createCategory(Long userId, CategoryRequestDTO categoryRequestDTO) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new IllegalArgumentException("cannot find user"));

if (categoryRepository.existsByUserIdAndName(categoryRequestDTO.getUserId(), categoryRequestDTO.getName())) {
if (categoryRepository.existsByUserIdAndName(userId, categoryRequestDTO.getName())) {
throw new IllegalArgumentException("User already has a category with the same name");
}

Expand All @@ -47,12 +47,12 @@ public CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO)

// custom 카테고리 생성 -> 소비 목표 테이블에 초기 값 추가
ConsumptionGoal consumptionGoal = ConsumptionGoal.builder()
.user(user)
.category(savedCategory)
.goalMonth(LocalDate.now().withDayOfMonth(1)) // custom 카테고리를 생성한 현재 달(지금)로 설정
.goalAmount(0L)
.consumeAmount(0L)
.build();
.user(user)
.category(savedCategory)
.goalMonth(LocalDate.now().withDayOfMonth(1)) // custom 카테고리를 생성한 현재 달(지금)로 설정
.goalAmount(0L)
.consumeAmount(0L)
.build();

consumptionGoalRepository.save(consumptionGoal);
return categoryConverter.toCategoryResponseDTO(savedCategory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.time.LocalDate;

import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestParam;

import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalListRequestDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto;
Expand All @@ -15,20 +15,30 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;

public interface ConsumptionGoalApi {
@Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 조회하는 API 입니다.")

@Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 Top4 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 조회하는 API 입니다.")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
@Parameters({@Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다)"),
@Parameters({@Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다."),
@Parameter(name = "userId", description = "로그인 한 유저 아이디"),
@Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"),
@Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"),
@Parameter(name = "peerGender", description = "또래 성별")})
ResponseEntity<?> getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top, Long userId,
ResponseEntity<?> getTopGoalCategoriesList(int top, Long userId,
int peerAgeStart, int peerAgeEnd, String peerGender);

@Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 전체 조회하는 API 입니다.")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
@Parameters({@Parameter(name = "userId", description = "로그인 한 유저 아이디"),
@Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"),
@Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"),
@Parameter(name = "peerGender", description = "또래 성별")})
ResponseEntity<?> getTopGoalCategoriesPage(Long userId,
int peerAgeStart, int peerAgeEnd, String peerGender, Pageable pageable);

@Operation(summary = "또래가 가장 큰 계획을 세운 카테고리와 이번 주 사용한 금액 조회 API", description = "로그인 한 유저의 또래 중 가장 큰 소비 목표 금액을 가진 카테고리와 이번 주 사용한 금액을 조회하는 API 입니다")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
@Parameters({@Parameter(name = "userId", description = "로그인 한 유저 아이디")})
ResponseEntity<?> getTopGoalCategory(@RequestParam(name = "userId") Long userId);
ResponseEntity<?> getTopGoalCategory(Long userId);

@Operation(summary = "또래나이와 성별 조회 API", description = "또래나이와 성별을 조회하는 API 입니다.")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
Expand All @@ -46,12 +56,22 @@ ResponseEntity<?> getTopGoalCategories(@RequestParam(name = "top", defaultValue
ResponseEntity<ConsumptionGoalResponseListDto> updateOrElseGenerateConsumptionGoal(Long userId,
ConsumptionGoalListRequestDto consumptionGoalListRequestDto);

@Operation(summary = "또래들이 가장 많이한 소비 카테고리 조회 API", description = "특정 사용자의 소비 카테고리별 소비 금액을 조회하는 API 입니다.")
@Operation(summary = "또래들이 가장 많이한 소비 카테고리 조회 Top4 API", description = "특정 사용자의 소비 카테고리별 소비 금액을 조회하는 API 입니다.")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
@Parameters({@Parameter(name = "top", description = "가장 큰 소비 카테고리의 개수를 지정합니다. (기본값은 5입니다)"),
@Parameters({@Parameter(name = "top", description = "가장 큰 소비 카테고리의 개수를 지정합니다."),
@Parameter(name = "userId", description = "로그인 한 유저 아이디"),
@Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"),
@Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"),
@Parameter(name = "peerGender", description = "또래 성별")})
ResponseEntity<?> getConsumptionGoal(int top, Long userId, int peerAgeStart, int peerAgeEnd, String peerGender);
}
ResponseEntity<?> getConsumptionGoalList(int top, Long userId, int peerAgeStart, int peerAgeEnd,
String peerGender);

@Operation(summary = "또래들이 가장 많이한 소비 카테고리 조회 API", description = "특정 사용자의 소비 카테고리별 소비 금액을 전체 조회하는 API 입니다.")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
@Parameters({@Parameter(name = "userId", description = "로그인 한 유저 아이디"),
@Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"),
@Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"),
@Parameter(name = "peerGender", description = "또래 성별")})
ResponseEntity<?> getConsumptionGoalPage(Long userId, int peerAgeStart, int peerAgeEnd, String peerGender,
Pageable pageable);
}
Loading

0 comments on commit 89022f9

Please sign in to comment.