-
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 remote-tracking branch 'origin/feat/community' into dev-check
- Loading branch information
Showing
38 changed files
with
1,045 additions
and
97 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
110 changes: 110 additions & 0 deletions
110
src/main/java/com/numberone/backend/domain/article/controller/ArticleController.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,110 @@ | ||
package com.numberone.backend.domain.article.controller; | ||
|
||
import com.numberone.backend.domain.article.dto.request.UploadArticleRequest; | ||
import com.numberone.backend.domain.article.dto.response.*; | ||
import com.numberone.backend.domain.article.service.ArticleService; | ||
import com.numberone.backend.domain.comment.dto.request.CreateCommentRequest; | ||
import com.numberone.backend.domain.comment.dto.response.CreateCommentResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.net.URI; | ||
|
||
@Slf4j | ||
@RequestMapping("/api/articles") | ||
@RequiredArgsConstructor | ||
@RestController | ||
public class ArticleController { | ||
|
||
private final ArticleService articleService; | ||
|
||
|
||
@Operation(summary = "게시글 작성 API", description = """ | ||
동네생활 게시글 등록 api 입니다. | ||
반드시 access token 을 헤더에 담아서 요청해주세요. | ||
1. title 은 글 제목 입니다 (not null) | ||
2. content 는 글 내용 입니다 (not null) | ||
3. articleTag 는 게시글 태그 입니다. LIFE(일상), FRAUD(사기), SAFETY(안전), REPORT(제보) | ||
4. imageList 는 이미지 (MultiPart) 리스트 입니다. | ||
5. thumbNailImageIdx 는 썸네일 이미지의 인덱스 입니다. (0,1,2, ... | ||
imageList 에 이미지를 담아서 보내는 경우, | ||
idx 에 따라서 썸네일 이미지를 결정합니다. | ||
""") | ||
|
||
@PostMapping | ||
public ResponseEntity<UploadArticleResponse> uploadArticle(@RequestBody @Valid UploadArticleRequest request) { | ||
return ResponseEntity.created(URI.create("/api/articles")) | ||
.body(articleService.uploadArticle(request)); | ||
} | ||
|
||
@Operation(summary = "게시글을 삭제하는 API 입니다.", description = """ | ||
게시글 id 를 PathVariable 으로 넘겨주세요. | ||
해당 게시글을 삭제 상태로 변경합니다. | ||
""") | ||
@PutMapping("{article-id}/delete") | ||
public ResponseEntity<DeleteArticleResponse> deleteArticle(@PathVariable("article-id") Long articleId) { | ||
return ResponseEntity.ok(articleService.deleteArticle(articleId)); | ||
} | ||
|
||
@Operation(summary = "게시글 상세 조회 API 입니다.", description = """ | ||
게시글 id 를 PathVariable 으로 넘겨주세요. | ||
""") | ||
@GetMapping("{article-id}") | ||
public ResponseEntity<GetArticleDetailResponse> getArticleDetails(@PathVariable("article-id") Long articleId) { | ||
return ResponseEntity.ok(articleService.getArticleDetail(articleId)); | ||
} | ||
|
||
|
||
@Operation(summary = "게시글 리스트 조회 no offset Paging API 입니다.", description = """ | ||
요청 예시 url 은 다음과 같습니다. | ||
`/api/articles?size=5` | ||
size 는 페이지의 사이즈를 의미하고, default 는 20 입니다. | ||
정렬 순서는 articleId 순입니다. ( = 생성 시간 순 ) | ||
ModelAttribute 로 lastArticleId 와 tag 를 넘겨주세요 ( 둘 다 nullable ) | ||
tag 가 null 이면, tag 상관 없이 전체 조회를 수행합니다. | ||
tag 가 null 이 아니면, 해당 tag 에 해당하는 게시글만 조회합니다. | ||
lastArticleId 는 직전에 조회한 게시글 중 가장 먀지막(작은) articleId 를 의미합니다. | ||
- 첫 페이지를 요청할 경우에는 lastArticleId 를 null 로 보내야합니다. | ||
- 첫 페이지 이후에 대한 요청은, 직전 페이지 요청에서 얻어온 lastArticleId 를 넣어서 보내면 그 다음 페이지를 호출합니다. | ||
""") | ||
@GetMapping | ||
public ResponseEntity<Slice<GetArticleListResponse>> getArticlePages( | ||
Pageable pageable, | ||
@ModelAttribute ArticleSearchParameter param) { | ||
return ResponseEntity.ok(articleService.getArticleListPaging(param, pageable)); | ||
} | ||
|
||
@Operation(summary = "게시글에 댓글 작성하기", description = """ | ||
게시글에 댓글을 작성하는 API 입니다. | ||
게시글 아이디는 Path Parameter 으로 넘겨주세요 (article-id) | ||
""") | ||
@PostMapping("comments/{article-id}") | ||
public ResponseEntity<CreateCommentResponse> createComment( | ||
@PathVariable("article-id") Long articleId, | ||
@RequestBody @Valid CreateCommentRequest request) { | ||
return ResponseEntity.created( | ||
URI.create(String.format("/api/articles/comment/%s", articleId))) | ||
.body(articleService.createComment(articleId, request)); | ||
|
||
} | ||
|
||
|
||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/numberone/backend/domain/article/dto/request/UploadArticleRequest.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,35 @@ | ||
package com.numberone.backend.domain.article.dto.request; | ||
|
||
import com.numberone.backend.domain.article.entity.ArticleTag; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.util.List; | ||
|
||
@ToString | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class UploadArticleRequest { | ||
|
||
// 글 관련 | ||
@NotNull(message = "글 제목은 null 일 수 없습니다.") | ||
private String title; // 제목 | ||
|
||
@NotNull(message = "내용은 null 일 수 없습니다.") | ||
private String content; // 내용 | ||
|
||
@NotNull(message = """ | ||
게시글의 태그를 하나 선택해주세요. | ||
LIFE(일상), FRAUD(사기), SAFETY(안전), REPORT(제보) | ||
""") | ||
private ArticleTag articleTag; // 게시글 태그 | ||
|
||
// 이미지 관련 | ||
private List<MultipartFile> imageList; // 이미지 리스트 | ||
private Long thumbNailImageIdx; // 썸네일 이미지의 순서 (0,1,2,...) | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/numberone/backend/domain/article/dto/response/ArticleSearchParameter.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,14 @@ | ||
package com.numberone.backend.domain.article.dto.response; | ||
|
||
import com.numberone.backend.domain.article.entity.ArticleTag; | ||
import lombok.*; | ||
|
||
@ToString | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class ArticleSearchParameter { | ||
private ArticleTag tag; | ||
private Long lastArticleId; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/numberone/backend/domain/article/dto/response/DeleteArticleResponse.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,24 @@ | ||
package com.numberone.backend.domain.article.dto.response; | ||
|
||
import com.numberone.backend.domain.article.entity.Article; | ||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@ToString | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class DeleteArticleResponse { | ||
|
||
private Long id; | ||
private LocalDateTime deletedAt; | ||
|
||
public static DeleteArticleResponse of(Article article){ | ||
return DeleteArticleResponse.builder() | ||
.id(article.getId()) | ||
.deletedAt(article.getModifiedAt()) | ||
.build(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...main/java/com/numberone/backend/domain/article/dto/response/GetArticleDetailResponse.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,57 @@ | ||
package com.numberone.backend.domain.article.dto.response; | ||
|
||
import com.numberone.backend.domain.article.entity.Article; | ||
import com.numberone.backend.domain.member.entity.Member; | ||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@ToString | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class GetArticleDetailResponse { | ||
|
||
// 게시글 관련 | ||
private Long articleId; | ||
private Integer likeCount; | ||
private LocalDateTime createdAt; | ||
private LocalDateTime modifiedAt; | ||
private String title; | ||
private String content; | ||
|
||
// 작성자 관련 | ||
private String memberName; | ||
private String memberNickName; | ||
private String address; // todo: 더미 데이터 | ||
private Long ownerMemberId; | ||
|
||
// 이미지 관련 | ||
private List<String> imageUrls; | ||
private String thumbNailImageUrl; | ||
|
||
public static GetArticleDetailResponse of(Article article, List<String> imageUrls, String thumbNailImageUrl, Member member){ | ||
return GetArticleDetailResponse.builder() | ||
.articleId(article.getId()) | ||
.title(article.getTitle()) | ||
.content(article.getContent()) | ||
.likeCount( | ||
Optional.ofNullable( | ||
article.getLikeCount() | ||
).orElse(0) | ||
) | ||
.createdAt(article.getCreatedAt()) | ||
.modifiedAt(article.getModifiedAt()) | ||
.ownerMemberId(member.getId()) | ||
.memberName(member.getRealName()) | ||
.memberNickName(member.getNickName()) | ||
.imageUrls(imageUrls) | ||
.thumbNailImageUrl(thumbNailImageUrl) | ||
.address("서울시 광진구 자양동") // 교체 | ||
.build(); | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/com/numberone/backend/domain/article/dto/response/GetArticleListResponse.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,72 @@ | ||
package com.numberone.backend.domain.article.dto.response; | ||
|
||
import com.numberone.backend.domain.article.entity.Article; | ||
import com.numberone.backend.domain.article.entity.ArticleStatus; | ||
import com.numberone.backend.domain.article.entity.ArticleTag; | ||
import com.numberone.backend.domain.articleimage.entity.ArticleImage; | ||
import com.numberone.backend.domain.member.entity.Member; | ||
import com.querydsl.core.annotations.QueryProjection; | ||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
@ToString | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class GetArticleListResponse { | ||
|
||
private ArticleTag tag; | ||
private Long id; | ||
private String title; | ||
private String content; | ||
private String address; | ||
private String ownerNickName; | ||
private Long ownerId; | ||
private LocalDateTime createdAt; | ||
private ArticleStatus articleStatus; | ||
private String thumbNailImageUrl; | ||
private Long thumbNailImageId; | ||
|
||
private Integer articleLikeCount; | ||
private Integer commentCount; | ||
|
||
|
||
@QueryProjection | ||
public GetArticleListResponse(Article article, Long ownerId, Long thumbNailImageId) { | ||
this.tag = article.getArticleTag(); | ||
this.id = article.getId(); | ||
this.title = article.getTitle(); | ||
this.content = article.getContent(); | ||
this.address = article.getAddress(); | ||
this.ownerId = ownerId; | ||
this.createdAt = article.getCreatedAt(); | ||
this.articleStatus = article.getArticleStatus(); | ||
this.thumbNailImageId = thumbNailImageId; | ||
this.articleLikeCount = article.getLikeCount(); | ||
this.commentCount = article.getCommentCount(); | ||
} | ||
|
||
public void setOwnerNickName(String nickName){ | ||
this.ownerNickName = nickName; | ||
} | ||
|
||
public void setThumbNailImageUrl(String thumbNailImageUrl){ | ||
this.thumbNailImageUrl = thumbNailImageUrl; | ||
} | ||
|
||
public void updateInfo(Optional<Member> owner, Optional<ArticleImage> articleImage){ | ||
owner.ifPresentOrElse( | ||
o -> setOwnerNickName(o.getNickName()), | ||
() -> setOwnerNickName("알 수 없는 사용자") | ||
); | ||
articleImage.ifPresentOrElse( | ||
image -> setThumbNailImageUrl(image.getImageUrl()), | ||
() -> setThumbNailImageUrl("") | ||
); | ||
} | ||
|
||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/numberone/backend/domain/article/dto/response/UploadArticleResponse.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,36 @@ | ||
package com.numberone.backend.domain.article.dto.response; | ||
|
||
import com.numberone.backend.domain.article.entity.Article; | ||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@ToString | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class UploadArticleResponse { | ||
|
||
private Long articleId; | ||
private LocalDateTime createdAt; | ||
|
||
// 이미지 관련 | ||
private List<String> imageUrls; | ||
private String thumbNailImageUrl; | ||
|
||
// 작성자 주소 | ||
private String address; // todo: 더미 데이터 | ||
|
||
public static UploadArticleResponse of(Article article, List<String> imageUrls, String thumbNailImageUrl){ | ||
return UploadArticleResponse.builder() | ||
.articleId(article.getId()) | ||
.createdAt(article.getCreatedAt()) | ||
.imageUrls(imageUrls) | ||
.thumbNailImageUrl(thumbNailImageUrl) | ||
.address("서울시 광진구 자양동") | ||
.build(); | ||
} | ||
|
||
} |
Oops, something went wrong.