Skip to content

Commit

Permalink
feat: 게시글 생성, 수정 API
Browse files Browse the repository at this point in the history
  • Loading branch information
birdieHyun committed Dec 16, 2023
1 parent 70ed486 commit 2acf007
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import yonseigolf.server.board.dto.request.CreateBoardRequest;
import yonseigolf.server.board.dto.request.CreateBoardTemplateRequest;
import yonseigolf.server.board.dto.request.PostReplyRequest;
import yonseigolf.server.board.dto.request.UpdateBoardRequest;
import yonseigolf.server.board.dto.response.AllBoardTemplatesResponse;
Expand Down Expand Up @@ -129,16 +130,18 @@ public ResponseEntity<CustomResponse<SingleBoardTemplateResponse>> getBoardTempl
}

@PostMapping("/admin/boards/templates")
public ResponseEntity<CustomResponse<Void>> createBoardTemplate() {
public ResponseEntity<CustomResponse<Void>> createBoardTemplate(@RequestBody CreateBoardTemplateRequest request) {

boardTemplateService.createBoardTemplate(request);
return ResponseEntity
.ok()
.body(CustomResponse.successResponse("게시글 템플릿 생성 성공"));
}

@PatchMapping("/admin/boards/templates/{templateId}")
public ResponseEntity<CustomResponse<Void>> updateBoardTemplate(@PathVariable Long templateId) {
public ResponseEntity<CustomResponse<Void>> updateBoardTemplate(@PathVariable Long templateId, @RequestBody CreateBoardTemplateRequest request) {

boardTemplateService.updateBoardTemplate(templateId, request);
return ResponseEntity
.ok()
.body(CustomResponse.successResponse("게시글 템플릿 수정 성공"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package yonseigolf.server.board.dto.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CreateBoardTemplateRequest {

private String title;
private String contents;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public class BoardTemplate {
private Long id;
private String title;
private String contents;

public void update(String title, String contents) {
this.title = title;
this.contents = contents;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import yonseigolf.server.board.dto.request.CreateBoardTemplateRequest;
import yonseigolf.server.board.dto.response.AllBoardTemplatesResponse;
import yonseigolf.server.board.dto.response.BoardTemplatesResponse;
import yonseigolf.server.board.dto.response.SingleBoardTemplateResponse;
Expand Down Expand Up @@ -45,6 +47,24 @@ public SingleBoardTemplateResponse findBoardTemplate(long id) {
.build();
}

public void createBoardTemplate(CreateBoardTemplateRequest request) {

BoardTemplate boardTemplate = BoardTemplate.builder()
.title(request.getTitle())
.contents(request.getContents())
.build();

boardTemplateRepository.save(boardTemplate);
}

@Transactional
public void updateBoardTemplate(long id, CreateBoardTemplateRequest request) {

BoardTemplate boardTemplate = findBoardTemplateById(id);

boardTemplate.update(request.getTitle(), request.getContents());
}

// TODO: 적절한 예외 처리 하기
public void deleteBoardTemplate(long id) {

Expand Down

0 comments on commit 2acf007

Please sign in to comment.