Skip to content

Commit

Permalink
Merge pull request #196 from kssumin/main
Browse files Browse the repository at this point in the history
[BE/FIX] attend 도메인 리팩터링
  • Loading branch information
kssumin authored Jan 10, 2024
2 parents f7dae84 + a70169f commit b0b7d68
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public AttendModel changeStatus(String beforeStatus, String afterStatus) {
return this;
}

public AttendModel changeStatus(String afterStatus) {
public AttendModel changeStatusByManager(String beforeStatus, String afterStatus) {
validateChangeByManager(beforeStatus);
this.status = AttendStatus.find(afterStatus);

return this;
Expand Down Expand Up @@ -61,6 +62,10 @@ private void validateChange(String beforeStatus) {
isSameBeforeStatus(beforeStatus);
}

private void validateChangeByManager(String beforeStatus) {
isSameBeforeStatus(beforeStatus);
}

private void canChange(String beforeStatus) {
if (AttendStatus.isSame(beforeStatus, AttendStatus.NONRELATED)) {
throw new DeniedSaveAttendException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Slf4j
public class SelectAttendTargetService implements AttendTargetService {
private final AttendRepository attendRepository;
private final AttendEntityConverter entityConverter;
Expand Down Expand Up @@ -102,23 +100,21 @@ private <T extends MemberIdModel> void validateAllFind(
if (requestEntities.size() == findEntities.size()) {
return;
}
log.info(String.valueOf(findDifferent(requestEntities, findEntities).size()));
throw new NotFoundMemberException();
}

private <T extends MemberIdModel> List<Long> findDifferent(
List<Long> requestIds, List<T> findModels) {
List<Long> findModelIds =
findModels.stream().map(MemberIdModel::getId).collect(Collectors.toList());

findModels.stream().map(MemberIdModel::getMemberId).collect(Collectors.toList());
requestIds.removeAll(findModelIds);
return requestIds;
}

private void updateAttendStatus(
AttendModel model, List<ChangeAllAttendStatusRequest> requests, AttendManager attendManager) {
ChangeAllAttendStatusRequest request = findUpdateRequest(model.getMemberId(), requests);
model.changeStatus(request.getAfterAttendStatus());
model.changeStatusByManager(request.getBeforeAttendStatus(), request.getAfterAttendStatus());

if (Objects.equals(request.getAfterAttendStatus(), AttendStatus.NONRELATED.getStatus())) {
attendManager.addNonRelated(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -28,6 +30,8 @@
@Table(
name = AttendEntity.ENTITY_PREFIX,
indexes = @Index(name = "idx_program", columnList = "attend_program_id"))
@SQLDelete(sql = "UPDATE attend SET is_deleted=true where attend_id=?")
@Where(clause = "is_deleted=false")
public class AttendEntity extends BaseEntity {
public static final String ENTITY_PREFIX = "attend";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ApiResponse<SuccessBody<ChangeAttendStatusResponse>> changeAttendStatus(
public ApiResponse<SuccessBody<ChangeAttendStatusResponse>> getAttendStatus(
@Member Long memberId, @PathVariable("programId") Long programId) {
ChangeAttendStatusResponse response = getAttendStatusUsecase.getStatus(memberId, programId);
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.UPDATE);
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GET);
}

@GetMapping("/attend/programs/{programId}/members")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import org.springframework.data.repository.query.Param;

public interface AuthInfoRepository extends JpaRepository<AuthInfoEntity, Long> {
@Query(
"SELECT a FROM AuthInfoEntity a WHERE a.isDeleted=false AND a.memberId=:memberId AND a.token =:token")
@Query("SELECT a FROM AuthInfoEntity a WHERE a.memberId=:memberId AND a.token =:token")
Optional<AuthInfoEntity> findByMemberIdAndToken(
@Param("memberId") Long memberId, @Param("token") String token);

@Query("SELECT a FROM AuthInfoEntity a WHERE a.isDeleted=false AND a.token =:token")
@Query("SELECT a FROM AuthInfoEntity a WHERE a.token =:token")
Optional<AuthInfoEntity> findByToken(@Param("token") String token);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import org.springframework.data.repository.query.Param;

public interface OauthInfoRepository extends JpaRepository<OauthInfoEntity, Long> {
@Query("SELECT o FROM OauthInfoEntity o WHERE o.isDeleted=false AND o.oauthId=:oauthId")
@Query("SELECT o FROM OauthInfoEntity o WHERE o.oauthId=:oauthId")
Optional<OauthInfoEntity> findByOauthId(@Param("oauthId") String oauthId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.blackcompany.eeos.common.application.model;

public interface MemberIdModel {
Long getId();
Long getMemberId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ private void canEdit(ActiveStatus requestStatus) {
throw new DeniedUpdateActiveException(requestStatus.getStatus());
}
}

@Override
public Long getMemberId() {
return id;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.blackcompany.eeos.member.persistence;

import com.blackcompany.eeos.auth.application.domain.OauthServerType;
import com.blackcompany.eeos.common.application.model.MemberIdModel;
import com.blackcompany.eeos.common.persistence.BaseEntity;
import com.blackcompany.eeos.member.application.model.ActiveStatus;
import javax.persistence.Column;
Expand All @@ -20,6 +19,8 @@
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -33,7 +34,9 @@
@Index(name = "idx_name", columnList = "member_name"),
@Index(name = "idx_active_status", columnList = "member_active_status")
})
public class MemberEntity extends BaseEntity implements MemberIdModel {
@SQLDelete(sql = "UPDATE member SET is_deleted=true where member_id=?")
@Where(clause = "is_deleted=false")
public class MemberEntity extends BaseEntity {

public static final String ENTITY_PREFIX = "member";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public interface MemberRepository extends JpaRepository<MemberEntity, Long> {
@Query("SELECT m FROM MemberEntity m WHERE m.isDeleted=false ORDER BY m.name")
List<MemberEntity> findMembers();

@Query("SELECT m FROM MemberEntity m WHERE m.isDeleted=false AND m.id IN :ids")
@Query("SELECT m FROM MemberEntity m WHERE m.id IN :ids AND m.isDeleted=false ORDER BY m.name")
List<MemberEntity> findMembersByIds(@Param("ids") List<Long> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -27,6 +29,8 @@
@Table(
name = ProgramEntity.ENTITY_PREFIX,
indexes = @Index(name = "idx_program_date", columnList = "program_date"))
@SQLDelete(sql = "UPDATE program SET is_deleted=true where program_id=?")
@Where(clause = "is_deleted=false")
public class ProgramEntity extends BaseEntity {

public static final String ENTITY_PREFIX = "program";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ApiResponse<SuccessBody<PageResponse<QueryProgramsResponse>>> findAll(
public ApiResponse<SuccessBody<Void>> delete(
@Member Long memberId, @PathVariable("programId") Long programId) {
deleteProgramUsecase.delete(memberId, programId);
return ApiResponseGenerator.success(HttpStatus.OK, MessageCode.UPDATE);
return ApiResponseGenerator.success(HttpStatus.OK, MessageCode.DELETE);
}

@GetMapping("/{programId}/accessRight")
Expand Down

0 comments on commit b0b7d68

Please sign in to comment.