update
This commit is contained in:
@@ -54,5 +54,6 @@ function removeArticle(id) {
|
||||
export default {
|
||||
getArticles,
|
||||
getArticle,
|
||||
postArticle
|
||||
postArticle,
|
||||
removeArticle
|
||||
}
|
||||
@@ -34,15 +34,23 @@
|
||||
const result = await articleApi.getArticle.bind(this)(articleId);
|
||||
this.article = result.data;
|
||||
this.init = true;
|
||||
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
remove() {
|
||||
async remove() {
|
||||
const articleId = this.$route.params.id;
|
||||
if(!confirm('정말 삭제하시겠습니까?')) return;
|
||||
|
||||
try {
|
||||
await articleApi.removeArticle.bind(this)(articleId);
|
||||
await this.$router.push('/articles');
|
||||
} catch (e) {
|
||||
alert('문제가 발생하였습니다.');
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,10 @@ public class Article {
|
||||
@LastModifiedDate
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
public Article(ArticleRequestDto articleRequestDto) {
|
||||
public Article(ArticleRequestDto articleRequestDto, User user) {
|
||||
this.title = articleRequestDto.getTitle();
|
||||
this.content = articleRequestDto.getContent();
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@PrePersist
|
||||
|
||||
@@ -38,7 +38,9 @@ public class ArticleController {
|
||||
return articleService.save(articleRequestDto, user);
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@DeleteMapping(value = "/{articleId}")
|
||||
@Transactional
|
||||
public void deleteArticle(@PathVariable Long articleId, @AuthenticationPrincipal User user) {
|
||||
articleService.delete(articleId, user);
|
||||
}
|
||||
|
||||
@@ -12,4 +12,5 @@ public class ArticleRequestDto {
|
||||
|
||||
@NotNull
|
||||
private String content;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.example.vue.domain.article;
|
||||
|
||||
import com.example.vue.domain.user.User;
|
||||
import com.example.vue.domain.user.UserResponseDto;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -12,6 +13,7 @@ public class ArticleResponseDto {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String content;
|
||||
private UserResponseDto user;
|
||||
|
||||
@JsonProperty("isOwn")
|
||||
private boolean isOwn;
|
||||
@@ -25,5 +27,6 @@ public class ArticleResponseDto {
|
||||
this.createdAt = article.getCreatedAt();
|
||||
this.updatedAt = article.getUpdatedAt();
|
||||
this.isOwn = article.compareUser(user);
|
||||
this.user = new UserResponseDto(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ public class ArticleService {
|
||||
private final ArticleRepository articleRepository;
|
||||
|
||||
public ArticleResponseDto save(ArticleRequestDto articleRequestDto, User user) {
|
||||
Article article = articleRepository.save(new Article(articleRequestDto));
|
||||
|
||||
Article article = articleRepository.save(new Article(articleRequestDto, user));
|
||||
|
||||
return new ArticleResponseDto(article, user);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user