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