Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public UserCharacter updateCharacter(UserCharacterUpdateRequestDTO userCharacter
return userCharacter;
}

@Transactional
public void deleteCharacterByAccountId(String accountId) {
userCharacterRepository.deleteByAccountId(accountId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.List;

@RestController
@RequestMapping("/api/request")
@RequestMapping("/api/project")
public class ProjectController {

private final ProjectService projectService;
Expand Down Expand Up @@ -47,9 +47,9 @@ public ResponseEntity<Project> registerProject(
@ApiResponse(responseCode = "200", description = "프로젝트 의뢰가 성공적으로 조회됨"),
@ApiResponse(responseCode = "404", description = "프로젝트 의뢰를 찾을 수 없음")
})
@GetMapping("/{requestId}")
public ResponseEntity<Project> getProjectById(@PathVariable Long requestId) {
Project project = projectService.findProjectByRequestId(requestId);
@GetMapping("/{projectId}")
public ResponseEntity<Project> getProjectById(@PathVariable Long projectId) {
Project project = projectService.findProjectByProjectId(projectId);
if (project != null) {
return ResponseEntity.ok(project);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public Project registProject(ProjectRegistRequestDTO projectRegistRequestDTO, St
));
}

public Project findProjectByRequestId(Long requestId) {
return projectRepository.findById(requestId).orElse(null);
public Project findProjectByProjectId(Long projectId) {
return projectRepository.findById(projectId).orElse(null);
}

public List<Project> findProjectsByAccountId(String accountId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.mtvs.devlinkbackend.support.controller;

import com.mtvs.devlinkbackend.support.dto.SupportRegistRequestDTO;
import com.mtvs.devlinkbackend.support.entity.Support;
import com.mtvs.devlinkbackend.support.service.SupportService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/support")
public class SupportController {
private final SupportService supportService;

public SupportController(SupportService supportService) {
this.supportService = supportService;
}

/**
* 프로젝트 지원을 생성하는 API
* @param supportRegistRequestDTO 지원 요청 데이터
* @return 생성된 지원 정보
*/
@Operation(summary = "프로젝트 지원 생성", description = "프로젝트에 대한 새로운 지원을 생성합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "지원이 성공적으로 생성됨"),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터")
})
@PostMapping
public ResponseEntity<Support> createSupport(@RequestBody SupportRegistRequestDTO supportRegistRequestDTO) {
Support createdSupport = supportService.createSupport(supportRegistRequestDTO);
return new ResponseEntity<>(createdSupport, HttpStatus.CREATED);
}

/**
* 프로젝트 ID로 지원 목록을 조회하는 API
* @param projectId 프로젝트 ID
* @return 프로젝트에 대한 지원 목록
*/
@Operation(summary = "프로젝트 ID로 지원 조회", description = "특정 프로젝트에 대한 모든 지원 목록을 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "지원 목록 조회 성공"),
@ApiResponse(responseCode = "404", description = "해당 프로젝트를 찾을 수 없음")
})
@GetMapping("/project/{projectId}")
public ResponseEntity<List<Support>> getSupportsByProjectId(@PathVariable Long projectId) {
List<Support> supports = supportService.findSupportsByProjectId(projectId);
return new ResponseEntity<>(supports, HttpStatus.OK);
}

/**
* 팀 ID로 지원 목록을 조회하는 API
* @param teamId 팀 ID
* @return 해당 팀의 지원 목록
*/
@Operation(summary = "팀 ID로 지원 조회", description = "특정 팀에 대한 모든 지원 목록을 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "지원 목록 조회 성공"),
@ApiResponse(responseCode = "404", description = "해당 팀을 찾을 수 없음")
})
@GetMapping("/team/{teamId}")
public ResponseEntity<List<Support>> getSupportsByTeamId(@PathVariable Long teamId) {
List<Support> supports = supportService.findSupportsByTeamId(teamId);
return new ResponseEntity<>(supports, HttpStatus.OK);
}

/**
* 지원을 삭제하는 API
* @param supportId 삭제할 지원 ID
*/
@Operation(summary = "지원 삭제", description = "지정된 ID의 지원을 삭제합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "지원이 성공적으로 삭제됨"),
@ApiResponse(responseCode = "404", description = "해당 지원을 찾을 수 없음")
})
@DeleteMapping("/{supportId}")
public ResponseEntity<Void> deleteSupport(@PathVariable Long supportId) {
supportService.deleteSupport(supportId);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mtvs.devlinkbackend.support.dto;

import lombok.*;

@Setter @Getter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class SupportRegistRequestDTO {
private Long projectId;
private Long teamId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.mtvs.devlinkbackend.support.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Table(name = "SUPPORT")
@Entity(name = "Support")
@NoArgsConstructor
@Getter
@ToString
public class Support {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "SUPPORT_ID")
private Long supportId;

@Column(name = "PROJECT_ID", nullable = false)
private Long projectId;

@Column(name = "TEAM_ID", nullable = false)
private Long teamId;

@Column(name = "SUPPORT_CONFIRMATION")
private String supportConfirmation; // 상태 : waiting, accepted, rejected

public Support(Long projectId, Long teamId, String supportConfirmation) {
this.projectId = projectId;
this.teamId = teamId;
this.supportConfirmation = supportConfirmation;
}

public void setProjectId(Long projectId) {
this.projectId = projectId;
}

public void setTeamId(Long teamId) {
this.teamId = teamId;
}

public void setSupportConfirmation(String supportConfirmation) {
this.supportConfirmation = supportConfirmation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mtvs.devlinkbackend.support.repository;

import com.mtvs.devlinkbackend.support.entity.Support;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SupportRepository extends JpaRepository<Support, Long> {
List<Support> findSupportsByProjectId(Long projectId);
List<Support> findSupportsByTeamId(Long teamId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mtvs.devlinkbackend.support.service;

import com.mtvs.devlinkbackend.support.dto.SupportRegistRequestDTO;
import com.mtvs.devlinkbackend.support.entity.Support;
import com.mtvs.devlinkbackend.support.repository.SupportRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SupportService {
private final SupportRepository supportRepository;

public SupportService(SupportRepository supportRepository) {
this.supportRepository = supportRepository;
}

@Transactional
public Support createSupport(SupportRegistRequestDTO supportRegistRequestDTO) {
return supportRepository.save(new Support(
supportRegistRequestDTO.getProjectId(),
supportRegistRequestDTO.getTeamId(),
"waiting"
));
}

public List<Support> findSupportsByProjectId(Long projectId) {
return supportRepository.findSupportsByProjectId(projectId);
}

public List<Support> findSupportsByTeamId(Long teamId) {
return supportRepository.findSupportsByTeamId(teamId);
}

public void deleteSupport(Long supportId) {
supportRepository.deleteById(supportId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void testCreateRequest(ProjectRegistRequestDTO projectRegistRequestDTO, S
@Order(1)
public void testFindRequestByRequestId(long questionId) {
Assertions.assertDoesNotThrow(() ->
System.out.println("Request = " + projectService.findProjectByRequestId(questionId)));
System.out.println("Request = " + projectService.findProjectByProjectId(questionId)));
}

@DisplayName("계정 ID에 따른 의뢰 paging 조회 테스트")
Expand Down Expand Up @@ -174,7 +174,7 @@ public void testFindRequestsByProgressClassification(String progressClassificati
@Order(2)
public void testFindRequestsByTitleContainingIgnoreCase(String title) {
Assertions.assertDoesNotThrow(() ->
System.out.println("Request = " + projectService.findRequestsByTitleContainingIgnoreCase(title)));
System.out.println("Request = " + projectService.findProjectsByTitleContainingIgnoreCase(title)));
}

@DisplayName("필요 직군보다 더 많이 모집하는 의뢰 조회 테스트")
Expand Down
94 changes: 94 additions & 0 deletions src/test/java/com/mtvs/devlinkbackend/crud/SupportCRUDTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.mtvs.devlinkbackend.crud;

import com.mtvs.devlinkbackend.support.dto.SupportRegistRequestDTO;
import com.mtvs.devlinkbackend.support.entity.Support;
import com.mtvs.devlinkbackend.support.repository.SupportRepository;
import com.mtvs.devlinkbackend.support.service.SupportService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest
@Transactional
public class SupportCRUDTest {

private Support support1;
private Support support2;
@Autowired
private SupportRepository supportRepository;
@Autowired
private SupportService supportService;

@BeforeEach
public void setUp() {
MockitoAnnotations.openMocks(this);

// 미리 삽입할 Support 객체 생성
support1 = new Support(1L, 2L, "waiting");
support2 = new Support(1L, 3L, "accepted");

// Mocking the repository calls
supportRepository.save(support1);
supportRepository.save(support2);
}

@Test
public void testCreateSupport() {
// given
SupportRegistRequestDTO supportRegistRequestDTO = new SupportRegistRequestDTO(1L, 2L);

// when
Support createdSupport = supportService.createSupport(supportRegistRequestDTO);

// then
assertNotNull(createdSupport, "Created support should not be null");
assertEquals(support1.getProjectId(), createdSupport.getProjectId(), "Project ID should match");
assertEquals(support1.getTeamId(), createdSupport.getTeamId(), "Team ID should match");
assertEquals("waiting", createdSupport.getSupportConfirmation(), "Status should be 'waiting'");
}

@Test
public void testFindSupportsByProjectId() {
// when
List<Support> foundSupports = supportService.findSupportsByProjectId(1L);

// then
assertNotNull(foundSupports, "Found supports should not be null");
assertEquals(2, foundSupports.size(), "The size of found supports should be 2");
assertEquals(support1.getProjectId(), foundSupports.get(0).getProjectId(), "First support project ID should match");
assertEquals(support2.getTeamId(), foundSupports.get(1).getTeamId(), "Second support team ID should match");
}

@Test
public void testFindSupportsByTeamId() {
// when
List<Support> foundSupports = supportService.findSupportsByTeamId(2L);

// then
assertNotNull(foundSupports, "Found supports should not be null");
assertEquals(1, foundSupports.size(), "The size of found supports should be 1");
assertEquals(support1.getTeamId(), foundSupports.get(0).getTeamId(), "Support team ID should match");
assertEquals(support1.getSupportConfirmation(), foundSupports.get(0).getSupportConfirmation(), "Support status should match");
}

@Test
public void testDeleteSupport() {
// given
Long supportId = support1.getSupportId();

// when
supportService.deleteSupport(supportId);
List<Support> foundSupports = supportService.findSupportsByProjectId(1L);
System.out.println(foundSupports);

// then
assertEquals(1, foundSupports.size());
}
}