Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ dependencies {
"com.querydsl:querydsl-apt:${queryDslVersion}:jpa")
}


// QueryDSL
sourceSets {
main {
Expand All @@ -117,3 +118,4 @@ sourceSets {
tasks.named('test') {
useJUnitPlatform()
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Objects;

@Entity
@Getter
@Builder
@NoArgsConstructor
public class Company extends BaseTimeEntity {


@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "COMPANY_ID")
private Long id;
private String name;

public Company(Long id, String name){
@Builder
public Company(String name) {

Objects.requireNonNull(id, "id가 null입니다.");
Objects.requireNonNull(name, "name이 null입니다.");

this.id = id;
this.name = name;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.interviewPrep.quiz.company.repository;

import com.example.interviewPrep.quiz.company.domain.Company;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface CompanyRepository extends JpaRepository<Company, Long> {

Optional<Company> findByName(String companyName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum ErrorCode {

NOT_FOUND_ANSWER("not_found_answer", "answer를 찾을 수 없습니다."),
NOT_FOUND_QUESTION("not_found_question", "Question with ID not found."),
NOT_FOUND_COMPANY("not_found_company", "Company with ID not found."),
NOT_FOUND_MEMBER("not_found_member", "member를 찾을 수 없습니다."),
NOT_FOUND_COMMENT("not_found_comment", "comment를 찾을 수 없습니다."),
NOT_FOUND_EXAM("not_found_exam", "해당 모의고사를 찾을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.*;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
Expand All @@ -34,7 +35,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String header = request.getHeader(HttpHeaders.AUTHORIZATION);

if (header != null && header.startsWith("Bearer")) {
if (header != null && header.startsWith("Bearer") && !header.endsWith("null")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 .. 추가된 조건은 왜 그런거에요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 회원가입할 때는 header가 Bearer null 이라는 문자열로 전달되는데,
그러한 경우에 저 if문에 진입하지 않아야 하므로(왜냐면 access토큰이 없으므로)
저런 조건을 추가했습니다

try {

String accessToken = header.substring(7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.example.interviewPrep.quiz.domain.BaseTimeEntity;
import com.example.interviewPrep.quiz.member.dto.Role;
import lombok.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Objects;
Expand All @@ -15,6 +17,7 @@ public class Member extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "MEMBER_ID")
private Long id;

private String email;
Expand Down Expand Up @@ -47,14 +50,6 @@ public Member(Long id, String email, String password, String type, String nickNa
this.isPaid = isPaid;
}

public static Member createMemberEntity(String email, String password, String nickName) {
return Member.builder()
.email(email)
.password(password)
.nickName(nickName)
.isPaid(false)
.build();
}

public void setEmail(String email) {
Objects.requireNonNull(email, "email이 없습니다.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.example.interviewPrep.quiz.member.dto.request;

import com.example.interviewPrep.quiz.member.domain.Member;
import com.example.interviewPrep.quiz.member.dto.Role;
import com.example.interviewPrep.quiz.utils.SHA256Util;
import lombok.Builder;
import lombok.Getter;

Expand All @@ -8,25 +11,50 @@
@Getter
public class MemberRequest {

private final String name;
private final String nickName;
private final String email;
private final String password;
private final String passwordConfirm;
private final String nickName;
private final String type;
private final String role;
private String newPassword;

@Builder
public MemberRequest(String email, String password, String passwordConfirm, String nickName, String type) {
public MemberRequest(String name, String nickName, String email, String password, String passwordConfirm, String type, String role) {
Objects.requireNonNull(name, "name이 null입니다.");
Objects.requireNonNull(nickName, "nickName이 null입니다.");
Objects.requireNonNull(email, "email이 null입니다.");
Objects.requireNonNull(password, "password가 null입니다.");
Objects.requireNonNull(passwordConfirm, "passwordConfirm이 null입니다.");
Objects.requireNonNull(nickName, "nickName이 null입니다.");
Objects.requireNonNull(type, "type이 null입니다.");
Objects.requireNonNull(role, "role이 null입니다.");

this.name = name;
this.nickName = nickName;
this.email = email;
this.password = password;
this.passwordConfirm = passwordConfirm;
this.nickName = nickName;
this.type = type;
this.role = role;
}

public static Member createMember(MemberRequest memberRequest) {
String password = SHA256Util.encryptSHA256(memberRequest.password);

Role memberRole = Role.USER;
if (memberRequest.role.equals("MENTOR")) {
memberRole = Role.MENTOR;
}

return Member.builder()
.name(memberRequest.name)
.nickName(memberRequest.nickName)
.email(memberRequest.email)
.password(password)
.type(memberRequest.type)
.role(memberRole)
.isPaid(false)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;

import java.util.Optional;

import static com.example.interviewPrep.quiz.exception.advice.ErrorCode.DUPLICATE_EMAIL;
import static com.example.interviewPrep.quiz.exception.advice.ErrorCode.NOT_FOUND_MEMBER;
import static com.example.interviewPrep.quiz.member.domain.Member.createMemberEntity;
import static com.example.interviewPrep.quiz.member.dto.response.MemberResponse.createMemberResponse;

@Service
Expand All @@ -33,20 +34,20 @@ public void createMember(MemberRequest memberRequest) {

AES256 aes256 = new AES256();
String email = memberRequest.getEmail();
String password = SHA256Util.encryptSHA256(memberRequest.getPassword());
String nickName = memberRequest.getNickName();

if (isDuplicatedEmail(email)) {
throw new CommonException(DUPLICATE_EMAIL);
}

Member member = createMemberEntity(email, password, nickName);
Member member = MemberRequest.createMember(memberRequest);

memberRepository.save(member);

}

public boolean isDuplicatedEmail(String email) {
return memberRepository.existsByEmail(email);
Optional<Member> member = memberRepository.findByEmail(email);
return member.isPresent();
}

public boolean isDuplicatedNickName(String nickName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public ResponseEntity<Page<QuestionResponse>> getQuestionsByType(@PathVariable(r
return ResponseEntity.ok(questionService.findByType(type, pageable));
}


@GetMapping("/by-company/{companyName}")
public ResponseEntity<List<QuestionResponse>> getQuestionsByCompany(@PathVariable String companyName) {
return ResponseEntity.ok(questionService.findByCompany(companyName));
}

@PutMapping("/{id}")
public ResponseEntity<Void> update(@PathVariable Long id, @RequestBody @Valid QuestionRequest questionRequest) {
questionService.updateQuestion(id, questionRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,38 @@ public class Question extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "QUESTION_ID")
private Long id;
private String title;
private String type;
private String difficulty;
private boolean freeOfCharge;

@Builder
public Question(String title, String type, String difficulty, boolean freeOfCharge) {
public Question(Long id, String title, String type, String difficulty, boolean freeOfCharge) {
Objects.requireNonNull(id, "id가 null입니다.");
Objects.requireNonNull(title, "title이 null입니다.");
Objects.requireNonNull(type, "type이 null입니다.");
Objects.requireNonNull(difficulty, "difficulty가 null입니다.");

this.id = id;
this.title = title;
this.type = type;
this.difficulty = difficulty;
this.freeOfCharge = freeOfCharge;
}

@Builder
public Question(String title, String type, String difficulty, boolean freeOfCharge) {
Objects.requireNonNull(title, "title이 null입니다.");
Objects.requireNonNull(type, "type이 null입니다.");
Objects.requireNonNull(difficulty, "difficulty가 null입니다.");

this.title = title;
this.type = type;
this.difficulty = difficulty;
this.freeOfCharge = freeOfCharge;
}

public void changeTitleOrType(String title, String type) {
this.title = title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,28 @@ public class QuestionResponse {
private final Long id;
private final String title;
private final String type;
private final boolean status;
private final String difficulty;
private final boolean freeOfCharge;

@Builder
public QuestionResponse(Long id, String title, String type, boolean status){
Objects.requireNonNull(id, "id가 null입니다.");
public QuestionResponse(Long id, String title, String type, String difficulty, boolean freeOfCharge) {
Objects.requireNonNull(title, "title이 null입니다.");
Objects.requireNonNull(type, "type이 null입니다.");

this.id = id;
this.title = title;
this.type = type;
this.status = status;
this.difficulty = difficulty;
this.freeOfCharge = freeOfCharge;
}

public static QuestionResponse createQuestionResponse(Question question){
public static QuestionResponse createQuestionResponse(Question question) {
return QuestionResponse.builder()
.id(question.getId())
.title(question.getTitle())
.type(question.getType())
.difficulty(question.getDifficulty())
.freeOfCharge(question.isFreeOfCharge())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Primary
public interface QuestionRepository extends JpaRepository<Question, Long> {

Optional<Question> findById(Long id);
Optional<Question> findById(Long questionId);

Optional<Question> findByTitle(String title);

Expand Down
Loading