Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pp449 committed Oct 19, 2024
2 parents 5d937e6 + 1bd4df4 commit 9f0fdc0
Show file tree
Hide file tree
Showing 151 changed files with 4,813 additions and 1,947 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/frontend-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Set timezone to Asia/Seoul
run: sudo timedatectl set-timezone Asia/Seoul

# 노드 설치
- name: Install Nodejs
uses: actions/setup-node@v4
Expand Down
464 changes: 231 additions & 233 deletions backend/src/main/java/corea/ContextInitializer.java

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion backend/src/main/java/corea/DataInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void run(ApplicationArguments args) {
LocalDateTime.of(2024, 12, 25, 12, 30),
LocalDateTime.of(2025, 1, 3, 12, 0),
RoomClassification.BACKEND, RoomStatus.OPEN));
roomRepository.save(
Room closedRoom = roomRepository.save(
new Room("방 제목 10", "방 설명 10", 3,
null, null, List.of("TDD", "클린코드"),
1, 20, member1,
Expand Down Expand Up @@ -204,6 +204,7 @@ public void run(ApplicationArguments args) {
participationRepository.save(new Participation(room7, member1, MemberRole.BOTH, room7.getMatchingSize()));
participationRepository.save(new Participation(room7, member2, MemberRole.BOTH, room7.getMatchingSize()));

participationRepository.save(new Participation(closedRoom, member1, MemberRole.BOTH, closedRoom.getMatchingSize()));
participationRepository.save(new Participation(roomProgress, member1, MemberRole.BOTH, roomProgress.getMatchingSize()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public AuthInfo resolveArgument(MethodParameter parameter, ModelAndViewContainer
if (accessToken.equals(ANONYMOUS)) {
throw new CoreaException(ExceptionType.AUTHORIZATION_ERROR);
}
log.info("로그인 시도[토큰={}]", accessToken);

long memberId = tokenService.findMemberIdByToken(accessToken);
Member member = memberRepository.findById(memberId)
Expand Down
13 changes: 11 additions & 2 deletions backend/src/main/java/corea/auth/service/LoginService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import corea.member.domain.Member;
import corea.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static corea.exception.ExceptionType.INVALID_TOKEN;
import static corea.exception.ExceptionType.TOKEN_EXPIRED;

@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand All @@ -35,7 +37,13 @@ public TokenInfo login(GithubUserInfo userInfo) {
}

private Member register(GithubUserInfo userInfo) {
return memberRepository.save(new Member(userInfo.login(), userInfo.avatarUrl(), userInfo.name(), userInfo.email(), true, userInfo.id()));
Member member = memberRepository.save(new Member(userInfo.login(), userInfo.avatarUrl(), userInfo.name(), userInfo.email(), true, userInfo.id()));
logCreateMembers(member);
return member;
}

private void logCreateMembers(Member member) {
log.info("멤버를 생성했습니다. 멤버 id={}, 멤버 이름={},깃허브 id={}, 닉네임={}", member.getId(), member.getName(), member.getGithubUserId(), member.getUsername());
}

private String extendAuthorization(Member member) {
Expand All @@ -56,7 +64,8 @@ public String refresh(String refreshToken) {
.orElseThrow(() -> new CoreaException(INVALID_TOKEN));
return tokenService.createAccessToken(info.getMember());
} catch (CoreaException e) {
if (e.getExceptionType().equals(TOKEN_EXPIRED)) {
if (e.getExceptionType()
.equals(TOKEN_EXPIRED)) {
logoutService.logoutByExpiredRefreshToken(refreshToken);
}
throw e;
Expand Down
6 changes: 4 additions & 2 deletions backend/src/main/java/corea/exception/ExceptionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
@Getter
public enum ExceptionType {

ALREADY_APPLY(HttpStatus.BAD_REQUEST, "해당 방에 이미 참여했습니다."),
NOT_ALREADY_APPLY(HttpStatus.BAD_REQUEST, "아직 참여하지 않은 방입니다."),
ALREADY_PARTICIPATED_ROOM(HttpStatus.BAD_REQUEST, "해당 방에 이미 참여했습니다."),
NOT_PARTICIPATED_ROOM(HttpStatus.BAD_REQUEST, "아직 참여하지 않은 방입니다."),
ROOM_STATUS_INVALID(HttpStatus.BAD_REQUEST, "방이 마감되었습니다."),
MEMBER_IS_NOT_MANAGER(HttpStatus.BAD_REQUEST, "매니저가 아닙니다."),
ROOM_PARTICIPANT_EXCEED(HttpStatus.BAD_REQUEST, "방 참여 인원 수가 최대입니다."),
PARTICIPANT_SIZE_LACK(HttpStatus.BAD_REQUEST, "참여 인원이 부족하여 매칭을 진행할 수 없습니다."),
PARTICIPANT_SIZE_LACK_DUE_TO_PULL_REQUEST(HttpStatus.BAD_REQUEST, "pull request 미제출로 인해 인원이 부족하여 매칭을 진행할 수 없습니다."),
Expand All @@ -26,6 +27,7 @@ public enum ExceptionType {
INVALID_TOKEN(HttpStatus.UNAUTHORIZED, "토큰이 올바르지 않습니다."),
AUTHORIZATION_ERROR(HttpStatus.UNAUTHORIZED, "인증에 실패했습니다."),
ROOM_DELETION_AUTHORIZATION_ERROR(HttpStatus.UNAUTHORIZED, "방 삭제 권한이 없습니다. 방 생성자만 방을 삭제할 수 있습니다."),
FEEDBACK_UPDATE_AUTHORIZATION_ERROR(HttpStatus.UNAUTHORIZED, "피드백 수정 권한이 없습니다. 피드백 작성자만 피드백을 수정할 수 있습니다."),

MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 멤버를 찾을 수 없습니다."),
ROOM_NOT_FOUND(HttpStatus.NOT_FOUND, "방을 찾을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import corea.auth.annotation.LoginMember;
import corea.auth.domain.AuthInfo;
import corea.feedback.dto.DevelopFeedbackRequest;
import corea.feedback.dto.DevelopFeedbackCreateRequest;
import corea.feedback.dto.DevelopFeedbackResponse;
import corea.feedback.dto.DevelopFeedbackUpdateRequest;
import corea.feedback.service.DevelopFeedbackService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -16,15 +17,13 @@ public class DevelopFeedbackController implements DevelopFeedbackControllerSpeci

private final DevelopFeedbackService developFeedbackService;

@Override
@PostMapping
public ResponseEntity<Void> create(@PathVariable long roomId, @LoginMember AuthInfo authInfo, @RequestBody DevelopFeedbackRequest request) {
public ResponseEntity<Void> create(@PathVariable long roomId, @LoginMember AuthInfo authInfo, @RequestBody DevelopFeedbackCreateRequest request) {
developFeedbackService.create(roomId, authInfo.getId(), request);
return ResponseEntity.ok()
.build();
}

@Override
@GetMapping
public ResponseEntity<DevelopFeedbackResponse> developFeedback(
@PathVariable long roomId, @RequestParam String username, @LoginMember AuthInfo authInfo) {
Expand All @@ -33,10 +32,9 @@ public ResponseEntity<DevelopFeedbackResponse> developFeedback(
.body(response);
}

@Override
@PutMapping("/{feedbackId}")
public ResponseEntity<Void> update(
@PathVariable long roomId, @PathVariable long feedbackId, @LoginMember AuthInfo authInfo, @RequestBody DevelopFeedbackRequest request) {
@PathVariable long roomId, @PathVariable long feedbackId, @LoginMember AuthInfo authInfo, @RequestBody DevelopFeedbackUpdateRequest request) {
developFeedbackService.update(feedbackId, authInfo.getId(), request);
return ResponseEntity.ok()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import corea.auth.domain.AuthInfo;
import corea.exception.ExceptionType;
import corea.feedback.dto.DevelopFeedbackRequest;
import corea.feedback.dto.DevelopFeedbackCreateRequest;
import corea.feedback.dto.DevelopFeedbackResponse;
import corea.feedback.dto.DevelopFeedbackUpdateRequest;
import corea.global.annotation.ApiErrorResponses;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -26,7 +27,7 @@ ResponseEntity<Void> create(
@Parameter(description = "방 아이디", example = "1")
long roomId,
AuthInfo authInfo,
DevelopFeedbackRequest request);
DevelopFeedbackCreateRequest request);

@Operation(summary = "개발 관련 피드백 리스트를 반환합니다.",
description = "자신에게 사람들이 남긴 개발 능력 관련 피드백을 읽어옵니다. <br>" +
Expand Down Expand Up @@ -59,5 +60,5 @@ ResponseEntity<Void> update(
@Parameter(description = "피드백 아이디", example = "2")
long feedbackId,
AuthInfo authInfo,
DevelopFeedbackRequest request);
DevelopFeedbackUpdateRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public DevelopFeedback(long roomId, Member deliver, Member receiver, int evaluat
this(null, roomId, deliver, receiver, evaluatePoint, keywords, feedBackText, recommendationPoint);
}

public boolean isNotMatchingDeliver(long deliverId) {
return deliver.isNotMatchingId(deliverId);
}

public void update(int evaluationPoint, List<String> feedbackKeywords, String feedbackText, int recommendationPoint) {
this.evaluatePoint = evaluationPoint;
this.keywords = FeedbackKeywordConverter.convertToKeywords(feedbackKeywords);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package corea.feedback.domain;

import corea.exception.CoreaException;
import corea.exception.ExceptionType;
import corea.feedback.dto.FeedbackOutput;
import corea.feedback.repository.DevelopFeedbackRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class DevelopFeedbackReader {

private final DevelopFeedbackRepository developFeedbackRepository;

public Map<Long, List<FeedbackOutput>> collectDeliverDevelopFeedback(long feedbackDeliverId) {
return developFeedbackRepository.findAllByDeliverId(feedbackDeliverId)
.stream()
.map(FeedbackOutput::fromDeliver)
.collect(Collectors.groupingBy(FeedbackOutput::roomId));
}

public Map<Long, List<FeedbackOutput>> collectReceivedDevelopFeedback(long feedbackReceiverId) {
return developFeedbackRepository.findAllByReceiverId(feedbackReceiverId)
.stream()
.map(FeedbackOutput::fromReceiver)
.collect(Collectors.groupingBy(FeedbackOutput::roomId));
}

public DevelopFeedback findById(long feedbackId) {
return developFeedbackRepository.findById(feedbackId)
.orElseThrow(() -> new CoreaException(ExceptionType.FEEDBACK_NOT_FOUND));
}

public DevelopFeedback findDevelopFeedback(long roomId, long deliverId, String username) {
return developFeedbackRepository.findByRoomIdAndDeliverIdAndReceiverUsername(roomId, deliverId, username)
.orElseThrow(() -> new CoreaException(ExceptionType.FEEDBACK_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package corea.feedback.domain;

import corea.exception.CoreaException;
import corea.exception.ExceptionType;
import corea.feedback.dto.DevelopFeedbackUpdateInput;
import corea.feedback.repository.DevelopFeedbackRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Component
@RequiredArgsConstructor
@Transactional
public class DevelopFeedbackWriter {

private final DevelopFeedbackRepository developFeedbackRepository;

public DevelopFeedback create(DevelopFeedback developFeedback, long roomId, long deliverId, long receiverId) {
validateAlreadyExist(roomId, deliverId, receiverId);
log.info("개발 피드백 작성 [방 ID={}, 작성자 ID={}, 수신자 ID={}]", roomId, deliverId, receiverId);

return developFeedbackRepository.save(developFeedback);
}

private void validateAlreadyExist(long roomId, long deliverId, long receiverId) {
if (developFeedbackRepository.existsByRoomIdAndDeliverIdAndReceiverId(roomId, deliverId, receiverId)) {
throw new CoreaException(ExceptionType.ALREADY_COMPLETED_FEEDBACK);
}
}

public void update(DevelopFeedback developFeedback, long deliverId, DevelopFeedbackUpdateInput input) {
validateUpdateAuthority(developFeedback, deliverId);
log.info("개발 피드백 업데이트 [피드백 ID={}, 작성자 ID={}, 요청값={}]", developFeedback.getId(), developFeedback, input);

developFeedback.update(
input.evaluationPoint(),
input.feedbackKeywords(),
input.feedbackText(),
input.recommendationPoint()
);
}

private void validateUpdateAuthority(DevelopFeedback developFeedback, long deliverId) {
if (developFeedback.isNotMatchingDeliver(deliverId)) {
throw new CoreaException(ExceptionType.FEEDBACK_UPDATE_AUTHORIZATION_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package corea.feedback.domain;

import corea.feedback.dto.FeedbackOutput;
import corea.feedback.repository.SocialFeedbackRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class SocialFeedbackReader {

private final SocialFeedbackRepository socialFeedbackRepository;

public Map<Long, List<FeedbackOutput>> collectDeliverSocialFeedback(long feedbackDeliverId) {
return socialFeedbackRepository.findAllByDeliverId(feedbackDeliverId)
.stream()
.map(FeedbackOutput::fromDeliver)
.collect(Collectors.groupingBy(FeedbackOutput::roomId));
}

public Map<Long, List<FeedbackOutput>> collectReceivedSocialFeedback(long feedbackReceiverId) {
return socialFeedbackRepository.findAllByReceiverId(feedbackReceiverId)
.stream()
.map(FeedbackOutput::fromReceiver)
.collect(Collectors.groupingBy(FeedbackOutput::roomId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package corea.feedback.dto;

import corea.feedback.domain.DevelopFeedback;
import corea.feedback.util.FeedbackKeywordConverter;
import corea.member.domain.Member;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

import java.util.List;

@Schema(description = "개발 능력 관련 피드백 작성 요청")
public record DevelopFeedbackCreateRequest(@Schema(description = "리뷰이 아이디", example = "2")
@NotNull
long receiverId,

@Schema(description = "평가 점수", example = "4")
@NotNull
int evaluationPoint,

@Schema(description = "선택한 피드백 키워드", example = "[\"코드를 이해하기 쉬웠어요\", \"컨벤션이 잘 지켜졌어요\"]")
@NotNull
List<String> feedbackKeywords,

@Schema(description = "부가 작성 가능한 피드백 텍스트", example = "처음 자바를 접해봤다고 했는데 생각보다 매우 잘 구성되어 있는 코드였습니다. ...")
String feedbackText,

@Schema(description = "랭킹에 필요한 추천 점수", example = "2")
int recommendationPoint) {

public DevelopFeedback toEntity(long roomId, Member deliver, Member receiver) {
return new DevelopFeedback(
roomId,
deliver,
receiver,
evaluationPoint,
FeedbackKeywordConverter.convertToKeywords(feedbackKeywords),
feedbackText,
recommendationPoint
);
}
}

This file was deleted.

Loading

0 comments on commit 9f0fdc0

Please sign in to comment.