Skip to content

Commit

Permalink
feat(ArticleController): 아티클 수정 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
shin-jisong committed Dec 23, 2024
1 parent 4ff3b43 commit a53fe75
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bang_ggood.article.controller;

import com.bang_ggood.article.dto.request.ArticleCreateRequest;
import com.bang_ggood.article.dto.request.ArticleUpdateRequest;
import com.bang_ggood.article.dto.response.ArticleResponse;
import com.bang_ggood.article.dto.response.ArticlesResponses;
import com.bang_ggood.article.service.ArticleService;
Expand All @@ -13,6 +14,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.net.URI;
Expand Down Expand Up @@ -43,6 +45,13 @@ public ResponseEntity<ArticlesResponses> readArticles() {
return ResponseEntity.ok(articleService.readArticles());
}

@PutMapping("/articles/{id}")
public ResponseEntity<Void> updateArticle(@AdminPrincipal User user,
@PathVariable("id") Long id, @Valid @RequestBody ArticleUpdateRequest request) {
articleService.updateArticle(id, request.toEntity());
return ResponseEntity.noContent().build();
}

@DeleteMapping("/articles/{id}")
public ResponseEntity<ArticleResponse> deleteArticle(@AdminPrincipal User user,
@PathVariable("id") Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.bang_ggood.article.domain.Article;
import com.bang_ggood.article.dto.request.ArticleCreateRequest;
import com.bang_ggood.article.dto.request.ArticleUpdateRequest;

public class ArticleFixture {

Expand All @@ -28,4 +29,8 @@ public static Article ARTICLE_4() {
public static ArticleCreateRequest ARTICLE_CREATE_REQUEST() {
return new ArticleCreateRequest("제목", "내용", "키워드", "요약", "썸네일");
}

public static ArticleUpdateRequest ARTICLE_UPDATE_REQUEST() {
return new ArticleUpdateRequest("제목", "내용", "키워드", "요약", "썸네일");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ void readArticlesListView() {
.statusCode(200);
}

@DisplayName("아티클 수정 성공")
@Test
void updateArticle() {
Article article = articleRepository.save(ArticleFixture.ARTICLE());

RestAssured.given().log().all()
.contentType(ContentType.JSON)
.headers(this.adminHeaders)
.body(ArticleFixture.ARTICLE_UPDATE_REQUEST())
.when().put("/articles/" + article.getId())
.then().log().all()
.statusCode(204);
}

@DisplayName("아티클 삭제 성공")
@Test
void deleteArticle() {
Expand Down

0 comments on commit a53fe75

Please sign in to comment.