Skip to content

Commit

Permalink
Merge branch 'main' into fe/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
JaeHongDev authored Jul 8, 2024
2 parents 1c64262 + a483afb commit a1320d6
Show file tree
Hide file tree
Showing 34 changed files with 538 additions and 60 deletions.
7 changes: 6 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ out/
.vscode/


/src/main/resources/**
/src/main/resources/*.yml
/src/main/resources/*.key
/src/main/resources/*.pub
/src/main/resources/*.properties
/src/main/resources/*.st

15 changes: 15 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## 깃 컨벤션

- feat: 새로운 기능 추가
- fix: 버그 수정
- docs: 문서 수정
- style: 코드 스타일 변경 (코드 포매팅, 세미콜론 누락 등)
- design: 사용자 UI 디자인 변경 (CSS 등)
- test: 테스트 코드, 리팩토링 (Test Code)
- refactor: 리팩토링 (Production Code)
- build: 빌드 파일 수정
- ci: CI 설정 파일 수정
- perf: 성능 개선
- chore: 자잘한 수정이나 빌드 업데이트
- rename: 파일 혹은 폴더명을 수정만 한 경우
- remove: 파일을 삭제만 한 경우
15 changes: 13 additions & 2 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ version = '0.0.1-SNAPSHOT'

jib {
from {
image = 'openjdk:21-jdk'
image = 'bellsoft/liberica-openjdk-alpine:21'
}

to {
Expand All @@ -39,6 +39,7 @@ jib {

container {
jvmFlags = [
'-Duser.timezone="Asia/Seoul"',
'--enable-preview',
String.format('-Dspring.profiles.active=%s', "prod"),
'-Xms1024m',
Expand Down Expand Up @@ -75,7 +76,7 @@ dependencies {


// jwt
implementation 'org.springframework.security:spring-security-oauth2-jose:6.2.4'
implementation 'org.springframework.security:spring-security-oauth2-jose:6.2.3'

// cloud speech
implementation 'com.google.cloud:google-cloud-speech:4.38.0'
Expand All @@ -85,6 +86,15 @@ dependencies {
// validation
implementation 'org.springframework.boot:spring-boot-starter-validation'

// flyway
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-mysql'

// mysql
implementation platform("com.google.cloud:spring-cloud-gcp-dependencies:5.4.3")
implementation "com.google.cloud:spring-cloud-gcp-starter-sql-mysql"
implementation "com.google.cloud:spring-cloud-gcp-starter-storage"

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand All @@ -96,6 +106,7 @@ dependencies {
//developmentOnly 'org.springframework.boot:spring-boot-devtools'
// h2
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

Expand Down
2 changes: 1 addition & 1 deletion backend/secret
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package in.backend.core.auth.application;


import in.backend.core.auth.application.payload.IssuedToken;
import in.backend.core.auth.domain.Visitor;
import in.backend.core.auth.infrastrcutrue.RefreshTokenWriter;
import in.backend.core.auth.infrastrcutrue.RefreshTokenReader;
import in.backend.global.provider.JwtProvider;
import java.time.Instant;
import lombok.RequiredArgsConstructor;
Expand All @@ -12,21 +10,16 @@
@Service
@RequiredArgsConstructor
public class TokenReissue {

private final JwtProvider jwtProvider;
private final RefreshTokenWriter refreshTokenWriter;

public IssuedToken publish(Visitor visitor) {
var now = Instant.now();
private final RefreshTokenReader refreshTokenReader;

var accessToken = jwtProvider.createAccessToken(visitor.memberId(), now);
var refreshToken = jwtProvider.createRefreshToken(visitor.memberId(), now);
public String publish(String refreshToken) {
jwtProvider.validRefreshToken(refreshToken);

refreshTokenWriter.write(visitor.memberId(), refreshToken);

return IssuedToken.builder()
.accessToken(accessToken)
.refreshToken(refreshToken)
.build();
return jwtProvider.createAccessToken(
refreshTokenReader.read(refreshToken).getId(),
Instant.now()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;


@Getter
@Entity
@NoArgsConstructor
@Table(name = "REFRESH_TOKENS")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package in.backend.core.auth.infrastrcutrue;


import in.backend.core.auth.entity.RefreshTokenEntity;
import in.backend.global.exception.GlobalExceptionCode;
import in.backend.global.exception.RefreshTokenException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -14,4 +17,9 @@ public class RefreshTokenReader {
public boolean existsBy(Long memberId) {
return refreshTokenRepository.existsById(memberId);
}

public RefreshTokenEntity read(String refreshToken) {
return refreshTokenRepository.findByToken(refreshToken)
.orElseThrow(() -> new RefreshTokenException(GlobalExceptionCode.NOT_FOUND_REFRESH_TOKEN));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package in.backend.core.auth.infrastrcutrue;

import in.backend.core.auth.entity.RefreshTokenEntity;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface RefreshTokenRepository extends JpaRepository<RefreshTokenEntity, Long> {

Optional<RefreshTokenEntity> findByToken(String refreshToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand Down Expand Up @@ -69,17 +70,14 @@ public OAuthProfileResponse getProfile(@ModelAttribute OAuthProfileRequest profi
return socialLoginProcessor.findProfile(profile);
}

@MemberOnly
@PostMapping("/token/reissue")
public ResponseEntity<AccessTokenResponse> reIssue(
@Auth Visitor visitor,
HttpServletResponse response
@CookieValue("refreshToken") final String refreshToken
) {
var issuedToken = tokenReissue.publish(visitor);
response.addHeader(SET_COOKIE, cookieProvider.createCookie(issuedToken.refreshToken()).toString());
var accessToken = tokenReissue.publish(refreshToken);

return ResponseEntity.status(CREATED)
.body(new AccessTokenResponse(issuedToken.accessToken()));
.body(new AccessTokenResponse(accessToken));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@Getter
@Entity
@Table(name = "interview")
@Table(name = "interviews")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class InterviewEntity extends BaseEntity {

Expand All @@ -42,7 +42,7 @@ public class InterviewEntity extends BaseEntity {
/**
* 현재 진행 중인 면접 질문 번호
*/
@Column(nullable = false)
@Column(nullable = false, name = "interview_index")
private int index;
/**
* 인터뷰 면접 질문의 수
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import in.backend.core.interview.presentation.payload.InterviewQuestionResponse;
import in.backend.core.interview.presentation.payload.InterviewSubmitRequest;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -87,10 +88,10 @@ public FeedbackResponse requestFeedback(
@Auth Visitor visitor,
@RequestBody FeedbackRequest request
) {
return feedbackProvider.execute(request.question, request.answer);
return feedbackProvider.execute(request.question, request.answer, request.tailQuestions);
}

public record FeedbackRequest(String question, String answer) {
public record FeedbackRequest(String question, String answer, List<String> tailQuestions) {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package in.backend.core.question.application;

import in.backend.global.entity.ActionType;

public record QuestionSaveCommand(
ActionType action,
Long questionId,
Long questionSetId,
Integer sequence,
String question
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package in.backend.core.question.application;


import in.backend.core.question.application.QuestionWriter.QuestionInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class QuestionService {
private final QuestionWriter questionWriter;

public Long save(QuestionSaveCommand command) {
return switch (command.action()) {
case CREATE -> questionWriter.write(new QuestionInfo(command));
case UPDATE -> questionWriter.write(command.questionId(), new QuestionInfo(command));
case DELETE -> throw new UnsupportedOperationException();
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,31 @@ public class QuestionWriter {
private final QuestionReader questionReader;


public Long execute(QuestionInfo questionInfo) {
return questionRepository.save(questionInfo.toEntity()).getId();
public Long write(QuestionInfo questionInfo) {
return questionRepository.save(questionInfo.toEntity())
.getId();
}

public void update(Long questionId, QuestionInfo questionInfo) {
public Long write(Long questionId, QuestionInfo questionInfo) {
var question = questionReader.read(questionId);

question.update(questionInfo);

return question.getId();
}

public record QuestionInfo(
String content,
String referenceLinks,
int sequence
) {

public QuestionInfo(QuestionSaveCommand command) {
this(command.question(), command.sequence());
}

public QuestionEntity toEntity() {
return QuestionEntity.builder()
.content(content)
.referenceLinks(referenceLinks)
.sequence(sequence)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public QuestionEntity(

public void update(QuestionInfo questionInfo) {
applyIfPresent(questionInfo.content(), value -> this.content = value);
applyIfPresent(questionInfo.referenceLinks(), value -> this.referenceLinks = value);
applyIfPresent(questionInfo.sequence(), value -> this.sequence = value);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package in.backend.core.question.presentation;


import in.backend.core.auth.domain.Visitor;
import in.backend.core.auth.domain.attributes.Auth;
import in.backend.core.question.presentation.payload.QuestionSaveRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/questions")
public class QuestionApi {


@PostMapping
public void save(
@RequestBody QuestionSaveRequest questionSaveRequest,
@Auth Visitor visitor
) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package in.backend.core.question.presentation.payload;

public record QuestionDetailResponse(
Long questionId,
Long questionSetId,
String question,
Integer sequence
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package in.backend.core.question.presentation.payload;

import in.backend.global.entity.ActionType;

public record QuestionSaveRequest(
ActionType action,
Long questionId,
Long questionSetId,
Integer sequence,
String question
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package in.backend.core.questionset.application;

import lombok.Builder;
import org.springframework.web.multipart.MultipartFile;

@Builder
public record QuestionSetCreator(
String title,
String description,
String thumbnailUrl,
MultipartFile multipartFile,
int defaultTailQuestionDepth,
int defaultTimeToAnswer,
int defaultTimeToThink
) {
}
Loading

0 comments on commit a1320d6

Please sign in to comment.