Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/MADA-UMC/MADA-Server into s…
Browse files Browse the repository at this point in the history
…erver-heerang
  • Loading branch information
Jeonghee-Han committed Oct 2, 2024
2 parents 0d3d978 + 28cce9e commit 07d3dab
Show file tree
Hide file tree
Showing 26 changed files with 116 additions and 119 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM openjdk:11-jdk
EXPOSE 8080
ARG JAR_FILE=build/libs/*.jar
ARG JAR_FILE=build/libs/*-SNAPSHOT.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-jar","-Dspring.config.location=classpath:/application.properties,classpath:/application-DB.properties,classpath:/application-jwt.properties,classpath:/application-oauth2.properties","/app.jar"]

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// security 설정 유의, 개발 후 적용
// implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-test:2.7.13'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.boot:spring-boot-starter-validation'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.umc.mada.auth.handler;

import com.umc.mada.auth.handler.jwt.JwtTokenProvider;
import com.umc.mada.exception.NotFoundUserException;
import com.umc.mada.user.domain.CusomtUserDetails;
import com.umc.mada.user.domain.User;
import com.umc.mada.user.repository.UserRepository;
Expand All @@ -15,7 +16,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Optional;

@Component
@RequiredArgsConstructor
Expand All @@ -27,15 +27,15 @@ public class OAuth2LoginSuccessHandler implements AuthenticationSuccessHandler {
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
OAuth2User oAuth2User = (OAuth2User)authentication.getPrincipal();
// OAuth2Attributes oAuth2Attributes = OAuth2Attributes.of(provider, userNameAttributeName, oAuth2User.getAttributes());
// Optional<User> findUser = userRepository.findByAuthId()
// Optional<User> findUser = userRepository.findByAuthIdAndAccountExpired()

//jwt 생성
String accessToken = jwtTokenProvider.createAccessToken(oAuth2User);
String refreshToken = jwtTokenProvider.createRefreshToken(oAuth2User);

//refreshtoken을 DB에 저장해야함
Optional<User> userOptional = userRepository.findByAuthId(oAuth2User.getName());
User user = userOptional.get(); //TODO: null값 체크하기
// User user = userRepository.findByAuthIdAndAccountExpired(authentication.getName(), false).orElseThrow(()-> new RuntimeException("올바른 유저 ID가 아닙니다."));
User user = userRepository.findByAuthId(oAuth2User.getName()).orElseThrow(()-> new NotFoundUserException("유저를 찾을 수 없습니다."));
user.setRefreshToken(refreshToken);

// tokenResponse(response, accessToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private OAuth2User process(OAuth2UserRequest userRequest, OAuth2User oAuth2User)
OAuth2Attributes oAuth2Attributes = OAuth2Attributes.of(provider, userNameAttributeName, oAuth2User.getAttributes());

Optional<User> userOptional = userRepository.findByAuthId(oAuth2Attributes.getAuthId());
// Optional<User> userOptional = userRepository.findByAuthIdAndAccountExpired(oAuth2Attributes.getAuthId(), false);

User user;
boolean newUser=false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ public interface CalendarRepository extends JpaRepository<Calendar,Long> {
"and MONTH(c.startDate) <= :m and MONTH(c.endDate) >= :m "
)
List<Calendar> findCalendarMonth(User user , int y, int m);

@Query("select c from Calendar c where c.user = :user and c.startDate <= :date and c.endDate >= :date")
List<Calendar> findCalendarDay(User user, LocalDate date);
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ public List<Calendar> readCalendarsByDate(List<Calendar> calendarList, LocalDate

private User getUser(Authentication authentication) throws NoSuchElementException {
try{
Optional<User> userOptional = userRepository.findByAuthId(authentication.getName());
return userOptional.get();
return userRepository.findByAuthIdAndAccountExpired(authentication.getName(), false).orElseThrow(()-> new RuntimeException("올바른 유저 ID가 아닙니다."));
}catch (RuntimeException e){
throw new NoSuchElementException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public CategoryController(CategoryService categoryService, UserRepository userRe
@PostMapping
public ResponseEntity<Map<String, Object>> addCategory(Authentication authentication, @Valid @RequestBody CategoryRequestDto categoryRequestDto) {
// 카테고리 생성 API
Optional<User> userOptional = userRepository.findByAuthId(authentication.getName());
User user = userOptional.get();
User user = userRepository.findByAuthIdAndAccountExpired(authentication.getName(), false).orElseThrow(()-> new RuntimeException("올바른 유저 ID가 아닙니다."));
CategoryResponseDto newCategory = categoryService.createCategory(user, categoryRequestDto);
Map<String, Object> data = new LinkedHashMap<>();
data.put("Category", newCategory);
Expand All @@ -49,8 +48,7 @@ public ResponseEntity<Map<String, Object>> addCategory(Authentication authentica
@PatchMapping("/{categoryId}")
public ResponseEntity<Map<String, Object>> updateCategory(Authentication authentication,@PathVariable int categoryId, @Valid @RequestBody CategoryRequestDto categoryRequestDto) {
// 카테고리 수정 API
Optional<User> userOptional = userRepository.findByAuthId(authentication.getName());
User user = userOptional.get();
User user = userRepository.findByAuthIdAndAccountExpired(authentication.getName(), false).orElseThrow(()-> new RuntimeException("올바른 유저 ID가 아닙니다."));
CategoryResponseDto updatedCategory = categoryService.updateCategory(user, categoryId, categoryRequestDto);
Map<String, Object> data = new LinkedHashMap<>();
data.put("Category", updatedCategory);
Expand All @@ -70,8 +68,7 @@ public ResponseEntity<Map<String, Object>> updateCategory(Authentication authent
public ResponseEntity<Map<String, Object>> deleteCategory(Authentication authentication, @PathVariable int categoryId) {
// 카테고리 삭제 API
try{
Optional<User> userOptional = userRepository.findByAuthId(authentication.getName());
User user = userOptional.get();
User user = userRepository.findByAuthIdAndAccountExpired(authentication.getName(), false).orElseThrow(()-> new RuntimeException("올바른 유저 ID가 아닙니다."));
categoryService.deleteCategory(user,categoryId);
Map<String, Object> result = new LinkedHashMap<>();
//result.put("status", 200);
Expand All @@ -87,8 +84,7 @@ public ResponseEntity<Map<String, Object>> deleteCategory(Authentication authent
public ResponseEntity<Map<String, Object>> inactiveCategory(Authentication authentication, @PathVariable int categoryId) {
//카테고리 종료 API
try{
Optional<User> userOptional = userRepository.findByAuthId(authentication.getName());
User user = userOptional.get();
User user = userRepository.findByAuthIdAndAccountExpired(authentication.getName(), false).orElseThrow(()-> new RuntimeException("올바른 유저 ID가 아닙니다."));
categoryService.inactiveCategory(user, categoryId);
Map<String, Object> result = new LinkedHashMap<>();
return ResponseEntity.ok().body(result);
Expand All @@ -101,8 +97,7 @@ public ResponseEntity<Map<String, Object>> inactiveCategory(Authentication authe
public ResponseEntity<Map<String, Object>> activeCategory(Authentication authentication, @PathVariable int categoryId) {
//종료된 카테고리 복원 API
try{
Optional<User> userOptional = userRepository.findByAuthId(authentication.getName());
User user = userOptional.get();
User user = userRepository.findByAuthIdAndAccountExpired(authentication.getName(), false).orElseThrow(()-> new RuntimeException("올바른 유저 ID가 아닙니다."));
categoryService.activeCategory(user, categoryId);
Map<String, Object> result = new LinkedHashMap<>();
return ResponseEntity.ok().body(result);
Expand All @@ -115,8 +110,7 @@ public ResponseEntity<Map<String, Object>> activeCategory(Authentication authent
public ResponseEntity<Map<String, Object>> getAllCategories(Authentication authentication) {
// 특정 유저 카테고리 목록 조회 API (카테고리 목록)
try {
Optional<User> userOptional = userRepository.findByAuthId(authentication.getName());
User user = userOptional.get();
User user = userRepository.findByAuthIdAndAccountExpired(authentication.getName(), false).orElseThrow(()-> new RuntimeException("올바른 유저 ID가 아닙니다."));
List<CategoryResponseDto> allCategories = categoryService.getAllCategories(user);
Map<String, Object> data = new LinkedHashMap<>();
data.put("CategoryList", allCategories);
Expand All @@ -135,8 +129,7 @@ public ResponseEntity<Map<String, Object>> getAllCategories(Authentication authe
public ResponseEntity<Map<String, Object>> getHomeCategories(Authentication authentication, @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
// 특정 유저 카테고리 목록 조회 API (home)
try {
Optional<User> userOptional = userRepository.findByAuthId(authentication.getName());
User user = userOptional.get();
User user = userRepository.findByAuthIdAndAccountExpired(authentication.getName(), false).orElseThrow(()-> new RuntimeException("올바른 유저 ID가 아닙니다."));
List<CategoryResponseDto> homeCategories = categoryService.getHomeCategories(user, date);
Map<String, Object> data = new LinkedHashMap<>();
data.put("CategoryList", homeCategories);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public ResponseEntity<Void> buyItem(Authentication authentication, @PathVariable


private User findUser(Authentication authentication){
Optional<User> userOptional = userRepository.findByAuthId(authentication.getName());
User user = userRepository.findByAuthIdAndAccountExpired(authentication.getName(), false).orElseThrow(()-> new RuntimeException("올바른 유저 ID가 아닙니다."));
// User user = userOptional.get(); //TODO: get값이 NULL인 경우를 체크해줘야함
return userOptional.get();
return user;
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/umc/mada/custom/domain/ItemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public enum ItemType {
I1("color"),
I2("set"),
I3("item"),
I4("background");
//UNKNOWN("알수없음");
I4("background"),
I5("default");

private final String itemType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.umc.mada.custom.domain.CustomItem;
import com.umc.mada.custom.domain.HaveItem;
import com.umc.mada.custom.domain.ItemType;
import com.umc.mada.user.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -18,7 +19,8 @@ public interface HaveItemRepository extends JpaRepository<HaveItem, Long> {
List<HaveItem> findByUser(User user);
List<HaveItem> findByUserAndWearing(User user, boolean wearing);
boolean existsByCustomItemAndUser(CustomItem customItem, User user);

@Query("delete from HaveItem h where h.user = :user and h.customItem.unlockCondition = :unlockCond")
Boolean deleteByUserAndUnlockCond(@Param("user") User user, @Param("unlockCond") CustomItem.ItemUnlockCondition unlockCond);
@Query("select h.customItem from HaveItem h where h.user = :user and h.wearing = :wearing")
List<CustomItem> findCustomItemByUserAndWearing(@Param("user") User user, @Param("wearing") boolean wearing);
}
4 changes: 2 additions & 2 deletions src/main/java/com/umc/mada/custom/service/CustomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public CustomItemsResponse checkHaveItem(List<CustomItem> itemList, User user){
boolean haveItemCheck = haveItemRepository.existsByCustomItemAndUser(item, user);

//출석 아이템인데 소유하고 있지 않다면 목록에 추가하지 않기
if(!haveItemCheck && item.getUnlockCondition().equals(CustomItem.ItemUnlockCondition.ATTENDANCE)) continue;
// if(!haveItemCheck && item.getUnlockCondition().equals(CustomItem.ItemUnlockCondition.ATTENDANCE)) continue;

//해당 아이템을 소유하고 있다면 true;
if(haveItemCheck) have = true;
Expand Down Expand Up @@ -107,7 +107,7 @@ public UserCharacterResponse changeUserItem(User user, List<Integer> items_id){/
//아이템의 카테고리가 겹치지 않도록 확인
String[] itemCategories = item.getCategory().split(",");
for(String category: itemCategories){
if(itemsCategory.contains(category)){
if(!category.equals(ItemType.I5.getItemType())&&itemsCategory.contains(category)){
throw new DuplicationItemException(ErrorType.DUPLICATE_ITEM_CATEGORY.getMessage());
}
itemsCategory.add(category);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/umc/mada/exception/ControllerAdvice.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public ResponseEntity<ErrorResponse> buyDuplicateItemHandler(final BuyOwnedItemE
public ResponseEntity<ErrorResponse> notAllowToWearingHandler(final NotAllowToWearingException e){
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorResponse(e.getMessage()));
}

@ExceptionHandler(NotFoundUserException.class)
public ResponseEntity<ErrorResponse> notFoundUserHandler(final NotFoundUserException e){
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorResponse(e.getMessage()));
}

@ExceptionHandler(ServerInternalException.class)
public ResponseEntity<ErrorResponse> testErrorHandler(final ServerInternalException e, HttpServletRequest httpServletRequest){
ErrorResponse errorResponse = ErrorResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.umc.mada.exception;

public class NotFoundUserException extends RuntimeException{
public NotFoundUserException(final String message){
super(message);
}
}
5 changes: 2 additions & 3 deletions src/main/java/com/umc/mada/my/service/MyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.umc.mada.my.dto.MyResponseDto;
import com.umc.mada.my.repository.MyRepository;
import com.umc.mada.user.domain.User;
import com.umc.mada.user.service.UserService;
import com.umc.mada.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -36,8 +35,8 @@ public List<MyResponseDto> findRandomSaying() {
}

private User getUser(Authentication authentication){
Optional<User> optionalUser = userRepository.findByAuthId(authentication.getName());
return optionalUser.get();
User user= userRepository.findByAuthIdAndAccountExpired(authentication.getName(), false).orElseThrow(()-> new RuntimeException("올바른 유저 ID가 아닙니다."));
return user;
}

public Map<String, Object> findMyProfileList(Authentication authentication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,4 @@ public ResponseEntity<Map<String, Object>> getTodoAndCalendar(Authentication aut
Map<String, Object> map = timetableService.getTodoAndCalendar(user, date);
return ResponseEntity.ok().body(map);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ public interface TimetableRepository extends JpaRepository<Timetable, Integer> {
List<Timetable> findTimetablesByUserIdAndDayOfWeekIsNot(User userId, DayOfWeek dayOfWeek);
List<Timetable> findTimetablesByUserIdAndDateIsAndDayOfWeek(User userId, LocalDate date, DayOfWeek dayOfWeek);
List<Timetable> findTimetablesByUserIdAndDayOfWeekAndIsDeletedIsFalse(User userId, DayOfWeek dayOfWeek);

}
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,4 @@ private boolean isSameSchedule(Timetable dailyEntry, Timetable weeklyEntry) {
dailyEntry.getColor().equals(weeklyEntry.getColor()) &&
Objects.equals(dailyEntry.getMemo(), weeklyEntry.getMemo());
}
}
}
Loading

0 comments on commit 07d3dab

Please sign in to comment.