Skip to content

Commit

Permalink
Merge pull request #40 from HanaFun/dev
Browse files Browse the repository at this point in the history
build: 배포 확인
  • Loading branch information
yubin-im authored Jul 2, 2024
2 parents 5ab7a2d + 4e9a170 commit d216173
Show file tree
Hide file tree
Showing 116 changed files with 3,465 additions and 28 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CD with Gradle

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: make application yml
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml
shell: bash

- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew clean build -x test
- name: Docker build & push to docker repo
run: |
docker login -u ${{ secrets.DOCKER_USERNAME_YUB }} -p ${{ secrets.DOCKER_PASSWORD_YUB }}
docker build -f Dockerfile -t "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest" .
docker push "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest"
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ec2-user
key: ${{ secrets.EC2_SSH_KEY }}
script: |
sudo docker ps
sudo docker pull "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest"
sudo docker stop hanafun
sudo docker rm hanafun
sudo docker run -d -p 8080:8080 --name hanafun "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest"
sudo docker image prune -f
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM openjdk:17-jdk
LABEL maintainer="yubin"
ARG JAR_FILE=build/libs/*.jar
ADD ${JAR_FILE} app.jar
EXPOSE 8099
ENTRYPOINT ["java","-jar","/app.jar"]
20 changes: 18 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,33 @@ repositories {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
//Jwt
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.2'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2'

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// Spring Security
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// AWS S3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
}

tasks.named('test') {
useJUnitPlatform()
}

bootJar {
duplicatesStrategy = 'exclude'
}

jar { enabled = false }
4 changes: 4 additions & 0 deletions src/main/java/com/hanaro/hanafun/HanafunApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

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

@SpringBootApplication
@EnableJpaAuditing
@EnableScheduling
public class HanafunApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.hanaro.hanafun.account.controller;

import com.hanaro.hanafun.account.dto.AccountResDto;
import com.hanaro.hanafun.account.service.impl.AccountServiceImpl;
import com.hanaro.hanafun.common.dto.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/account")
@RequiredArgsConstructor
public class AccountController {
private final AccountServiceImpl accountService;

@GetMapping("/list")
ResponseEntity<ApiResponse> readAccountList(@AuthenticationPrincipal Long userId){
List<AccountResDto> accountResDtoList = accountService.readAccountList(userId);
return ResponseEntity.ok(new ApiResponse(true, "ok", accountResDtoList));
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.hanaro.hanafun.account.domain;

import com.hanaro.hanafun.common.domain.BaseEntity;
import com.hanaro.hanafun.user.domain.UserEntity;
import jakarta.persistence.*;
import lombok.*;

@Entity
@Table(name = "account")
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AccountEntity extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "account_id")
private Long accountId;

@ManyToOne(optional = false)
@JoinColumn(name = "user_id", nullable = false)
private UserEntity userEntity;

@Column(name = "account_number", length = 20, nullable = false)
private String accountNumber;

@Column(name = "account_name", length = 50)
private String accountName;

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

@Column(name = "balance", nullable = false)
private Integer balance;

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

@Column(name = "is_deleted", nullable = false)
private Boolean isDeleted;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hanaro.hanafun.account.domain;

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface AccountRepository extends JpaRepository<AccountEntity, Long> {
Optional<List<AccountEntity>> findByUserEntityUserId(Long userId);
}
17 changes: 17 additions & 0 deletions src/main/java/com/hanaro/hanafun/account/dto/AccountResDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.hanaro.hanafun.account.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AccountResDto {
private long accountId;
private String accountName;
private String accountNumber;
private int balance;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hanaro.hanafun.account.exception;

import com.hanaro.hanafun.common.exception.CustomException;
import org.springframework.http.HttpStatus;

public class AccountBalanceException extends CustomException {
static String MESSAGE = "INSUFFICIENT_BALANCE";
public AccountBalanceException(){
super(MESSAGE);
}
@Override
public HttpStatus getHttpStatus() {
return HttpStatus.BAD_REQUEST;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.hanaro.hanafun.account.exception;

import com.hanaro.hanafun.common.exception.CustomException;
import org.springframework.http.HttpStatus;

public class AccountNotFoundException extends CustomException {
static String MESSAGE = "ACCOUNT_NOT_FOUND";

public AccountNotFoundException(){
super(MESSAGE);
}
@Override
public HttpStatus getHttpStatus() {
return HttpStatus.NOT_FOUND;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/hanaro/hanafun/account/mapper/AccountMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.hanaro.hanafun.account.mapper;

import com.hanaro.hanafun.account.domain.AccountEntity;
import com.hanaro.hanafun.account.dto.AccountResDto;
import lombok.experimental.UtilityClass;

@UtilityClass
public class AccountMapper {
public static AccountResDto entityToAccountResDto(AccountEntity accountEntity){
if(accountEntity == null) return null;

return AccountResDto.builder()
.accountId(accountEntity.getAccountId())
.accountNumber(accountEntity.getAccountNumber())
.accountName(accountEntity.getAccountName())
.balance(accountEntity.getBalance())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.hanaro.hanafun.account.service;

import com.hanaro.hanafun.account.dto.AccountResDto;

import java.util.List;

public interface AccountService {
List<AccountResDto> readAccountList(Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.hanaro.hanafun.account.service.impl;

import com.hanaro.hanafun.account.domain.AccountEntity;
import com.hanaro.hanafun.account.domain.AccountRepository;
import com.hanaro.hanafun.account.dto.AccountResDto;
import com.hanaro.hanafun.account.exception.AccountNotFoundException;
import com.hanaro.hanafun.account.mapper.AccountMapper;
import com.hanaro.hanafun.account.service.AccountService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class AccountServiceImpl implements AccountService {
private final AccountRepository accountRepository;

@Override
public List<AccountResDto> readAccountList(Long userId) {
List<AccountEntity> accountEntityList = accountRepository.findByUserEntityUserId(userId).orElseThrow(() -> new AccountNotFoundException());
if(accountEntityList.isEmpty()){
throw new AccountNotFoundException();
}

return accountEntityList.stream().map(AccountMapper::entityToAccountResDto).toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.hanaro.hanafun.category.controller;

import com.hanaro.hanafun.category.dto.response.CategoryResDto;
import com.hanaro.hanafun.category.service.CategoryService;
import com.hanaro.hanafun.common.dto.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class CategoryController {
private final CategoryService categoryService;

@GetMapping("/category")
public ResponseEntity<ApiResponse> categoryList() {
List<CategoryResDto> categoryResDtoList = categoryService.categoryList();
return ResponseEntity.ok(new ApiResponse<>(true, "ok", categoryResDtoList));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hanaro.hanafun.category.domain;

import com.hanaro.hanafun.common.domain.BaseEntity;
import jakarta.persistence.*;
import lombok.*;

@Entity
@Table(name = "category")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Builder
@AllArgsConstructor
public class CategoryEntity extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long categoryId;

@Column(nullable = false)
private String categoryName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.hanaro.hanafun.category.domain;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CategoryRepository extends JpaRepository<CategoryEntity, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hanaro.hanafun.category.dto.response;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class CategoryResDto {
private Long categoryId;
private String categoryName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.hanaro.hanafun.category.exception;

import com.hanaro.hanafun.common.exception.CustomException;
import org.springframework.http.HttpStatus;

public class CategoryNotFoundException extends CustomException {
static String MESSAGE = "CATEGORY_NOT_FOUND";

public CategoryNotFoundException() {
super(MESSAGE);
}

@Override
public HttpStatus getHttpStatus() {
return HttpStatus.NOT_FOUND;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.hanaro.hanafun.category.service;

import com.hanaro.hanafun.category.dto.response.CategoryResDto;

import java.util.List;

public interface CategoryService {
List<CategoryResDto> categoryList();
}
Loading

0 comments on commit d216173

Please sign in to comment.