-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from 2E1I/dev
cicd test
- Loading branch information
Showing
23 changed files
with
295 additions
and
147 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
.../java/com/e2i1/linkeepserver/domain/collaborators/repository/CollaboratorsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package com.e2i1.linkeepserver.domain.collaborators.repository; | ||
|
||
import com.e2i1.linkeepserver.domain.collaborators.entity.CollaboratorsEntity; | ||
import org.springframework.data.repository.Repository; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CollaboratorsRepository extends Repository<CollaboratorsEntity, Long> { | ||
public interface CollaboratorsRepository extends JpaRepository<CollaboratorsEntity, Long> { | ||
|
||
Optional<CollaboratorsEntity> findByUserIdAndCollectionId(Long userId, Long collectionId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 48 additions & 4 deletions
52
src/main/java/com/e2i1/linkeepserver/domain/links/business/LinksBusiness.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,73 @@ | ||
package com.e2i1.linkeepserver.domain.links.business; | ||
|
||
import com.e2i1.linkeepserver.common.annotation.Business; | ||
import com.e2i1.linkeepserver.domain.collaborators.service.CollaboratorsService; | ||
import com.e2i1.linkeepserver.domain.collections.entity.CollectionsEntity; | ||
import com.e2i1.linkeepserver.domain.collections.service.CollectionsService; | ||
import com.e2i1.linkeepserver.domain.links.converter.LinksConverter; | ||
import com.e2i1.linkeepserver.domain.links.dto.LinkReqDTO; | ||
import com.e2i1.linkeepserver.domain.links.dto.LinkResDTO; | ||
import com.e2i1.linkeepserver.domain.links.dto.SearchLinkResDTO; | ||
import com.e2i1.linkeepserver.domain.links.entity.LinksEntity; | ||
import com.e2i1.linkeepserver.domain.links.service.LinksService; | ||
import com.e2i1.linkeepserver.domain.users.entity.UsersEntity; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Business | ||
@RequiredArgsConstructor | ||
public class LinksBusiness { | ||
|
||
private final LinksService linksService; | ||
private final LinksConverter linksConverter; | ||
|
||
private final CollectionsService collectionsService; | ||
|
||
private final CollaboratorsService collaboratorsService; | ||
|
||
/** | ||
* link 저장하기 | ||
* link 저장하기 해당 컬렉션에 권한 있는지 확인 후 저장하기 | ||
*/ | ||
public LinksEntity save(LinkReqDTO req) { | ||
CollectionsEntity collection = collectionsService.findById(req.getCollectionId()); | ||
LinksEntity linkEntity = linksConverter.toEntity(req, collection); | ||
public LinksEntity save(LinkReqDTO req, UsersEntity user) { | ||
/* | ||
내가 해당 collection의 작업자일 때만 링크 저장 가능 | ||
만약 해당 collection이 존재하지 않거나, 내가 collection의 작업자가 아니라면 예외가 발생한다 | ||
*/ | ||
CollectionsEntity collection = collectionsService.findByIdWithThrow(req.getCollectionId()); | ||
collaboratorsService.findByUserIdAndCollectionIdWithThrow(user.getId(), collection.getId()); | ||
|
||
LinksEntity linkEntity = linksConverter.toEntity(req, collection, user); | ||
return linksService.save(linkEntity); | ||
} | ||
|
||
/** | ||
* link 단건 조회 현재 로그인된 유저가 생성한 link가 아닌 경우, link 조회수 1증가 즉, 자기가 만든 link는 아무리 조회해도 조회수 증가 안함 | ||
*/ | ||
@Transactional | ||
public LinkResDTO findOneById(Long linkId, Long userId) { | ||
LinksEntity link = linksService.findOneByIdAndUserId(linkId); | ||
|
||
// 현재 로그인된 유저의 링크가 아닐 경우에만 조회 수 증가 | ||
if (!userId.equals(link.getUser().getId())) { | ||
// link 객체는 linksService를 통해서 가져온거라 현재 영속성 컨텍스트 안에 있음 | ||
// 이렇게 수정만해도 transaction 끝날 때, dirty checking을 통해 자동으로 DB에 수정사항 반영된다. | ||
link.updateView(); | ||
} | ||
return linksConverter.toResponse(link); | ||
} | ||
|
||
// TODO : 검색어를 공백 기준으로 나누고 이들이 모두 존재하는 레코드들을 리턴하도록 메서드 수정하기 | ||
|
||
/** | ||
* 링크 title, description을 조회해 해당 검색어 들어있는 링크 목록 가져오기 | ||
*/ | ||
public List<SearchLinkResDTO> searchLinks(String searchTerm) { | ||
List<LinksEntity> linkList = linksService.searchLinks(searchTerm); | ||
|
||
return linkList.stream() | ||
.map(linksConverter::toSearchResponse) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
Oops, something went wrong.