forked from EveryUniv/next-student-council-backend
-
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.
Merge pull request #10 from gutanbug/feat/trade
feat: 단국거래 게시판 서비스 로직 추가 및 강제 회원가입 수정
- Loading branch information
Showing
11 changed files
with
321 additions
and
18 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
52 changes: 52 additions & 0 deletions
52
src/main/java/com/dku/council/domain/with_dankook/model/dto/TradeImageDto.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,52 @@ | ||
package com.dku.council.domain.with_dankook.model.dto; | ||
|
||
import com.dku.council.domain.with_dankook.model.entity.TradeImage; | ||
import com.dku.council.infra.nhn.s3.service.ObjectUploadContext; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import org.springframework.http.MediaType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public class TradeImageDto { | ||
|
||
@Schema(description = "이미지 아이디", example = "1") | ||
private final Long id; | ||
|
||
@Schema(description = "이미지 url", example = "http://1.2.3.4/1ddee68d-6afb-48d0-9cb6-04a8d8fea4ae.png") | ||
private final String url; | ||
|
||
@Schema(description = "썸네일 이미지 url (없으면 기본 이미지)", example = "http://1.2.3.4/thumb-1ddee68d-6afb-48d0-9cb6-04a8d8fea4ae.png") | ||
private final String thumbnailUrl; | ||
|
||
@Schema(description = "원본이미지 파일 이름", example = "my_image.png") | ||
private final String originalName; | ||
|
||
@Schema(description = "이미지 파일 타입", example = "image/jpeg") | ||
private final String mimeType; | ||
|
||
public TradeImageDto(ObjectUploadContext context, TradeImage image) { | ||
this.id = image.getId(); | ||
this.url = context.getImageUrl(image.getFileId()); | ||
this.thumbnailUrl = context.getThumbnailUrl(image.getThumbnailId()); | ||
this.originalName = image.getFileName(); | ||
|
||
String fileMimeType = image.getMimeType(); | ||
this.mimeType = Objects.requireNonNullElse(fileMimeType, MediaType.APPLICATION_OCTET_STREAM_VALUE); | ||
} | ||
|
||
public static List<TradeImageDto> listOf(ObjectUploadContext context, List<TradeImage> entities) { | ||
List<TradeImage> result = new ArrayList<>(); | ||
|
||
for (TradeImage entity : entities) { | ||
if (entity.getThumbnailId() != null) { | ||
result.add(entity); | ||
} | ||
} | ||
return result.stream() | ||
.map(image -> new TradeImageDto(context, image)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/dku/council/domain/with_dankook/model/dto/list/SummarizedTradeDto.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,37 @@ | ||
package com.dku.council.domain.with_dankook.model.dto.list; | ||
|
||
import com.dku.council.domain.with_dankook.model.dto.TradeImageDto; | ||
import com.dku.council.domain.with_dankook.model.entity.type.Trade; | ||
import com.dku.council.infra.nhn.s3.service.ObjectUploadContext; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
public class SummarizedTradeDto extends SummarizedWithDankookDto{ | ||
|
||
@Schema(description = "제목", example = "게시글 제목") | ||
private final String title; | ||
|
||
@Schema(description = "가격", example = "10000") | ||
private final int price; | ||
|
||
@Schema(description = "내용", example = "게시글 본문") | ||
private final String content; | ||
|
||
@Schema(description = "거래 장소", example = "단국대학교 정문") | ||
private final String tradePlace; | ||
|
||
@Schema(description = "이미지 목록") | ||
private final List<TradeImageDto> images; | ||
|
||
public SummarizedTradeDto(SummarizedWithDankookDto dto, Trade trade, ObjectUploadContext context){ | ||
super(dto); | ||
this.title = trade.getTitle(); | ||
this.price = trade.getPrice(); | ||
this.content = trade.getContent(); | ||
this.tradePlace = trade.getTradePlace(); | ||
this.images = TradeImageDto.listOf(context, trade.getImages()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ain/java/com/dku/council/domain/with_dankook/model/dto/list/SummarizedWithDankookDto.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,37 @@ | ||
package com.dku.council.domain.with_dankook.model.dto.list; | ||
|
||
import com.dku.council.domain.with_dankook.model.entity.WithDankook; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
public class SummarizedWithDankookDto { | ||
|
||
@Schema(description = "With-Dankook 게시글 아이디", example = "1") | ||
private final Long id; | ||
|
||
@Schema(description = "작성자", example = "익명") | ||
private final String author; | ||
|
||
@Schema(description = "생성 날짜") | ||
private final LocalDateTime createdAt; | ||
|
||
@Schema(description = "채팅 링크", example = "https://open.kakao.com/o/ghjgjgjg") | ||
private final String chatLink; | ||
|
||
public SummarizedWithDankookDto(int bodySize, WithDankook withDankook) { | ||
this.id = withDankook.getId(); | ||
this.author = withDankook.getDisplayingUsername(); | ||
this.createdAt = withDankook.getCreatedAt(); | ||
this.chatLink = withDankook.getChatLink(); | ||
} | ||
|
||
public SummarizedWithDankookDto(SummarizedWithDankookDto copy) { | ||
this.id = copy.getId(); | ||
this.author = copy.getAuthor(); | ||
this.createdAt = copy.getCreatedAt(); | ||
this.chatLink = copy.getChatLink(); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/dku/council/domain/with_dankook/repository/spec/WithDankookSpec.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,26 @@ | ||
package com.dku.council.domain.with_dankook.repository.spec; | ||
|
||
import com.dku.council.domain.with_dankook.model.WithDankookStatus; | ||
import com.dku.council.domain.with_dankook.model.entity.WithDankook; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
public class WithDankookSpec { | ||
|
||
public static <T extends WithDankook> Specification<T> withActive() { | ||
return (root, query, builder) -> | ||
builder.equal(root.get("withDankookStatus"), WithDankookStatus.ACTIVE); | ||
} | ||
|
||
public static <T extends WithDankook> Specification<T> withTitleOrBody(String keyword) { | ||
if (keyword == null || keyword.equals("null")) { | ||
return Specification.where(null); | ||
} | ||
|
||
String pattern = "%" + keyword + "%"; | ||
return (root, query, builder) -> | ||
builder.or( | ||
builder.like(root.get("title"), pattern), | ||
builder.like(root.get("content"), pattern) | ||
); | ||
} | ||
} |
Oops, something went wrong.