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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity(name = "community_comment")
@Getter
@NoArgsConstructor
Expand Down Expand Up @@ -47,6 +49,7 @@ public CommunityComment(CommunityPost post, User user, String content, Community
/// 댓글 신고 상태 변경
public void updateStatus(ReportStatus status) {
this.status = status;
this.updatedAt = LocalDateTime.now();
}

/// 대댓글 여부 확인
Expand All @@ -56,6 +59,7 @@ public boolean isReply() {

/// 댓글 소프트 삭제
public void markAsDeleted() {
this.deletedAt = java.time.LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
this.deletedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.onebyone.kindergarten.domain.communityComments.entity.CommunityComment;
import com.onebyone.kindergarten.domain.communityComments.dto.response.CommentResponseDTO;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -64,6 +65,6 @@ Page<CommentResponseDTO> findAllCommentsWithRepliesByPostId(
Optional<CommunityComment> findByIdWithUser(@Param("id") Long id);

@Modifying
@Query("UPDATE community_comment c SET c.deletedAt = CURRENT_TIMESTAMP WHERE c.parent.id = :parentId")
void updateRepliesDeletedAt(@Param("parentId") Long parentId);
@Query("UPDATE community_comment c SET c.updatedAt = :now, c.deletedAt = :now WHERE c.parent.id = :parentId")
void updateRepliesDeletedAt(@Param("parentId") Long parentId, @Param("now") LocalDateTime now);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.onebyone.kindergarten.domain.user.entity.User;
import com.onebyone.kindergarten.domain.user.service.UserService;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Collections;

Expand Down Expand Up @@ -164,7 +165,7 @@ public void deleteComment(Long commentId, String email) {

// 대댓글이 있는 원댓글인 경우 대댓글들도 함께 삭제
if (isOriginalComment) {
commentRepository.updateRepliesDeletedAt(commentId);
commentRepository.updateRepliesDeletedAt(commentId, LocalDateTime.now());
}

// 원댓글이었다면 게시글의 댓글 수 감소
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity
@Getter
@NoArgsConstructor
Expand Down Expand Up @@ -73,10 +75,12 @@ public void decreaseLikeCount() {
/// 게시물 신고 상태 변경
public void updateStatus(ReportStatus status) {
this.status = status;
this.updatedAt = LocalDateTime.now();
}

/// 게시물 소프트 삭제
public void markAsDeleted() {
this.deletedAt = java.time.LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
this.deletedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity
@Getter
@NoArgsConstructor
Expand Down Expand Up @@ -43,10 +45,12 @@ public Inquiry(User user, String title, String content) {
public void answerInquiry(String answer) {
this.answer = answer;
this.status = InquiryStatus.ANSWERED;
this.updatedAt = LocalDateTime.now();
}

// 문의 마감
public void closeInquiry() {
this.status = InquiryStatus.CLOSED;
this.updatedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity(name = "kindergarten_internship_review")
@Getter
@Builder
Expand Down Expand Up @@ -70,6 +72,7 @@ public void updateReview(ModifyInternshipReviewRequestDTO request) {
this.learningSupportScore = request.getLearningSupportScore();
this.instructionTeacherComment = request.getInstructionTeacherComment();
this.instructionTeacherScore = request.getInstructionTeacherScore();
this.updatedAt = LocalDateTime.now();
}

public void minusLikeCount() {
Expand All @@ -82,6 +85,7 @@ public void plusLikeCount() {

/// 리뷰 소프트 삭제
public void markAsDeleted() {
this.deletedAt = java.time.LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
this.deletedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,23 @@ public Kindergarten createInternshipReview(CreateInternshipReviewRequestDTO requ

public Kindergarten modifyInternshipReview(ModifyInternshipReviewRequestDTO request, String email) {
User user = userService.getUserByEmail(email);

Kindergarten kindergarten = kindergartenService.getKindergartenById(request.getKindergartenId());

KindergartenInternshipReview review = kindergartenInternshipReviewRepository
.findById(request.getInternshipReviewId())
.orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_INTERNSHIP_REVIEW));

if (!review.getUser().equals(user)) {
throw new BusinessException(ErrorCodes.INCORRECT_USER_EXCEPTION);
// 리뷰와 유치원이 다를 때
if (!review.getKindergarten().getId().equals(kindergarten.getId())) {
throw new BusinessException(ErrorCodes.INCORRECT_KINDERGARTEN_EXCEPTION);
}

review.updateReview(request);
// 리뷰 작성자가 다를 때
if (!review.getUser().getId().equals(user.getId())) {
throw new BusinessException(ErrorCodes.REVIEW_EDIT_NOT_OWNER);
}

review.updateReview(request);
return kindergarten;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.onebyone.kindergarten.domain.kindergartenWorkHistories.dto.KindergartenWorkHistoryResponse;
import com.onebyone.kindergarten.domain.kindergartenWorkHistories.service.KindergartenWorkHistoryService;
import com.onebyone.kindergarten.global.common.ResponseDto;
import com.onebyone.kindergarten.global.facade.KindergartenWorkHistoryFacade;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
Expand All @@ -18,14 +19,15 @@
@RequiredArgsConstructor
@RequestMapping("/certification")
public class KindergartenWorkHistoryController {
private final KindergartenWorkHistoryFacade kindergartenWorkHistoryFacade;
private final KindergartenWorkHistoryService workHistoryService;

@PostMapping
@Operation(summary = "유치원 근무 이력 추가", description = "유치원 근무 이력을 추가합니다.")
public ResponseDto<KindergartenWorkHistoryResponse> addCertification(
@AuthenticationPrincipal UserDetails userDetails,
@RequestBody KindergartenWorkHistoryRequest request) {
return ResponseDto.success(workHistoryService.addCertification(userDetails.getUsername(), request));
return ResponseDto.success(kindergartenWorkHistoryFacade.addCertification(userDetails.getUsername(), request));
}

@GetMapping
Expand All @@ -39,7 +41,7 @@ public ResponseDto<List<KindergartenWorkHistoryResponse>> getCertification(@Auth
public ResponseDto<Void> deleteCertification(
@AuthenticationPrincipal UserDetails userDetails,
@PathVariable Long certificationId) {
workHistoryService.deleteCertification(userDetails.getUsername(), certificationId);
kindergartenWorkHistoryFacade.deleteCertification(userDetails.getUsername(), certificationId);
return ResponseDto.success(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,8 @@ public class KindergartenWorkHistoryService {
private final KindergartenWorkHistoryRepository workHistoryRepository;
private final KindergartenRepository kindergartenRepository;

/// 경력 개월 수 계산
private int calculateCareerMonths(User user, LocalDate startDate, LocalDate endDate, boolean isAdding) {
int currentCareerMonths = user.getCareer() == null ? 0 : Integer.parseInt(user.getCareer());
long monthsBetween = ChronoUnit.MONTHS.between(startDate, endDate);
return isAdding ?
currentCareerMonths + (int)monthsBetween :
currentCareerMonths - (int)monthsBetween;
}

/// 유치원 근무 이력 추가
@Transactional
public KindergartenWorkHistoryResponse addCertification(String email, KindergartenWorkHistoryRequest request) {

// 유치원 이름으로 유치원 조회
Kindergarten kindergarten = kindergartenRepository.findByName(request.getKindergartenName())
.orElseThrow(() -> new BusinessException(ErrorCodes.KINDERGARTEN_NOT_FOUND));

// 사용자 조회
User user = userService.getUserByEmail(email);

// 유치원 경력 개월 수 업데이트
int newCareerMonths = calculateCareerMonths(
user,
request.getStartDate(),
request.getEndDate(),
true
);
userService.updateCareer(user, String.valueOf(newCareerMonths));

public KindergartenWorkHistoryResponse addCertification(User user, Kindergarten kindergarten, KindergartenWorkHistoryRequest request) {
// 유치원 근무 이력 저장
KindergartenWorkHistory workHistory = request.toEntity(user, kindergarten);
workHistoryRepository.save(workHistory);
Expand All @@ -73,32 +46,12 @@ public List<KindergartenWorkHistoryResponse> getCertification(String email) {
return workHistoryRepository.findDtosByUser(user);
}

/// 유치원 근무 이력 삭제
@Transactional
public void deleteCertification(String email, Long historyId) {

// 유치원 근무 이력 조회
KindergartenWorkHistory workHistory = workHistoryRepository.findByIdWithKindergarten(historyId)
.orElseThrow(() -> new BusinessException(ErrorCodes.WORK_HISTORY_NOT_FOUND));

// 사용자 조회
User user = userService.getUserByEmail(email);

// 유치원 근무 이력 소유자 확인
if (!workHistory.getUser().equals(user)) {
throw new BusinessException(ErrorCodes.UNAUTHORIZED_DELETE);
}

// 유치원 경력 개월 수 업데이트
int newCareerMonths = calculateCareerMonths(
user,
workHistory.getStartDate(),
workHistory.getEndDate(),
false
);
userService.updateCareer(user, String.valueOf(newCareerMonths));
public KindergartenWorkHistory getKindergartenWorkHistory(Long certificationId) {
return workHistoryRepository.findById(certificationId).orElseThrow(() -> new BusinessException(ErrorCodes.WORK_HISTORY_NOT_FOUND));
}

// 유치원 근무 이력 삭제
/// 유치원 근무 이력 삭제
public void deleteCertification(KindergartenWorkHistory workHistory) {
workHistoryRepository.delete(workHistory);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity(name = "kindergarten_work_review")
@Builder
@NoArgsConstructor
Expand Down Expand Up @@ -90,6 +92,7 @@ public void updateReview(ModifyWorkReviewRequestDTO request) {
this.managerScore = request.getManagerScore();
this.customerComment = request.getCustomerComment();
this.customerScore = request.getCustomerScore();
this.updatedAt = LocalDateTime.now();
}

public void minusLikeCount() {
Expand All @@ -102,6 +105,7 @@ public void plusLikeCount() {

/// 리뷰 소프트 삭제
public void markAsDeleted() {
this.deletedAt = java.time.LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
this.deletedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public Kindergarten modifyWorkReview(ModifyWorkReviewRequestDTO request, String
KindergartenWorkReview review = workReviewRepository.findById(request.getWorkReviewId())
.orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_WORK_REVIEW));

if (!review.getUser().equals(user)) {
if (!review.getKindergarten().getId().equals(kindergarten.getId())) {
throw new BusinessException(ErrorCodes.INCORRECT_KINDERGARTEN_EXCEPTION);
}

if (!review.getUser().getId().equals(user.getId())) {
throw new BusinessException(ErrorCodes.REVIEW_EDIT_NOT_OWNER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Entity
Expand Down Expand Up @@ -113,14 +114,17 @@ public void update(KindergartenDTO kindergartenDTO) {
this.specialPupilCount = kindergartenDTO.getSpecialPupilCount();
this.latitude = kindergartenDTO.getLatitude();
this.longitude = kindergartenDTO.getLongitude();
this.updatedAt = LocalDateTime.now();
}

public void updateInternshipReviewAggregate(KindergartenInternshipReviewAggregate kindergartenInternshipReviewAggregate ) {
this.kindergartenInternshipReviewAggregate = kindergartenInternshipReviewAggregate;
this.updatedAt = LocalDateTime.now();
}

public void updateWorkReviewAggregate(KindergartenWorkReviewAggregate kindergartenWorkReviewAggregate) {
this.kindergartenWorkReviewAggregate = kindergartenWorkReviewAggregate;
this.updatedAt = LocalDateTime.now();
}

public KindergartenSimpleDTO toSimpleDTO() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Entity(name = "kindergarten_internship_review_aggregate")
@Getter
Expand All @@ -31,15 +32,10 @@ public class KindergartenInternshipReviewAggregate extends BaseEntity {
@Column(name = "instruction_teacher_score_aggregate", precision = 10, scale = 2)
private BigDecimal instructionTeacherScoreAggregate; // 지도교사 총합

public void updateWorkEnvironmentScoreAggregate(BigDecimal avgWorkEnvironmentScore) {
public void updateScoreAggregates(BigDecimal avgWorkEnvironmentScore, BigDecimal avgLearningSupportScore, BigDecimal avgInstructionTeacherScore) {
this.workEnvironmentScoreAggregate = avgWorkEnvironmentScore;
}

public void updateLearningSupportScoreAggregate(BigDecimal avgLearningSupportScore) {
this.learningSupportScoreAggregate = avgLearningSupportScore;
}

public void updateInstructionTeacherScoreAggregate(BigDecimal avgInstructionTeacherScore) {
this.instructionTeacherScoreAggregate = avgInstructionTeacherScore;
this.updatedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Entity(name = "kindergarten_work_review_aggregate")
@Getter
Expand Down Expand Up @@ -37,23 +38,12 @@ public class KindergartenWorkReviewAggregate extends BaseEntity {
@Column(name = "customer_score_aggregate", precision = 10, scale = 2)
private BigDecimal customerScoreAggregate; // 고객 총합

public void updateBenefitAndSalaryScoreAggregate(BigDecimal avgBenefitAndSalary) {
public void updateScoreAggregates(BigDecimal avgBenefitAndSalary, BigDecimal avgWorkLifeBalance, BigDecimal avgWorkEnvironment, BigDecimal avgManager, BigDecimal avgCustomer) {
this.benefitAndSalaryScoreAggregate = avgBenefitAndSalary;
}

public void updateWorkLiftBalanceScoreAggregate(BigDecimal avgWorkLifeBalance) {
this.workLiftBalanceScoreAggregate = avgWorkLifeBalance;
}

public void updateWorkEnvironmentScoreAggregate(BigDecimal avgWorkEnvironment) {
this.workEnvironmentScoreAggregate = avgWorkEnvironment;
}

public void updateManagerScoreAggregate(BigDecimal avgManager) {
this.managerScoreAggregate = avgManager;
}

public void updateCustomerScoreAggregate(BigDecimal avgCustomer) {
this.customerScoreAggregate = avgCustomer;
this.updatedAt = LocalDateTime.now();
}
}
Loading