Skip to content

Commit

Permalink
Merge pull request #56 from Sopo2023/feat/#55
Browse files Browse the repository at this point in the history
feat: load portfolio
  • Loading branch information
GayeongKimm authored Aug 1, 2024
2 parents 7c426ee + 5e45314 commit e493e57
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import kr.hs.dgsw.SOPO_server_v2.domain.auth.dto.req.ReProvideTokenReq;
import kr.hs.dgsw.SOPO_server_v2.domain.auth.dto.req.SignInReq;
import kr.hs.dgsw.SOPO_server_v2.domain.auth.dto.req.SignUpReq;
import kr.hs.dgsw.SOPO_server_v2.domain.auth.dto.res.ReProvideTokenRes;
import kr.hs.dgsw.SOPO_server_v2.domain.auth.dto.res.TokenRes;
import kr.hs.dgsw.SOPO_server_v2.domain.auth.service.AuthEmailService;
import kr.hs.dgsw.SOPO_server_v2.domain.auth.service.AuthService;
import kr.hs.dgsw.SOPO_server_v2.domain.auth.service.AuthTokenService;
import kr.hs.dgsw.SOPO_server_v2.global.common.dto.res.JsonWebTokenResponse;
import kr.hs.dgsw.SOPO_server_v2.global.response.Response;
import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "Auth", description = "Auth Api")
@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import kr.hs.dgsw.SOPO_server_v2.domain.file.entity.FileEntity;
import kr.hs.dgsw.SOPO_server_v2.domain.member.enums.MemberCategory;
import kr.hs.dgsw.SOPO_server_v2.domain.member.enums.MemberState;
import kr.hs.dgsw.SOPO_server_v2.domain.portfolio.entity.PortfolioEntity;
import kr.hs.dgsw.SOPO_server_v2.global.common.entity.BaseTimeEntity;
import lombok.*;
import lombok.experimental.SuperBuilder;
Expand Down Expand Up @@ -56,4 +57,8 @@ public class MemberEntity extends BaseTimeEntity {
@OneToOne(fetch = FetchType.LAZY, orphanRemoval = true)
@JoinColumn(name = "member_file")
private FileEntity memberProfile;

@OneToOne(fetch = FetchType.LAZY, orphanRemoval = true)
@JoinColumn(name = "member_portfolio")
private PortfolioEntity portfolioEntity;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import kr.hs.dgsw.SOPO_server_v2.domain.member.presentation.dto.req.MemberModifyReq;
import kr.hs.dgsw.SOPO_server_v2.domain.member.presentation.dto.res.ReadProfileRes;
import kr.hs.dgsw.SOPO_server_v2.domain.member.service.MemberProfileService;
import kr.hs.dgsw.SOPO_server_v2.domain.member.service.MemberService;
import kr.hs.dgsw.SOPO_server_v2.global.response.Response;
import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "Member", description = "Member Api")
@RestController
Expand All @@ -22,9 +23,4 @@ public class MemberController {
public Response deleteMember(){
return memberService.deleteMember();
}
@Operation(description = "나의 프로필 보기")
@GetMapping
public ResponseData<ReadProfileRes> readProfile(){
return memberService.readProfile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ public Response modifyMember(
@RequestBody MemberModifyReq memberModifyReq) {
return memberProfileService.memberModify(memberModifyReq);
}

@Operation(description = "나의 프로필 보기")
@GetMapping
public ResponseData<ReadProfileRes> readProfile(){
return memberProfileService.readProfile();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ public Response memberModify(MemberModifyReq memberModifyReq) {
return Response.of(HttpStatus.OK, "성공");
}

@Transactional(rollbackFor = Exception.class)
public ResponseData<ReadProfileRes> readProfile(){
MemberEntity member = getCurrentMember.current();

return ResponseData.of(HttpStatus.OK, "조회 성공", ReadProfileRes.of(memberRepository.findByMemberId(member.getMemberId())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import kr.hs.dgsw.SOPO_server_v2.domain.member.entity.MemberEntity;
import kr.hs.dgsw.SOPO_server_v2.domain.member.enums.MemberState;
import kr.hs.dgsw.SOPO_server_v2.domain.member.presentation.dto.res.ReadProfileRes;
import kr.hs.dgsw.SOPO_server_v2.domain.member.repository.MemberRepository;
import kr.hs.dgsw.SOPO_server_v2.global.error.custom.member.MemberNotCoincideException;
import kr.hs.dgsw.SOPO_server_v2.global.infra.security.GetCurrentMember;
import kr.hs.dgsw.SOPO_server_v2.global.response.Response;
import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
Expand All @@ -16,22 +13,13 @@
@Component
@RequiredArgsConstructor
public class MemberService {

private final MemberRepository memberRepository;
private final GetCurrentMember getCurrentMember;

@Transactional(rollbackFor = Exception.class)
public Response deleteMember(){
MemberEntity member = getCurrentMember.current();
member.setMemberState(MemberState.DELETED);
return Response.of(HttpStatus.OK, "성공");
}

@Transactional(rollbackFor = Exception.class)
public ResponseData<ReadProfileRes> readProfile(){
MemberEntity member = getCurrentMember.current();

return ResponseData.of(HttpStatus.OK, "조회 성공", ReadProfileRes.of(memberRepository.findByMemberId(member.getMemberId())));
}
}

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;
}
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;
}
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
}
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);
}
}
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()
);
}
}
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);
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers("/member/**").hasAuthority("ROLE_ACTIVE")
.requestMatchers("/contest/**").hasAuthority("ROLE_ACTIVE")
.requestMatchers("/like/**").hasAuthority("ROLE_ACTIVE")
.requestMatchers("/profile/**").hasAuthority("ROLE_ACTIVE")
.anyRequest().authenticated()
.and()
.formLogin().disable()
Expand Down

0 comments on commit e493e57

Please sign in to comment.