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

#339 엔티티 ID strategy AUTO -> IDENTITY 및 데이터 변경으로 인한 실행오류 수정 #340

Merged
merged 3 commits into from
Jul 29, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Entity
@EntityListeners(UserEntityListener.class)
public class Admin extends BaseEntity {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;
@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Entity
public class PushNotification extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@EntityListeners(CartEntityListener.class)
public class Cart extends BaseEntity {

@Id @GeneratedValue(strategy = GenerationType.AUTO)
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@SQLDelete(sql = "UPDATE cart_food SET is_enable = false, updated_at = current_timestamp WHERE id = ?")
public class CartFood extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@SQLDelete(sql = "UPDATE food SET is_enable = false, updated_at = current_timestamp WHERE id = ?")
@EntityListeners(FoodEntityListener.class)
public class Food extends BaseEntity {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;
private String foodName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
@NoArgsConstructor
@Schema(name = "FridgeMainRes", description = "냉장고 식품 정보")
public class FridgeMainRes {
@Schema(name = "fridgeDiscard", description = "냉장고 낭비된 식품 정보")
private FridgeDiscardRes fridgeDiscard;
@Schema(name = "foodList", description = "냉장고 식품 정보")
private List<FridgeFoodsRes> foodList = new ArrayList<>();

public static FridgeMainRes toFridgeDto(FridgeDiscardRes fridgeDiscard, List<FridgeFood> fridgeFoods) {
return new FridgeMainRes(isNullFoodDiscardRes(fridgeDiscard), fridgeFoods.stream()
public static FridgeMainRes toFridgeDto(List<FridgeFood> fridgeFoods) {
return new FridgeMainRes(fridgeFoods.stream()
.map(ff -> new FridgeFoodsRes(ff.getId(), ff.getFood().getFoodName(), AwsS3ImageUrlUtil.toUrl(ff.getFood().getFoodImgKey()), FridgeUtils.calShelfLife(ff.getShelfLife())))
.collect(Collectors.toList()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class Fridge extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@SQLDelete(sql = "UPDATE fridge_food SET is_enable = false, updated_at = current_timestamp WHERE id = ?")
public class FridgeFood extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@SQLDelete(sql = "UPDATE fridge_user SET is_enable = false, updated_at = current_timestamp WHERE id = ?")
@EntityListeners(FridgeUserEntityListener.class)
public class FridgeUser extends BaseEntity {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public FridgeMainRes getFoods(Long fridgeId, Long userId, String category) {

if (category == null) {
// 값이 없으면 전체 조회
return FridgeMainRes.toFridgeDto(this.fridgeFoodRepository.findByFridgeForDisCardFood(fridge), this.fridgeFoodRepository.findByFridgeAndIsEnableOrderByShelfLife(fridge, true));
return FridgeMainRes.toFridgeDto(this.fridgeFoodRepository.findByFridgeAndIsEnableOrderByShelfLife(fridge, true));
} else {
// 값이 있으면 특정 값을 불러온 조회
return FridgeMainRes.toFridgeDto(this.fridgeFoodRepository.findByFridgeForDisCardFood(fridge), this.fridgeFoodRepository.findByFridgeAndFood_FoodCategoryAndIsEnableOrderByShelfLife(fridge, FoodCategory.getFoodCategoryByName(category), true));
return FridgeMainRes.toFridgeDto(this.fridgeFoodRepository.findByFridgeAndFood_FoodCategoryAndIsEnableOrderByShelfLife(fridge, FoodCategory.getFoodCategoryByName(category), true));
}
}

Expand Down Expand Up @@ -251,7 +251,7 @@ public void addFridgeFood(FridgeFoodsReq fridgeFoodsReq, Long fridgeId, Long use
Food food = foodRepository.findByFoodName(fridgeFoodReq.getFoodName())
.orElseGet(() -> {
Food save = foodRepository.save(Food.toEntity(fridgeFoodReq));
amazonSQSSender.sendMessage(FoodData.toDto(save));
// amazonSQSSender.sendMessage(FoodData.toDto(save));
return save;
});

Expand All @@ -276,7 +276,7 @@ public void modifyFridgeFood(Long fridgeId, Long fridgeFoodId, FridgeFoodReq fri
Food food = this.foodRepository.findByFoodName(fridgeFoodReq.getFoodName())
.orElseGet(() -> {
Food save = foodRepository.save(Food.toEntity(fridgeFoodReq));
amazonSQSSender.sendMessage(FoodData.toDto(save));
// amazonSQSSender.sendMessage(FoodData.toDto(save));
return save;
});
modifyFridgeFood.updateFridgeFoodInfo(food);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.time.LocalDateTime;

@Getter
@RequiredArgsConstructor
@AllArgsConstructor
public class ResponseCustom<T>{

Expand All @@ -20,6 +19,15 @@ public class ResponseCustom<T>{
private T data;
private LocalDateTime timeStamp;

// 성공
public ResponseCustom() {
this.data = null;
this.timeStamp = LocalDateTime.now();
this.httpStatus = HttpStatus.OK.value();
this.message = ReturnCode.SUCCESS.getMessage();
this.code = ReturnCode.SUCCESS.getCode();
}

Comment on lines +22 to +30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니도 🙌 꼼꼼하게 봐줘서 고마옹

// 성공
public ResponseCustom(T data) {
this.data = data;
Expand All @@ -39,7 +47,7 @@ public ResponseCustom(ReturnCode returnCode) {
}

public static <T> ResponseCustom<T> success() {
return new ResponseCustom<>(null);
return new ResponseCustom<>();
}

public static <T> ResponseCustom<T> success(@Nullable T data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@EntityListeners(UserEntityListener.class)
public class User extends BaseEntity {

@Id @GeneratedValue(strategy = GenerationType.AUTO)
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;

Expand Down
Loading