Skip to content

Commit

Permalink
feat: 지원 공고 상태 수정 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
tape4 committed Jul 19, 2024
1 parent dee7638 commit e63cf30
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.web.bind.annotation.*;
import umc.kkijuk.server.common.LoginUser;
import umc.kkijuk.server.recruit.controller.port.RecruitService;
import umc.kkijuk.server.recruit.domain.RecruitStatusUpdate;
import umc.kkijuk.server.recruit.domain.RecruitUpdate;
import umc.kkijuk.server.recruit.controller.response.RecruitResponse;
import umc.kkijuk.server.recruit.domain.Recruit;
Expand All @@ -30,11 +31,20 @@ public ResponseEntity<RecruitResponse> create(@RequestBody @Valid RecruitCreateD
}

@PutMapping("/{recruitId}")
public ResponseEntity<Long> modify(@RequestBody @Valid RecruitUpdate recruitUpdate,
@PathVariable Long recruitId) {
public ResponseEntity<Long> update(@RequestBody @Valid RecruitUpdate recruitUpdate,
@PathVariable long recruitId) {
LoginUser loginUser = LoginUser.get();
return ResponseEntity
.status(HttpStatus.OK)
.body(recruitService.update(recruitId, recruitUpdate).getId());
}

@PatchMapping("/{recruitId}")
public ResponseEntity<Long> updateState(@RequestBody @Valid RecruitStatusUpdate recruitStatusUpdate,
@PathVariable long recruitId) {
LoginUser loginUser = LoginUser.get();
return ResponseEntity
.ok()
.body(recruitService.updateStatus(recruitId, recruitStatusUpdate).getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import umc.kkijuk.server.recruit.domain.Recruit;
import umc.kkijuk.server.recruit.domain.RecruitCreateDto;
import umc.kkijuk.server.recruit.domain.RecruitStatusUpdate;
import umc.kkijuk.server.recruit.domain.RecruitUpdate;

import javax.net.ssl.SSLSession;

public interface RecruitService {
Recruit create(RecruitCreateDto recruitCreateDto);

Recruit update(Long recruitId, RecruitUpdate recruitUpdate);

Recruit getById(long id);

Recruit updateStatus(long recruitId, RecruitStatusUpdate recruitStatusUpdate);
}
13 changes: 13 additions & 0 deletions src/main/java/umc/kkijuk/server/recruit/domain/Recruit.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,17 @@ public Recruit update(RecruitUpdate recruitUpdate) {
.link(recruitUpdate.getLink())
.build();
}

public Recruit updateStatus(RecruitStatusUpdate recruitStatusUpdate) {
return Recruit.builder()
.id(this.id)
.title(this.getTitle())
.status(recruitStatusUpdate.getStatus())
.startTime(this.getStartTime())
.endTime(this.getEndTime())
.applyDate(this.getApplyDate())
.tags(this.getTags())
.link(this.getLink())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package umc.kkijuk.server.recruit.domain;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.*;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RecruitStatusUpdate {
@NotNull
@Schema(description = "변경될 공고 상태", example = "REJECTED", type = "string")
private RecruitStatus status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import umc.kkijuk.server.recruit.controller.port.RecruitService;
import umc.kkijuk.server.recruit.domain.Recruit;
import umc.kkijuk.server.recruit.domain.RecruitCreateDto;
import umc.kkijuk.server.recruit.domain.RecruitStatusUpdate;
import umc.kkijuk.server.recruit.domain.RecruitUpdate;
import umc.kkijuk.server.recruit.service.port.RecruitRepository;

Expand Down Expand Up @@ -40,5 +41,11 @@ public Recruit update(Long recruitId, RecruitUpdate recruitUpdate) {
return recruitRepository.save(recruit);
}


@Override
@Transactional
public Recruit updateStatus(long recruitId, RecruitStatusUpdate recruitStatusUpdate) {
Recruit recruit = getById(recruitId);
recruit = recruit.updateStatus(recruitStatusUpdate);
return recruitRepository.save(recruit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import org.junit.jupiter.api.Test;
import umc.kkijuk.server.common.domian.exception.ResourceNotFoundException;
import umc.kkijuk.server.recruit.controller.port.RecruitService;
import umc.kkijuk.server.recruit.domain.Recruit;
import umc.kkijuk.server.recruit.domain.RecruitCreateDto;
import umc.kkijuk.server.recruit.domain.RecruitStatus;
import umc.kkijuk.server.recruit.domain.RecruitUpdate;
import umc.kkijuk.server.recruit.domain.*;
import umc.kkijuk.server.recruit.mock.FakeRecruitRepository;
import umc.kkijuk.server.recruit.service.port.RecruitRepository;

Expand Down Expand Up @@ -141,7 +138,40 @@ void init() {

//when
//then
Assertions.assertThatThrownBy(
assertThatThrownBy(
() -> recruitService.update(2L, recruitUpdate)).isInstanceOf(ResourceNotFoundException.class);
}

@Test
void status만_수정시_없는_리소스로의_요청은_에러() {
//given
RecruitStatusUpdate recruitStatusUpdate = RecruitStatusUpdate.builder()
.status(RecruitStatus.ACCEPTED).build();

//when
//then
assertThatThrownBy(
() -> recruitService.updateStatus(2L, recruitStatusUpdate)).isInstanceOf(ResourceNotFoundException.class);
}

@Test
void 기존_recruit_status_수정() {
//given
RecruitStatusUpdate recruitStatusUpdate = RecruitStatusUpdate.builder()
.status(RecruitStatus.ACCEPTED).build();

//when
Recruit result = recruitService.updateStatus(1L, recruitStatusUpdate);
assertAll(
() -> assertThat(result.getId()).isEqualTo(1L),
() -> assertThat(result.getTitle()).isEqualTo("test-title"),
() -> assertThat(result.getStatus()).isEqualTo(RecruitStatus.ACCEPTED),
() -> assertThat(result.getStartTime()).isEqualTo(LocalDateTime.of(2024, 7, 19, 2, 30)),
() -> assertThat(result.getEndTime().isEqual(LocalDateTime.of(2024, 7, 31, 17, 30))),
() -> assertThat(result.getApplyDate().isEqual(LocalDate.of(2024, 7, 19))),
() -> assertThat(result.getTags().size()).isEqualTo(3),
() -> assertEquals(result.getTags(), Arrays.asList("코딩 테스트", "인턴", "대외 활동")),
() -> assertThat(result.getLink()).isEqualTo("test-link")
);
}
}

0 comments on commit e63cf30

Please sign in to comment.