Skip to content

Commit

Permalink
feat : update, delete api
Browse files Browse the repository at this point in the history
  • Loading branch information
programmerDH-github committed Aug 19, 2023
1 parent 0e21a5e commit 176b8af
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@Mapper
public interface QuestionMapper {
void insertQuestion(QuestionDto questionDto);
void updateQuestion(QuestionDto questionDto);
void deleteQuestion(int qNo);
QuestionDto getQuestionByPNO(int pNo);
List<QuestionDto> getQuestionByCategory(String category);

Expand Down
31 changes: 28 additions & 3 deletions src/main/java/com/bside/BSIDE/contents/web/QuestionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import java.util.List;
import java.util.Map;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down Expand Up @@ -207,4 +206,30 @@ public ResponseEntity<?> getQuestions(@RequestParam(defaultValue = "1") int page
}

}

/* 질문 리스트 수정 */
@PutMapping("/question/update")
@Operation(summary = "질문 리스트 수정")
public ResponseEntity<String> updateQuestion(@RequestBody Map<String, Object> object) {
QuestionDto question = new QuestionDto();

question.setQNo((Integer)object.get("qNo"));
question.setQQuestion((String) object.get("qQuestion"));
question.setQCategory((String) object.get("qCategory"));
question.setQWriter((String) object.get("qWriter"));
questionService.updateQuestion(question);

String message = String.format(object.get("qNo") + "에 해당하는 질문을 수정하였습니다.");
return ResponseEntity.ok(message);
}

/* 질문 리스트 삭제 */
@DeleteMapping("/question/delete/{qNo}")
@Operation(summary = "질문 리스트 삭제")
public ResponseEntity<String> deleteQuestion(@PathVariable int qNo) {
questionService.deleteQuestion(qNo);

String message = String.format(qNo + "에 해당하는 질문을 삭제하였습니다.");
return ResponseEntity.ok(message);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/bside/BSIDE/service/QuestionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

public interface QuestionService {
void insertQuestion(QuestionDto questionDto);
void updateQuestion(QuestionDto questionDto);
void deleteQuestion(int qNo);
QuestionDto getQuestionByPNO(int pNo);
List<QuestionDto> getQuestionByCategory(String category);

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/bside/BSIDE/service/QuestionServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public QuestionServiceImpl(QuestionMapper questionMapper) {
this.questionMapper = questionMapper;
}

@Override
public void updateQuestion(QuestionDto questionDto) {
questionMapper.updateQuestion(questionDto);
}

@Override
public void deleteQuestion(int qNo) {
questionMapper.deleteQuestion(qNo);
}

@Override
public void insertQuestion(QuestionDto questionDto) {
questionMapper.insertQuestion(questionDto);
Expand Down
15 changes: 14 additions & 1 deletion src/main/resources/sqlmap/mapper/question/QuestionMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,24 @@
AND DAY(a.a_created_at) = DAY(#{date})
</select>

<!-- 질문목록 조회 -->
<!-- 질문 리스트 조회 -->
<select id="selectListQuestion" resultType="com.bside.BSIDE.contents.domain.QuestionDto">
SELECT q_no AS qNo, q_question AS qQuestion, q_category AS qCategory, q_writer AS qWriter, q_created_at AS qCreatedAt
FROM bside.question
ORDER BY q_created_at DESC
</select>

<!-- 질문 리스트 수정 -->
<update id="updateQuestion" parameterType="com.bside.BSIDE.contents.domain.QuestionDto">
UPDATE bside.question
SET q_question = #{qQuestion}, q_category = #{qCategory}, q_writer = #{qWriter}
WHERE q_no = #{qNo}
</update>

<!-- 질문 리스트 삭제 -->
<delete id="deleteQuestion" parameterType="int">
DELETE FROM bside.question
WHERE q_no = #{qNo}
</delete>

</mapper>

0 comments on commit 176b8af

Please sign in to comment.