Skip to content

Commit

Permalink
Revert "Merge branch 'auth-refactor'"
Browse files Browse the repository at this point in the history
This reverts commit bfeee0b, reversing
changes made to af2e0cd.
  • Loading branch information
dkflfkd53 committed Aug 27, 2024
1 parent bfeee0b commit 6dc6318
Show file tree
Hide file tree
Showing 42 changed files with 181 additions and 357 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.example.whopper.application.library.impl;

import com.example.whopper.application.library.usecase.ChangeLibraryAccessRightUseCase;
import com.example.whopper.domain.library.LibraryModel;
import com.example.whopper.domain.library.LibraryRepository;
import com.example.whopper.domain.library.LibraryMongoRepository;
import com.example.whopper.domain.library.LibraryEntity;
import com.example.whopper.domain.library.type.AccessRight;
import com.example.whopper.common.exception.library.LibraryNotFoundException;
import com.example.whopper.interfaces.library.dto.LibraryElementDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -13,14 +13,15 @@
@RequiredArgsConstructor
public class ChangeLibraryAccessRightService implements ChangeLibraryAccessRightUseCase {

private final LibraryRepository libraryRepository;
private final LibraryMongoRepository libraryMongoRepository;

@Override
@Transactional
public void changeLibraryAccessRight(String libraryId, LibraryElementDto.AccessRight accessRight) {
LibraryModel library = libraryRepository.findById(libraryId)
public void changeLibraryAccessRight(String libraryId, AccessRight accessRight) {
LibraryEntity library = libraryMongoRepository.findById(libraryId)
.orElseThrow(() -> LibraryNotFoundException.EXCEPTION);

libraryRepository.save(library.changeAccessRight(accessRight));
library.changeAccessRight(accessRight);
libraryMongoRepository.save(library);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.example.whopper.application.library.impl;

import com.example.whopper.application.library.usecase.CreateLibraryUseCase;
import com.example.whopper.domain.library.LibraryModel;
import com.example.whopper.domain.library.LibraryRepository;
import com.example.whopper.domain.library.LibraryMongoRepository;
import com.example.whopper.domain.library.ResumeIndex;
import com.example.whopper.domain.library.LibraryEntity;
import com.example.whopper.domain.library.type.AccessRight;
import com.example.whopper.common.http.response.DataResponseInfo;
import com.example.whopper.interfaces.library.dto.LibraryElementDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -15,13 +16,21 @@
@RequiredArgsConstructor
public class CreateLibraryService implements CreateLibraryUseCase {

private final LibraryRepository libraryRepository;
private final LibraryMongoRepository libraryMongoRepository;

@Override
@Transactional
public void createLibrary(Integer grade, String filePath, DataResponseInfo<LibraryElementDto.ResumeIndex> index) {
public void createLibrary(Integer grade, String filePath, DataResponseInfo<ResumeIndex> index) {
LocalDateTime now = LocalDateTime.now();

libraryRepository.save(new LibraryModel(null, now.getYear(), grade, filePath, now, LibraryElementDto.AccessRight.PRIVATE, index.data()));
libraryMongoRepository.save(
LibraryEntity.builder()
.year(now.getYear())
.grade(grade)
.filePath(filePath)
.createAt(now)
.accessRight(AccessRight.PRIVATE)
.index(index.data())
.build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import com.example.whopper.application.file.usecase.PdfUseCase;
import com.example.whopper.application.library.usecase.FindLibraryDetailUseCase;
import com.example.whopper.domain.library.LibraryModel;
import com.example.whopper.domain.library.LibraryMongoRepository;
import com.example.whopper.domain.library.LibraryEntity;
import com.example.whopper.domain.library.LibraryRepository;
import com.example.whopper.interfaces.library.dto.response.LibraryDetailResponse;
import com.example.whopper.common.exception.library.LibraryNotFoundException;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,15 +14,15 @@
@RequiredArgsConstructor
public class FindLibraryDetailService implements FindLibraryDetailUseCase {

private final LibraryRepository libraryRepository;
private final LibraryMongoRepository libraryMongoRepository;
private final PdfUseCase pdfUseCase;

@Override
@Transactional(readOnly = true)
public LibraryDetailResponse findLibraryDetail(String id) {
LibraryModel library = libraryRepository.findById(id)
public LibraryDetailResponse findLibraryDetail(String libraryId) {
LibraryEntity library = libraryMongoRepository.findById(libraryId)
.orElseThrow(() -> LibraryNotFoundException.EXCEPTION);

return new LibraryDetailResponse(library, pdfUseCase.getPdfFileUrl(library.filePath()));
return new LibraryDetailResponse(library, pdfUseCase.getPdfFileUrl(library.getFilePath()));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.whopper.application.library.impl;

import com.example.whopper.application.library.usecase.FindLibraryIndexUseCase;
import com.example.whopper.domain.library.LibraryModel;
import com.example.whopper.domain.library.LibraryRepository;
import com.example.whopper.domain.library.LibraryMongoRepository;
import com.example.whopper.domain.library.LibraryEntity;
import com.example.whopper.interfaces.library.dto.response.LibraryIndexResponse;
import com.example.whopper.common.exception.library.LibraryNotFoundException;
import lombok.RequiredArgsConstructor;
Expand All @@ -13,14 +13,14 @@
@RequiredArgsConstructor
public class FindLibraryIndexService implements FindLibraryIndexUseCase {

private final LibraryRepository libraryRepository;
private final LibraryMongoRepository libraryMongoRepository;

@Override
@Transactional(readOnly = true)
public LibraryIndexResponse findLibraryIndex(String id) {
LibraryModel library = libraryRepository.findById(id)
public LibraryIndexResponse findLibraryIndex(String libraryId) {
LibraryEntity library = libraryMongoRepository.findById(libraryId)
.orElseThrow(() -> LibraryNotFoundException.EXCEPTION);

return new LibraryIndexResponse(library.index());
return new LibraryIndexResponse(library.getIndex());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.example.whopper.application.file.usecase.PdfUseCase;
import com.example.whopper.application.library.usecase.FindLibraryUseCase;
import com.example.whopper.domain.library.LibraryModel;
import com.example.whopper.domain.library.LibraryRepository;
import com.example.whopper.domain.library.LibraryMongoRepository;
import com.example.whopper.domain.library.LibraryEntity;
import com.example.whopper.interfaces.library.dto.response.LibraryDetailResponse;
import com.example.whopper.interfaces.library.dto.response.LibraryResponse;
import com.example.whopper.common.exception.library.LibraryNotFoundException;
Expand All @@ -17,24 +17,24 @@
@RequiredArgsConstructor
public class FindLibraryService implements FindLibraryUseCase {

private final LibraryRepository libraryRepository;
private final LibraryMongoRepository libraryMongoRepository;
private final PdfUseCase pdfUseCase;

@Override
public LibraryDetailResponse findLibraryDetail(String id) {
LibraryModel library = libraryRepository.findById(id)
public LibraryDetailResponse findLibraryDetail(String libraryId) {
LibraryEntity library = libraryMongoRepository.findById(libraryId)
.orElseThrow(() -> LibraryNotFoundException.EXCEPTION);

return new LibraryDetailResponse(library, pdfUseCase.getPdfFileUrl(library.filePath()));
return new LibraryDetailResponse(library, pdfUseCase.getPdfFileUrl(library.getFilePath()));
}

@Override
public DataResponseInfo<LibraryResponse> findLibrary(Integer year) {
var library = (year == 0)
? libraryRepository.findAll()
: libraryRepository.findAllByYear(year);
? libraryMongoRepository.findAll()
: libraryMongoRepository.findAllByYear(year);

return DataResponseInfo.of(library
return DataResponseInfo.of(library.stream()
.map(LibraryResponse::fromEntity)
.toList());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.whopper.application.library.usecase;

import com.example.whopper.interfaces.library.dto.LibraryElementDto;
import com.example.whopper.domain.library.type.AccessRight;

public interface ChangeLibraryAccessRightUseCase {
void changeLibraryAccessRight(String libraryId, LibraryElementDto.AccessRight accessRight);
void changeLibraryAccessRight(String libraryId, AccessRight accessRight);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.whopper.application.library.usecase;

import com.example.whopper.domain.library.ResumeIndex;
import com.example.whopper.common.http.response.DataResponseInfo;
import com.example.whopper.interfaces.library.dto.LibraryElementDto;

public interface CreateLibraryUseCase {
void createLibrary(Integer grade, String filePath, DataResponseInfo<LibraryElementDto.ResumeIndex> index);
void createLibrary(Integer grade, String filePath, DataResponseInfo<ResumeIndex> index);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public abstract class AbstractUpdateElementServiceBase<T> {

@Transactional
public void update(T request) {
final var resume = currentStudent.getResume();
var resume = currentStudent.getResume();

if (!resume.status().equals(ResumeElementDto.Status.ONGOING)) {
throw ResumeModificationException.EXCEPTION;
}

final var newResume = updateResume(resume, request);
var newResume = updateResume(resume, request);
resumeRepository.save(newResume);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import com.example.whopper.application.teacher.component.TeacherComponent;
import com.example.whopper.domain.feedback.FeedbackModel;
import com.example.whopper.domain.feedback.FeedbackRepository;
import com.example.whopper.domain.library.LibraryRepository;
import com.example.whopper.domain.resume.ResumeModel;
import com.example.whopper.domain.resume.ResumeRepository;
import com.example.whopper.interfaces.resume.dto.response.CompletionElementLevelResponse;
import com.example.whopper.interfaces.resume.dto.response.*;
import com.example.whopper.common.exception.resume.ResumeNotFoundException;
import com.example.whopper.domain.library.LibraryMongoRepository;
import com.example.whopper.domain.library.ShardLibrary;
import com.example.whopper.application.student.component.CurrentStudent;
import com.example.whopper.common.http.response.DataResponseInfo;
import lombok.RequiredArgsConstructor;
Expand All @@ -28,15 +29,15 @@
class FindResumeService implements FindResumeUseCase {
private final ResumeRepository resumeRepository;
private final FeedbackRepository feedbackRepository;
private final LibraryRepository libraryRepository;
private final LibraryMongoRepository libraryMongoRepository;
private final CurrentStudent currentStudent;
private final TeacherComponent teacherComponent;

@Override
public ResumeResponse getIntroduceRecentlySharedResumes() {
var currentStudentResume = currentStudent.getResume();
var libraries = libraryRepository.findTop3ByOrderByCreateAtDesc()
.map(ResumeResponse.ShardLibrary::toShardLibrary)
var libraries = libraryMongoRepository.findTop3ByOrderByCreateAtDesc()
.map(ShardLibrary::fromLibraryEntity)
.toList();

return ResumeResponse.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@Builder
@AllArgsConstructor
@Document(collection = "feedback_repo")
@AllArgsConstructor(access = AccessLevel.PRIVATE)
class FeedbackEntity {
@Id
private String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,8 @@
import org.mapstruct.MappingConstants;
import org.mapstruct.ReportingPolicy;

import java.util.Optional;
import java.util.stream.Stream;

@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface FeedbackEntityMapper {
FeedbackModel toModel(FeedbackEntity entity);
FeedbackEntity toEntity(FeedbackModel model);

default Optional<FeedbackModel> toOptionalModel(Optional<FeedbackEntity> entity) {
return entity.map(this::toModel);
}

default Stream<FeedbackModel> toStreamLibraryModel(Stream<FeedbackEntity> entityStream) {
return entityStream.map(this::toModel);
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package com.example.whopper.domain.feedback;

import com.example.whopper.interfaces.feedback.dto.FeedbackElementDto;
import lombok.Builder;

@Builder
public record FeedbackModel(
String id,
String comment,
FeedbackElementDto.Type type,
String documentId,
String resumeId,
FeedbackElementDto.Status status,
Boolean rejected,
FeedbackElementDto.Writer writer

) {

public FeedbackModel update(String comment) {
return new FeedbackModel(id, comment, type, documentId, status, rejected, writer);
return new FeedbackModel(id, comment, type, resumeId, status, rejected, writer);
}

public FeedbackModel confirm() {
return new FeedbackModel(id, comment, type, documentId, FeedbackElementDto.Status.CONFIRMED, rejected, writer);
return new FeedbackModel(id, comment, type, resumeId, FeedbackElementDto.Status.CONFIRMED, rejected, writer);
}

public FeedbackModel reject() {
return new FeedbackModel(id, comment, type, documentId, status, true, writer);
return new FeedbackModel(id, comment, type, resumeId, status, true, writer);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;
import java.util.stream.Stream;

interface FeedbackMongoRepository extends MongoRepository<FeedbackEntity, String> {
public interface FeedbackMongoRepository extends MongoRepository<FeedbackEntity, String> {
Stream<FeedbackEntity> findAllByResumeIdAndStatus(String resumeId, FeedbackEntity.Status status);
int countByResumeId(String resumeId);
void deleteAllByResumeId(String resumeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
public interface FeedbackRepository {
FeedbackModel save(FeedbackModel feedback);
Optional<FeedbackModel> findById(String id);
Stream<FeedbackModel> findAllByResumeIdAndStatus(String resumeId, FeedbackElementDto.Status status);
int countByResumeId(String resumeId);
void deleteById(String id);
void deleteAllByResumeId(String resumeId);
Stream<FeedbackModel> findAllByResumeIdAndStatus(String resumeId, FeedbackElementDto.Status status);
Stream<FeedbackModel> findAllByWriterId(String WriterId);
Stream<FeedbackModel> findAllByResumeIdAndWriterId(String resumeId, String WriterId);
Stream<FeedbackModel> findAllByResumeIdInAndWriterId(List<String> resumeIds, String WriterId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ public FeedbackModel save(FeedbackModel feedback) {
}

public Optional<FeedbackModel> findById(String id) {
final var result = feedbackMongoRepository.findById(id);
return feedbackMongoRepository.findById(id)
.map(feedbackEntityMapper::toModel);
}

return feedbackEntityMapper.toOptionalModel(result);
public Stream<FeedbackModel> findAllByResumeIdAndStatus(String resumeId, FeedbackElementDto.Status status) {
return feedbackMongoRepository.findAllByResumeIdAndStatus(resumeId, feedbackElementMapper.toStatusEntity(status))
.map(feedbackEntityMapper::toModel);
}

public int countByResumeId(String resumeId) {
Expand All @@ -40,27 +44,18 @@ public void deleteAllByResumeId(String resumeId) {
feedbackMongoRepository.deleteAllByResumeId(resumeId);
}

public Stream<FeedbackModel> findAllByResumeIdAndStatus(String resumeId, FeedbackElementDto.Status status) {
final var result = feedbackMongoRepository.findAllByResumeIdAndStatus(resumeId, feedbackElementMapper.toStatusEntity(status));

return feedbackEntityMapper.toStreamLibraryModel(result);
}

public Stream<FeedbackModel> findAllByWriterId(String writerId) {
final var result = feedbackMongoRepository.findAllByWriterId(writerId);

return feedbackEntityMapper.toStreamLibraryModel(result);
return feedbackMongoRepository.findAllByWriterId(writerId)
.map(feedbackEntityMapper::toModel);
}

public Stream<FeedbackModel> findAllByResumeIdAndWriterId(String resumeId, String writerId) {
final var result = feedbackMongoRepository.findAllByResumeIdAndWriterId(resumeId, writerId);

return feedbackEntityMapper.toStreamLibraryModel(result);
return feedbackMongoRepository.findAllByResumeIdAndWriterId(resumeId, writerId)
.map(feedbackEntityMapper::toModel);
}

public Stream<FeedbackModel> findAllByResumeIdInAndWriterId(List<String> resumeIds, String writerId) {
final var result = feedbackMongoRepository.findAllByResumeIdInAndWriterId(resumeIds, writerId);

return feedbackEntityMapper.toStreamLibraryModel(result);
return feedbackMongoRepository.findAllByResumeIdInAndWriterId(resumeIds, writerId)
.map(feedbackEntityMapper::toModel);
}
}
Loading

0 comments on commit 6dc6318

Please sign in to comment.