Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ebextensions/build-dev.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ files:

# run app
killall java
java -Dspring.profiles.active=dev -Dfile.encoding=UTF-8 -jar $JAR_PATH
java -Dspring.profiles.active=dev -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Seoul -jar $JAR_PATH
2 changes: 1 addition & 1 deletion .ebextensions/build-prod.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ files:

# run app
killall java
java -Dspring.profiles.active=prod -Dfile.encoding=UTF-8 -jar $JAR_PATH
java -Dspring.profiles.active=prod -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Seoul -jar $JAR_PATH
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
11 changes: 9 additions & 2 deletions src/main/java/com/strcat/controller/BoardController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.strcat.controller;

import com.strcat.domain.Board;
import com.strcat.domain.User;
import com.strcat.dto.CreateBoardReqDto;
import com.strcat.dto.CreateContentReqDto;
import com.strcat.dto.DeleteContentReqDto;
import com.strcat.dto.ReadBoardResDto;
import com.strcat.dto.ReadBoardSummaryResDto;
import com.strcat.dto.ReadPublicBoardResDto;
import com.strcat.service.BoardService;
import com.strcat.service.ContentService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -15,7 +17,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.Optional;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatusCode;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -102,7 +104,7 @@ public ReadBoardSummaryResDto readSummary(@PathVariable(name = "boardId") String
@ApiResponse(responseCode = "401", description = "인증 실패", content = {
@Content(examples = {@ExampleObject("인증 실패")})})
public ReadBoardResDto deleteContents(@PathVariable(name = "boardId") String encryptedBoardId, @RequestBody
DeleteContentReqDto dto, Authentication authentication) {
DeleteContentReqDto dto, Authentication authentication) {
if (authentication == null) {
throw new ResponseStatusException(HttpStatusCode.valueOf(401));
}
Expand All @@ -111,4 +113,9 @@ public ReadBoardResDto deleteContents(@PathVariable(name = "boardId") String enc

return contentService.deleteContent(encryptedBoardId, dto, user);
}

@GetMapping("/public")
public List<ReadPublicBoardResDto> readPublicBoards() {
return boardService.readPublicBoard().stream().map(Board::toReadPublicBoardResDto).toList();
}
}
28 changes: 24 additions & 4 deletions src/main/java/com/strcat/domain/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.strcat.dto.ReadBoardResDto;
import com.strcat.dto.ReadBoardSummaryResDto;
import com.strcat.dto.ReadMyInfoResDto;
import com.strcat.dto.ReadPublicBoardResDto;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -20,7 +21,6 @@
import java.util.List;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

Expand All @@ -46,6 +46,9 @@ public class Board {
@Column(name = "encrypted_id", columnDefinition = "TEXT", unique = true)
private String encryptedId;

@Column(name = "is_public", nullable = false, columnDefinition = "bit(1) default 0")
private Boolean isPublic = false;

@JsonIgnore
@ManyToOne
@JoinColumn(name = "user_id", nullable = false) // 외래키 컬럼 지정
Expand All @@ -58,10 +61,11 @@ public class Board {
@OneToMany(mappedBy = "board", cascade = CascadeType.ALL)
private List<History> history;

public Board(String title, String theme, User user) {
public Board(String title, String theme, User user, Boolean isPublic) {
this.title = title;
this.theme = theme;
this.user = user;
this.isPublic = isPublic;
}

public Long calculateTotalContentLength() {
Expand All @@ -70,8 +74,19 @@ public Long calculateTotalContentLength() {
.sum();
}

public LocalDateTime findLastContentCreatedTime() {
if (!contents.isEmpty()) {
return contents.stream()
.map(Content::getCreatedAt)
.max(LocalDateTime::compareTo)
.orElse(null);
} else {
return createdAt;
}
}

private BoardResponse toBoardResponse() {
return new BoardResponse(encryptedId, title, theme, contents);
return new BoardResponse(encryptedId, title, theme, isPublic, contents);
}

public ReadBoardResDto toReadBoardResDto(Boolean isOwner) {
Expand All @@ -83,6 +98,11 @@ public ReadBoardSummaryResDto toReadBoardSummaryDto() {
}

public ReadMyInfoResDto toReadMyInfoResDto() {
return new ReadMyInfoResDto(encryptedId, title);
return new ReadMyInfoResDto(encryptedId, title, isPublic);
}

public ReadPublicBoardResDto toReadPublicBoardResDto() {
return new ReadPublicBoardResDto(encryptedId, title, theme, findLastContentCreatedTime(), contents.size(),
calculateTotalContentLength());
}
}
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: 3 additions & 0 deletions src/main/java/com/strcat/dto/BoardResponse.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 com.strcat.domain.Content;
import java.util.List;
import lombok.EqualsAndHashCode;
Expand All @@ -15,5 +16,7 @@ public class BoardResponse {
private final String id;
private final String title;
private final String theme;
@JsonProperty("public")
private final Boolean isPublic;
private final List<Content> contents;
}
3 changes: 3 additions & 0 deletions src/main/java/com/strcat/dto/CreateBoardReqDto.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 CreateBoardReqDto {
private final String title;
private final String theme;
@JsonProperty("public")
private final Boolean isPublic;
}
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;
}
22 changes: 22 additions & 0 deletions src/main/java/com/strcat/dto/ReadPublicBoardResDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.strcat.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@RequiredArgsConstructor
@Getter
@EqualsAndHashCode
@ToString
public class ReadPublicBoardResDto {
private final String id;
private final String title;
private final String theme;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul")
private final LocalDateTime lastContentCreatedAt;
private final Integer contentCount;
private final Long contentTextCount;
}
1 change: 1 addition & 0 deletions src/main/java/com/strcat/repository/BoardRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
@Repository
public interface BoardRepository extends JpaRepository<Board, Long> {
Optional<Board> findByEncryptedId(String encryptedId);
List<Board> findByIsPublicTrue();
}
9 changes: 6 additions & 3 deletions src/main/java/com/strcat/service/BoardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BoardService {
public String createBoard(CreateBoardReqDto dto, Long userId) {
Board board;
User user = userRepository.findById(userId).orElseThrow(() -> new NotAcceptableException("유저가 존재하지 않습니다."));
board = new Board(dto.getTitle(), dto.getTheme(), user);
board = new Board(dto.getTitle(), dto.getTheme(), user, dto.getIsPublic());
board = boardRepository.save(board);

String encryptedBoardId = secureDataUtils.encrypt(board.getId());
Expand All @@ -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 All @@ -55,5 +56,7 @@ public ReadBoardSummaryResDto readSummary(String encryptedBoardId) {
.toReadBoardSummaryDto();
}


public List<Board> readPublicBoard() {
return boardRepository.findByIsPublicTrue();
}
}
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());
}
}
Loading