Skip to content

Commit

Permalink
feat: 특정 사용자가 특정 동행글에 대한 동행 신청 상태 조회 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
chaechaen committed Jan 2, 2025
1 parent ef32ab4 commit f65d2cc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.on.server.domain.alarm.application.AlertService;
import com.on.server.domain.alarm.application.FcmService;
import com.on.server.domain.alarm.domain.AlertType;
import com.on.server.domain.alarm.dto.FcmRequestDto;
import com.on.server.domain.companyParticipant.domain.repository.CompanyParticipantRepository;
import com.on.server.domain.companyParticipant.dto.CompanyParticipantRequestDTO;
import com.on.server.domain.companyParticipant.dto.CompanyParticipantResponseDTO;
Expand All @@ -12,19 +11,23 @@
import com.on.server.domain.companyPost.domain.CompanyPost;
import com.on.server.domain.companyPost.domain.repository.CompanyPostRepository;
import com.on.server.domain.user.domain.User;
import com.on.server.domain.user.domain.repository.UserRepository;
import com.on.server.global.common.ResponseCode;
import com.on.server.global.common.exceptions.BadRequestException;
import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;

@Service
@RequiredArgsConstructor
@Transactional
public class CompanyParticipantService {

private final CompanyParticipantRepository companyParticipantRepository;
private final CompanyPostRepository companyPostRepository;
private final UserRepository userRepository;
private final FcmService fcmService;
private final AlertService alertService;

Expand Down Expand Up @@ -57,4 +60,20 @@ public CompanyParticipantResponseDTO applyToCompanyPost(User user, CompanyPartic
.companyParticipantStatus(companyParticipant.getCompanyParticipantstatus())
.build();
}


// 특정 사용자가 특정 동행글에 대한 동행 신청 상태 확인
@Transactional(readOnly = true)
public List<CompanyParticipantResponseDTO> getCompanyParticipantStatus(Long userId, Long companyPostId) {

userRepository.findById(userId).
orElseThrow(() -> new BadRequestException(ResponseCode.ROW_DOES_NOT_EXIST, "사용자를 찾을 수 없습니다. ID: " + userId));
companyPostRepository.findById(companyPostId)
.orElseThrow(() -> new BadRequestException(ResponseCode.ROW_DOES_NOT_EXIST, "게시글을 찾을 수 없습니다. ID: " + companyPostId));

return companyParticipantRepository.findByUser_IdAndCompanyPost_Id(userId, companyPostId)
.stream()
.map(CompanyParticipantResponseDTO::from)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CompanyParticipantRepository extends JpaRepository<CompanyParticipant, Long> {

CompanyParticipant findByUserAndCompanyPostId(User userParticipant, Long companyPostId);

List<CompanyParticipant> findByUser_IdAndCompanyPost_Id(Long userId, Long companyPostId);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.on.server.domain.companyParticipant.dto;
import com.on.server.domain.companyParticipant.domain.CompanyParticipant;
import com.on.server.domain.companyParticipant.domain.CompanyParticipantStatus;
import com.on.server.domain.companyPost.domain.CompanyPost;
import com.on.server.domain.companyPost.dto.CompanyPostResponseDTO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -22,4 +25,13 @@ public class CompanyParticipantResponseDTO {

// 상태
private CompanyParticipantStatus companyParticipantStatus;

public static CompanyParticipantResponseDTO from(CompanyParticipant companyParticipant) {
return CompanyParticipantResponseDTO.builder()
.companyParticipantId(companyParticipant.getId())
.companyPostId(companyParticipant.getCompanyPost().getId())
.userId(companyParticipant.getUser().getId())
.companyParticipantStatus(companyParticipant.getCompanyParticipantstatus())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@Tag(name = "동행 신청하기")
@RestController
Expand All @@ -39,4 +38,14 @@ public ResponseEntity<CompanyParticipantResponseDTO> applyToCompanyPost (

return ResponseEntity.ok(responseDTO);
}

@Operation(summary = "특정 사용자가 특정 동행글에 대한 동행 신청 상태 확인")
@PreAuthorize("@securityService.isNotTemporaryUser()")
@GetMapping("/status/{userId}/{companyPostId}")
public ResponseEntity<List<CompanyParticipantResponseDTO>> getCompanyParticipantStatus(@PathVariable Long userId,
@PathVariable Long companyPostId) {

List<CompanyParticipantResponseDTO> status = companyParticipantService.getCompanyParticipantStatus(userId, companyPostId);
return ResponseEntity.ok(status);
}
}

0 comments on commit f65d2cc

Please sign in to comment.