-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/borrowPosts' of https://github.com/billbill-pro…
…ject/bill-api-server into feature/borrowPosts
- Loading branch information
Showing
65 changed files
with
1,847 additions
and
53 deletions.
There are no files selected for viewing
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
20 changes: 20 additions & 0 deletions
20
src/main/java/site/billbill/apiserver/api/auth/dto/request/IdentityVerificationRequest.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,20 @@ | ||
package site.billbill.apiserver.api.auth.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import lombok.Data; | ||
import site.billbill.apiserver.common.enums.user.identity.IdentityVerificationOperator; | ||
|
||
@Data | ||
public class IdentityVerificationRequest { | ||
@Schema(description = "회원 본명", example = "홍길동") | ||
private String name; | ||
@Schema(description = "회원 전화번호", example = "010-1234-5678") | ||
private String phoneNumber; | ||
@Schema(description = "주민번호 앞 7자리", example = "0001013") | ||
private String identityNumber; | ||
@Enumerated(EnumType.STRING) | ||
@Schema(description = "본인인증 통신사", example = "SKT") | ||
private IdentityVerificationOperator operator; | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/java/site/billbill/apiserver/api/auth/service/OAuthService.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 site.billbill.apiserver.api.auth.service; | ||
|
||
import site.billbill.apiserver.common.utils.jwt.dto.JwtDto; | ||
|
||
public interface OAuthService { | ||
JwtDto kakaoCallback(String code); | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/site/billbill/apiserver/api/auth/service/OAuthServiceImpl.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,82 @@ | ||
package site.billbill.apiserver.api.auth.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import site.billbill.apiserver.common.enums.exception.ErrorCode; | ||
import site.billbill.apiserver.common.enums.user.Provider; | ||
import site.billbill.apiserver.common.enums.user.UserRole; | ||
import site.billbill.apiserver.common.utils.ULID.ULIDUtil; | ||
import site.billbill.apiserver.common.utils.jwt.JWTUtil; | ||
import site.billbill.apiserver.common.utils.jwt.dto.JwtDto; | ||
import site.billbill.apiserver.common.utils.users.oauth.kakao.KakaoUtil; | ||
import site.billbill.apiserver.exception.CustomException; | ||
import site.billbill.apiserver.external.oauth.kakao.dto.response.KakaoUserInfoResponse; | ||
import site.billbill.apiserver.model.user.UserIdentityJpaEntity; | ||
import site.billbill.apiserver.model.user.UserJpaEntity; | ||
import site.billbill.apiserver.repository.user.UserIdentityRepository; | ||
import site.billbill.apiserver.repository.user.UserRepository; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Optional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class OAuthServiceImpl implements OAuthService { | ||
private final KakaoUtil kakaoUtil; | ||
private final JWTUtil jwtUtil; | ||
private final UserRepository userRepository; | ||
private final UserIdentityRepository userIdentityRepository; | ||
|
||
@Override | ||
public JwtDto kakaoCallback(String code) { | ||
String accessToken = kakaoUtil.getAccessToken(code); | ||
if (accessToken == null) | ||
throw new CustomException(ErrorCode.ServerError, "토큰을 발급받는데 실패했습니다.", HttpStatus.INTERNAL_SERVER_ERROR); | ||
KakaoUserInfoResponse userInfo = kakaoUtil.getUserInfo(accessToken); | ||
|
||
Optional<UserJpaEntity> optionalUser = userRepository.findByProviderId(userInfo.partner.getUuid()); | ||
|
||
// 만약 이미 가입된 회원이라면 토큰 반환 | ||
if (optionalUser.isPresent()) { | ||
return jwtUtil.generateJwtDto(optionalUser.get().getUserId(), optionalUser.get().getRole()); | ||
} | ||
|
||
// 만약 신규 회원이라면 | ||
String userId = ULIDUtil.generatorULID("USER"); | ||
|
||
String birthDateString = userInfo.kakaoAccount.getBirthYear() + userInfo.kakaoAccount.getBirthDay(); | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); | ||
LocalDate birth = LocalDate.parse(birthDateString, formatter); | ||
|
||
char gender = Character.toUpperCase(userInfo.kakaoAccount.getGender().charAt(0)); | ||
|
||
UserJpaEntity user = UserJpaEntity.builder() | ||
.userId(userId) | ||
.email(userInfo.kakaoAccount.getEmail()) | ||
.password(null) | ||
.nickname(userInfo.kakaoAccount.profile.getNickName()) | ||
.profile(userInfo.kakaoAccount.profile.getProfileImageUrl()) | ||
.provider(Provider.KAKAO) | ||
.providerId(userInfo.getId().toString()) | ||
.role(UserRole.USER) | ||
.withdrawAt(null) | ||
.build(); | ||
|
||
UserIdentityJpaEntity userIdentity = UserIdentityJpaEntity.builder() | ||
.userId(userId) | ||
.name(userInfo.kakaoAccount.getName()) | ||
.phoneNumber(userInfo.kakaoAccount.getPhoneNumber().replace("+82 ", "0")) | ||
.birth(birth) | ||
.gender(gender) | ||
.build(); | ||
|
||
userRepository.save(user); | ||
userIdentityRepository.save(userIdentity); | ||
|
||
// UserAgreeHist 랑 UserDevice, UserLocation 은 별도로 추가해야됨 | ||
|
||
return jwtUtil.generateJwtDto(userId, UserRole.USER); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/site/billbill/apiserver/api/base/controller/BaseController.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,39 @@ | ||
package site.billbill.apiserver.api.base.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
import site.billbill.apiserver.api.auth.dto.request.SignupRequest; | ||
import site.billbill.apiserver.api.base.dto.request.ReportRequest; | ||
import site.billbill.apiserver.api.base.service.BaseService; | ||
import site.billbill.apiserver.common.enums.base.ReportType; | ||
import site.billbill.apiserver.common.response.BaseResponse; | ||
import site.billbill.apiserver.common.utils.jwt.dto.JwtDto; | ||
|
||
@Slf4j | ||
@RestController | ||
@Tag(name = "Base", description = "Base API") | ||
@RequestMapping("/api/v1/base") | ||
@RequiredArgsConstructor | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "400", description = "Server Error", content = @Content), | ||
@ApiResponse(responseCode = "404", description = "Server Error", content = @Content), | ||
@ApiResponse(responseCode = "500", description = "Server Error", content = @Content) | ||
}) | ||
public class BaseController { | ||
private final BaseService baseService; | ||
|
||
@Operation(summary = "신고하기", description = "신고하기 API") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
@PostMapping("/report/{type}") | ||
public BaseResponse<String> report(@PathVariable ReportType type, @RequestBody ReportRequest request) { | ||
baseService.report(type, request); | ||
return new BaseResponse<>(null); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/site/billbill/apiserver/api/base/dto/request/ReportRequest.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,15 @@ | ||
package site.billbill.apiserver.api.base.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Data; | ||
import site.billbill.apiserver.common.enums.base.ReportCode; | ||
|
||
@Data | ||
public class ReportRequest { | ||
@Schema(description = "신고할 유저 ID", example = "USER-XXXXX") | ||
private String userId; | ||
@Schema(description = "신고 사유 코드", example = "FRAUD / HARMFUL / DRUG / IMPOSTER / UNHEALTHY / ETC") | ||
private ReportCode reportCode; | ||
@Schema(description = "신고 상세 사유", example = "상세 설명") | ||
private String description; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/site/billbill/apiserver/api/base/service/BaseService.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 site.billbill.apiserver.api.base.service; | ||
|
||
import site.billbill.apiserver.api.base.dto.request.ReportRequest; | ||
import site.billbill.apiserver.common.enums.base.ReportType; | ||
|
||
public interface BaseService { | ||
void report(ReportType type, ReportRequest request); | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/site/billbill/apiserver/api/base/service/BaseServiceImpl.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,38 @@ | ||
package site.billbill.apiserver.api.base.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.slf4j.MDC; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import site.billbill.apiserver.api.base.dto.request.ReportRequest; | ||
import site.billbill.apiserver.common.enums.base.ReportStatus; | ||
import site.billbill.apiserver.common.enums.base.ReportType; | ||
import site.billbill.apiserver.common.utils.jwt.JWTUtil; | ||
import site.billbill.apiserver.model.report.ReportHistJpaEntity; | ||
import site.billbill.apiserver.repository.report.ReportHistRepository; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class BaseServiceImpl implements BaseService { | ||
private final ReportHistRepository reportHistRepository; | ||
|
||
@Override | ||
@Transactional | ||
public void report(ReportType type, ReportRequest request) { | ||
String currentUserId = MDC.get(JWTUtil.MDC_USER_ID); | ||
|
||
ReportHistJpaEntity reportHistJpaEntity = ReportHistJpaEntity.builder() | ||
.reportSeq(null) | ||
.reportType(type) | ||
.targetId(request.getUserId()) | ||
.reporterId(currentUserId) | ||
.reportCode(request.getReportCode()) | ||
.description(request.getDescription()) | ||
.reportStatus(ReportStatus.REPORTED) | ||
.build(); | ||
|
||
reportHistRepository.save(reportHistJpaEntity); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/site/billbill/apiserver/api/chat/controller/ChatController.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,52 @@ | ||
package site.billbill.apiserver.api.chat.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.jboss.logging.MDC; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import site.billbill.apiserver.api.chat.dto.request.ChatRequest; | ||
import site.billbill.apiserver.api.chat.dto.response.ChatResponse; | ||
import site.billbill.apiserver.api.chat.service.ChatService; | ||
import site.billbill.apiserver.common.response.BaseResponse; | ||
import site.billbill.apiserver.common.utils.jwt.JWTUtil; | ||
|
||
@Slf4j | ||
@RestController | ||
@Tag(name = "Chat", description = "Chat API") | ||
@RequestMapping("/api/v1/chat") | ||
@RequiredArgsConstructor | ||
public class ChatController { | ||
private final ChatService chatService; | ||
|
||
@Operation(summary = "채팅방 나가기", description = "채팅방 나가기 API") | ||
@PatchMapping("/{channelId}") | ||
public BaseResponse<String> leaveChatChannel(@PathVariable(value = "channelId") String channelId) { | ||
log.info("api 호출 정상적~"); | ||
String userId = MDC.get(JWTUtil.MDC_USER_ID).toString(); | ||
return new BaseResponse<>(chatService.leaveChatChannel(channelId,userId)); | ||
} | ||
|
||
@Operation(summary = "채팅방 생성 및 id 조회", description = "빌리기 버튼 누를 때 api") | ||
@PostMapping("") | ||
public BaseResponse<String> startChannel(@RequestBody ChatRequest.borrowInfo request) { | ||
log.info("api 호출 정상적~"); | ||
String userId = MDC.get(JWTUtil.MDC_USER_ID).toString(); | ||
return new BaseResponse<>(chatService.startChannel(request, userId)); | ||
} | ||
|
||
@Operation(summary = "채팅방 info 조회", description = "채팅방 info 조회 API") | ||
@GetMapping("/{channelId}") | ||
public BaseResponse<ChatResponse.ViewChannelInfoResponse> getInfoChannel(@PathVariable(value = "channelId") String channelId) { | ||
log.info("api 호출 정상적~"); | ||
String userId = MDC.get(JWTUtil.MDC_USER_ID).toString(); | ||
return new BaseResponse<>(chatService.getInfoChannel(channelId,userId)); | ||
} | ||
} |
Oops, something went wrong.