Skip to content

Commit

Permalink
Merge pull request #65 from Gamegoo-repo/feat/41
Browse files Browse the repository at this point in the history
[Feat/41] Riot API 개발
  • Loading branch information
rimi3226 authored Jul 15, 2024
2 parents 7c49146 + 4be3ce8 commit 2a0fb52
Show file tree
Hide file tree
Showing 38 changed files with 12,373 additions and 255 deletions.
59 changes: 37 additions & 22 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ name: Java CICD with Gradle & Docker
on:
pull_request:
types: [ closed ]
push:
workflow_dispatch: # 수동 실행 가능

jobs:
build-and-push-image:
build:
runs-on: ubuntu-latest

steps:
# JDK 17 설치 (1)
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# repository checkout (2)
- name: Checkout
uses: actions/checkout@v3

# 환경 변수 설정 (0)
# 환경 변수 설정 (3)
- name: Set Yaml
uses: microsoft/variable-substitution@v1
with:
Expand All @@ -30,46 +33,58 @@ jobs:
spring.jwt.secret: ${{ secrets.JWT_SECRET }}
spring.mail.password: ${{ secrets.GMAIL_PWD }}

# Spring Boot 어플리케이션 Build (1)
# Spring Boot 어플리케이션 Build (4)
- name: Spring Boot Build
run: ./gradlew clean build -x test --warning-mode=all --stacktrace

# Docker 이미지 Build (2)
# Docker 이미지 Build (5)
- name: docker image build
run: docker build -t rimi3226/gamegoo .

# DockerHub Login (3)
# DockerHub Login (6)
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PW }}

# Docker Hub push (4)
# Docker Hub push (7)
- name: docker Hub push
run: docker push rimi3226/gamegoo

# Configure AWS Credentials (6) - AWS 접근 권한 취득(IAM)
# GET GitHub IP (8)
- name: get GitHub IP
id: ip
run: echo "ipv4=$(curl -s https://api.ipify.org)" >> $GITHUB_ENV

# Configure AWS Credentials (9) - AWS 접근 권한 취득(IAM)
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2

# Build 번호 부여 (7)
- name: Build Number
id: build-number
run: echo "::set-output name=BUILD_NUMBER::$(date '+%-d.%-m.%Y.%-H.%-M.%-S')"
# Add github ip to AWS (10)
- name: Add GitHub IP to AWS
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ env.ipv4 }}/32
# Elastic Beanstalk Deploy with docker (8)
- name: Deploy to EB
uses: einaregilsson/beanstalk-deploy@v20
# AWS EC2 Server Connect & Docker 명령어 실행 (11)
- name: AWS EC2 Connection
uses: appleboy/ssh-action@master
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: Gamegoo
environment_name: Gamegoo-env
region: ap-northeast-2
version_label: ${{ steps.build-number.outputs.BUILD_NUMBER }}
deployment_package: ./elasticbeanstalk/docker-compose.yml
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PEM_KEY }}
port: ${{ secrets.EC2_SSH_PORT }}
timeout: 50s
script: |
sudo docker stop gamegoo_api
sudo docker rm gamegoo_api
sudo docker run -it -d -p 8080:8080 --name gamegoo_api rimi3226/gamegoo
# REMOVE Github IP FROM security group (12)
- name: Remove IP FROM security group
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ env.ipv4 }}/32
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public enum ErrorStatus implements BaseErrorCode {
EMAIL_NOT_FOUND(HttpStatus.NOT_FOUND, "EMAIL404", "해당 이메일을 찾을 수 없습니다."),
EMAIL_INVALID(HttpStatus.BAD_REQUEST, "EMAIL400", "인증 코드가 불일치합니다."),

// Riot 관련 에러
RIOT_NOT_FOUND(HttpStatus.NOT_FOUND, "RIOT404", "해당 Riot 계정이 존재하지 않습니다."),
CHAMPION_NOT_FOUND(HttpStatus.NOT_FOUND, "CHAMPION404", "해당 챔피언이 존재하지 않습니다"),
// 차단 관련 에러
TARGET_MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "BLOCK401", "차단 대상 회원을 찾을 수 없습니다."),
ALREADY_BLOCKED(HttpStatus.BAD_REQUEST, "BLOCK402", "이미 차단한 회원입니다."),
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/gamegoo/config/AppConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.gamegoo.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.web.client.RestTemplate;

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class AppConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
5 changes: 3 additions & 2 deletions src/main/java/com/gamegoo/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public AuthenticationManager authenticationManager(AuthenticationConfiguration c

@Bean
public JWTFilter jwtFilter() {
List<String> excludedPaths = Arrays.asList("/swagger-ui/", "/v3/api-docs", "/api/member/join", "/api/member/login", "/api/member/email", "/api/member/refresh");
List<String> excludedPaths = Arrays.asList("/swagger-ui/", "/v3/api-docs", "/api/member/join", "/api/member/login", "/api/member/email", "/api/member/refresh", "/api/member/riot");
return new JWTFilter(jwtUtil, excludedPaths, customUserDetailService);

}
Expand All @@ -57,7 +57,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.httpBasic(AbstractHttpConfigurer::disable)

.authorizeHttpRequests((auth) -> auth
.antMatchers("/", "/api/member/join", "/api/member/login", "/api/member/email/**", "/api/member/refresh").permitAll()
.antMatchers("/", "/api/member/join", "/api/member/login", "/api/member/email/**", "/api/member/refresh", "/api/member/riot").permitAll()

.antMatchers("/", "/swagger-ui/**", "/v3/api-docs/**").permitAll()
.anyRequest().authenticated())
.addFilterBefore(new JWTExceptionHandlerFilter(), UsernamePasswordAuthenticationFilter.class)
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/com/gamegoo/controller/member/AuthController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.gamegoo.controller.member;

import com.gamegoo.apiPayload.ApiResponse;
import com.gamegoo.dto.member.*;
import com.gamegoo.dto.member.MemberRequest;
import com.gamegoo.service.member.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
Expand All @@ -20,22 +20,24 @@ public class AuthController {

@PostMapping("/join")
@Operation(summary = "회원가입 API 입니다.", description = "API for join")
public ApiResponse<Object> joinMember(@RequestBody JoinRequestDTO joinRequestDTO) {
authService.joinMember(joinRequestDTO);
public ApiResponse<String> joinMember(@RequestBody MemberRequest.JoinRequestDTO joinRequestDTO) {
String email = joinRequestDTO.getEmail();
String password = joinRequestDTO.getPassword();
authService.joinMember(email, password);
return ApiResponse.onSuccess("회원가입에 성공했습니다.");
}

@PostMapping("/email/send")
@Operation(summary = "이메일 인증코드 전송 API 입니다.", description = "API for sending email")
public ApiResponse<Object> sendEmail(@RequestBody EmailRequestDTO emailRequestDTO) {
public ApiResponse<String> sendEmail(@RequestBody MemberRequest.EmailRequestDTO emailRequestDTO) {
String email = emailRequestDTO.getEmail();
authService.sendEmail(email);
return ApiResponse.onSuccess("인증 이메일을 발송했습니다.");
}

@PostMapping("/email/verify")
@Operation(summary = "이메일 인증코드 검증 API 입니다.", description = "API for email verification")
public ApiResponse<Object> verifyEmail(@RequestBody EmailCodeRequestDTO emailCodeRequestDTO) {
public ApiResponse<String> verifyEmail(@RequestBody MemberRequest.EmailCodeRequestDTO emailCodeRequestDTO) {
String email = emailCodeRequestDTO.getEmail();
String code = emailCodeRequestDTO.getCode();
authService.verifyEmail(email, code);
Expand All @@ -44,11 +46,11 @@ public ApiResponse<Object> verifyEmail(@RequestBody EmailCodeRequestDTO emailCod

@PostMapping("/refresh")
@Operation(summary = "refresh token을 통한 access, refresh token 재발급 API 입니다.", description = "API for Refresh Token")
public ApiResponse<Object> refreshTokens(@RequestBody RefreshTokenRequestDTO refreshTokenRequestDTO) {
public ApiResponse<Object> refreshTokens(@RequestBody MemberRequest.RefreshTokenRequestDTO refreshTokenRequestDTO) {

String refreshToken = refreshTokenRequestDTO.getRefresh_token();

RefreshTokenResponseDTO refreshTokenResponseDTO = authService.verifyRefreshToken(refreshToken);
MemberRequest.RefreshTokenResponseDTO refreshTokenResponseDTO = authService.verifyRefreshToken(refreshToken);

return ApiResponse.onSuccess(refreshTokenResponseDTO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.gamegoo.apiPayload.ApiResponse;
import com.gamegoo.apiPayload.code.status.ErrorStatus;
import com.gamegoo.apiPayload.exception.handler.MemberHandler;
import com.gamegoo.dto.member.PasswordRequestDTO;
import com.gamegoo.dto.member.MemberRequest;
import com.gamegoo.service.member.PasswordService;
import com.gamegoo.util.JWTUtil;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -23,7 +23,7 @@ public class PasswordController {

@PostMapping("/check")
@Operation(summary = "비밀번호 확인 API 입니다.", description = "API for checking password")
public ApiResponse<Object> checkPassword(@RequestBody PasswordRequestDTO passwordRequestDTO) {
public ApiResponse<String> checkPassword(@RequestBody MemberRequest.PasswordRequestDTO passwordRequestDTO) {
Long currentUserId = JWTUtil.getCurrentUserId(); //헤더에 있는 jwt 토큰에서 id를 가져오는 코드

boolean isPasswordValid = passwordService.checkPasswordById(currentUserId, passwordRequestDTO.getPassword()); //request body에 있는 password와 currentUserId를 전달
Expand All @@ -37,7 +37,7 @@ public ApiResponse<Object> checkPassword(@RequestBody PasswordRequestDTO passwor

@PostMapping("/reset")
@Operation(summary = "비밀번호 재설정 API 입니다.", description = "API for reseting password")
public ApiResponse<Object> resetPassword(@RequestBody PasswordRequestDTO passwordRequestDTO) {
public ApiResponse<String> resetPassword(@RequestBody MemberRequest.PasswordRequestDTO passwordRequestDTO) {
Long currentUserId = JWTUtil.getCurrentUserId();

passwordService.updatePassword(currentUserId, passwordRequestDTO.getPassword());
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/com/gamegoo/controller/member/ProfileController.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.gamegoo.controller.member;

import com.gamegoo.apiPayload.ApiResponse;
import com.gamegoo.dto.member.GameStyleRequestDTO;
import com.gamegoo.dto.member.PositionRequestDTO;
import com.gamegoo.dto.member.ProfileImageRequestDTO;
import com.gamegoo.domain.gamestyle.MemberGameStyle;
import com.gamegoo.dto.member.MemberRequest;
import com.gamegoo.dto.member.MemberResponse;
import com.gamegoo.service.member.ProfileService;
import com.gamegoo.util.JWTUtil;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequiredArgsConstructor
Expand All @@ -22,18 +24,21 @@ public class ProfileController {

@PutMapping("/gamestyle")
@Operation(summary = "gamestyle 추가 및 수정 API 입니다.", description = "API for Gamestyle addition and modification ")
public ApiResponse<Object> addGameStyle(@RequestBody GameStyleRequestDTO gameStyleRequestDTO) {
Long userId = JWTUtil.getCurrentUserId();
List<String> gamestylelist = gameStyleRequestDTO.getGamestyle();
public ApiResponse<List<MemberResponse.GameStyleResponseDTO>> addGameStyle(@RequestBody MemberRequest.GameStyleRequestDTO gameStyleRequestDTO) {
Long memberId = JWTUtil.getCurrentUserId();

profileService.addMemberGameStyles(userId, gamestylelist);
List<MemberGameStyle> memberGameStyles = profileService.addMemberGameStyles(gameStyleRequestDTO, memberId);
List<MemberResponse.GameStyleResponseDTO> dtoList = memberGameStyles.stream().map(memberGameStyle -> MemberResponse.GameStyleResponseDTO.builder()
.gameStyleId(memberGameStyle.getGameStyle().getId())
.gameStyleName(memberGameStyle.getGameStyle().getStyleName())
.build()).collect(Collectors.toList());

return ApiResponse.onSuccess("게임 스타일 수정이 완료되었습니다.");
return ApiResponse.onSuccess(dtoList);
}

@PutMapping("/position")
@Operation(summary = "주/부 포지션 수정 API 입니다.", description = "API for Main/Sub Position Modification")
public ApiResponse<Object> modifyPosition(@RequestBody PositionRequestDTO positionRequestDTO) {
public ApiResponse<String> modifyPosition(@RequestBody @Valid MemberRequest.PositionRequestDTO positionRequestDTO) {
Long userId = JWTUtil.getCurrentUserId();
int mainP = positionRequestDTO.getMainP();
int subP = positionRequestDTO.getSubP();
Expand All @@ -45,7 +50,7 @@ public ApiResponse<Object> modifyPosition(@RequestBody PositionRequestDTO positi

@PutMapping("/profile_image")
@Operation(summary = "프로필 이미지 수정 API 입니다.", description = "API for Profile Image Modification")
public ApiResponse<Object> modifyPosition(@RequestBody ProfileImageRequestDTO profileImageDTO) {
public ApiResponse<String> modifyPosition(@RequestBody MemberRequest.ProfileImageRequestDTO profileImageDTO) {
Long userId = JWTUtil.getCurrentUserId();
String profileImage = profileImageDTO.getProfile_image();

Expand All @@ -56,7 +61,7 @@ public ApiResponse<Object> modifyPosition(@RequestBody ProfileImageRequestDTO pr

@DeleteMapping("")
@Operation(summary = "회원 탈퇴 API 입니다.", description = "API for Member")
public ApiResponse<Object> blindMember() {
public ApiResponse<String> blindMember() {
Long userId = JWTUtil.getCurrentUserId();

profileService.deleteMember(userId);
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/gamegoo/controller/member/RiotController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.gamegoo.controller.member;

import com.gamegoo.apiPayload.ApiResponse;
import com.gamegoo.dto.member.MemberRequest;
import com.gamegoo.service.member.RiotService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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 javax.validation.Valid;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/member")
@Slf4j
public class RiotController {
private final RiotService riotService;

@PostMapping("/riot")
@Operation(summary = "회원가입 시 riot API를 통해 소환사명을 인증하는 API", description = "API for verifying by riot API")
public ApiResponse<String> VerifyRiot(@RequestBody @Valid MemberRequest.verifyRiotRequestDTO verifyRiotRequestDTO) {
String gameName = verifyRiotRequestDTO.getGame_name();
String tag = verifyRiotRequestDTO.getTag();
String email = verifyRiotRequestDTO.getEmail();

riotService.updateMemberRiotInfo(gameName, tag, email);

return ApiResponse.onSuccess("Riot 계정이 연동되었습니다.");

}
}
5 changes: 4 additions & 1 deletion src/main/java/com/gamegoo/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public class Member extends BaseDateTimeEntity {
private String gameuserName;

@Column(name = "tier")
private Integer tier;
private String tier;

@Column(name = "rank")
private String rank;

@Column(name = "winrate")
private double winRate;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/gamegoo/domain/champion/Champion.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "Champion")
@Getter
@Setter
public class Champion {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "champion_id", nullable = false)
@Column(name = "id", nullable = false)
private Long id;

@Column(name = "champion_name", nullable = false, length = 30)
private String champion_name;

@Column(name = "name", nullable = false, length = 30)
private String name;

}
Loading

0 comments on commit 2a0fb52

Please sign in to comment.