-
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.
Merge pull request #55 from Stumeet/dev
✨ [STMT-146] 분야 정보를 관리하는 도메인 정의 (#54)
- Loading branch information
Showing
20 changed files
with
440 additions
and
20 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
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
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
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
6 changes: 6 additions & 0 deletions
6
...n/java/com/stumeet/server/profession/adapter/out/persistence/JpaProfessionRepository.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,6 @@ | ||
package com.stumeet.server.profession.adapter.out.persistence; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface JpaProfessionRepository extends JpaRepository<ProfessionJpaEntity, Long> { | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/stumeet/server/profession/adapter/out/persistence/ProfessionJpaEntity.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.stumeet.server.profession.adapter.out.persistence; | ||
|
||
import com.stumeet.server.common.model.BaseTimeEntity; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.hibernate.annotations.Comment; | ||
|
||
@Entity | ||
@Table(name = "profession") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Builder | ||
@Getter | ||
public class ProfessionJpaEntity extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Comment("분야 ID") | ||
private Long id; | ||
|
||
@Column(name = "name", nullable = false) | ||
@Comment("이름") | ||
private String name; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "parent_id") | ||
@Comment("대분류 분야") | ||
private ProfessionJpaEntity parent; | ||
} |
23 changes: 23 additions & 0 deletions
23
...a/com/stumeet/server/profession/adapter/out/persistence/ProfessionPersistenceAdapter.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,23 @@ | ||
package com.stumeet.server.profession.adapter.out.persistence; | ||
|
||
import com.stumeet.server.common.annotation.PersistenceAdapter; | ||
import com.stumeet.server.common.exception.model.BusinessException; | ||
import com.stumeet.server.common.response.ErrorCode; | ||
import com.stumeet.server.profession.application.port.out.ProfessionQueryPort; | ||
import com.stumeet.server.profession.domain.Profession; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@PersistenceAdapter | ||
@RequiredArgsConstructor | ||
public class ProfessionPersistenceAdapter implements ProfessionQueryPort { | ||
private final ProfessionPersistenceMapper professionPersistenceMapper; | ||
private final JpaProfessionRepository jpaProfessionRepository; | ||
|
||
@Override | ||
public Profession getById(Long id) { | ||
ProfessionJpaEntity entity = jpaProfessionRepository.findById(id) | ||
.orElseThrow(() -> new BusinessException(ErrorCode.NOT_EXIST_EXCEPTION)); | ||
|
||
return professionPersistenceMapper.toDomain(entity); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...va/com/stumeet/server/profession/adapter/out/persistence/ProfessionPersistenceMapper.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,50 @@ | ||
package com.stumeet.server.profession.adapter.out.persistence; | ||
|
||
import com.stumeet.server.profession.domain.Profession; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ProfessionPersistenceMapper { | ||
|
||
public ProfessionJpaEntity toEntity(Profession domain) { | ||
if (domain == null) { | ||
return null; | ||
} | ||
ProfessionJpaEntity parent = null; | ||
|
||
if (domain.getParent() != null) { | ||
parent = ProfessionJpaEntity.builder() | ||
.id(domain.getId()) | ||
.name(domain.getName()) | ||
.parent(null) | ||
.build(); | ||
} | ||
|
||
return ProfessionJpaEntity.builder() | ||
.id(domain.getId()) | ||
.name(domain.getName()) | ||
.parent(parent) | ||
.build(); | ||
} | ||
|
||
public Profession toDomain(ProfessionJpaEntity entity) { | ||
if (entity == null) { | ||
return null; | ||
} | ||
Profession parent = null; | ||
|
||
if (entity.getParent() != null) { | ||
parent = Profession.builder() | ||
.id(entity.getId()) | ||
.name(entity.getName()) | ||
.parent(null) | ||
.build(); | ||
} | ||
|
||
return Profession.builder() | ||
.id(entity.getId()) | ||
.name(entity.getName()) | ||
.parent(parent) | ||
.build(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/stumeet/server/profession/application/port/in/ProfessionQueryUseCase.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,7 @@ | ||
package com.stumeet.server.profession.application.port.in; | ||
|
||
import com.stumeet.server.profession.domain.Profession; | ||
|
||
public interface ProfessionQueryUseCase { | ||
Profession getById(Long id); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/stumeet/server/profession/application/port/out/ProfessionQueryPort.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,7 @@ | ||
package com.stumeet.server.profession.application.port.out; | ||
|
||
import com.stumeet.server.profession.domain.Profession; | ||
|
||
public interface ProfessionQueryPort { | ||
Profession getById(Long id); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/stumeet/server/profession/application/service/ProfessionQueryService.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,21 @@ | ||
package com.stumeet.server.profession.application.service; | ||
|
||
import com.stumeet.server.common.annotation.UseCase; | ||
import com.stumeet.server.profession.application.port.in.ProfessionQueryUseCase; | ||
import com.stumeet.server.profession.application.port.out.ProfessionQueryPort; | ||
import com.stumeet.server.profession.domain.Profession; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@UseCase | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class ProfessionQueryService implements ProfessionQueryUseCase { | ||
|
||
private final ProfessionQueryPort professionQueryPort; | ||
|
||
@Override | ||
public Profession getById(Long id) { | ||
return professionQueryPort.getById(id); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/stumeet/server/profession/domain/Profession.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,19 @@ | ||
package com.stumeet.server.profession.domain; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Builder | ||
@Getter | ||
public class Profession { | ||
|
||
private Long id; | ||
|
||
private String name; | ||
|
||
private Profession parent; | ||
|
||
} |
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
Oops, something went wrong.