Skip to content

Commit

Permalink
Merge pull request #61 from kssumin/feat/#268/teambuilding-complete
Browse files Browse the repository at this point in the history
[BE/FEAT] 팀빌딩 진행 결과를 볼 수 있다.
  • Loading branch information
kssumin authored Feb 21, 2024
2 parents 9261af0 + 9124220 commit 9cf3835
Show file tree
Hide file tree
Showing 27 changed files with 515 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.blackcompany.eeos.common.persistence;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter
public class IntegerArrayConverter implements AttributeConverter<List<Long>, String> {

private static final String SPLIT_CHAR = ",";

@Override
public String convertToDatabaseColumn(List<Long> attribute) {
return attribute.stream().map(String::valueOf).collect(Collectors.joining(SPLIT_CHAR));
}

@Override
public List<Long> convertToEntityAttribute(String dbData) {
return Arrays.stream(dbData.split(SPLIT_CHAR))
.map(String::trim)
.map(Long::parseLong)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public void update(Long memberId, AttendTeamBuildingRequest request) {
private TeamBuildingTargetModel getTargetByActiveBuilding(Long memberId) {
Long teamBuildingId = find(TeamBuildingStatus.PROGRESS).getId();

TeamBuildingTargetEntity entity =
queryTeamBuildingTargetService.getTarget(memberId, teamBuildingId);
return entityConverter.from(entity);
return queryTeamBuildingTargetService.getTarget(memberId, teamBuildingId);
}

private void validateAttendTeamBuilding() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.blackcompany.eeos.target.application.service;

import com.blackcompany.eeos.target.application.exception.NotFoundTargetTeamBuildingException;
import com.blackcompany.eeos.target.persistence.TeamBuildingTargetEntity;
import com.blackcompany.eeos.target.application.model.TeamBuildingTargetModel;
import com.blackcompany.eeos.target.application.model.converter.TeamBuildingTargetEntityConverter;
import com.blackcompany.eeos.target.persistence.TeamBuildingTargetRepository;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -12,10 +15,18 @@
@RequiredArgsConstructor
public class QueryTeamBuildingTargetService {
private final TeamBuildingTargetRepository teamBuildingTargetRepository;
private final TeamBuildingTargetEntityConverter entityConverter;

public TeamBuildingTargetEntity getTarget(Long memberId, Long teamBuildingId) {
public TeamBuildingTargetModel getTarget(Long memberId, Long teamBuildingId) {
return teamBuildingTargetRepository
.findByTeamBuildingIdAndMemberId(teamBuildingId, memberId)
.map(entityConverter::from)
.orElseThrow(NotFoundTargetTeamBuildingException::new);
}

public List<TeamBuildingTargetModel> getTarget(Long teamBuildingId) {
return teamBuildingTargetRepository.findByTeamBuildingId(teamBuildingId).stream()
.map(entityConverter::from)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.blackcompany.eeos.target.persistence;

import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface TeamBuildingTargetRepository
extends JpaRepository<TeamBuildingTargetEntity, Long> {
Optional<TeamBuildingTargetEntity> findByTeamBuildingIdAndMemberId(
Long teamBuildingId, Long memberId);

List<TeamBuildingTargetEntity> findByTeamBuildingId(Long teamBuildingId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.blackcompany.eeos.teamBuilding.application.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder(toBuilder = true)
public class EachMemberResponse {
private Long memberId;
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.blackcompany.eeos.teamBuilding.application.dto;

import com.blackcompany.eeos.common.support.dto.AbstractResponseDto;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder(toBuilder = true)
public class ResultTeamBuildingResponse implements AbstractResponseDto {
private String accessRights;
private List<List<EachMemberResponse>> results;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.blackcompany.eeos.teamBuilding.application.dto.converter;

import com.blackcompany.eeos.teamBuilding.application.dto.EachMemberResponse;
import com.blackcompany.eeos.teamBuilding.application.dto.ResultTeamBuildingResponse;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class ResultTeamBuildingResponseConverter {
public ResultTeamBuildingResponse from(
String accessRight, List<List<EachMemberResponse>> results) {
return ResultTeamBuildingResponse.builder().accessRights(accessRight).results(results).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.blackcompany.eeos.teamBuilding.application.exception;

import com.blackcompany.eeos.common.exception.BusinessException;
import org.springframework.http.HttpStatus;

/** 조회할 팀빌딩이 존재하지 않을 때 발생하는 예외 */
public class NotFoundResultException extends BusinessException {
private static final String FAIL_CODE = "6009";

public NotFoundResultException() {
super(FAIL_CODE, HttpStatus.NOT_FOUND);
}

@Override
public String getMessage() {
return "결과를 조회할 팀빌딩이 존재하지 않습니다.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class RestrictTeamBuildingModel implements AbstractModel {
private Long version;

public RestrictTeamBuildingModel addActiveCount() {
totalActiveCount++;
validateCreation();
totalActiveCount++;

return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.blackcompany.eeos.teamBuilding.application.model;

import lombok.Getter;

@Getter
public enum TeamBuildingAccessRights {
/** 읽기, 수정 권한 있음 */
EDIT("edit"),
/** 읽기 권한 있음 */
READ_ONLY("read_only");

private final String accessRight;

TeamBuildingAccessRights(String accessRight) {
this.accessRight = accessRight;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,24 @@ public void validateEdit(Long memberId) {
}
}

public TeamBuildingModel updateStatus(String status, Long memberId) {
validateEdit(memberId);

this.status = status;
return this;
}

public void validateAttend() {
validateStatus();
}

public TeamBuildingAccessRights getAccessRight(Long memberId) {
if (this.memberId.equals(memberId)) {
return TeamBuildingAccessRights.EDIT;
}
return TeamBuildingAccessRights.READ_ONLY;
}

private void validateStatus() {
if (!TeamBuildingStatus.validateSame(status, TeamBuildingStatus.PROGRESS)) {
throw new DeniedSaveAttendTeamBuildingException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@ public TeamBuildingEntity toEntity(TeamBuildingModel source) {
.memberId(source.getMemberId())
.build();
}

public TeamBuildingEntity toEntity(TeamBuildingModel source, TeamBuildingStatus status) {
return TeamBuildingEntity.builder()
.id(source.getId())
.title(source.getTitle())
.content(source.getContent())
.maxTeamSize(source.getMaxTeamSize())
.status(status)
.memberId(source.getMemberId())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.blackcompany.eeos.teamBuilding.application.model.converter;

import com.blackcompany.eeos.teamBuilding.persistence.TeamBuildingResultEntity;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Component;

@Component
public class TeamBuildingResultConverter {
public TeamBuildingResultEntity from(List<String> memberIds, Long teamBuildinId) {
return TeamBuildingResultEntity.builder()
.teamBuildingId(teamBuildinId)
.memberIds(memberIds.stream().map(Long::parseLong).collect(Collectors.toList()))
.build();
}
}

This file was deleted.

Loading

0 comments on commit 9cf3835

Please sign in to comment.