-
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.
Browse files
Browse the repository at this point in the history
feat: load portfolio
- Loading branch information
Showing
14 changed files
with
204 additions
and
27 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
48 changes: 48 additions & 0 deletions
48
src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/portfolio/entity/PortfolioEntity.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,48 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.domain.portfolio.entity; | ||
|
||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.Size; | ||
import kr.hs.dgsw.SOPO_server_v2.domain.member.entity.MemberEntity; | ||
import kr.hs.dgsw.SOPO_server_v2.domain.portfolio.enums.PortfolioState; | ||
import kr.hs.dgsw.SOPO_server_v2.global.common.entity.BaseTimeEntity; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.util.List; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@SuperBuilder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EntityListeners(AuditingEntityListener.class) | ||
@Table(name = "tb_portfolio") | ||
@DynamicUpdate | ||
@AllArgsConstructor | ||
public class PortfolioEntity extends BaseTimeEntity { | ||
@Id | ||
@Column(name = "portfolio_id") | ||
private Long portfolioId; | ||
|
||
|
||
@Column(name = "portfolio_title") | ||
private String portfolioTitle; | ||
|
||
@Builder.Default | ||
@Enumerated(EnumType.STRING) | ||
private PortfolioState portfolioState = PortfolioState.PENDING; | ||
|
||
|
||
@Column(name = "portfolio_content") | ||
private String portfolioContent; | ||
|
||
@OneToOne(fetch = FetchType.LAZY, orphanRemoval = true) | ||
@JoinColumn(name = "portfolio_tag") | ||
private TagEntity tagEntity; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "member_id") | ||
private MemberEntity member; | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/portfolio/entity/TagEntity.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,33 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.domain.portfolio.entity; | ||
|
||
import jakarta.persistence.*; | ||
import kr.hs.dgsw.SOPO_server_v2.domain.member.entity.MemberEntity; | ||
import kr.hs.dgsw.SOPO_server_v2.global.common.entity.BaseTimeEntity; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@Entity | ||
@Getter | ||
@SuperBuilder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EntityListeners(AuditingEntityListener.class) | ||
@Table(name = "tb_tag") | ||
@DynamicUpdate | ||
@AllArgsConstructor | ||
public class TagEntity extends BaseTimeEntity { | ||
@Id | ||
@Column(name = "tag_id") | ||
private Long tagId; | ||
|
||
private String tagName; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "portfolio_id") | ||
private PortfolioEntity portfolioEntity; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "member_id") | ||
private MemberEntity memberEntity; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/portfolio/enums/PortfolioState.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,5 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.domain.portfolio.enums; | ||
|
||
public enum PortfolioState { | ||
PENDING, ACTIVE | ||
} |
28 changes: 28 additions & 0 deletions
28
.../hs/dgsw/SOPO_server_v2/domain/portfolio/presentation/controller/PortfolioController.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 kr.hs.dgsw.SOPO_server_v2.domain.portfolio.presentation.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import kr.hs.dgsw.SOPO_server_v2.domain.portfolio.presentation.dto.res.LoadPortfolioRes; | ||
import kr.hs.dgsw.SOPO_server_v2.domain.portfolio.service.PortfolioService; | ||
import kr.hs.dgsw.SOPO_server_v2.global.page.PageRequest; | ||
import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@Tag(name = "Portfolio", description = "Portfolio Api") | ||
@RestController | ||
@RequestMapping(value = "/portfolio") | ||
@RequiredArgsConstructor | ||
public class PortfolioController { | ||
private final PortfolioService portfolioService; | ||
|
||
@Operation(description = "최신 포트폴리오 불러오기") | ||
@GetMapping | ||
public ResponseData<List<LoadPortfolioRes>> loadPortfolio( | ||
@ModelAttribute PageRequest pageRequest | ||
){ | ||
return portfolioService.pagingPortfolio(pageRequest); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ava/kr/hs/dgsw/SOPO_server_v2/domain/portfolio/presentation/dto/res/LoadPortfolioRes.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,15 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.domain.portfolio.presentation.dto.res; | ||
|
||
import kr.hs.dgsw.SOPO_server_v2.domain.portfolio.entity.PortfolioEntity; | ||
|
||
public record LoadPortfolioRes( | ||
String portfolioTitle, | ||
String memberName | ||
) { | ||
public static LoadPortfolioRes of(PortfolioEntity portfolioEntity) { | ||
return new LoadPortfolioRes( | ||
portfolioEntity.getPortfolioTitle(), | ||
portfolioEntity.getMember().getMemberName() | ||
); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/portfolio/repository/PortfolioRepository.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 kr.hs.dgsw.SOPO_server_v2.domain.portfolio.repository; | ||
|
||
import kr.hs.dgsw.SOPO_server_v2.domain.portfolio.entity.PortfolioEntity; | ||
import kr.hs.dgsw.SOPO_server_v2.domain.portfolio.enums.PortfolioState; | ||
import kr.hs.dgsw.SOPO_server_v2.global.page.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.EntityGraph; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface PortfolioRepository extends JpaRepository<PortfolioEntity, Long> { | ||
|
||
@Query("SELECT p FROM PortfolioEntity p WHERE p.portfolioState = :state ORDER BY p.createdAt DESC") | ||
List<PortfolioEntity> findPortfoliosByState(@Param("state") PortfolioState state); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/portfolio/service/PortfolioService.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,32 @@ | ||
package kr.hs.dgsw.SOPO_server_v2.domain.portfolio.service; | ||
|
||
import kr.hs.dgsw.SOPO_server_v2.domain.portfolio.entity.PortfolioEntity; | ||
import kr.hs.dgsw.SOPO_server_v2.domain.portfolio.enums.PortfolioState; | ||
import kr.hs.dgsw.SOPO_server_v2.domain.portfolio.presentation.dto.res.LoadPortfolioRes; | ||
import kr.hs.dgsw.SOPO_server_v2.domain.portfolio.repository.PortfolioRepository; | ||
import kr.hs.dgsw.SOPO_server_v2.global.page.PageRequest; | ||
import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class PortfolioService { | ||
private final PortfolioRepository portfolioRepository; | ||
|
||
public ResponseData<List<LoadPortfolioRes>> pagingPortfolio(PageRequest pageRequest){ | ||
List<PortfolioEntity> portfolioEntities = portfolioRepository.findPortfoliosByState(PortfolioState.ACTIVE); | ||
|
||
List<LoadPortfolioRes> loadPortfolioReqList = portfolioEntities.stream() | ||
.map(LoadPortfolioRes::of) | ||
.skip((pageRequest.page() - 1) * pageRequest.size()) | ||
.limit(pageRequest.size()) | ||
.collect(Collectors.toList()); | ||
|
||
return ResponseData.of(HttpStatus.OK, "성공", loadPortfolioReqList); | ||
} | ||
} |
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