-
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
68 changed files
with
2,123 additions
and
117 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
126 changes: 126 additions & 0 deletions
126
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,126 @@ | ||
package com.numberone.backend.domain.article.controller; | ||
|
||
import com.numberone.backend.domain.article.dto.request.ModifyArticleRequest; | ||
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 com.numberone.backend.support.redis.like.service.RedisLockLikeFacade; | ||
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; | ||
private final RedisLockLikeFacade redisLockLikeFacade; | ||
|
||
@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 으로 넘겨주세요. | ||
해당 게시글을 삭제 상태로 변경합니다. | ||
""") | ||
@PatchMapping("{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) { // todo: 해당 유저가 좋아요를 눌렀는지 여부까지 표시되도록 수정 | ||
return ResponseEntity.ok(articleService.getArticleListPaging(param, pageable)); | ||
} | ||
|
||
@Operation(summary = "게시글에 댓글 작성하기", description = """ | ||
게시글에 댓글을 작성하는 API 입니다. | ||
게시글 아이디는 Path variable 으로 넘겨주세요 (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)); | ||
|
||
} | ||
|
||
@Operation(summary = "게시글 수정하기", description = """ | ||
게시글 내용을 수정하는 API 입니다. | ||
반드시 access token 을 헤더에 포함해서 요청해주세요. | ||
article-id 는 path variable 으로 넘겨주세요. | ||
""") | ||
@PutMapping("{article-id}/modify") | ||
public ResponseEntity<ModifyArticleResponse> modifyArticle( | ||
@PathVariable("article-id") Long articleId, | ||
@RequestBody @Valid ModifyArticleRequest request ){ | ||
return ResponseEntity.ok(articleService.modifyArticle(articleId, request)); | ||
} | ||
|
||
// todo: 게시글 신고 기능 | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/numberone/backend/domain/article/dto/request/ModifyArticleRequest.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,38 @@ | ||
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 ModifyArticleRequest { | ||
|
||
// 글 관련 | ||
@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,...) | ||
|
||
private Double longitude; | ||
private Double latitude; | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
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,...) | ||
|
||
private Double longitude; | ||
private Double latitude; | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
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,16 @@ | ||
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; | ||
private Double longitude; | ||
private Double latitude; | ||
} |
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(); | ||
} | ||
|
||
} |
Oops, something went wrong.