Skip to content

Commit

Permalink
[FEAT] recruit status change api (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
wken5577 authored Mar 29, 2024
1 parent 6613d12 commit 45e83f3
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build/
gg-pingpong-api/src/main/resources/application.yml
.DS_Store
python
/logs
**/logs


### STS ###
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ public void del() {
public Boolean isEnd() {
return LocalDateTime.now().isAfter(this.endTime);
}

public void setFinish(Boolean finish) {
this.isFinish = finish;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public GroupedOpenApi recruitGroup() {
public GroupedOpenApi recruitAdminGroup() {
return GroupedOpenApi.builder()
.group("recruit admin")
.pathsToMatch("admin/recruitments/**")
.pathsToMatch("/admin/recruitments/**")
.packagesToScan("gg.recruit.api.admin")
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package gg.recruit.api.admin.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import gg.recruit.api.admin.controller.request.UpdateStatusRequestDto;
import gg.recruit.api.admin.service.AdminRecruitmentService;
import gg.recruit.api.admin.service.UpdateRecruitStatusParam;
import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/admin/recruitments")
@RequiredArgsConstructor
public class AdminRecruitmentController {
private final AdminRecruitmentService adminRecruitmentService;

@PatchMapping("/{recruitId}/status")
public ResponseEntity<Void> updateRecruitStatus(@PathVariable Long recruitId,
@RequestBody UpdateStatusRequestDto requestDto) {

adminRecruitmentService.updateRecruitStatus(
new UpdateRecruitStatusParam(recruitId, requestDto.getFinish()));
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gg.recruit.api.admin.controller.request;

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

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class UpdateStatusRequestDto {
private Boolean finish;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gg.recruit.api.admin.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import gg.data.recruit.recruitment.Recruitments;
import gg.repo.recruit.user.recruitment.RecruitmentRepository;
import gg.utils.exception.custom.NotExistException;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class AdminRecruitmentService {
private final RecruitmentRepository recruitmentRepository;

@Transactional
public void updateRecruitStatus(UpdateRecruitStatusParam updateRecruitStatusParam) {
Recruitments recruitments = recruitmentRepository.findById(updateRecruitStatusParam.getRecruitId())
.orElseThrow(() -> new NotExistException("Recruitment not found."));
recruitments.setFinish(updateRecruitStatusParam.getFinish());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gg.recruit.api.admin.service;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public class UpdateRecruitStatusParam {
private Long recruitId;
private Boolean finish;
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public ResponseEntity<Void> updateApplication(@Login @Parameter(hidden = true) U
@DeleteMapping("/{recruitmentId}/applications/{applicationId}")
public ResponseEntity<Void> cancelApplication(@Login @Parameter(hidden = true) UserDto userDto,
@PathVariable Long recruitmentId, @PathVariable Long applicationId) {
applicationService.deleteApplication(new DelApplicationParam(userDto.getId(), recruitmentId, applicationId));
applicationService.deleteApplication(new DelApplicationParam(userDto.getId(), applicationId, recruitmentId));
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package gg.recruit.api.admin.controller;

import static org.junit.jupiter.api.Assertions.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;

import com.fasterxml.jackson.databind.ObjectMapper;

import gg.data.recruit.recruitment.Recruitments;
import gg.data.user.User;
import gg.recruit.api.admin.controller.request.UpdateStatusRequestDto;
import gg.recruit.api.user.RecruitMockData;
import gg.repo.recruit.user.recruitment.RecruitmentRepository;
import gg.utils.TestDataUtils;
import gg.utils.annotation.IntegrationTest;

@IntegrationTest
@Transactional
@AutoConfigureMockMvc
class AdminRecruitmentControllerTest {
@Autowired
private RecruitMockData recruitMockData;

@Autowired
private TestDataUtils testDataUtils;

@Autowired
private MockMvc mockMvc;

@Autowired
private ObjectMapper objectMapper;

@Autowired
private RecruitmentRepository recruitmentRepository;

@Test
@DisplayName("PATCH /admin/recruitments/{recruitId}/status -> 204 NO CONTENT TEST")
public void updateRecruitStatusTest() throws Exception {
//given
Recruitments recruitments = recruitMockData.createRecruitments();
UpdateStatusRequestDto requestDto = new UpdateStatusRequestDto(true);
User adminUser = testDataUtils.createAdminUser();

//when
mockMvc.perform(patch("/admin/recruitments/{recruitId}/status", recruitments.getId())
.header("Authorization", "Bearer " + testDataUtils.getLoginAccessTokenFromUser(adminUser))
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(requestDto)))
.andExpect(status().isNoContent());

//then
Recruitments updatedRecruitments = recruitmentRepository.findById(recruitments.getId()).get();
assertTrue(updatedRecruitments.getIsFinish());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down

0 comments on commit 45e83f3

Please sign in to comment.