Skip to content

Commit

Permalink
Merge pull request #7 from potenday-project/develop
Browse files Browse the repository at this point in the history
면접 관련 주요 기능
  • Loading branch information
HwangHoYoon authored Dec 11, 2023
2 parents 05bba9a + 26be93b commit 334de18
Show file tree
Hide file tree
Showing 32 changed files with 765 additions and 13 deletions.
59 changes: 59 additions & 0 deletions src/main/generated/com/chwipoClova/feedback/entity/QFeedback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.chwipoClova.feedback.entity;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.PathInits;


/**
* QFeedback is a Querydsl query type for Feedback
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QFeedback extends EntityPathBase<Feedback> {

private static final long serialVersionUID = -267482617L;

private static final PathInits INITS = PathInits.DIRECT2;

public static final QFeedback feedback = new QFeedback("feedback");

public final StringPath content = createString("content");

public final NumberPath<Long> feedbackId = createNumber("feedbackId", Long.class);

public final DateTimePath<java.util.Date> modifyDate = createDateTime("modifyDate", java.util.Date.class);

public final com.chwipoClova.qa.entity.QQa qa;

public final DateTimePath<java.util.Date> regDate = createDateTime("regDate", java.util.Date.class);

public final NumberPath<Integer> type = createNumber("type", Integer.class);

public QFeedback(String variable) {
this(Feedback.class, forVariable(variable), INITS);
}

public QFeedback(Path<? extends Feedback> path) {
this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS));
}

public QFeedback(PathMetadata metadata) {
this(metadata, PathInits.getFor(metadata, INITS));
}

public QFeedback(PathMetadata metadata, PathInits inits) {
this(Feedback.class, metadata, inits);
}

public QFeedback(Class<? extends Feedback> type, PathMetadata metadata, PathInits inits) {
super(type, metadata, inits);
this.qa = inits.isInitialized("qa") ? new com.chwipoClova.qa.entity.QQa(forProperty("qa"), inits.get("qa")) : null;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ public enum ExceptionCode {

FILE_EXT_IMAGE("851", "IMAGE 파일 형식이 아닙니다."),

FILE_SIZE("860", "파일 업로드 최대 크기는 50M 입니다."),
FILE_SIZE("852", "파일 업로드 최대 크기는 50M 입니다."),

RESUME_NULL("870", "이력서 정보가 올바르지 않습니다."),
RESUME_NULL("860", "이력서 정보가 올바르지 않습니다."),

RECRUIT_CONTENT_NULL("880", "채용공고 정보가 올바르지 않습니다.")
RECRUIT_CONTENT_NULL("870", "채용공고 정보가 올바르지 않습니다."),

INTERVIEW_NULL("880", "면접 정보가 올바르지 않습니다."),

QA_NULL("890", "질문 정보가 올바르지 않습니다."),

TOKEN_NULL("950", "토큰정보가 올바르지 않습니다.")

;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chwipoClova.common.filter;

import com.chwipoClova.common.exception.ExceptionCode;
import com.chwipoClova.common.response.CommonResponse;
import com.chwipoClova.common.utils.JwtUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -89,7 +90,7 @@ public void jwtExceptionHandler(HttpServletResponse response, String msg, HttpSt
response.setStatus(status.value());
response.setContentType("application/json");
try {
String json = new ObjectMapper().writeValueAsString(new CommonResponse<String>("RefreshToken Expired", null,"878"));
String json = new ObjectMapper().writeValueAsString(new CommonResponse<String>(ExceptionCode.TOKEN_NULL.getCode(), null,ExceptionCode.TOKEN_NULL.getMessage()));
response.getWriter().write(json);
} catch (Exception e) {
log.error(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
@AllArgsConstructor
public enum MessageCode {

OK("200", "OK"),

SUCCESS_SAVE("600", "정상적으로 저장되었습니다."),

SUCCESS_DELETE("601", "정상적으로 삭제되었습니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.chwipoClova.feedback.controller;

public class FeedbackController {
}
63 changes: 63 additions & 0 deletions src/main/java/com/chwipoClova/feedback/entity/Feedback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.chwipoClova.feedback.entity;


import com.chwipoClova.qa.entity.Qa;
import com.chwipoClova.user.entity.User;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;

import java.util.Date;

@Entity(name = "Feedback")
@Table(name = "Feedback")
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties()
@DynamicInsert
@Builder
@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class Feedback {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "feedbackId")
@Schema(description = "피드백 ID")
private Long feedbackId;

@Column(name = "type")
@Schema(description = "피드백타입(1, 2, 3)")
private Integer type;

@Column(name = "content")
@Schema(description = "피드백내용")
private String content;

@Column(name = "regDate")
@Schema(description = "등록일")
private Date regDate;

@Column(name = "modifyDate")
@Schema(description = "수정일")
private Date modifyDate;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "qaId")
private Qa qa;

// @PrePersist 메서드 정의 (최초 등록시 호출)
@PrePersist
public void prePersist() {
this.regDate = new Date(); // 현재 날짜와 시간으로 등록일 설정
}

@PreUpdate
public void preUpdate() {
this.modifyDate = new Date(); // 현재 날짜와 시간으로 수정일 업데이트
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.chwipoClova.feedback.repository;

import com.chwipoClova.feedback.entity.Feedback;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface FeedbackRepository extends JpaRepository<Feedback, Long> {

List<Feedback> findByQaQaIdOrderByFeedbackId(Long qaId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.chwipoClova.feedback.request;

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

@Data
public class FeedbackDataInsertReq {

@Schema(description = "피드백타입", example = "1", name = "type")
private Integer type;

@Schema(description = "피드백내용", example = "피드백1입니다.", name = "content")
private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.chwipoClova.feedback.request;

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

@Data
public class FeedbackInsertReq {

@Schema(description = "질문답변 ID", example = "1", name = "qaId")
private Long qaId;

@Schema(description = "질문", example = "질문1", name = "question")
private String question;

@Schema(description = "답변", example = "답변1", name = "answer")
private String answer;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.chwipoClova.feedback.request;

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

@Data
public class FeedbackListReq {

@Schema(description = "질문답변 ID", example = "1", name = "qaId")
private Long qaId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.chwipoClova.feedback.response;

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

@Data
public class FeedBackApiRes {

@Schema(description = "질문 ID", example = "1", name = "qaId")
private Long qaId;

@Schema(description = "피드백 타입", example = "1", name = "type")
private Integer type;

@Schema(description = "피드백 내용", example = "피드백1입니다.", name = "content")
private String content;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.chwipoClova.feedback.response;

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

import java.util.Date;

@Data
public class FeedbackInsertRes {
@Schema(description = "질문답변 ID", example = "1", name = "qaId")
private Long qaId;

@Schema(description = "피드백 ID", example = "1", name = "feedbackId")
private Long feedbackId;

@Schema(description = "피드백 타입", example = "1", name = "type")
private Integer type;

@Schema(description = "피드백 내용", example = "피드백입니다.", name = "content")
private String content;

@Schema(description = "등록일", example = "2023-12-09T10:13:17.838+00:00", name = "regDate")
private Date regDate;

@Schema(description = "수정일", example = "2023-12-09T10:13:17.838+00:00", name = "modifyDate")
private Date modifyDate;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.chwipoClova.feedback.response;

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

import java.util.Date;

@Data
@Builder
public class FeedbackListRes {
@Schema(description = "질문답변 ID", example = "1", name = "qaId")
private Long qaId;

@Schema(description = "피드백 ID", example = "1", name = "feedbackId")
private Long feedbackId;

@Schema(description = "피드백 타입", example = "1", name = "type")
private Integer type;

@Schema(description = "피드백 내용", example = "피드백입니다.", name = "content")
private String content;

@Schema(description = "등록일", example = "2023-12-09T10:13:17.838+00:00", name = "regDate")
private Date regDate;

@Schema(description = "수정일", example = "2023-12-09T10:13:17.838+00:00", name = "modifyDate")
private Date modifyDate;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.chwipoClova.feedback.service;

import com.chwipoClova.common.exception.CommonException;
import com.chwipoClova.common.exception.ExceptionCode;
import com.chwipoClova.common.response.CommonResponse;
import com.chwipoClova.common.response.MessageCode;
import com.chwipoClova.feedback.entity.Feedback;
import com.chwipoClova.feedback.repository.FeedbackRepository;
import com.chwipoClova.feedback.request.FeedbackInsertReq;
import com.chwipoClova.feedback.response.FeedBackApiRes;
import com.chwipoClova.feedback.response.FeedbackListRes;
import com.chwipoClova.qa.entity.Qa;
import com.chwipoClova.qa.repository.QaRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
@Service
@Slf4j
public class FeedbackService {

private final FeedbackRepository feedbackRepository;

private final QaRepository qaRepository;

@Transactional
public CommonResponse insertFeedback(List<FeedbackInsertReq> feedbackInsertListReq) throws IOException {

// TODO 피드백 연동 필요함
// 테스트 데이터
List<FeedBackApiRes> feedBackApiListRes = new ArrayList<>();
feedbackInsertListReq.stream().forEach(feedbackInsertReq -> {
Long qaId = feedbackInsertReq.getQaId();
FeedBackApiRes feedBackApiRes = new FeedBackApiRes();
feedBackApiRes.setQaId(qaId);
feedBackApiRes.setType(1);
feedBackApiRes.setContent("피드백1입니다.");
feedBackApiListRes.add(feedBackApiRes);
FeedBackApiRes feedBackApiRes2 = new FeedBackApiRes();
feedBackApiRes2.setQaId(qaId);
feedBackApiRes2.setType(2);
feedBackApiRes2.setContent("피드백2입니다.");
feedBackApiListRes.add(feedBackApiRes2);
});

feedBackApiListRes.stream().forEach(feedBackApiRes -> {
Long qaId = feedBackApiRes.getQaId();
Qa qa = qaRepository.findById(qaId).orElseThrow(() -> new CommonException(ExceptionCode.QA_NULL.getMessage(), ExceptionCode.QA_NULL.getCode()));

Feedback feedback = Feedback.builder()
.type(feedBackApiRes.getType())
.content(feedBackApiRes.getContent())
.qa(qa)
.build();
feedbackRepository.save(feedback);
});

return new CommonResponse<>(MessageCode.OK.getCode(), null, MessageCode.OK.getMessage());
}

public List<FeedbackListRes> selectFeedbackList(Long qaId) {
List<FeedbackListRes> feedbackListResList = new ArrayList<>();

List<Feedback> feedbackList = feedbackRepository.findByQaQaIdOrderByFeedbackId(qaId);
feedbackList.stream().forEach(feedback -> {
FeedbackListRes feedbackListRes = FeedbackListRes.builder()
.qaId(feedback.getQa().getQaId())
.feedbackId(feedback.getFeedbackId())
.type(feedback.getType())
.content(feedback.getContent())
.regDate(feedback.getRegDate())
.modifyDate(feedback.getModifyDate())
.build();
feedbackListResList.add(feedbackListRes);
});
return feedbackListResList;
}

}
Loading

0 comments on commit 334de18

Please sign in to comment.