Skip to content
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
2 changes: 1 addition & 1 deletion server/src/main/java/com/onetool/server/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import java.math.BigInteger;

@Profile("dev")
@Profile({"dev", "default"})
@Component
public class DataLoader implements CommandLineRunner {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,32 @@
@Repository
public interface BlueprintRepository extends JpaRepository<Blueprint, Long> {

@Query(value = "SELECT b FROM Blueprint b WHERE (b.blueprintName LIKE %:keyword% OR b.creatorName LIKE %:keyword%) AND b.inspectionStatus = :status AND b.isDeleted = false")
Page<Blueprint> findAllNameAndCreatorContaining(@Param("keyword") String keyword, @Param("status") InspectionStatus status, Pageable pageable);
@Query(value = """
SELECT b
FROM Blueprint b
WHERE (b.blueprintName LIKE %:keyword% OR b.creatorName LIKE %:keyword%)
AND b.inspectionStatus = :status
AND b.isDeleted = false
""")
Page<Blueprint> findAllNameAndCreatorContaining(@Param("keyword") String keyword,
@Param("status") InspectionStatus status,
Pageable pageable);

@Query(value = """
SELECT DISTINCT b
FROM Blueprint b
LEFT JOIN FETCH b.orderBlueprints
WHERE b IN :blueprints
""")
List<Blueprint> findWithOrderBlueprints(@Param("blueprints") List<Blueprint> blueprints);

@Query(value = """
SELECT DISTINCT b
FROM Blueprint b
LEFT JOIN FETCH b.cartBlueprints
WHERE b IN :blueprints
""")
List<Blueprint> findWithCartBlueprints(@Param("blueprints") List<Blueprint> blueprints);

@Query(value = "SELECT b FROM Blueprint b WHERE b.categoryId = " +
"(SELECT f.id FROM FirstCategory f WHERE f.name = :first) " +
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

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

반환 타입을 void로 변경하셨는데,
void로 변경했을때 이점이나 void가 왜 더 적절한지 이유가 궁금합니다!!

Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ public BlueprintService(BlueprintRepository blueprintRepository) {
this.blueprintRepository = blueprintRepository;
}

public boolean createBlueprint(final BlueprintRequest blueprintRequest) {
public void createBlueprint(final BlueprintRequest blueprintRequest) {
Blueprint blueprint = convertToBlueprint(blueprintRequest);
saveBlueprint(blueprint);
return true;
}

public BlueprintResponse findApprovedBlueprintById(Long id) {
Expand All @@ -48,27 +47,25 @@ public BlueprintResponse findApprovedBlueprintById(Long id) {
}

@Transactional
public Blueprint saveBlueprint(Blueprint blueprint) {
return blueprintRepository.save(blueprint);
public void saveBlueprint(Blueprint blueprint) {
blueprintRepository.save(blueprint);
}

@Transactional
public boolean updateBlueprint(BlueprintResponse blueprintResponse) {
public void updateBlueprint(BlueprintResponse blueprintResponse) {
Blueprint existingBlueprint = blueprintRepository.findById(blueprintResponse.id())
.orElseThrow(BlueprintNotFoundException::new);
Blueprint updatedBlueprint = updateExistingBlueprint(existingBlueprint, blueprintResponse);

saveBlueprint(updatedBlueprint);
return true;
}

@Transactional
public boolean deleteBlueprint(Long id) {
public void deleteBlueprint(Long id) {
blueprintRepository.findById(id)
.orElseThrow(BlueprintNotFoundException::new);

blueprintRepository.deleteById(id);
return true;
}

public List<BlueprintResponse> sortBlueprintsByCategory(BlueprintSortRequest blueprintSortRequest, Pageable pageable) {
Expand Down Expand Up @@ -101,11 +98,12 @@ private List<BlueprintResponse> sortBlueprintsWithCategory(Long categoryId, Page


public Page<SearchResponse> searchNameAndCreatorWithKeyword(String keyword, Pageable pageable) {
Page<Blueprint> result = blueprintRepository.findAllNameAndCreatorContaining(keyword, InspectionStatus.PASSED, pageable);
List<SearchResponse> list = result.getContent().stream()
.map(SearchResponse::from)
.collect(Collectors.toList());
return new PageImpl<>(list, pageable, result.getTotalElements());
Page<Blueprint> page = blueprintRepository.findAllNameAndCreatorContaining(keyword, InspectionStatus.PASSED, pageable);
List<Blueprint> withOrderBlueprints = blueprintRepository.findWithOrderBlueprints(page.getContent());
List<Blueprint> withCartBlueprints = blueprintRepository.findWithCartBlueprints(withOrderBlueprints);

List<SearchResponse> list = convertToSearchResponseList(withCartBlueprints);
return new PageImpl<>(list, pageable, page.getTotalElements());
}

public Page<SearchResponse> findAllByCategory(FirstCategoryType firstCategory, String secondCategory, Pageable pageable) {
Expand All @@ -117,9 +115,7 @@ public Page<SearchResponse> findAllByCategory(FirstCategoryType firstCategory, S

public Page<SearchResponse> findAll(Pageable pageable) {
Page<Blueprint> result = blueprintRepository.findByInspectionStatus(InspectionStatus.PASSED, pageable);
List<SearchResponse> list = result.getContent().stream()
.map(SearchResponse::from)
.collect(Collectors.toList());
List<SearchResponse> list = convertToSearchResponseList(result.getContent());
return new PageImpl<>(list, pageable, result.getTotalElements());
}

Expand All @@ -140,6 +136,18 @@ private Page<SearchResponse> findAllBySecondCategory(FirstCategoryType firstCate
return new PageImpl<>(list, pageable, result.getTotalElements());
}

private List<BlueprintResponse> convertToResponseList(List<Blueprint> blueprints) {
return blueprints.stream()
.map(BlueprintResponse::from)
.collect(Collectors.toList());
}

private List<SearchResponse> convertToSearchResponseList(List<Blueprint> blueprints) {
return blueprints.stream()
.map(SearchResponse::from)
.collect(Collectors.toList());
}

private Blueprint convertToBlueprint(final BlueprintRequest blueprintRequest) {
return Blueprint.fromRequest(blueprintRequest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

@Configuration
@EnableWebSecurity(debug = true)
@EnableWebSecurity
@AllArgsConstructor
public class SecurityConfig {

Expand Down
6 changes: 3 additions & 3 deletions server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ spring.datasource.url=jdbc:mysql://localhost:3306/onetool?serverTimezone=Asia/Se
spring.datasource.username=root
spring.datasource.password=1234

spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.sql.init.mode=always
spring.jpa.defer-datasource-initialization=true

spring.jpa.hibernate.ddl-auto=create

spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect

spring.config.import=optional:application-api.properties

#logging.level.org.springframework.security=info
logging.level.org.hibernate.type=trace
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void search_with_keyword() {
String keyword = "마을";
Pageable pageable = PageRequest.of(0, 5);
Page<SearchResponse> response = blueprintService.searchNameAndCreatorWithKeyword(keyword, pageable);
assertThat(response.getTotalElements()).isEqualTo(1);
assertThat(response.getTotalElements()).isEqualTo(6);
}

@DisplayName("id가 1인 Blueprint가 삭제 상태로 변경되는지 확인")
Expand Down