-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
22 changed files
with
534 additions
and
53 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
...iary/diary/dto/AddDiaryRecordRequest.java → ...ry/dto/request/AddDiaryRecordRequest.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
2 changes: 1 addition & 1 deletion
2
...diary/diary/dto/DiaryRegisterRequest.java → ...ary/dto/request/DiaryRegisterRequest.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
2 changes: 1 addition & 1 deletion
2
...ridiary/diary/dto/DiarySavedResponse.java → ...iary/dto/response/DiarySavedResponse.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
26 changes: 26 additions & 0 deletions
26
src/main/java/flab/nutridiary/diary/dto/response/query/DiaryRecordWithProduct.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,26 @@ | ||
package flab.nutridiary.diary.dto.response.query; | ||
|
||
import flab.nutridiary.commom.generic.Nutrition; | ||
import flab.nutridiary.diary.domain.MealType; | ||
import lombok.*; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDate; | ||
|
||
@EqualsAndHashCode(exclude = {"diaryId", "diaryRecordId"}) | ||
@Builder | ||
@RequiredArgsConstructor | ||
@ToString | ||
@Getter | ||
public class DiaryRecordWithProduct { | ||
private final Long diaryId; | ||
private final Long memberId; | ||
private final LocalDate diaryDate; | ||
private final Long diaryRecordId; | ||
private final MealType mealType; | ||
private final String productName; | ||
private final String productCorp; | ||
private final BigDecimal quantity; | ||
private final String clientChoiceServingUnitDescription; | ||
private final Nutrition calculatedNutrition; | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/main/java/flab/nutridiary/diary/repository/DiarySearchRepository.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,10 @@ | ||
package flab.nutridiary.diary.repository; | ||
|
||
import flab.nutridiary.diary.dto.response.query.DiaryRecordWithProduct; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public interface DiarySearchRepository { | ||
List<DiaryRecordWithProduct> findDiaryWithProductAllByMemberIdAndDiaryDate(Long memberId, LocalDate diaryDate); | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/flab/nutridiary/diary/repository/query/DiaryRecordWithProductRowMapper.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,44 @@ | ||
package flab.nutridiary.diary.repository.query; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import flab.nutridiary.commom.exception.SystemException; | ||
import flab.nutridiary.commom.generic.Nutrition; | ||
import flab.nutridiary.diary.domain.MealType; | ||
import flab.nutridiary.diary.dto.response.query.DiaryRecordWithProduct; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.jdbc.core.RowMapper; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class DiaryRecordWithProductRowMapper implements RowMapper<DiaryRecordWithProduct> { | ||
private final ObjectMapper objectMapper; | ||
|
||
@Override | ||
public DiaryRecordWithProduct mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
return DiaryRecordWithProduct.builder() | ||
.diaryId(rs.getLong("diary_id")) | ||
.memberId(rs.getLong("member_id")) | ||
.diaryDate(rs.getDate("diary_date").toLocalDate()) | ||
.diaryRecordId(rs.getLong("diary_record_id")) | ||
.mealType(MealType.valueOf(rs.getString("meal_type"))) | ||
.productName(rs.getString("product_name")) | ||
.productCorp(rs.getString("product_corp")) | ||
.quantity(rs.getBigDecimal("quantity")) | ||
.clientChoiceServingUnitDescription(rs.getString("client_choice_serving_unit_description")) | ||
.calculatedNutrition(getNutritionFromJsonString(rs.getString("calculated_nutrition"))) | ||
.build(); | ||
} | ||
|
||
private Nutrition getNutritionFromJsonString(String jsonString) { | ||
try { | ||
return objectMapper.readValue(jsonString, Nutrition.class); | ||
} catch (JsonProcessingException e) { | ||
throw new SystemException("Nutrition 객체 매핑 중 오류가 발생했습니다."); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/flab/nutridiary/diary/repository/query/JdbcTemplateDiarySearchRepository.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,36 @@ | ||
package flab.nutridiary.diary.repository.query; | ||
|
||
import flab.nutridiary.diary.dto.response.query.DiaryRecordWithProduct; | ||
import flab.nutridiary.diary.repository.DiarySearchRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class JdbcTemplateDiarySearchRepository implements DiarySearchRepository { | ||
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate; | ||
private final DiaryRecordWithProductRowMapper diaryRecordWithProductRowMapper; | ||
|
||
@Override | ||
public List<DiaryRecordWithProduct> findDiaryWithProductAllByMemberIdAndDiaryDate(Long memberId, LocalDate diaryDate) { | ||
String sql = "SELECT " + | ||
"d.diary_id, d.member_id, d.diary_date, " + | ||
"dr.diary_record_id, dr.meal_type, dr.quantity, dr.client_choice_serving_unit_description, dr.calculated_nutrition, " + | ||
"p.product_id, p.product_name, p.product_corp " + | ||
"FROM diary d " + | ||
"JOIN diary_record dr ON d.diary_id = dr.diary_id " + | ||
"JOIN product p ON dr.product_id = p.product_id " + | ||
"WHERE d.member_id = :memberId AND d.diary_date = :diaryDate"; | ||
|
||
MapSqlParameterSource parameters = new MapSqlParameterSource() | ||
.addValue("memberId", memberId) | ||
.addValue("diaryDate", diaryDate); | ||
|
||
return namedParameterJdbcTemplate.query(sql, parameters, diaryRecordWithProductRowMapper); | ||
} | ||
} |
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
4 changes: 2 additions & 2 deletions
4
src/main/java/flab/nutridiary/diary/service/DiaryRegisterService.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
22 changes: 22 additions & 0 deletions
22
src/main/java/flab/nutridiary/diary/service/DiarySearchService.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,22 @@ | ||
package flab.nutridiary.diary.service; | ||
|
||
import flab.nutridiary.diary.dto.response.query.DiaryRecordWithProduct; | ||
import flab.nutridiary.diary.repository.DiarySearchRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Transactional | ||
@Service | ||
@RequiredArgsConstructor | ||
public class DiarySearchService { | ||
private final DiarySearchRepository diarySearchRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public List<DiaryRecordWithProduct> getDiary(Long memberId, LocalDate diaryDate) { | ||
return diarySearchRepository.findDiaryWithProductAllByMemberIdAndDiaryDate(memberId, diaryDate); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/flab/nutridiary/diary/service/ProductIntakeInfoMapper.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
5 changes: 1 addition & 4 deletions
5
src/main/java/flab/nutridiary/product/repository/ProductCrudRepository.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 |
---|---|---|
@@ -1,11 +1,8 @@ | ||
package flab.nutridiary.product.repository; | ||
|
||
import flab.nutridiary.product.domain.Product; | ||
import org.springframework.data.jdbc.repository.query.Query; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface ProductCrudRepository extends CrudRepository<Product, Long> { | ||
|
||
@Query("select count(*) from product where product_normalized_name = :normalizedName") | ||
Integer isExistDuplicatedProductByNormalizedName(String normalizedName); | ||
int countByProductNormalizedName(String normalizedName); | ||
} |
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
Oops, something went wrong.