Skip to content

Commit

Permalink
Merge pull request #106 from mju-likelion/develop
Browse files Browse the repository at this point in the history
변경사항 적용 후 재배포
  • Loading branch information
jher235 authored Aug 5, 2024
2 parents c34eab4 + 2a96cf8 commit 5f6b600
Show file tree
Hide file tree
Showing 20 changed files with 182 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ jobs: # 실행할 작업들에 대한 설정
sudo docker pull ${{secrets.DOCKERHUB_USERNAME}}/${{secrets.DOCKERHUB_IMAGE}}
sudo docker ps -q | xargs -r sudo docker stop
sudo docker ps -aq | xargs -r sudo docker rm
sudo docker run --name redis --rm -d -p 6379:6379 redis
sudo docker run --name ${{secrets.DOCKERHUB_IMAGE}} --rm -d -p 8080:8080 ${{secrets.DOCKERHUB_USERNAME}}/${{secrets.DOCKERHUB_IMAGE}}
sudo docker run --name redis --rm -d -p 6379:6379 --net my-network redis
sudo docker run --name ${{secrets.DOCKERHUB_IMAGE}} --rm -d --net my-network -p 8080:8080 ${{secrets.DOCKERHUB_USERNAME}}/${{secrets.DOCKERHUB_IMAGE}}
sudo docker system prune -f
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'//AWS

implementation 'org.springframework.boot:spring-boot-starter-data-redis'//Redis

implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' //localDateTime json변환을 위함.
implementation 'com.fasterxml.jackson.core:jackson-databind'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
@EnableCaching
public class RefreshratorApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.hackathonteam1.refreshrator.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.context.annotation.Primary;
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.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisKeyValueAdapter;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;

@Configuration
public class RedisConfig {

Expand All @@ -25,8 +29,27 @@ public RedisConfig(@Value("${spring.data.redis.host}") String redisHost,
}

@Bean
public CacheManager redisCacheManager(){
RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig() //Redis 캐시 설정을 정의하기 위한 클래스, 기본 캐시 구성 가져옴.
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) //key를 String으로 직렬화
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())) //value를 json으로 직렬화
.entryTtl(Duration.ofMinutes(15L)); //캐시에 15분 저장

return RedisCacheManager.RedisCacheManagerBuilder
.fromConnectionFactory(redisConnectionFactoryForDb1()) //redis db1로 연결
.cacheDefaults(configuration)
.build();
}

@Bean
@Primary
public RedisConnectionFactory redisConnectionFactory(){
return new LettuceConnectionFactory(redisHost, redisPort);
return createLettuceConnectionFactory(0);
}

@Bean
public RedisConnectionFactory redisConnectionFactoryForDb1(){
return createLettuceConnectionFactory(1);
}

@Bean
Expand All @@ -39,4 +62,10 @@ public <K, V> RedisTemplate<K, V> redisTemplate(RedisConnectionFactory redisConn
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); //Hash의 value를 json으로 시리얼라이즈
return redisTemplate;
}
}

private LettuceConnectionFactory createLettuceConnectionFactory(int database){
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(redisHost, redisPort);
lettuceConnectionFactory.setDatabase(database);
return lettuceConnectionFactory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.UUID;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class AddFridgeDto {

//재료
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class PaginationDto {
private int currentPage;
private int totalPage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.hackathonteam1.refreshrator.dto.response.file;

import com.hackathonteam1.refreshrator.entity.Image;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.*;

import java.util.UUID;

@Getter
@Builder
@AllArgsConstructor
@Setter
@NoArgsConstructor
public class ImageDto {

private UUID id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
package com.hackathonteam1.refreshrator.dto.response.fridge;

import lombok.Builder;
import lombok.Getter;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;

import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import lombok.*;

import java.time.LocalDate;
import java.util.UUID;

@Builder
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class FridgeItemDto {
private UUID id;
private String ingredientName;
private UUID ingredientId;
@JsonSerialize(using = LocalDateSerializer.class)
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate expirationDate;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.hackathonteam1.refreshrator.dto.response.fridge;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.*;

import java.util.List;

@Getter
@Builder
@AllArgsConstructor
@Setter
@NoArgsConstructor
public class FridgeItemListDto {
private List<FridgeItemDto> coldStorage; // 냉장
private List<FridgeItemDto> frozen; // 냉동
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.hackathonteam1.refreshrator.dto.response.ingredient;

import com.hackathonteam1.refreshrator.entity.Ingredient;
import lombok.Builder;
import lombok.Getter;
import lombok.*;

import java.util.UUID;

@Builder
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class IngredientDto {

private UUID id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.hackathonteam1.refreshrator.dto.response.ingredient;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.*;

import java.util.List;

@Getter
@Builder
@AllArgsConstructor
@Setter
@NoArgsConstructor
public class IngredientListDto {
private List<IngredientDto> ingredients;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.hackathonteam1.refreshrator.dto.response.recipe;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.hackathonteam1.refreshrator.dto.response.file.ImageDto;
import com.hackathonteam1.refreshrator.entity.Image;
import com.hackathonteam1.refreshrator.entity.IngredientRecipe;
import com.hackathonteam1.refreshrator.entity.Recipe;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.*;

import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -16,20 +19,29 @@
@Getter
@Builder
@AllArgsConstructor
@Setter
@NoArgsConstructor
public class DetailRecipeDto {
private UUID id;
private String name;
private String writer;
private List<IngredientRecipeResponseDto> ingredientRecipes;
private String cookingStep;
private int likeCount;
private ImageDto image;
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime createdAt;
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime updatedAt;

public static DetailRecipeDto mapping(Recipe recipe, List<IngredientRecipe> ingredientRecipes){
List<IngredientRecipeResponseDto> ingredientDtos = ingredientRecipes.stream().map(
i->IngredientRecipeResponseDto.changeToDto(i)).collect(Collectors.toList());
return new DetailRecipeDto(recipe.getId(), recipe.getName(), ingredientDtos,
return new DetailRecipeDto(recipe.getId(), recipe.getName(), recipe.getUser().getName(), ingredientDtos,
recipe.getCookingStep(), recipe.getLikeCount(), ImageDto.mapping(recipe.getImage()),
recipe.getCreatedAt(), recipe.getUpdatedAt());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import com.hackathonteam1.refreshrator.entity.IngredientRecipe;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.UUID;

@Getter
@AllArgsConstructor
@Setter
@NoArgsConstructor
public class IngredientRecipeResponseDto {

private UUID id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
package com.hackathonteam1.refreshrator.dto.response.recipe;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.hackathonteam1.refreshrator.dto.response.file.ImageDto;
import com.hackathonteam1.refreshrator.entity.Recipe;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;
import java.util.UUID;

@Getter
@AllArgsConstructor
@Setter
@NoArgsConstructor
public class RecipeDto {

private UUID recipeId;
private String name;
private int likeCount;
private ImageDto image;

@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime createdAt;

@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime updatedAt;
public static RecipeDto mapping(Recipe recipe){
return new RecipeDto(recipe.getId(), recipe.getName(), recipe.getLikeCount(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.hackathonteam1.refreshrator.dto.response.PaginationDto;
import com.hackathonteam1.refreshrator.entity.Recipe;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.*;
import org.springframework.data.domain.Page;

import java.util.List;
Expand All @@ -13,6 +11,8 @@
@Getter
@AllArgsConstructor
@Builder
@NoArgsConstructor
@Setter
public class RecipeListDto {
private List<RecipeDto> recipeList;
private PaginationDto pagination;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public class Recipe extends BaseEntity{
@Column(nullable = false)
private String name;

@Column(nullable = false)
@Lob
@Column(nullable = false, length = 5000)
private String cookingStep;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.hackathonteam1.refreshrator.repository;

import com.hackathonteam1.refreshrator.entity.Image;
import com.hackathonteam1.refreshrator.entity.Recipe;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
import java.util.UUID;

public interface ImageRepository extends JpaRepository<Image, UUID> {
Optional<Image> findByRecipe(Recipe recipe);
}
Loading

0 comments on commit 5f6b600

Please sign in to comment.