Skip to content

Commit

Permalink
#82 fix : response 타입 ApplyStats -> String 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
rivkode committed Apr 24, 2024
1 parent fe17375 commit 5738005
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import com.querydsl.core.annotations.QueryProjection;
import com.seoultech.synergybe.domain.apply.ApplyStatus;
import lombok.Builder;

@Builder
public record GetApplyResponse(
String applyId,
ApplyStatus status
String status
) {
@QueryProjection
public GetApplyResponse(String applyId, ApplyStatus status) {
this(
applyId,
status.getName()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Slf4j
@Service
@Transactional
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class ApplyService {
private final ApplyRepository applyRepository;
Expand All @@ -34,8 +33,10 @@ public class ApplyService {
private final NotificationService notificationService;
private final IdGenerator idGenerator;

public GetApplyResponse createApply(User user, String projectId) {
@Transactional
public String createApply(String userId, String projectId) {
Project project = projectService.findProjectById(projectId);
User user = userService.getUser(userId);
String applyId = idGenerator.generateId(IdPrefix.APPLY);

Apply apply = Apply.builder()
Expand All @@ -47,26 +48,20 @@ public GetApplyResponse createApply(User user, String projectId) {
// User leader = userService.getUser(projectService.getProject(projectId).leaderId());
// notificationService.send(leader, NotificationType.PROJECT_APPLY, "프로젝트 신청이 완료되었습니다.", projectId);

GetApplyResponse getApplyResponse = GetApplyResponse.builder().build();

return getApplyResponse;
return savedApply.getId();
}

public void deleteApply(String userId, String projectId) {
Optional<Apply> applyOptional = applyRepository.findApplyByUserIdAndProjectId(userId, projectId);

if (applyOptional.isPresent()) {
applyRepository.delete(applyOptional.get());

} else {
throw new ApplyNotFoundException("존재하지 않는 신청내역입니다.");
}
@Transactional
public void deleteApply(String applyId) {
// todo
// 사용자 권한 검증
Apply apply = getApply(applyId);
applyRepository.delete(apply);
}

public void acceptApply(String userId, String projectId) {
Apply apply = applyRepository.findApplyByUserIdAndProjectId(userId, projectId)
.orElseThrow(() -> new ApplyNotFoundException("존재하지 않는 신청내역입니다."));

@Transactional
public void updateApplyStatusToAccept(String userId, String projectId) {
Apply apply = applyRepository.findApplyByUserIdAndProjectId(userId, projectId);
apply.changeStatusToAccept();
Project project = projectService.findProjectById(projectId);
User user = userService.getUser(userId);
Expand All @@ -79,16 +74,13 @@ public void acceptApply(String userId, String projectId) {
projectUserRepository.save(projectUser);
User applyUser = userService.getUser(userId);

// apply 삭제
// applyRepository.delete(apply);

// 알림 발송
// notificationService.send(applyUser, NotificationType.PROJECT_ACCEPT, "신청이 수락되었습니다.", projectId);
}

public void rejectApply(String userId, String projectId) {
Apply apply = applyRepository.findApplyByUserIdAndProjectId(userId, projectId)
.orElseThrow(() -> new ApplyNotFoundException("존재하지 않는 신청내역입니다."));
@Transactional
public void updateApplyStatusToReject(String userId, String projectId) {
Apply apply = applyRepository.findApplyByUserIdAndProjectId(userId, projectId);
apply.changeStatusToReject();

// apply 삭제
Expand All @@ -101,13 +93,11 @@ public void rejectApply(String userId, String projectId) {
// return RejectApplyResponse.from(apply);
}

public GetListApplyResponse getMyApplyList(User user) {
public GetListApplyResponse getMyApplyList(String userId) {
User user = userService.getUser(userId);
List<Apply> applies = applyRepository.findAllProcessByUserId(user.getUserId());

GetListApplyResponse getListApplyResponse = GetListApplyResponse.builder().build();

return getListApplyResponse;

return ApplyMapperEntityToDto.applyListToResponse(applies);
}

public GetListApplyUserResponse getApplyUserList(String projectId) {
Expand All @@ -116,8 +106,10 @@ public GetListApplyUserResponse getApplyUserList(String projectId) {
// user_id 는 PK가 아닌 UNIQUE KEY 이므로 findAllById() 사용 못함
List<User> users = userService.getUsers(userIds);

GetListApplyUserResponse getListApplyUserResponse = GetListApplyUserResponse.builder().build();
return ApplyMapperEntityToDto.userListToResponse(users);
}

return getListApplyUserResponse;
public Apply getApply(String applyId) {
return applyRepository.findById(applyId).orElseThrow(() -> new ApplyNotFoundException("신청내역이 존재하지 않습니다."));
}
}

0 comments on commit 5738005

Please sign in to comment.