-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 현재 작성중인 가계부 API, 가계부 총 금액 로직 추가
- Loading branch information
Showing
13 changed files
with
211 additions
and
6 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/com/bagasari/sacbagaji/config/QuerydslConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.bagasari.sacbagaji.config; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
|
||
@Configuration | ||
public class QuerydslConfig { | ||
|
||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory() { | ||
return new JPAQueryFactory(entityManager); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/bagasari/sacbagaji/model/dto/ProductListWithPurchaseDateDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.bagasari.sacbagaji.model.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ProductListWithPurchaseDateDTO { | ||
|
||
private LocalDate purchaseDate; | ||
private List<ProductDTO> products; | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/bagasari/sacbagaji/model/dto/res/CurrentAccountResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.bagasari.sacbagaji.model.dto.res; | ||
|
||
import com.bagasari.sacbagaji.model.dto.ProductListWithPurchaseDateDTO; | ||
import com.bagasari.sacbagaji.model.entity.AccountBook; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class CurrentAccountResponseDTO { | ||
|
||
private String name; | ||
private LocalDate startDate; | ||
private LocalDate endDate; | ||
private Integer totalPrice; | ||
private List<ProductListWithPurchaseDateDTO> products; | ||
|
||
public CurrentAccountResponseDTO(AccountBook accountBook, List<ProductListWithPurchaseDateDTO> products) { | ||
this.name = accountBook.getName(); | ||
this.startDate = accountBook.getStartDate(); | ||
this.endDate = accountBook.getEndDate(); | ||
this.totalPrice = accountBook.getTotalPrice(); | ||
this.products = products; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/bagasari/sacbagaji/repository/AccountBookRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.bagasari.sacbagaji.repository; | ||
|
||
import com.bagasari.sacbagaji.model.entity.AccountBook; | ||
|
||
public interface AccountBookRepositoryCustom { | ||
|
||
AccountBook findFirstByOrderByUpdateTimeDesc(String email); | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/bagasari/sacbagaji/repository/AccountBookRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.bagasari.sacbagaji.repository; | ||
|
||
import com.bagasari.sacbagaji.model.entity.AccountBook; | ||
import com.bagasari.sacbagaji.model.entity.QAccountBook; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class AccountBookRepositoryImpl implements AccountBookRepositoryCustom { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public AccountBook findFirstByOrderByUpdateTimeDesc(String email) { | ||
|
||
QAccountBook qa = QAccountBook.accountBook; | ||
|
||
return queryFactory | ||
.select(qa) | ||
.from(qa) | ||
.where(qa.user.email.eq(email)) | ||
.orderBy(qa.updateTime.desc()) | ||
.fetchFirst(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/bagasari/sacbagaji/repository/ProductRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.bagasari.sacbagaji.repository; | ||
|
||
import com.bagasari.sacbagaji.model.entity.Product; | ||
|
||
import java.util.List; | ||
|
||
public interface ProductRepositoryCustom { | ||
List<Product> findOrderByPurchaseDate(Long id); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/bagasari/sacbagaji/repository/ProductRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.bagasari.sacbagaji.repository; | ||
|
||
import com.bagasari.sacbagaji.model.entity.Product; | ||
import com.bagasari.sacbagaji.model.entity.QProduct; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
public class ProductRepositoryImpl implements ProductRepositoryCustom { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public List<Product> findOrderByPurchaseDate(Long id) { | ||
|
||
QProduct qp = QProduct.product; | ||
|
||
return queryFactory | ||
.select(qp) | ||
.from(qp) | ||
.where(qp.accountBook.id.eq(id)) | ||
.orderBy(qp.purchaseDate.desc()) | ||
.fetch(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters