-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
307 additions
and
175 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
server: | ||
port: 8080 | ||
|
||
spring: | ||
profiles: | ||
group: | ||
"local": "db, secret, s3, redis, email, firebase, security" | ||
"prod": "db, secret, s3, redis, email, firebase, security" | ||
default: local | ||
|
||
servlet: | ||
multipart: | ||
max-file-size: 20MB | ||
max-request-size: 20MB |
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
111 changes: 111 additions & 0 deletions
111
api/src/test/java/com/sponus/sponusbe/domain/organization/OrganizationServiceTest.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,111 @@ | ||
package com.sponus.sponusbe.domain.organization; | ||
|
||
import java.util.List; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.sponus.coredomain.domain.organization.Organization; | ||
import com.sponus.coredomain.domain.organization.enums.OrganizationType; | ||
import com.sponus.coredomain.domain.organization.enums.ProfileStatus; | ||
import com.sponus.sponusbe.domain.organization.dto.request.PageCondition; | ||
import com.sponus.sponusbe.domain.organization.dto.response.OrganizationSearchResponse; | ||
import com.sponus.sponusbe.domain.organization.dto.response.PageResponse; | ||
import com.sponus.sponusbe.domain.organization.service.OrganizationService; | ||
|
||
import jakarta.persistence.EntityManager; | ||
|
||
@SpringBootTest | ||
@Transactional | ||
@ActiveProfiles("test") | ||
class OrganizationServiceTest { | ||
|
||
@Autowired | ||
OrganizationService organizationService; | ||
|
||
@Autowired | ||
EntityManager em; | ||
|
||
@BeforeEach | ||
public void init() { | ||
for (int i = 1; i <= 5; i++) { | ||
Organization organization = Organization.builder() | ||
.email("sponus_company" + i + "@gmail.com") | ||
.name("sponus_company" + i) | ||
.password("sponus_company1234#") | ||
.organizationType(OrganizationType.COMPANY) | ||
.profileStatus(ProfileStatus.ACTIVE) | ||
.build(); | ||
|
||
em.persist(organization); | ||
} | ||
em.flush(); | ||
em.clear(); | ||
} | ||
|
||
@Test | ||
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) | ||
void searchV1() { | ||
// given | ||
PageCondition pageCondition = new PageCondition(0, 10); | ||
|
||
// when | ||
PageResponse<OrganizationSearchResponse> searchOrganizations = organizationService.searchOrganizations( | ||
pageCondition, "sponus", null); | ||
|
||
// then | ||
List<String> expectedOrganizationNames = List.of( | ||
"sponus_company1", | ||
"sponus_company2", | ||
"sponus_company3", | ||
"sponus_company4", | ||
"sponus_company5"); | ||
List<String> actualOrganizationNames = searchOrganizations.content().stream() | ||
.map(OrganizationSearchResponse::name) | ||
.toList(); | ||
|
||
System.out.println("========================"); | ||
for (String actualOrganizationName : actualOrganizationNames) { | ||
System.out.println(actualOrganizationName); | ||
} | ||
System.out.println("========================"); | ||
|
||
Assertions.assertThat(actualOrganizationNames).containsExactlyInAnyOrderElementsOf(expectedOrganizationNames); | ||
} | ||
|
||
@Test | ||
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) | ||
void searchV2() { | ||
// given | ||
PageCondition pageCondition = new PageCondition(0, 10); | ||
|
||
// when | ||
PageResponse<OrganizationSearchResponse> searchOrganizations = organizationService.searchOrganizationsV2( | ||
pageCondition, "sponus", null); | ||
|
||
// then | ||
List<String> expectedOrganizationNames = List.of( | ||
"sponus_company1", | ||
"sponus_company2", | ||
"sponus_company3", | ||
"sponus_company4", | ||
"sponus_company5"); | ||
List<String> actualOrganizationNames = searchOrganizations.content().stream() | ||
.map(OrganizationSearchResponse::name) | ||
.toList(); | ||
|
||
System.out.println("========================"); | ||
for (String actualOrganizationName : actualOrganizationNames) { | ||
System.out.println(actualOrganizationName); | ||
} | ||
System.out.println("========================"); | ||
|
||
Assertions.assertThat(actualOrganizationNames).containsExactlyInAnyOrderElementsOf(expectedOrganizationNames); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
...va/com/sponus/coredomain/domain/organization/repository/OrganizationRepositoryCustom.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,12 @@ | ||
package com.sponus.coredomain.domain.organization.repository; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import com.sponus.coredomain.domain.organization.Organization; | ||
import com.sponus.coredomain.domain.organization.repository.conditions.OrganizationSearchCondition; | ||
|
||
public interface OrganizationRepositoryCustom { | ||
|
||
Page<Organization> searchOrganizationV2(OrganizationSearchCondition condition, Pageable pageable); | ||
} |
66 changes: 66 additions & 0 deletions
66
...om/sponus/coredomain/domain/organization/repository/OrganizationRepositoryCustomImpl.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,66 @@ | ||
package com.sponus.coredomain.domain.organization.repository; | ||
|
||
import static com.sponus.coredomain.domain.organization.QOrganization.*; | ||
import static org.springframework.util.StringUtils.*; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.support.PageableExecutionUtils; | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import com.sponus.coredomain.domain.organization.Organization; | ||
import com.sponus.coredomain.domain.organization.enums.ProfileStatus; | ||
import com.sponus.coredomain.domain.organization.repository.conditions.OrganizationSearchCondition; | ||
|
||
import jakarta.persistence.EntityManager; | ||
|
||
public class OrganizationRepositoryCustomImpl implements OrganizationRepositoryCustom { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
public OrganizationRepositoryCustomImpl(EntityManager em) { | ||
this.queryFactory = new JPAQueryFactory(em); | ||
} | ||
|
||
@Override | ||
public Page<Organization> searchOrganizationV2(OrganizationSearchCondition condition, Pageable pageable) { | ||
|
||
List<Organization> content = queryFactory | ||
.selectFrom(organization) | ||
.where( | ||
keywordContains(condition.keyword()), | ||
organizationIdNotEq(condition.organizationId()), | ||
isActive() | ||
) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.fetch(); | ||
|
||
long count = queryFactory | ||
.selectFrom(organization) | ||
.where( | ||
keywordContains(condition.keyword()), | ||
organizationIdNotEq(condition.organizationId()), | ||
isActive() | ||
) | ||
.fetch() | ||
.size(); | ||
|
||
return PageableExecutionUtils.getPage(content, pageable, () -> count); | ||
} | ||
|
||
private BooleanExpression keywordContains(String keyword) { | ||
return hasText(keyword) ? organization.name.containsIgnoreCase(keyword) : null; | ||
} | ||
|
||
private BooleanExpression organizationIdNotEq(Long organizationId) { | ||
return organizationId != null ? organization.id.ne(organizationId) : null; | ||
} | ||
|
||
private BooleanExpression isActive() { | ||
return organization.profileStatus.eq(ProfileStatus.ACTIVE); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...nus/coredomain/domain/organization/repository/conditions/OrganizationSearchCondition.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,16 @@ | ||
package com.sponus.coredomain.domain.organization.repository.conditions; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record OrganizationSearchCondition( | ||
String keyword, | ||
Long organizationId | ||
) { | ||
public static OrganizationSearchCondition of(String keyword, Long organizationId) { | ||
return OrganizationSearchCondition.builder() | ||
.keyword(keyword) | ||
.organizationId(organizationId) | ||
.build(); | ||
} | ||
} |
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
56 changes: 33 additions & 23 deletions
56
core/core-infra-db/out/production/resources/application-db.yml
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,41 +1,51 @@ | ||
spring.config.activate.on-profile: local | ||
|
||
spring: | ||
config: | ||
activate: | ||
on-profile: local | ||
datasource: | ||
driver-class-name: org.postgresql.Driver | ||
url: jdbc:postgresql://localhost:5432/postgres | ||
username: postgres | ||
password: postgres! | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: jdbc:mysql://localhost:3307/sponus | ||
username: root | ||
password: root1234! | ||
jpa: | ||
database: postgresql | ||
database: mysql | ||
hibernate: | ||
ddl-auto: create-drop | ||
ddl-auto: create | ||
open-in-view: false | ||
show-sql: true | ||
generate-ddl: true | ||
defer-datasource-initialization: true | ||
|
||
sql: | ||
init: | ||
mode: always | ||
|
||
--- | ||
spring.config.activate.on-profile: prod | ||
|
||
spring: | ||
config: | ||
activate: | ||
on-profile: prod | ||
datasource: | ||
driver-class-name: org.postgresql.Driver | ||
url: ${DB_URL} | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: jdbc:mysql://${DB_URL} | ||
username: ${DB_USERNAME} | ||
password: ${DB_PW} | ||
password: ${DB_PASSWORD} | ||
|
||
jpa: | ||
database: postgresql | ||
database: mysql | ||
hibernate: | ||
ddl-auto: update | ||
open-in-view: false | ||
show-sql: true | ||
generate-ddl: true | ||
|
||
--- | ||
spring.config.activate.on-profile: test | ||
|
||
spring: | ||
datasource: | ||
driver-class-name: org.h2.Driver | ||
url: jdbc:h2:mem:sponus;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE | ||
username: sa | ||
password: | ||
jpa: | ||
hibernate: | ||
ddl-auto: create-drop | ||
open-in-view: false | ||
show-sql: true | ||
|
||
data: | ||
redis: | ||
host: localhost | ||
port: 6379 |
Oops, something went wrong.