-
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
32 changed files
with
736 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
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
package com.numberone.backend.domain.article.controller; | ||
|
||
import com.numberone.backend.domain.article.dto.request.UploadArticleRequest; | ||
import com.numberone.backend.domain.article.dto.response.DeleteArticleResponse; | ||
import com.numberone.backend.domain.article.dto.response.GetArticleDetailResponse; | ||
import com.numberone.backend.domain.article.dto.response.UploadArticleResponse; | ||
import com.numberone.backend.domain.article.service.ArticleService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import jakarta.validation.Valid; | ||
import jakarta.websocket.server.PathParam; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
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)); | ||
} | ||
|
||
|
||
} |
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,...) | ||
|
||
} |
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(); | ||
} | ||
|
||
} |
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(); | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/com/numberone/backend/domain/article/entity/Article.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,79 @@ | ||
package com.numberone.backend.domain.article.entity; | ||
|
||
import com.numberone.backend.config.basetime.BaseTimeEntity; | ||
import com.numberone.backend.domain.articleimage.entity.ArticleImage; | ||
import com.numberone.backend.domain.articleparticipant.entity.ArticleParticipant; | ||
import com.numberone.backend.domain.comment.entity.CommentEntity; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.Comment; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Comment("동네생활 게시글 정보") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@Entity | ||
@Table(name = "ARTICLE") | ||
public class Article extends BaseTimeEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "article_id") | ||
private Long id; | ||
|
||
@OneToMany(mappedBy = "article", cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true) | ||
private List<CommentEntity> comments = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "article", cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true) | ||
private List<ArticleParticipant> articleParticipants = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "article", cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true) | ||
private List<ArticleImage> articleImages = new ArrayList<>(); | ||
|
||
@Comment("썸네일 이미지 url ID") | ||
private Long thumbNailImageUrlId; | ||
|
||
@Comment("게시글 제목") | ||
private String title; | ||
|
||
@Comment("게시글 내용") | ||
private String content; | ||
|
||
@Comment("게시글 태그 (일상:LIFE, 사기:FRAUD, 치안:SAFETY, 제보:REPORT)") | ||
@Enumerated(EnumType.STRING) | ||
private ArticleTag articleTag; | ||
|
||
@Comment("게시글 상태 (ACTIVATED, DELETED)") | ||
@Enumerated(EnumType.STRING) | ||
private ArticleStatus articleStatus; | ||
|
||
@Comment("게시글 작성 당시 주소") | ||
private String address; | ||
|
||
@Comment("게시글 좋아요 개수") | ||
private Integer likeCount; // todo: 동시성 처리 | ||
|
||
@Comment("작성자 ID") | ||
private Long articleOwnerId; | ||
|
||
public Article(String title, String content, Long articleOwnerId, ArticleTag tag) { | ||
this.title = title; | ||
this.content = content; | ||
this.articleOwnerId = articleOwnerId; | ||
this.articleTag = tag; | ||
this.articleStatus = ArticleStatus.ACTIVATED; | ||
} | ||
|
||
public void updateArticleImage(List<ArticleImage> images, Long thumbNailImageUrlId) { | ||
this.articleImages = images; | ||
this.thumbNailImageUrlId = thumbNailImageUrlId; | ||
} | ||
|
||
public void updateArticleStatus(ArticleStatus status){ | ||
this.articleStatus = status; | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/numberone/backend/domain/article/entity/ArticleStatus.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,10 @@ | ||
package com.numberone.backend.domain.article.entity; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public enum ArticleStatus { | ||
ACTIVATED, | ||
DELETED; | ||
private String value; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/numberone/backend/domain/article/entity/ArticleTag.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,12 @@ | ||
package com.numberone.backend.domain.article.entity; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public enum ArticleTag { | ||
LIFE, // 일상 | ||
FRAUD, // 사기 | ||
SAFETY, // 치안 | ||
REPORT; // 제보 | ||
private String value; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/numberone/backend/domain/article/repository/ArticleRepository.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,7 @@ | ||
package com.numberone.backend.domain.article.repository; | ||
|
||
import com.numberone.backend.domain.article.entity.Article; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ArticleRepository extends JpaRepository<Article, Long> { | ||
} |
Oops, something went wrong.