Skip to content

Commit

Permalink
feat: save device token API
Browse files Browse the repository at this point in the history
  • Loading branch information
Seokyeong237 committed Feb 19, 2024
1 parent f2a56a9 commit dec1256
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/fullcar/core/response/SuccessCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public enum SuccessCode {
AVAILABLE_NICKNAME(OK, "사용 가능한 닉네임"),
UPDATE_SUCCESS(OK, "수정 성공"),
CODE_VERIFICATION_SUCCESS(OK, "인증 성공"),
WITHDRAW_SUCCESS(OK, "탈퇴 성공");
WITHDRAW_SUCCESS(OK, "탈퇴 성공"),
SAVE_DEVICE_TOKEN_SUCCESS(OK, "디바이스 토큰 등록 성공");

private final HttpStatus status;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import com.fullcar.core.exception.CustomException;
import com.fullcar.core.exception.NotFoundException;
import com.fullcar.core.response.ErrorCode;
import com.fullcar.member.application.auth.AppleAuthService;
import com.fullcar.member.application.auth.KakaoAuthService;
import com.fullcar.member.domain.car.CarRepository;
import com.fullcar.member.domain.mail.MailRepository;
import com.fullcar.member.domain.member.*;
import com.fullcar.member.presentation.member.dto.request.DeviceTokenRequestDto;
import com.fullcar.member.presentation.member.dto.request.NicknameRequestDto;
import com.fullcar.member.presentation.member.dto.request.OnBoardingRequestDto;
import com.fullcar.member.presentation.member.dto.response.DeviceTokenResponseDto;
import com.fullcar.member.presentation.member.dto.response.MemberGetResponseDto;
import com.fullcar.member.presentation.member.dto.response.NicknameResponseDto;
import com.fullcar.member.presentation.member.dto.response.OnBoardingResponseDto;
Expand Down Expand Up @@ -59,4 +57,13 @@ public NicknameResponseDto checkNicknameDuplication(NicknameRequestDto nicknameR
.build();
}
}

@Transactional
public DeviceTokenResponseDto postDeviceToken(Member member, DeviceTokenRequestDto deviceTokenRequestDto) {
memberRepository.saveAndFlush(member.saveDeviceToken(deviceTokenRequestDto));

return DeviceTokenResponseDto.builder()
.deviceToken(deviceTokenRequestDto.getDeviceToken())
.build();
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/fullcar/member/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fullcar.member.domain.car.CarId;
import com.fullcar.member.domain.auth.SocialId;
import com.fullcar.member.presentation.member.dto.request.DeviceTokenRequestDto;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -107,4 +108,9 @@ public Member deleted() {
this.gender = null;
return this;
}

public Member saveDeviceToken(DeviceTokenRequestDto deviceTokenRequestDto) {
this.deviceToken = deviceTokenRequestDto.getDeviceToken();
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fullcar.member.domain.member.Member;
import com.fullcar.member.domain.member.service.MailService;
import com.fullcar.member.presentation.member.dto.request.*;
import com.fullcar.member.presentation.member.dto.response.DeviceTokenResponseDto;
import com.fullcar.member.presentation.member.dto.response.MemberGetResponseDto;
import com.fullcar.member.presentation.member.dto.response.NicknameResponseDto;
import com.fullcar.member.presentation.member.dto.response.OnBoardingResponseDto;
Expand Down Expand Up @@ -84,4 +85,15 @@ public ApiResponse<Object> checkMailAuthenticationCode(@CurrentMember Member mem
mailService.checkMailAuthenticationCode(member, codeRequestDto);
return ApiResponse.success(SuccessCode.CODE_VERIFICATION_SUCCESS);
}

@Operation(summary = "디바이스 토큰 등록 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "디바이스 토큰 등록 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content)
})
@PostMapping("/device-token")
public ApiResponse<DeviceTokenResponseDto> postDeviceToken(@CurrentMember Member member, @RequestBody DeviceTokenRequestDto deviceTokenRequestDto) {
DeviceTokenResponseDto responseDto = memberService.postDeviceToken(member, deviceTokenRequestDto);
return ApiResponse.success(SuccessCode.SAVE_DEVICE_TOKEN_SUCCESS, responseDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.fullcar.member.presentation.member.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class DeviceTokenRequestDto {
@Schema(description = "디바이스 토큰", example = "123")
private String deviceToken;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.fullcar.member.presentation.member.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class DeviceTokenResponseDto {
@Schema(description = "디바이스 토큰", example = "123")
private String deviceToken;
}

0 comments on commit dec1256

Please sign in to comment.