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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'me.paulschwarz:spring-dotenv:4.0.0'
implementation 'me.paulschwarz:spring-dotenv:3.0.0'
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

// Swagger 설정
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing
@SpringBootApplication
public class DoDutchServerApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
public class AuthController {
private final AuthService authService;

/**
* 카카오 로그인 (웹)
*/
@PostMapping("/kakao/login")
@Operation(summary = "카카오 로그인 API (웹)")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공")
})
public ApiResponse<KakaoResponseDTO> login(@RequestBody KakaoRequestDTO kakaoRequestDTO,
HttpServletResponse response) {
KakaoResponseDTO kakaoResponseDTO = authService.loginWithKakao(kakaoRequestDTO.getAccessCode(), response);
Expand All @@ -35,22 +42,38 @@ public ApiResponse<KakaoResponseDTO> login(@RequestBody KakaoRequestDTO kakaoReq
*/
@PostMapping("/kakao/login-token")
@Operation(summary = "카카오 로그인 (모바일 SDK 액세스 토큰)", description = "모바일 앱에서 카카오 SDK로 획득한 액세스 토큰으로 로그인")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공")
})
public ApiResponse<KakaoResponseDTO> loginWithToken(@RequestBody KakaoRequestDTO kakaoRequestDTO,
HttpServletResponse response) {
KakaoResponseDTO kakaoResponseDTO = authService.loginWithKakaoToken(kakaoRequestDTO.getAccessToken(), response);
return ApiResponse.onSuccess(kakaoResponseDTO);
}

/**
* 회원가입
*/
@PostMapping("/signup")
@Operation(summary = "회원가입 API", description = "카카오 로그인 후 닉네임 설정하여 회원가입")
public ApiResponse<Object> signup(@RequestBody SignupRequestDTO signupRequestDTO,
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공")
})
public ApiResponse<Void> signup(@RequestBody SignupRequestDTO signupRequestDTO,
@RequestHeader("Authorization") String authHeader) {
String accessToken = authHeader.replace("Bearer ", "");
authService.signup(signupRequestDTO, accessToken);
return ApiResponse.onSuccess();
}

/**
* 토큰 갱신
*/
@PostMapping("/refresh-token")
@Operation(summary = "토큰 갱신 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공")
})
public ApiResponse<RefreshResponseDTO> refreshToken(@RequestBody RefreshRequestDTO refreshRequestDTO,
HttpServletResponse response) {
RefreshResponseDTO refreshResponseDTO = authService.refreshAccessToken(refreshRequestDTO);
Expand All @@ -62,13 +85,17 @@ public ApiResponse<RefreshResponseDTO> refreshToken(@RequestBody RefreshRequestD
* 카카오 OAuth 과정 없이 kakaoId로 바로 JWT 토큰 발급
*/
@PostMapping("/dev-login")
@Operation(summary = "개발 전용 로그인 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공")
})
public ApiResponse<KakaoResponseDTO> devLogin(@RequestParam String kakaoId) {
log.info("[DEV] Development login requested for kakaoId: {}", kakaoId);
KakaoResponseDTO response = authService.createTokensForDev(kakaoId);
return ApiResponse.onSuccess(response);
}

/*
/**
* 닉네임 중복 확인
*/
@PostMapping("/check-nickname")
Expand All @@ -81,15 +108,26 @@ public ApiResponse<Void> checkNickname(@RequestBody NicknameRequestDto requestDt
return ApiResponse.onSuccess();
}

/**
* 프리미엄 결제 준비
*/
@PostMapping("/premium")
@Operation(summary = "프리미엄 결제 준비 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공")
})
public ApiResponse<PayPremiumReadyResponseDto> premium(
@RequestBody PayPremiumReadyRequestDto requestDto
) {
PayPremiumReadyResponseDto responseDto = authService.premium(requestDto);
return ApiResponse.onSuccess(responseDto);
}

/**
* 프리미엄 결제 승인 콜백
*/
@GetMapping("/approve-callback")
@Operation(summary = "프리미엄 결제 승인 콜백 API")
public void approve(
@RequestParam("partner_order_id") String partnerOrderId,
@RequestParam("pg_token") String pgToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import graduation.project.DoDutch_server.global.common.exception.GeneralException;

import java.util.Map;
import java.util.Optional;
import java.util.UUID;

@RequiredArgsConstructor
Expand All @@ -51,6 +50,7 @@ public class AuthService {
private final JwtTokenProvider jwtTokenProvider;
private final KakaopayService kakaopayService;
private final PaymentOrderRepository paymentOrderRepository;
private final RestTemplate restTemplate = new RestTemplate();

@Value("${kakao.client-id}")
private String clientId;
Expand All @@ -68,8 +68,6 @@ public KakaoResponseDTO loginWithKakao(String accessCode, HttpServletResponse re

KakaoMemberAndExistDTO kakaoMemberAndExistDTO = getUserProfileByToken(accessToken);

Optional<Member> findMember = memberRepository.findById(kakaoMemberAndExistDTO.getMember().getId());

return getKakaoTokens(kakaoMemberAndExistDTO.getMember().getKakaoId(), kakaoMemberAndExistDTO.isExistingMember(), response);
}

Expand All @@ -85,8 +83,6 @@ public KakaoResponseDTO loginWithKakaoToken(String accessToken, HttpServletRespo
// OAuth 인증 코드 교환 과정을 건너뛰고 직접 액세스 토큰 사용
KakaoMemberAndExistDTO kakaoMemberAndExistDTO = getUserProfileByToken(accessToken);

Optional<Member> findMember = memberRepository.findById(kakaoMemberAndExistDTO.getMember().getId());

KakaoResponseDTO result = getKakaoTokens(kakaoMemberAndExistDTO.getMember().getKakaoId(),
kakaoMemberAndExistDTO.isExistingMember(),
response);
Expand Down Expand Up @@ -114,8 +110,7 @@ private String getAccessToken(String accessCode) {

// HTTP 요청 보내기
HttpEntity<MultiValueMap<String, String>> kakaoTokenRequest = new HttpEntity<>(body, headers);
RestTemplate rt = new RestTemplate();
ResponseEntity<String> response = rt.exchange(
ResponseEntity<String> response = restTemplate.exchange(
"https://kauth.kakao.com/oauth/token",
HttpMethod.POST,
kakaoTokenRequest,
Expand All @@ -124,14 +119,23 @@ private String getAccessToken(String accessCode) {

// HTTP 응답 (JSON) -> 액세스 토큰 파싱
String responseBody = response.getBody();
if (responseBody == null) {
throw new GeneralException(ErrorStatus.KAKAO_API_ERROR);
}

ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = null;
JsonNode jsonNode;
try {
jsonNode = objectMapper.readTree(responseBody);
} catch (JsonProcessingException e) {
e.printStackTrace();
throw new GeneralException(ErrorStatus.KAKAO_API_ERROR);
}
return jsonNode.get("access_token").asText(); //토큰 전송

JsonNode accessTokenNode = jsonNode.get("access_token");
if (accessTokenNode == null) {
throw new GeneralException(ErrorStatus.KAKAO_API_ERROR);
}
return accessTokenNode.asText(); //토큰 전송
}

// 카카오 API 호출해서 AccessToken으로 유저정보 가져오기(id)
Expand Down Expand Up @@ -175,15 +179,15 @@ public KakaoMemberAndExistDTO getUserProfileByToken(String accessToken){

boolean existMember = false;

if(memberRepository.findByKakaoId(member.getKakaoId()) != null) //DB에 회원정보 있으면 existMember = True
Member findMember = memberRepository.findByKakaoId(member.getKakaoId()); //DB에 회원정보 조회
if(findMember != null) //DB에 회원정보 있으면 existMember = True
{
existMember = true;
}
else {
memberRepository.save(member); //DB에 회원정보 없으면 저장
findMember = memberRepository.save(member); //DB에 회원정보 없으면 저장
}

Member findMember = memberRepository.findByKakaoId(kakaoInfoDto.getKakaoId());
return KakaoMemberAndExistDTO.builder()
.member(findMember)
.isExistingMember(existMember)
Expand Down Expand Up @@ -279,7 +283,7 @@ public KakaoResponseDTO createTokensForDev(String kakaoId) {
}

// 닉네임 중복 확인
@Transactional
@Transactional(readOnly = true)
public void checkNickname(NicknameRequestDto requestDto) {
String nickname = requestDto.nickname();
if (nickname == null || nickname.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package graduation.project.DoDutch_server.domain.expense.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import graduation.project.DoDutch_server.domain.expense.dto.*;
import graduation.project.DoDutch_server.domain.expense.service.ExpenseService;
import graduation.project.DoDutch_server.global.common.apiPayload.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
Expand All @@ -22,7 +19,7 @@
public class ExpenseController {
private final ExpenseService expenseService;

/*
/**
* 하나의 여행에 대한 전체 지출 목록 조회
*/
@GetMapping("/{tripId}/expense")
Expand All @@ -37,7 +34,7 @@ public ApiResponse<AllExpenseResponseDto> getExpensesByTrip(@PathVariable("tripI
}


/*
/**
* 하나의 여행에 대한 날짜별 지출 목록 조회
*/
@GetMapping("/{tripId}/expense/date")
Expand All @@ -52,7 +49,7 @@ public ApiResponse<List<AllExpenseByDateResponseDto>> getExpensesByTripAndDate(@
}


/*
/**
* 지출 세부 조회
*/
@Operation(summary = "지출 세부 조회 API")
Expand All @@ -67,27 +64,45 @@ public ApiResponse<ExpenseByExpenseIdResponseDto> getExpensesById(@PathVariable(
}


@Operation(summary = "지출 생성 API")
@Operation(summary = "지출 생성 API",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = @io.swagger.v3.oas.annotations.media.Content(
encoding = @io.swagger.v3.oas.annotations.media.Encoding(
name = "expenseRequestDto",
contentType = MediaType.APPLICATION_JSON_VALUE
)
)
)
)
@io.swagger.v3.oas.annotations.responses.ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공")
})
@PostMapping(value = "/{tripId}/expense", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ApiResponse<Object> addExpense(@PathVariable("tripId") Long tripId,
public ApiResponse<Void> addExpense(@PathVariable("tripId") Long tripId,
@RequestPart("expenseRequestDto") ExpenseRequestDto expenseRequestDto,
@RequestPart("expenseImages") List<MultipartFile> expenseImages
@RequestPart(value = "expenseImages", required = false) List<MultipartFile> expenseImages
) {
expenseService.addExpense(tripId, expenseRequestDto, expenseImages);

return ApiResponse.onSuccess();
}


@Operation(summary = "지출 수정 API")
@Operation(summary = "지출 수정 API",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = @io.swagger.v3.oas.annotations.media.Content(
encoding = @io.swagger.v3.oas.annotations.media.Encoding(
name = "expenseRequestDto",
contentType = MediaType.APPLICATION_JSON_VALUE
)
)
)
)
@io.swagger.v3.oas.annotations.responses.ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공")
})
@PatchMapping(value = "/{tripId}/expense/{expenseId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ApiResponse<Object> updateExpense(@PathVariable("tripId") Long tripId,
public ApiResponse<Void> updateExpense(@PathVariable("tripId") Long tripId,
@PathVariable("expenseId") Long expenseId,
@RequestPart("expenseRequestDto") ExpenseRequestDto expenseRequestDto,
@RequestPart(value = "expenseImages", required = false) List<MultipartFile> expenseImages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public static ExpenseByExpenseIdResponseDto toExpenseByExpenseIdResponseDto(Expe
.expenseDate(expense.getExpenseDate())
.title(expense.getTitle())
.amount(expense.getAmount())
.expenseImage(expense.getExpenseImageUrl())
.memo(expense.getMemo())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ public class ExpenseByExpenseIdResponseDto {
private LocalDate expenseDate;
private String title;
private int amount;
private String expenseImage;
private String memo;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class Expense extends BaseEntity {
private ExpenseCategory expenseCategory;
private LocalDate expenseDate;
private String memo;
private String expenseImageUrl;

@ManyToOne
@JoinColumn(name = "payer", nullable = true)
private Member payer;
Expand All @@ -43,7 +41,6 @@ public class Expense extends BaseEntity {
private List<ExpenseMember> expenseMembers = new ArrayList<>();

/**
*
* update 함수
*/
public void update(String title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package graduation.project.DoDutch_server.domain.expense.repository;

import graduation.project.DoDutch_server.domain.expense.entity.Expense;
import graduation.project.DoDutch_server.domain.member.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand Down
Loading
Loading