Skip to content

Commit

Permalink
[#131] feat: UserTagHistory domain 생성과 실패 기록 시 태그 히스토리 저장
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomo committed Oct 24, 2023
1 parent acc1e1e commit 5a08713
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.todaysfail.domains.usertaghistory.adpater;

import com.todaysfail.common.annotation.Adapter;
import com.todaysfail.domains.usertaghistory.domain.UserTagHistory;
import com.todaysfail.domains.usertaghistory.port.UserTagHistoryCommandPort;
import com.todaysfail.domains.usertaghistory.repository.UserTagHistoryRepository;
import lombok.RequiredArgsConstructor;

@Adapter
@RequiredArgsConstructor
public class UserTagHistoryCommandAdapter implements UserTagHistoryCommandPort {
private final UserTagHistoryRepository userTagHistoryRepository;

@Override
public UserTagHistory save(UserTagHistory userTagHistory) {
return userTagHistoryRepository.save(userTagHistory);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.todaysfail.domains.usertaghistory.adpater;

import com.todaysfail.common.annotation.Adapter;
import com.todaysfail.domains.usertaghistory.port.UserTagHistoryQueryPort;
import lombok.RequiredArgsConstructor;

@Adapter
@RequiredArgsConstructor
public class UserTagHistoryQueryAdapter implements UserTagHistoryQueryPort {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.todaysfail.domains.usertaghistory.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@Entity(name = "tbl_user_tag_history")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class UserTagHistory {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_tag_history_id")
private Long id;

private Long userId;

private Long tagId;

public static UserTagHistory registerUserTagHistory(Long userId, Long tagId) {
return new UserTagHistory(null, userId, tagId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.todaysfail.domains.usertaghistory.port;

import com.todaysfail.domains.usertaghistory.domain.UserTagHistory;

public interface UserTagHistoryCommandPort {
UserTagHistory save(UserTagHistory userTagHistory);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.todaysfail.domains.usertaghistory.port;

public interface UserTagHistoryQueryPort {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.todaysfail.domains.usertaghistory.repository;

import com.todaysfail.domains.usertaghistory.domain.UserTagHistory;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserTagHistoryRepository extends JpaRepository<UserTagHistory, Long> {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.todaysfail.domains.failure.service.FailureDomainService;
import com.todaysfail.domains.tag.domain.Tag;
import com.todaysfail.domains.tag.service.TagDomainService;
import com.todaysfail.domains.usertaghistory.domain.UserTagHistory;
import com.todaysfail.domains.usertaghistory.port.UserTagHistoryCommandPort;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,6 +25,7 @@ public class FailureRegisterUseCase {
private final CategoryQueryPort categoryQueryPort;
private final FailureDomainService failureDomainService;
private final TagDomainService tagDomainService;
private final UserTagHistoryCommandPort userTagHistoryCommandPort;

@Transactional
public FailureResponse execute(FailureRegisterRequest request) {
Expand All @@ -41,6 +44,9 @@ public FailureResponse execute(FailureRegisterRequest request) {
.secret(request.secret())
.build();
Failure registeredFailure = failureDomainService.register(failure, category, tags);
tags.stream()
.map(tag -> UserTagHistory.registerUserTagHistory(currentUserId, tag.getId()))
.forEach(userTagHistoryCommandPort::save);
return failureMapper.toFailureResponse(registeredFailure);
}
}

0 comments on commit 5a08713

Please sign in to comment.