Skip to content

Commit

Permalink
feat : JD 조회 Persistence 계층 생성(#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
isprogrammingfun committed May 19, 2024
1 parent 76cf594 commit c6801a2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.bamyanggang.domainmodule.domain.jobDescription.aggregate.Apply;
import com.bamyanggang.domainmodule.domain.jobDescription.repository.ApplyRepository;
import com.bamyanggang.persistence.common.exception.PersistenceException;
import com.bamyanggang.persistence.jobDescription.jpa.entity.ApplyJpaEntity;
import com.bamyanggang.persistence.jobDescription.jpa.repository.ApplyJpaRepository;
import com.bamyanggang.persistence.jobDescription.mapper.JobDescriptionMapper;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

Expand All @@ -20,4 +22,10 @@ public void save(Apply apply) {
applyJpaRepository.save(applyJpaEntity);
}

@Override
public Apply findByJobDescriptionId(UUID jobDescriptionId) {
return applyJpaRepository.findByJobDescriptionId(jobDescriptionId)
.map(jobDescriptionMapper::toApplyDomainEntity)
.orElse(null);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.bamyanggang.persistence.jobDescription;

import com.bamyanggang.domainmodule.common.pagination.SliceDomain;
import com.bamyanggang.domainmodule.domain.jobDescription.aggregate.JobDescription;
import com.bamyanggang.domainmodule.domain.jobDescription.repository.JobDescriptionRepository;
import com.bamyanggang.persistence.jobDescription.jpa.entity.JobDescriptionJpaEntity;
import com.bamyanggang.persistence.jobDescription.jpa.repository.JobDescriptionJpaRepository;
import com.bamyanggang.persistence.jobDescription.mapper.JobDescriptionMapper;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Repository;

@Repository
Expand All @@ -20,4 +24,33 @@ public void save(JobDescription jobDescription) {
jobDescriptionJpaRepository.save(jobDescriptionJpaEntity);
}

@Override
public SliceDomain<JobDescription> findAllByUserIdAndSortByCreatedAt(UUID userId, int page, int size) {
Pageable pageable = Pageable.ofSize(size).withPage(page);
Slice<JobDescriptionJpaEntity> jobDescriptionJpaEntitySlice = jobDescriptionJpaRepository.findAllByUserIdOrderByCreatedAtDesc(userId, pageable);
Slice<JobDescription> jobDescriptionSlice = jobDescriptionJpaEntitySlice.map(jobDescriptionMapper::toDomainEntity);
return new SliceDomain<>(jobDescriptionSlice.getContent(), jobDescriptionSlice.getNumber(), jobDescriptionSlice.getSize(), jobDescriptionSlice.hasNext());
}

@Override
public SliceDomain<JobDescription> findAllByUserId(UUID userId, int page, int size) {
Pageable pageable = Pageable.ofSize(size).withPage(page);
Slice<JobDescriptionJpaEntity> jobDescriptionJpaEntitySlice = jobDescriptionJpaRepository.findAllByUserIdOrderByCreatedAtDesc(userId, pageable);
Slice<JobDescription> jobDescriptionSlice = jobDescriptionJpaEntitySlice.map(jobDescriptionMapper::toDomainEntity);
return new SliceDomain<>(jobDescriptionSlice.getContent(), jobDescriptionSlice.getNumber(), jobDescriptionSlice.getSize(), jobDescriptionSlice.hasNext());
}

// @Override
// public Slice<JobDescription> findAllByUserIdAndSortByCreatedAt(UUID userId, Integer page, Integer size) {
// Pageable pageable = Pageable.ofSize(size).withPage(page);
// Slice<JobDescriptionJpaEntity> jobDescriptionJpaEntitySlice = jobDescriptionJpaRepository.findAllByUserIdOrderByCreatedAtDesc(userId, pageable);
// return jobDescriptionJpaEntitySlice.map(jobDescriptionMapper::toDomainEntity);
// }
//
// @Override
// public Slice<JobDescription> findAllByUserIdAndSortType(UUID userId, Pageable pageable) {
// Slice<JobDescriptionJpaEntity> jobDescriptionJpaEntitySlice = jobDescriptionJpaRepository.findAllByUserId(userId, pageable);
// return jobDescriptionJpaEntitySlice.map(jobDescriptionMapper::toDomainEntity);
// }

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.bamyanggang.persistence.jobDescription.jpa.repository;

import com.bamyanggang.persistence.jobDescription.jpa.entity.ApplyJpaEntity;
import java.util.Optional;
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ApplyJpaRepository extends JpaRepository<ApplyJpaEntity, UUID> {

Optional<ApplyJpaEntity> findByJobDescriptionId(UUID jobDescriptionId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

import com.bamyanggang.persistence.jobDescription.jpa.entity.JobDescriptionJpaEntity;
import java.util.UUID;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;

public interface JobDescriptionJpaRepository extends JpaRepository<JobDescriptionJpaEntity, UUID> {

Slice<JobDescriptionJpaEntity> findAllByUserId(UUID userId, Pageable pageable);

Slice<JobDescriptionJpaEntity> findAllByUserIdOrderByCreatedAtDesc(UUID userId, Pageable pageable);


}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void deleteByValue(Token token) {
}

@Override
public Token findByValue(@NotNull String value) {
public Token findByValue(String value) {
TokenJpaEntity tokenJpaEntity = tokenJpaRepository.findByValue(value)
.orElseThrow(() -> new PersistenceException.NotFound());
return userMapper.toDomainEntity(tokenJpaEntity);
Expand Down

0 comments on commit c6801a2

Please sign in to comment.