Skip to content

Commit

Permalink
feat: 보드 조회 및 드로워에서 isPublic 정보를 함께 읽어오도록 수정함
Browse files Browse the repository at this point in the history
  • Loading branch information
eesum committed Apr 12, 2024
1 parent ffddcc6 commit 2d3cac4
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
implementation platform('software.amazon.awssdk:bom:2.21.27')
implementation("software.amazon.awssdk:s3")
implementation "org.jboss.logging:jboss-logging:3.5.3.Final"
implementation 'software.amazon.awssdk:sts'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.3'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/strcat/domain/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ public ReadBoardSummaryResDto toReadBoardSummaryDto() {
}

public ReadMyInfoResDto toReadMyInfoResDto() {
return new ReadMyInfoResDto(encryptedId, title);
return new ReadMyInfoResDto(encryptedId, title, isPublic);
}
}
10 changes: 1 addition & 9 deletions src/main/java/com/strcat/domain/History.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.strcat.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.strcat.dto.HistoryDto;
import com.strcat.dto.HistoryItem;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
Expand All @@ -12,16 +10,10 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.apache.commons.lang3.builder.HashCodeExclude;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Entity
Expand Down Expand Up @@ -55,6 +47,6 @@ public History(User user, Board board, LocalDateTime visitedAt) {
}

public HistoryItem toDto() {
return new HistoryItem(board.getEncryptedId(), board.getTitle(), visitedAt);
return new HistoryItem(board.getEncryptedId(), board.getTitle(), board.getIsPublic(), visitedAt);
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/strcat/dto/HistoryItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.strcat.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;

Expand All @@ -11,7 +12,7 @@
"visitTime": "2024-02-07 07:54:54"
}
""")
public record HistoryItem(String encryptedBoardId, String title,
public record HistoryItem(String encryptedBoardId, String title, @JsonProperty("public") Boolean isPublic,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul")
LocalDateTime visitTime) {
}
1 change: 0 additions & 1 deletion src/main/java/com/strcat/dto/ReadBoardResDto.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.strcat.dto;

import com.strcat.domain.Board;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/strcat/dto/ReadMyInfoResDto.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.strcat.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -8,4 +9,6 @@
public class ReadMyInfoResDto {
private final String id;
private final String title;
@JsonProperty("public")
private final Boolean isPublic;
}
3 changes: 2 additions & 1 deletion src/main/java/com/strcat/service/BoardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public ReadBoardResDto readBoard(String encryptedBoardId, Long userId) {
.orElseThrow(() -> new NotAcceptableException("존재하지 않는 보드입니다."));
if (userId != null) {
recordHistoryUseCase.write(userId,
List.of(new HistoryItem(encryptedBoardId, board.getTitle(), LocalDateTime.now())));
List.of(new HistoryItem(encryptedBoardId, board.getTitle(), board.getIsPublic(),
LocalDateTime.now())));

Boolean isOwner = userId.equals(board.getUser().getId());
return board.toReadBoardResDto(isOwner);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/strcat/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import jakarta.transaction.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -65,7 +64,7 @@ public List<ReadMyInfoResDto> readMyBoardInfo(Long userId) {
List<Board> boards = user.getBoards();
return boards.stream()
.map(Board::toReadMyInfoResDto)
.collect(Collectors.toList());
.toList();
}


Expand All @@ -82,6 +81,7 @@ public HistoryDto postMyBoardHistory(Long userId, HistoryDto dto) {

return new HistoryDto(result.stream()
.map((history -> new HistoryItem(history.getBoard().getEncryptedId(), history.getBoard().getTitle(),
history.getBoard().getIsPublic(),
history.getVisitedAt()))).toList());
}
}
8 changes: 4 additions & 4 deletions src/test/java/com/strcat/user/UserServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class UserServiceTest {
private final UserService userService;
private final UserRepository userRepository;
private final BoardRepository boardRepository;
private final HistoryRepository historyRepository;
private final SecureDataUtils secureDataUtils;
private User me;
private List<Board> boards;
Expand All @@ -40,7 +39,6 @@ public UserServiceTest(UserRepository userRepository, BoardRepository boardRepos
HistoryRepository historyRepository) {
this.boardRepository = boardRepository;
this.userRepository = userRepository;
this.historyRepository = historyRepository;
this.secureDataUtils = new SecureDataUtils("testtesttesttesttesttesttesttest");
JwtUtils jwtUtils = new JwtUtils("testtesttesttesttesttesttesttesttesttest");
this.userService = new UserService(userRepository, boardRepository, historyRepository, jwtUtils);
Expand Down Expand Up @@ -70,7 +68,8 @@ public void beforeEach() {
public void 최근기록저장_성공() {
//given
List<HistoryItem> history = boards.stream()
.map((board) -> new HistoryItem(board.getEncryptedId(), board.getTitle(), LocalDateTime.now()))
.map((board) -> new HistoryItem(board.getEncryptedId(), board.getTitle(), board.getIsPublic(),
LocalDateTime.now()))
.toList();
HistoryDto historyDto = new HistoryDto(history);

Expand All @@ -87,7 +86,8 @@ public void beforeEach() {
User user = userRepository.findById(me.getId()).orElseThrow();
LocalDateTime now = LocalDateTime.now();
List<HistoryItem> history = boards.stream()
.map((board) -> new HistoryItem(board.getEncryptedId(), board.getTitle(), now)).toList();
.map((board) -> new HistoryItem(board.getEncryptedId(), board.getTitle(), board.getIsPublic(), now))
.toList();
HistoryDto historyDto = new HistoryDto(history);
user.setHistories(boards.stream().map((board) -> new History(user, board, now)).toList());
userService.postMyBoardHistory(user.getId(), historyDto);
Expand Down

0 comments on commit 2d3cac4

Please sign in to comment.