Skip to content

Commit

Permalink
Merge pull request #26 from pandahwang/dev
Browse files Browse the repository at this point in the history
구현 완료 버전 master 브랜치에 적용
  • Loading branch information
pandahwang authored Oct 15, 2024
2 parents 9714b24 + e5663aa commit dd3fdea
Show file tree
Hide file tree
Showing 40 changed files with 1,510 additions and 24 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Deploy To EC2

on:
push:
branches:
- master

jobs:
Deploy:
runs-on: ubuntu-latest
steps:
- name: SSH(원격 접속)로 EC2에 접속하기
uses: appleboy/[email protected]
env:
APPLICATION_PROPERTIES: ${{ secrets.APPLICATION_PROPERTIES }}
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
envs: APPLICATION_PROPERTIES
script_stop: true
script: |
cd /home/ubuntu/LostArk
rm -rf src/main/resources/application.properties
git pull origin master
echo "$APPLICATION_PROPERTIES" > src/main/resources/application.properties
./gradlew clean build
docker compose -f compose-prod.yml down
docker compose -f compose-prod.yml up --build -d
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:17-jdk

COPY build/libs/*SNAPSHOT.jar app.jar

ENTRYPOINT ["java", "-jar", "/app.jar"]
5 changes: 5 additions & 0 deletions Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:17-jdk

COPY build/libs/*SNAPSHOT.jar app.jar

ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=prod", "/app.jar"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
로스트아크 직업 추천 팀 프로제트
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ dependencies {
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation("com.googlecode.json-simple:json-simple:1.1.1")
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
}

tasks.named('test') {
Expand Down
19 changes: 19 additions & 0 deletions compose-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
api-server:
build:
context: .
dockerfile: ./Dockerfile-prod
ports:
- 8080:8080
depends_on:
cache-server:
condition: service_healthy
cache-server:
image: redis
command: redis-server --maxmemory 512mb --maxmemory-policy allkeys-lru
ports:
- 6379:6379
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 5s
retries: 10
16 changes: 16 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
api-server:
build: .
ports:
- 8080:8080
depends_on:
cache-server:
condition: service_healthy
cache-server:
image: redis
ports:
- 6379:6379
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 5s
retries: 10
41 changes: 41 additions & 0 deletions src/main/java/com/TeamNull/LostArk/LostArk/Job/JobAttributes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.TeamNull.LostArk.LostArk.Job;


import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

@Getter
@Setter
public class JobAttributes {
private final String jobName;
private final int Agreeableness;
private final int conscientiousness;
private final int extraversion;
private final int openness;
private final int neuroticism;
private final String color;
private final String icon;

@JsonCreator
public JobAttributes(
@JsonProperty("jobName") String jobName,
@JsonProperty("Agreeableness") int Agreeableness,
@JsonProperty("conscientiousness") int conscientiousness,
@JsonProperty("extraversion") int extraversion,
@JsonProperty("openness") int openness,
@JsonProperty("neuroticism") int neuroticism,
@JsonProperty("color") String color,
@JsonProperty("icon") String icon) {
this.jobName = jobName;
this.Agreeableness = Agreeableness;
this.conscientiousness = conscientiousness;
this.extraversion = extraversion;
this.openness = openness;
this.neuroticism = neuroticism;
this.color = color;
this.icon = icon;
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/TeamNull/LostArk/LostArk/Job/TopFactor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.TeamNull.LostArk.LostArk.Job;

import jakarta.persistence.Embeddable;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Embeddable
public class TopFactor {
private String jobName;
private double value;

public TopFactor(String jobName, double value) {
this.jobName = jobName;
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.TeamNull.LostArk.LostArk.Job;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter
public class TopFactorConverter implements AttributeConverter<TopFactor, String> {

@Override
public String convertToDatabaseColumn(TopFactor topFactor) {
// 예: "jobName:value" 형식으로 직렬화
return topFactor.getJobName() + ":" + topFactor.getValue();
}

@Override
public TopFactor convertToEntityAttribute(String dbData) {
// 역직렬화: "jobName:value" 형식을 객체로 변환
String[] data = dbData.split(":");
return new TopFactor(data[0], Double.parseDouble(data[1]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
public class LostArkApplication {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.TeamNull.LostArk.LostArk.config;

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;

@Configuration
@EnableCaching // Spring Boot의 캐싱 설정을 활성화
public class RedisCacheConfig {
@Bean
public CacheManager commentCacheManager(RedisConnectionFactory redisConnectionFactory) {
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration
.defaultCacheConfig()
// Redis에 Key를 저장할 때 String으로 직렬화(변환)해서 저장
.serializeKeysWith(
RedisSerializationContext.SerializationPair.fromSerializer(
new StringRedisSerializer()))
// Redis에 Value를 저장할 때 Json으로 직렬화(변환)해서 저장
.serializeValuesWith(
RedisSerializationContext.SerializationPair.fromSerializer(
new Jackson2JsonRedisSerializer<Object>(Object.class)
)
)
// 데이터의 만료기간(TTL) 설정
.entryTtl(Duration.ofMinutes(1L));

return RedisCacheManager
.RedisCacheManagerBuilder
.fromConnectionFactory(redisConnectionFactory)
.cacheDefaults(redisCacheConfiguration)
.build();
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/TeamNull/LostArk/LostArk/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.TeamNull.LostArk.LostArk.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;

@Configuration
public class RedisConfig {
@Value("${spring.data.redis.host}")
private String host;

@Value("${spring.data.redis.port}")
private int port;

@Bean
public LettuceConnectionFactory redisConnectionFactory() {
// Lettuce라는 라이브러리를 활용해 Redis 연결을 관리하는 객체를 생성하고
// Redis 서버에 대한 정보(host, port)를 설정한다.
return new LettuceConnectionFactory(new RedisStandaloneConfiguration(host, port));
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/TeamNull/LostArk/LostArk/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.TeamNull.LostArk.LostArk.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(
"http://localhost:3000",
"http://52.79.232.220:3000",
"http://classtest.site",
"http://la.classtest.site",
"https://classtest.site",
"https://la.classtest.site"
)
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*")
.allowCredentials(true);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,66 @@
package com.TeamNull.LostArk.LostArk.controller;

import com.TeamNull.LostArk.LostArk.dto.CommentDto;
import com.TeamNull.LostArk.LostArk.service.CommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


import java.util.*;


@RestController
@RequestMapping("/api/comment")
@RequiredArgsConstructor
public class CommentController {

private final CommentService commentService;

@Cacheable(cacheNames = "getComments", key = "'comments:page:' + #page + ':searchText:' + #searchText", cacheManager = "commentCacheManager")
@GetMapping("/{page}")
public Map<String, Object> commentPage(@PathVariable Integer page,
@RequestParam(required = false) String searchText,
@PageableDefault(size = 5, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) {
return commentService.getComments(page, searchText, pageable);
}


@PostMapping("/{userID}")
@CacheEvict(cacheNames = "getComments", allEntries = true, cacheManager = "commentCacheManager")
public void addComment(@PathVariable("userID") UUID userID, @RequestBody CommentDto commentDto)
{
commentService.getAddComment(commentDto.getContent(),
commentDto.getPassword(),
commentDto.getNickname(),
userID
);
}

@DeleteMapping("/delete/{userID}/{commentId}")
@CacheEvict(cacheNames = "getComments", allEntries = true, cacheManager = "commentCacheManager")
public ResponseEntity<String> commentDelete(@PathVariable("userID") UUID userID,
@PathVariable Integer commentId,
@RequestBody CommentDto dropComment)
{
return commentService.getCommentDelete(userID,commentId,dropComment.getPassword());
}

@PutMapping("/update/{userID}/{commentId}")
@CacheEvict(cacheNames = "getComments", allEntries = true, cacheManager = "commentCacheManager")
public ResponseEntity<String> commentUpdate(@PathVariable("userID") UUID userID,
@PathVariable int commentId,
@RequestBody CommentDto updatedComment) {
return commentService.getCommentUpdate(userID, commentId, updatedComment.getPassword(), updatedComment.getContent());
}

}




Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
package com.TeamNull.LostArk.LostArk.controller;

import com.TeamNull.LostArk.LostArk.dto.DataDto;
import com.TeamNull.LostArk.LostArk.service.DataService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class DataController {

private final DataService dataService;

@GetMapping("/statistics/data")

public List<DataDto> read () {
List<DataDto> resData = null;
try {
resData = dataService.read();
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
return resData;
}
}
Loading

0 comments on commit dd3fdea

Please sign in to comment.