Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: SpringSecurity 적용 및 도메인별로 파일 구성 변경 #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 102 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,102 @@
# 🍸12조 알딸딸
### 📝 코드 컨벤션
- ENCODING: UTF-8
- FORMAT: 중괄호 필수 작성(if, else..)
- 어노테이션: 1줄씩 작성
- 패키지명: 소문자
- 클래스명: UpperCamelCase, 명사
- 매소드명: LowerCamelCase, 동사
- 상수: CONSTANT_CASE
---
### 🐾 커밋 컨벤션
- [INITIAL] — repository를 생성하고 최초에 파일을 업로드 할 때
- [ADD] — 신규 파일 추가
- [UPDATE] — 코드 변경이 일어날때
- [REFACTOR] — 코드를 리팩토링 했을때
- [FIX] — 잘못된 링크 정보 변경, 필요한 모듈 추가 및 삭제
- [REMOVE] — 파일 제거
- [STYLE] — 디자인 관련 변경사항
# 🍸 01 | 프로젝트 소개 [알딸딸]
<div align = "center">
<img width="80%" src="https://github.com/klettermi/alttalttal/assets/95194606/9e229920-20a6-4fef-81a7-af990df56319"/>
</div>
<br>


```
🍸 모두가 함께 공유할 수 있는 칵테일 플랫폼
- 모든 사람이 칵테일 레시피를 조회할 수 있는 서비스
- 원하는 레시피를 찜할 수 있는 서비스
- 신뢰되는 사용자들의 의견 나눔 서비스
```
- 모든 사람이 인증 과정 없이 칵테일 레시피를 조회할 수 있습니다.
- 회원은 원하는 레시피를 찜하여 마이페이지에서 볼 수 있습니다.
- 회원은 모두와 소통할 수 있는 라운지를 이용할 수 있습니다.
- 회원가입, 로그인 및 로그아웃을 통해 회원 관리가 가능합니다.
- 마이페이지에서 닉네임을 수정하거나 찜목록을 볼 수 있습니다.


# 🥂 02 | 프로젝트 목표

1️⃣ **레시피 조회**
<div align = "center">
<img width="70%" src="https://github.com/klettermi/alttalttal/assets/95194606/bf8a3f85-4a93-4a0e-b3d1-faffb80f0f4c"/>
</div>
<br>

2️⃣ **원하는 레시피를 찜하고 해제하기**
<div align = "center">
<img width="70%" src="https://github.com/klettermi/alttalttal/assets/95194606/f20d91a4-03a9-4448-b089-8f02ca6894d5"/>
</div>
<br>

3️⃣ **라운지**
<div align = "center">
<img width="70%" src="https://github.com/klettermi/alttalttal/assets/95194606/6ed81291-c0da-4abd-a4ce-a50234a42b56"/>
</div>
<br>

4️⃣ **회원가입, 로그인 및 로그아웃**
- 회원가입/로그인
<div align = "center">
<img width="70%" src="https://github.com/klettermi/alttalttal/assets/95194606/1797aacc-cc70-45d2-842d-aa21230ceee0"/>
</div>

- 로그아웃
<div align = "center">
<img width="70%" src="https://github.com/klettermi/alttalttal/assets/95194606/2ab0b3bc-3848-407f-a317-5936b2d06040"/>
</div>

5️⃣ **마이페이지**
<div align = "center">
<img width="70%" src="https://github.com/klettermi/alttalttal/assets/95194606/f41b86b9-be73-4289-9071-9dbe3c22d17f"/>
</div>

# ⚙️ 03 | 아키텍쳐
## 서비스 아키텍쳐
<div align = "center">
<img width="70%" src="https://github.com/klettermi/alttalttal/assets/95194606/e053cafb-aedb-4d38-bbe0-a733ef0a0a98"/>
</div>

## ERD
<div align = "center">
<img width="70%" src="https://github.com/klettermi/alttalttal/assets/95194606/6c8f9c94-3035-4caa-894d-877770842a2e"/>
</div>
<div align = "center">
<img width="40%" src="https://github.com/klettermi/alttalttal/assets/95194606/80c745d2-9134-411a-84dd-6ac3d636a996">
</div>


## API 명세서 (swagger)
<img width="819" alt="image" src="https://github.com/klettermi/alttalttal/assets/95194606/bcee5734-58c8-49f0-858e-2b3844b8c6c4">
<img width="949" alt="image" src="https://github.com/klettermi/alttalttal/assets/95194606/51d641f5-cafa-4865-ab52-2f50a962035c">


# 🎯 04 | 트러블 슈팅

- 로그아웃 구현
- 문제: Front-end에서 토큰을 삭제해주는 방식이 보안상 문제가 될 수 있다고 판단
- 해결 방안: Back-end에서도 보안 유지를 위해 로그아웃 로직을 구현
로그아웃 요청이 오면 Refresh Token을 Redis에서 삭제 시킨 후 AccessToken을 BlackList로 Redis에 저장
로그아웃 후 해당 유저가 요청을 보낼 때 접근이 불가능하도록 구현
- 기존의 파일 구조를 도메인 별로 변경
- 문제: 비즈니스 도메인을 명확하게 구분하고 확정성, 유지보수성을 향상시킬 수 있도록 파일 구조 변경 필요
- 해결 방안: 도메인 별로 리팩토링 진행
불필요한 @EnableJpaRepositories, @EnableMongoRepositoies 삭제
- Spring Security 적용
- 문제: Spring Security가 적용되어 있지 않아
웹 응용 프로그램 및 서비스에서 보안을 효과적으로 관리하고 강화하기 위해 적용 필요
- 해결 방안: Spring Security 적용

# 🛠️ 05 | 기술 스택

| Backend | Tech | Spring Boot Spring JPA Spring Security |
| --- | --- | --- |
| | Platform | Ubuntu |
| | DB | AWS RDS(Mysql) Redis MongoDB |
| | DevOps | AWS EC2 Docker |



Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
@EnableJpaAuditing
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
// mysql repository와 mongodb repository의 package로 나눔
@EnableJpaRepositories(basePackages = "com.alttalttal.mini_project.repository")
@EnableMongoRepositories(basePackages = "com.alttalttal.mini_project.mongo.repository")

public class MiniProjectApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.alttalttal.mini_project.controller;
package com.alttalttal.mini_project.domain.lounge.controller;

import com.alttalttal.mini_project.dto.LoungeRequestDto;
import com.alttalttal.mini_project.dto.LoungeResponseDto;
import com.alttalttal.mini_project.dto.MessageResponseDto;
import com.alttalttal.mini_project.jwt.JwtUtil;
import com.alttalttal.mini_project.service.LoungeService;
import com.alttalttal.mini_project.domain.lounge.dto.LoungeRequestDto;
import com.alttalttal.mini_project.domain.lounge.dto.LoungeResponseDto;
import com.alttalttal.mini_project.global.dto.MessageResponseDto;
import com.alttalttal.mini_project.global.jwt.JwtUtil;
import com.alttalttal.mini_project.domain.lounge.service.LoungeService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.alttalttal.mini_project.dto;
package com.alttalttal.mini_project.domain.lounge.dto;

import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.alttalttal.mini_project.dto;
package com.alttalttal.mini_project.domain.lounge.dto;

import com.alttalttal.mini_project.domain.lounge.entity.LoungeEntity;
import lombok.Getter;

import java.time.LocalDateTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.alttalttal.mini_project.dto;
package com.alttalttal.mini_project.domain.lounge.entity;


import com.alttalttal.mini_project.entity.Timestamped;
import com.alttalttal.mini_project.entity.User;
import com.alttalttal.mini_project.domain.lounge.dto.LoungeRequestDto;
import com.alttalttal.mini_project.global.entity.Timestamped;
import com.alttalttal.mini_project.domain.user.entity.User;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.alttalttal.mini_project.repository;
package com.alttalttal.mini_project.domain.lounge.repository;

import com.alttalttal.mini_project.dto.LoungeEntity;
import com.alttalttal.mini_project.domain.lounge.entity.LoungeEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface LoungeRepository extends JpaRepository<LoungeEntity, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.alttalttal.mini_project.service;
package com.alttalttal.mini_project.domain.lounge.service;

import com.alttalttal.mini_project.dto.LoungeRequestDto;
import com.alttalttal.mini_project.dto.LoungeResponseDto;
import com.alttalttal.mini_project.dto.LoungeEntity;
import com.alttalttal.mini_project.entity.User;
import com.alttalttal.mini_project.jwt.JwtUtil;
import com.alttalttal.mini_project.repository.LoungeRepository;
import com.alttalttal.mini_project.domain.lounge.dto.LoungeRequestDto;
import com.alttalttal.mini_project.domain.lounge.dto.LoungeResponseDto;
import com.alttalttal.mini_project.domain.lounge.entity.LoungeEntity;
import com.alttalttal.mini_project.domain.user.entity.User;
import com.alttalttal.mini_project.global.jwt.JwtUtil;
import com.alttalttal.mini_project.domain.lounge.repository.LoungeRepository;
import com.alttalttal.mini_project.global.token.ServiceManagerImpl;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import com.alttalttal.mini_project.dto.MessageResponseDto;
import com.alttalttal.mini_project.global.dto.MessageResponseDto;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.alttalttal.mini_project.controller;
package com.alttalttal.mini_project.domain.main.controller;

import com.alttalttal.mini_project.dto.MainPageResponseDto;
import com.alttalttal.mini_project.service.MainPageService;
import com.alttalttal.mini_project.domain.main.dto.MainPageResponseDto;
import com.alttalttal.mini_project.domain.main.service.MainPageService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.alttalttal.mini_project.dto;
package com.alttalttal.mini_project.domain.main.dto;

import com.alttalttal.mini_project.domain.lounge.dto.LoungeResponseDto;
import com.alttalttal.mini_project.domain.recipe.dto.simpleRecipesResponseDto;
import lombok.Getter;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.alttalttal.mini_project.domain.main.service;

import com.alttalttal.mini_project.domain.lounge.dto.LoungeResponseDto;
import com.alttalttal.mini_project.domain.main.dto.MainPageResponseDto;
import com.alttalttal.mini_project.domain.recipe.dto.simpleRecipesResponseDto;
import com.alttalttal.mini_project.domain.recipe.entity.MongoRecipe;
import com.alttalttal.mini_project.domain.recipe.repository.MongoRecipeRepository;
import com.alttalttal.mini_project.domain.lounge.repository.LoungeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Service
@RequiredArgsConstructor
public class MainPageService {
private final MongoRecipeRepository mongoRecipeRepository;
private final LoungeRepository loungeRepository;
public MainPageResponseDto getMainPage() {
List<MongoRecipe> mongoRecipeList = mongoRecipeRepository.findAll();
mongoRecipeList.sort(Comparator.comparingInt(mongoRecipe -> mongoRecipe.getZzimUserIdList().size()));
Collections.reverse(mongoRecipeList);
List<simpleRecipesResponseDto> simpleRecipesResponseDtoList = mongoRecipeList.stream().limit(9).map(simpleRecipesResponseDto::new).toList();
List<LoungeResponseDto> loungeResponseDtoList = loungeRepository.findAll().stream().map(LoungeResponseDto::new).toList();
return new MainPageResponseDto(simpleRecipesResponseDtoList, loungeResponseDtoList);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.alttalttal.mini_project.controller;
package com.alttalttal.mini_project.domain.mypage.controller;

import com.alttalttal.mini_project.dto.MypageRequestDto;
import com.alttalttal.mini_project.dto.MypageResponseDto;
import com.alttalttal.mini_project.jwt.JwtUtil;
import com.alttalttal.mini_project.service.MypageService;
import com.alttalttal.mini_project.domain.mypage.dto.MypageRequestDto;
import com.alttalttal.mini_project.domain.mypage.dto.MypageResponseDto;
import com.alttalttal.mini_project.global.jwt.JwtUtil;
import com.alttalttal.mini_project.domain.mypage.service.MypageService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.alttalttal.mini_project.dto;
package com.alttalttal.mini_project.domain.mypage.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.alttalttal.mini_project.dto;
package com.alttalttal.mini_project.domain.mypage.dto;

import com.alttalttal.mini_project.entity.User;
import com.alttalttal.mini_project.domain.lounge.dto.LoungeResponseDto;
import com.alttalttal.mini_project.domain.user.entity.User;
import com.alttalttal.mini_project.domain.recipe.dto.simpleRecipesResponseDto;
import lombok.Getter;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.alttalttal.mini_project.service;

import com.alttalttal.mini_project.dto.MypageRequestDto;
import com.alttalttal.mini_project.dto.MypageResponseDto;
import com.alttalttal.mini_project.dto.simpleRecipesResponseDto;
import com.alttalttal.mini_project.entity.User;
import com.alttalttal.mini_project.jwt.JwtUtil;
import com.alttalttal.mini_project.mongo.repository.MongoRecipeRepository;
package com.alttalttal.mini_project.domain.mypage.service;

import com.alttalttal.mini_project.domain.mypage.dto.MypageRequestDto;
import com.alttalttal.mini_project.domain.mypage.dto.MypageResponseDto;
import com.alttalttal.mini_project.domain.recipe.dto.simpleRecipesResponseDto;
import com.alttalttal.mini_project.domain.user.entity.User;
import com.alttalttal.mini_project.global.jwt.JwtUtil;
import com.alttalttal.mini_project.domain.recipe.repository.MongoRecipeRepository;
import com.alttalttal.mini_project.global.token.ServiceManagerImpl;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.alttalttal.mini_project.controller;
package com.alttalttal.mini_project.domain.recipe.controller;

import com.alttalttal.mini_project.dto.MessageResponseDto;
import com.alttalttal.mini_project.dto.RecipeResponseDto;
import com.alttalttal.mini_project.dto.simpleRecipesResponseDto;
import com.alttalttal.mini_project.jwt.JwtUtil;
import com.alttalttal.mini_project.repository.UserRepository;
import com.alttalttal.mini_project.service.RecipeService;
import com.alttalttal.mini_project.global.dto.MessageResponseDto;
import com.alttalttal.mini_project.domain.recipe.dto.RecipeResponseDto;
import com.alttalttal.mini_project.domain.recipe.dto.simpleRecipesResponseDto;
import com.alttalttal.mini_project.global.jwt.JwtUtil;
import com.alttalttal.mini_project.domain.recipe.service.RecipeService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.alttalttal.mini_project.dto;
package com.alttalttal.mini_project.domain.recipe.dto;

import com.alttalttal.mini_project.entity.recipe_component.Ingredient;
import com.alttalttal.mini_project.domain.recipe.entity.recipe_component.Ingredient;
import lombok.Getter;

@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.alttalttal.mini_project.dto;
package com.alttalttal.mini_project.domain.recipe.dto;

import com.alttalttal.mini_project.entity.recipe_component.MakingDetail;
import com.alttalttal.mini_project.domain.recipe.entity.recipe_component.MakingDetail;
import lombok.Getter;

@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.alttalttal.mini_project.dto;
package com.alttalttal.mini_project.domain.recipe.dto;

import com.alttalttal.mini_project.entity.MongoRecipe;
import com.alttalttal.mini_project.domain.recipe.entity.MongoRecipe;
import lombok.Getter;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.alttalttal.mini_project.dto;
package com.alttalttal.mini_project.domain.recipe.dto;

import com.alttalttal.mini_project.entity.MongoRecipe;
import com.alttalttal.mini_project.domain.recipe.entity.MongoRecipe;
import lombok.Getter;

@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.alttalttal.mini_project.entity;
package com.alttalttal.mini_project.domain.recipe.entity;

import com.alttalttal.mini_project.entity.recipe_component.Ingredient;
import com.alttalttal.mini_project.entity.recipe_component.MakingDetail;
import com.alttalttal.mini_project.entity.recipe_component.Zzim;
import com.alttalttal.mini_project.domain.recipe.entity.recipe_component.Ingredient;
import com.alttalttal.mini_project.domain.recipe.entity.recipe_component.MakingDetail;
import com.alttalttal.mini_project.domain.recipe.entity.recipe_component.Zzim;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.alttalttal.mini_project.entity.recipe_component;
package com.alttalttal.mini_project.domain.recipe.entity.recipe_component;

import jakarta.persistence.Embeddable;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.alttalttal.mini_project.entity.recipe_component;
package com.alttalttal.mini_project.domain.recipe.entity.recipe_component;

import jakarta.persistence.Embeddable;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.alttalttal.mini_project.entity.recipe_component;
package com.alttalttal.mini_project.domain.recipe.entity.recipe_component;

import jakarta.persistence.*;
import lombok.Getter;
Expand Down
Loading