Skip to content

Commit

Permalink
Merge pull request #667 from peer-42seoul/665-feat-팀-설정페이지-쇼케이스-상태정보
Browse files Browse the repository at this point in the history
feat:getShowcasePageInfo, changetShowcasePublic api
  • Loading branch information
weejihye authored Jan 23, 2024
2 parents 9326d6c + 14c61bf commit d249189
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion private-resources
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ public Long createShowcase(@RequestBody @Valid ShowcaseCreateDto request, Authen
public ResponseEntity<Object> deleteShowcase(@PathVariable Long showcaseId, Authentication auth){
return showcaseService.deleteShowcase(showcaseId, User.authenticationToUser(auth));
}

@GetMapping("/page/{teamId}")
public ShowcasePageInfoResponse getShowcasePageInfo(@PathVariable Long teamId, Authentication auth){
return showcaseService.getShowcasePageInfo(teamId, User.authenticationToUser(auth));
}

@PostMapping("/public/{showcaseId}")
public boolean changeShowcasePublic(@PathVariable Long showcaseId, Authentication auth){
return showcaseService.changeShowcasePublic(showcaseId, User.authenticationToUser(auth));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package peer.backend.dto.board.team;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@AllArgsConstructor
@Builder
@JsonIgnoreProperties({"published", "public"})
public class ShowcasePageInfoResponse {
@JsonProperty("isPublished")
private boolean isPublihsed;
@JsonProperty("isPublic")
private boolean isPublic;
private Long showcaseId;
}
8 changes: 8 additions & 0 deletions src/main/java/peer/backend/entity/board/team/Post.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package peer.backend.entity.board.team;

import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import peer.backend.dto.board.team.PostLinkResponse;
import peer.backend.dto.board.team.PostUpdateRequest;
import peer.backend.dto.board.team.ShowcaseUpdateDto;
Expand Down Expand Up @@ -43,6 +44,9 @@ public class Post extends BaseEntity{
@Column(nullable = false)
private String title;

@Column
private boolean isPublic = true;

@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<UserPortfolio> userPortfolioHistories;

Expand All @@ -59,6 +63,10 @@ public class Post extends BaseEntity{
@OneToMany(mappedBy = "post", cascade = CascadeType.PERSIST, orphanRemoval = true)
private List<PostLink> links;

public void changeIsPublic(){
this.isPublic = !this.isPublic;
}

public void update(PostUpdateRequest request){
this.title = request.getTitle();
this.content = request.getContent();
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/peer/backend/service/board/team/ShowcaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,34 @@ public ResponseEntity<Object> deleteShowcase(Long showcaseId, User user){
boardRepository.delete(post.getBoard());
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

@Transactional
public ShowcasePageInfoResponse getShowcasePageInfo(Long teamId, User user) {
if (!teamService.isLeader(teamId, user))
throw new ForbiddenException("리더가 아닙니다.");
Optional<Post> post = postRepository.findByBoardTeamIdAndBoardType(teamId, BoardType.SHOWCASE);
if (post.isEmpty())
return ShowcasePageInfoResponse.builder()
.isPublihsed(false)
.isPublic(false)
.showcaseId(0L)
.build();
Post showcase = post.get();
return ShowcasePageInfoResponse.builder()
.isPublihsed(true)
.isPublic(showcase.isPublic())
.showcaseId(showcase.getId())
.build();
}

@Transactional
public boolean changeShowcasePublic(Long showcaseId, User user){
Post post = postRepository.findById(showcaseId)
.orElseThrow(() -> new NotFoundException("존재하지 않는 쇼케이스입니다."));
if (!teamService.isLeader(post.getBoard().getTeam().getId(), user))
throw new ForbiddenException("리더가 아닙니다.");
post.changeIsPublic();

return post.isPublic();
}
}

0 comments on commit d249189

Please sign in to comment.