Skip to content

Commit

Permalink
Merge pull request #113 from mju-likelion/develop
Browse files Browse the repository at this point in the history
변경사항 적용 후 재배포
  • Loading branch information
jher235 authored Aug 6, 2024
2 parents 5f6b600 + ed0860d commit 4c245c3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ 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 --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 run --name ${{secrets.DOCKERHUB_IMAGE}} --rm -d -p 8080:8080 ${{secrets.DOCKERHUB_USERNAME}}/${{secrets.DOCKERHUB_IMAGE}}
- name: ssh connect & production # EC2에 접속하여 도커 이미지 실행
uses: appleboy/ssh-action@master
with:
host: ${{secrets.HOST2}} # EC2 인스턴스의 IP 주소
username: ${{secrets.USERNAME}} # EC2 인스턴스의 사용자 이름 (ubuntu)
key: ${{secrets.PASSWORD}} # EC2 인스턴스의 비밀번호 (SSH 키)
script: | # 실행할 스크립트
sudo docker login --username ${{secrets.DOCKERHUB_USERNAME}} --password ${{secrets.DOCKERHUB_PASSWORD}}
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 ${{secrets.DOCKERHUB_IMAGE}} --rm -d -p 8080:8080 ${{secrets.DOCKERHUB_USERNAME}}/${{secrets.DOCKERHUB_IMAGE}}
sudo docker system prune -f
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.util.List;

Expand All @@ -24,6 +26,7 @@ public class Recipe extends BaseEntity{
private String cookingStep;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "user_id")
private User user;

@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
Expand All @@ -35,6 +38,7 @@ public class Recipe extends BaseEntity{
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "image_id")
@Nullable
@OnDelete(action = OnDeleteAction.SET_NULL)
private Image image;

@Formula("(select count(rl.id) from recipe_like rl where rl.recipe_id = id)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class User extends BaseEntity{
@Column(nullable = false)
private String password;

@OneToMany(mappedBy = "user", cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL,orphanRemoval = true, fetch = FetchType.LAZY)
private List<Recipe> recipes;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

Expand All @@ -19,4 +21,6 @@ public interface RecipeRepository extends JpaRepository<Recipe, UUID> {
Page<Recipe> findAllByIngredientRecipesContain(@Param("ingredients") Set<Ingredient> ingredients, @Param("match") int match, Pageable pageable);
Page<Recipe> findAll(Pageable pageable);
Page<Recipe> findAllByUser(User user, Pageable pageable);

Optional<List<Recipe>> findAllByUser(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
import com.hackathonteam1.refreshrator.exception.NotFoundException;
import com.hackathonteam1.refreshrator.exception.UnauthorizedException;
import com.hackathonteam1.refreshrator.exception.errorcode.ErrorCode;
import com.hackathonteam1.refreshrator.repository.FridgeRepository;
import com.hackathonteam1.refreshrator.repository.RecipeLikeRepository;
import com.hackathonteam1.refreshrator.repository.UserRepository;
import com.hackathonteam1.refreshrator.repository.*;
import com.hackathonteam1.refreshrator.util.RedisUtil;
import com.hackathonteam1.refreshrator.util.S3Uploader;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
Expand All @@ -39,6 +38,9 @@ public class AuthService {
private final PasswordHashEncryption passwordHashEncryption;
private final JwtTokenProvider jwtTokenProvider;
private final RecipeLikeRepository recipeLikeRepository;
private final S3Uploader s3Uploader;
private final ImageRepository imageRepository;
private final RecipeRepository recipeRepository;

private final RedisUtil<String, RefreshToken> redisUtilForRefreshToken;
private final RedisUtil<String, String> redisUtilForUserId;
Expand Down Expand Up @@ -77,6 +79,17 @@ public void signin(SigninDto signinDto){

//회원탈퇴
public void leave(User user){
//레시피를 삭제하기 전, 유저의 레시피 내 이미지를 S3에서 모두 삭제
if(user.getRecipes()!=null){
List<Recipe> recipes = findAllRecipesByUser(user);

recipes.forEach(recipe-> {
if(recipe.isContainingImage()){
Image image = findImageByRecipe(recipe);
s3Uploader.removeS3File(image.getUrl().split("/")[3]);
}
});
}
//탈퇴
userRepository.delete(user);
}
Expand Down Expand Up @@ -180,4 +193,12 @@ private <T> void checkValidPage(Page<T> pages, int page){
throw new NotFoundException(ErrorCode.PAGE_NOT_FOUND);
}
}

private Image findImageByRecipe(Recipe recipe){
return imageRepository.findByRecipe(recipe).orElseThrow(()->new NotFoundException(ErrorCode.IMAGE_NOT_FOUND));
}

private List<Recipe> findAllRecipesByUser(User user){
return recipeRepository.findAllByUser(user).orElseThrow(()-> new NotFoundException(ErrorCode.RECIPE_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ public void deleteLikeFromRecipe(User user, UUID recipeId){
// 해당 레시피에서 내가 누른 좋아요 반환
RecipeLike recipeLike = this.findMyRecipeLike(user, recipe);
recipe.getUser().getRecipeLikes().remove(recipeLike);
recipe.getRecipeLikes().remove(recipeLike);
this.recipeLikeRepository.delete(recipeLike);
}

Expand Down

0 comments on commit 4c245c3

Please sign in to comment.