Skip to content

Commit

Permalink
Merge branch 'main' into questionAnswer
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/resources/sqlmap/mapper/question/QuestionMapper.xml
  • Loading branch information
programmerDH-github committed Aug 19, 2023
2 parents 8254bad + 176b8af commit a71dbf4
Show file tree
Hide file tree
Showing 13 changed files with 291 additions and 90 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ target/
!**/src/main/**/target/
!**/src/test/**/target/

### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
.target/

### STS ###
.apt_generated
.classpath
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source> // 사용하는 Java 버전에 맞게 변경합니다.
<target>17</target> // 사용하는 Java 버전에 맞게 변경합니다.
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.bside.BSIDE.contents.domain;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

@Data
public class QuestionListOutDto {
@Schema(description = "현재 페이지 번호", example = "1", nullable = false)
private Integer pageNo;

@Schema(description = "페이지당 들어갈 컬럼 수", example = "20", nullable = false)
private Integer pageSize;

@Schema(description = "질문 contents", nullable = true)
private List<QuestionDto> grid;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.springframework.data.domain.Page;

import com.bside.BSIDE.contents.domain.CountAnsweredQuestionsByMonthDto;
import com.bside.BSIDE.contents.domain.QuestionAndAnswerDto;
import com.bside.BSIDE.contents.domain.QuestionCountDto;
import com.bside.BSIDE.contents.domain.QuestionDto;



@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 All @@ -28,4 +28,8 @@ public interface QuestionMapper {

List<QuestionAndAnswerDto> getQuestionsAndAnswersByMonthAndEmail(String email, String date);
List<QuestionAndAnswerDto> getQuestionsAndAnswersByDayAndEmail(String email, String date);

List<QuestionDto> selectListQuestion();
// List<QuestionDto> selectListQuestion(QuestionListInDto questionListInDto);
// List<QuestionDto> selectListQuestion(int pageNo, int pageSize);
}
127 changes: 96 additions & 31 deletions src/main/java/com/bside/BSIDE/contents/web/QuestionController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.bside.BSIDE.contents.web;

import java.util.List;
import java.util.Map;

import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
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 All @@ -19,7 +20,6 @@
import com.bside.BSIDE.contents.domain.QuestionAndAnswerDto;
import com.bside.BSIDE.contents.domain.QuestionCountDto;
import com.bside.BSIDE.contents.domain.QuestionDto;
import com.bside.BSIDE.service.AnswerService;
import com.bside.BSIDE.service.QuestionService;

import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -30,51 +30,54 @@
* @일자 2023.04.23.
**/

@CrossOrigin
@CrossOrigin(origins = { "http://localhost:3000", "http://www.goming.site" }, allowCredentials = "true")
@RestController
@RequestMapping("/question")
public class QuestionController {

private final QuestionService questionService;
private final AnswerService answerService;

public QuestionController(QuestionService questionService, AnswerService answerService) {
public QuestionController(QuestionService questionService) {
this.questionService = questionService;
this.answerService = answerService;
}

/* 질문 저장 */
@PostMapping("/insertQuestion")
@Operation(summary = "질문 저장")
public ResponseEntity<Void> createQuestion(@RequestBody QuestionDto questionDto) {
questionService.insertQuestion(questionDto);
return new ResponseEntity<>(HttpStatus.CREATED);
public ResponseEntity<String> createQuestion(@RequestBody Map<String, Object> obj) {
QuestionDto qDto = new QuestionDto();
qDto.setQCategory((String) obj.get("qCategory"));
qDto.setQWriter((String) obj.get("qWriter"));
qDto.setQQuestion((String) obj.get("qQuestion"));

questionService.insertQuestion(qDto);
return ResponseEntity.ok("입력되었습니다.");
}

@GetMapping("/unanswered")
@GetMapping("/unanswered/{writer}")
@Operation(summary = "금일 답변하지 않은 개수 조회")
public ResponseEntity<Integer> countUnansweredQuestionsToday(@RequestParam("writer") String writer) {
Integer count = 3 - questionService.countUnansweredQuestions(writer)
public ResponseEntity<Integer> countUnansweredQuestionsToday(@PathVariable("writer") String writer) {
Integer count = 3 - questionService.countAnsweredQuestionsToday(writer)
- questionService.countPassQuestions(writer);
System.out.println("사용자가 아직 답변하지 않은 질문은 " + questionService.countUnansweredQuestions(writer) + "개입니다.");
System.out.println("사용자가 답변한 질문은 " + questionService.countAnsweredQuestionsToday(writer) + "개입니다.");
System.out.println("사용자가 답변하지 않겠다고 넘긴 질문은 " + questionService.countPassQuestions(writer) + "개입니다.");
return ResponseEntity.ok(count);
}

/* 이번달에 답변한 질문 개수 조회 */
@GetMapping("/answered/month")
@GetMapping("/answered/month/{writer}")
@Operation(summary = "이번달에 답변한 질문 개수 조회")
public ResponseEntity<Integer> countAnsweredQuestionsThisMonth(@RequestParam("writer") String writer) {
public ResponseEntity<Integer> countAnsweredQuestionsThisMonth(@PathVariable("writer") String writer) {
Integer count = questionService.countAnsweredQuestionsThisMonth(writer);
String message = String.format("이번 달에 답변한 질문 개수는 " + count + "개 입니다.");
System.out.println(message);
return ResponseEntity.ok(count);
}

/* 오늘 답변한 질문 개수 조회 */
@GetMapping("/answered/day")
@GetMapping("/answered/day/{writer}")
@Operation(summary = "오늘 답변한 질문 개수 조회")
public ResponseEntity<Integer> countAnsweredQuestionsToday(@RequestParam("writer") String writer) {
public ResponseEntity<Integer> countAnsweredQuestionsToday(@PathVariable("writer") String writer) {
Integer count = questionService.countAnsweredQuestionsToday(writer);
String message = String.format("오늘 답변한 질문 개수는 " + count + "개 입니다.");
System.out.println(message);
Expand Down Expand Up @@ -136,7 +139,7 @@ public ResponseEntity<?> getQuestionsAndAnswersByMonthAndEmail(@PathVariable Str

/* YYYY 입력했을 경우 */
if (dateArr.length == 1) {
return ResponseEntity.ok("YYYY-MM 의 형식 또는 YYYY-MM-DD 의 형식으로 입력해주세요.");
return ResponseEntity.ok("YYYY-MM 의 형식으로 입력해주세요.");
}
/* YYYY-MM 입력했을 경우 */
else if (dateArr.length == 2) {
Expand All @@ -151,20 +154,82 @@ else if (dateArr.length == 2) {
ResponseEntity.ok("선택한 날짜의 값이 존재하지 않습니다.");
}

// 페이징 처리를 위한 Pageable 생성
int totalElements = questionAndAnswers.size();
int totalPages = (int) Math.ceil((double) totalElements / size);
int currentPage = Math.min(Math.max(1, page), totalPages);
int startIndex = (currentPage - 1) * size;
int endIndex = Math.min(startIndex + size, totalElements);
System.out.println(page + "@##!#!##!#$$!@$!@$!@4pagE@#!@@#$!@$!@$");
if (page > 0) {
// 페이징 처리를 위한 Pageable 생성
int totalElements = questionAndAnswers.size();
int totalPages = (int) Math.ceil((double) totalElements / size);
int currentPage = Math.min(Math.max(1, page), totalPages);
int startIndex = (currentPage - 1) * size;
int endIndex = Math.min(startIndex + size, totalElements);

// 해당 페이지에 맞게 데이터 분할
List<QuestionAndAnswerDto> pageContent = questionAndAnswers.subList(startIndex, endIndex);

// PagedResponse 객체 생성
PagedResponse<QuestionAndAnswerDto> pagedResponse = new PagedResponse<>(pageContent, currentPage, size,
totalElements);
return ResponseEntity.ok(pagedResponse);
} else {
return ResponseEntity.ok(questionAndAnswers);
}

// 해당 페이지에 맞게 데이터 분할
List<QuestionAndAnswerDto> pageContent = questionAndAnswers.subList(startIndex, endIndex);
}

/* 질문 리스트 조회 */
@GetMapping("/questions")
@Operation(summary = "질문 리스트 조회")
public ResponseEntity<?> getQuestions(@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "15") int size) {

// PagedResponse 객체 생성
PagedResponse<QuestionAndAnswerDto> pagedResponse = new PagedResponse<>(pageContent, currentPage, size,
totalElements);
List<QuestionDto> question = questionService.selectListQuestion();

System.out.println(question);

if (page > 0) {
// 페이징 처리를 위한 Pageable 생성
int totalElements = question.size();
int totalPages = (int) Math.ceil((double) totalElements / size);
int currentPage = Math.min(Math.max(1, page), totalPages);
int startIndex = (currentPage - 1) * size;
int endIndex = Math.min(startIndex + size, totalElements);

// 해당 페이지에 맞게 데이터 분할
List<QuestionDto> pageContent = question.subList(startIndex, endIndex);

// PagedResponse 객체 생성
PagedResponse<QuestionDto> pagedResponse = new PagedResponse<>(pageContent, currentPage, size,
totalElements);
return ResponseEntity.ok(pagedResponse);
} else {
return ResponseEntity.ok(question);
}

return ResponseEntity.ok(pagedResponse);
}

/* 질문 리스트 수정 */
@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);
}
}
7 changes: 4 additions & 3 deletions src/main/java/com/bside/BSIDE/service/QuestionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.bside.BSIDE.contents.domain.CountAnsweredQuestionsByMonthDto;
import com.bside.BSIDE.contents.domain.QuestionAndAnswerDto;
import com.bside.BSIDE.contents.domain.QuestionCountDto;
import com.bside.BSIDE.contents.domain.QuestionDto;

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 All @@ -25,4 +24,6 @@ public interface QuestionService {

List<QuestionAndAnswerDto> getQuestionsAndAnswersByMonthAndEmail(String email, String date);
List<QuestionAndAnswerDto> getQuestionsAndAnswersByDayAndEmail(String email, String date);

List<QuestionDto> selectListQuestion();
}
19 changes: 17 additions & 2 deletions src/main/java/com/bside/BSIDE/service/QuestionServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import com.bside.BSIDE.contents.domain.CountAnsweredQuestionsByMonthDto;
Expand All @@ -20,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 Expand Up @@ -80,5 +89,11 @@ public List<QuestionAndAnswerDto> getQuestionsAndAnswersByMonthAndEmail(String e
public List<QuestionAndAnswerDto> getQuestionsAndAnswersByDayAndEmail(String email, String date) {
return questionMapper.getQuestionsAndAnswersByDayAndEmail(email, date);
}


@Override
public List<QuestionDto> selectListQuestion() {
return questionMapper.selectListQuestion();
}

}

11 changes: 7 additions & 4 deletions src/main/java/com/bside/BSIDE/user/service/EmailService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.bside.BSIDE.user.service;

import org.springframework.web.multipart.MultipartFile;

public interface EmailService {
String sendCodeMessage(String to)throws Exception;
String sendTemporaryPassword(String to, String temporaryPassword)throws Exception;
void sendByMonth(String email,String sendEmail, String date) throws Exception;
void scheduleMonthlyEmail() throws Exception;
String sendCodeMessage(String to) throws Exception;
String sendTemporaryPassword(String to, String temporaryPassword) throws Exception;
void sendByMonth(String email, String sendEmail, String date) throws Exception;
void sendByMonthBlob(String email, String sendEmail, String date, MultipartFile imageData) throws Exception;
void scheduleMonthlyEmail() throws Exception;
}
Loading

0 comments on commit a71dbf4

Please sign in to comment.