-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat] : 메시지 Enum 추가 & 보험 API 구현 완료
- Loading branch information
Showing
11 changed files
with
149 additions
and
12 deletions.
There are no files selected for viewing
25 changes: 20 additions & 5 deletions
25
src/main/java/Weflo/backend/controller/insurance/InsuranceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
package Weflo.backend.controller.insurance; | ||
|
||
import Weflo.backend.dto.user.response.InsuranceResponse; | ||
import Weflo.backend.global.ApiResponse; | ||
import Weflo.backend.global.status.Message; | ||
import Weflo.backend.service.insurance.InsuranceService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping(value = "/api") | ||
@RequestMapping(value = "/api/insurance") | ||
public class InsuranceController { | ||
private final InsuranceService insuranceService; | ||
@GetMapping("/{user_id}") | ||
public ApiResponse<InsuranceResponse> getInsuranceDetails(@PathVariable("user_id") Long userId) { | ||
InsuranceResponse insuranceResponse = insuranceService.getInsuranceDetails(userId); | ||
|
||
return ApiResponse.onSuccess(Message._GET_INSURANCE_MESSAGE.getMessage(), insuranceResponse); | ||
} | ||
|
||
@PostMapping("join/{user_id}") | ||
public ApiResponse<InsuranceResponse> joinInsurance(@PathVariable("user_id") Long userId) { | ||
InsuranceResponse insuranceResponse = insuranceService.joinInsurance(userId); | ||
|
||
} | ||
return ApiResponse.onSuccessCreated(Message._JOIN_SUCCESS_MESSAGE.getMessage(), insuranceResponse); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package Weflo.backend.global.status; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum Message { | ||
_GET_ALL_ORDER_PARTS_MESSAGE("주문할 모든 부품을 조회합니다."), | ||
_GET_ORDER_PARTS_DETAILS_MESSAGE("해당 드론의 부품 주문을 상세 조회합니다."), | ||
_GET_QUOTATION_MESSAGE("견적서를 조회합니다."), | ||
_ORDER_SUCCESS_MESSAGE("부품 주문에 성공했습니다."), | ||
_GET_ALL_ORDER_HISTORIES_MESSAGE("주문 배송 내역을 조회합니다."), | ||
_GET_DELIVERY_DETAILS_MESSAGE("특정 배송의 상세 내역을 조회합니다."), | ||
_CHANGE_DELIVERY_STATUS_MESSAGE("배송 상태 변경에 성공했습니다."), | ||
_GET_INSURANCE_MESSAGE("유저의 보험 페이지를 조회합니다."), | ||
_JOIN_SUCCESS_MESSAGE("유저가 보험 가입에 성공했습니다."), | ||
_GET_ALL_CHECK_HISTORIES_MESSAGE("모든 수리/점검 내역을 조회합니다."), | ||
_GET_CHECK_HISTORY_DETAILS_MESSAGE("특정 드론의 수리/점검 상세 내역을 조회합니다."), | ||
_DISPOSE_SUCCESS_MESSAGE("드론 폐기에 성공했습니다."); | ||
|
||
private final String message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/Weflo/backend/repository/user/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package Weflo.backend.repository.user; | ||
|
||
import Weflo.backend.domain.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/Weflo/backend/service/insurance/InsuranceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package Weflo.backend.service.insurance; | ||
|
||
import Weflo.backend.dto.user.response.InsuranceResponse; | ||
|
||
public interface InsuranceService { | ||
InsuranceResponse getInsuranceDetails(Long userId); | ||
InsuranceResponse joinInsurance(Long userId); | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/Weflo/backend/service/insurance/InsuranceServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package Weflo.backend.service.insurance; | ||
|
||
import Weflo.backend.domain.User; | ||
import Weflo.backend.dto.user.response.InsuranceResponse; | ||
import Weflo.backend.repository.user.UserRepository; | ||
import com.amazonaws.services.kms.model.NotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class InsuranceServiceImpl implements InsuranceService { | ||
private final UserRepository userRepository; | ||
|
||
@Override | ||
public InsuranceResponse getInsuranceDetails(Long userId) { | ||
User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new NotFoundException("User not found")); | ||
|
||
return InsuranceResponse.builder() | ||
.isJoin(user.getIsJoin()) | ||
.joinDate(user.getJoinDate()) | ||
.updateDate(user.getUpdateDate()) | ||
.insuranceRate(user.getInsuranceRate()) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public InsuranceResponse joinInsurance(Long userId) { | ||
User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new NotFoundException("User not found")); | ||
|
||
LocalDate now = LocalDate.now(); | ||
|
||
User newUserInfo = User.builder() | ||
.id(user.getId()) | ||
.loginId(user.getLoginId()) | ||
.loginPassword(user.getLoginPassword()) | ||
.name(user.getName()) | ||
.tel(user.getTel()) | ||
.address(user.getAddress()) | ||
.isJoin(true) | ||
.joinDate(now) | ||
.updateDate(now.plusYears(3)) | ||
.insuranceRate(10) | ||
.build(); | ||
|
||
userRepository.save(newUserInfo); | ||
|
||
return InsuranceResponse.builder() | ||
.isJoin(newUserInfo.getIsJoin()) | ||
.joinDate(newUserInfo.getJoinDate()) | ||
.updateDate(newUserInfo.getUpdateDate()) | ||
.insuranceRate(newUserInfo.getInsuranceRate()) | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters