File tree Expand file tree Collapse file tree
main/java/org/ject/support/domain
test/java/org/ject/support/domain/admin/service Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,4 +19,9 @@ public interface AdminTempApplyApiSpec {
1919 summary = "임시 저장한 지원서 수 조회" ,
2020 description = "임시 저장한 지원서 총 개수를 조회합니다." )
2121 TempSavedApplyCountResponse getTempSavedApplyCount ();
22+
23+ @ Operation (
24+ summary = "임시 저장된 지원서 삭제" ,
25+ description = "임시 저장된 지원서를 삭제합니다." )
26+ void deleteTempApply (@ PathVariable ("tempApplyId" ) Long tempApplyId );
2227}
Original file line number Diff line number Diff line change 55import org .ject .support .domain .admin .service .AdminTempApplyService ;
66import org .ject .support .domain .apply .dto .TempApplyDetailResponse ;
77import org .springframework .security .access .prepost .PreAuthorize ;
8+ import org .springframework .web .bind .annotation .DeleteMapping ;
89import org .springframework .web .bind .annotation .GetMapping ;
910import org .springframework .web .bind .annotation .PathVariable ;
1011import org .springframework .web .bind .annotation .RequestMapping ;
@@ -28,4 +29,10 @@ public TempApplyDetailResponse getTempApplyDetail(@PathVariable("tempApplyId") L
2829 public TempSavedApplyCountResponse getTempSavedApplyCount () {
2930 return adminTempApplyService .getTempSavedApplyCount ();
3031 }
32+
33+ @ DeleteMapping ("/{tempApplyId}" )
34+ @ PreAuthorize ("hasRole('ROLE_ADMIN')" )
35+ public void deleteTempApply (@ PathVariable final Long tempApplyId ) {
36+ adminTempApplyService .deleteTempApply (tempApplyId );
37+ }
3138}
Original file line number Diff line number Diff line change 1313import org .springframework .stereotype .Service ;
1414import org .springframework .transaction .annotation .Transactional ;
1515
16+ import java .util .List ;
17+ import java .util .Map ;
18+
1619@ Service
1720@ RequiredArgsConstructor
1821@ Transactional (readOnly = true )
@@ -29,8 +32,8 @@ public TempApplyDetailResponse getTempApplyDetail(Long tempApplyId) {
2932
3033 return TempApplyDetailResponse .from (
3134 apply ,
32- string2MapSerializer .serializeAsMap (tempApplicationForm .getContent ()),
33- tempApplicationForm .getPortfolios ()
35+ tempApplicationForm == null ? Map . of () : string2MapSerializer .serializeAsMap (tempApplicationForm .getContent ()),
36+ tempApplicationForm == null ? List . of () : tempApplicationForm .getPortfolios ()
3437 .stream ()
3538 .map (ApplyPortfolioDto ::from )
3639 .toList ());
@@ -40,4 +43,12 @@ public TempSavedApplyCountResponse getTempSavedApplyCount() {
4043 Long count = applyRepository .countByStatus (Apply .Status .TEMP_SAVED );
4144 return new TempSavedApplyCountResponse (count );
4245 }
46+
47+ @ Transactional
48+ public void deleteTempApply (Long applyId ) {
49+ Apply apply = applyRepository .findByIdAndStatusWithMember (applyId , Apply .Status .TEMP_SAVED )
50+ .orElseThrow (() -> new ApplyException (ApplyErrorCode .NOT_FOUND_APPLY ));
51+ apply .getMember ().deleteProfile ();
52+ applyRepository .delete (apply );
53+ }
4354}
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public record TempApplyDetailResponse(
1818 String lastModifiedAt ,
1919 JobFamily recruitJobFamily ,
2020 TempApplicationFormResponse tempApplicationFormResponse
21- ) {
21+ ) {
2222
2323 public static TempApplyDetailResponse from (
2424 Apply apply ,
Original file line number Diff line number Diff line change @@ -107,4 +107,50 @@ class AdminTempApplyServiceTest extends UnitTestSupport {
107107 verify (applyRepository ).countByStatus (targetStatus );
108108 assertThat (result ).isEqualTo (new TempSavedApplyCountResponse (tempSavedCount ));
109109 }
110+
111+ @ Test
112+ void 존재하지_않는_임시_저장_상태의_지원서를_삭제_할_경우_예외_발생 () {
113+ // given
114+ Long tempApplyId = 1L ;
115+ given (applyRepository .findByIdAndStatusWithMember (tempApplyId , Apply .Status .TEMP_SAVED ))
116+ .willReturn (Optional .empty ());
117+
118+ // when, then
119+ assertThatThrownBy (() -> adminTempApplyService .deleteTempApply (tempApplyId ))
120+ .isInstanceOf (ApplyException .class );
121+ }
122+
123+ @ Test
124+ void 임시_저장된_지원서를_삭제한다 () {
125+ // given
126+ Long tempApplyId = 1L ;
127+ Member member = Member .builder ()
128+ .name ("김젝트" )
129+ .build ();
130+ Semester semester = Semester .builder ()
131+ .name ("1" )
132+ .build ();
133+ Recruit recruit = Recruit .builder ()
134+ .semester (semester )
135+ .build ();
136+ ApplicationForm applicationForm = ApplicationForm .builder ()
137+ .content ("{}" )
138+ .build ();
139+ Apply tempSavedApply = Apply .builder ()
140+ .id (tempApplyId )
141+ .member (member )
142+ .recruit (recruit )
143+ .status (Apply .Status .TEMP_SAVED )
144+ .applicationForm (applicationForm )
145+ .build ();
146+ given (applyRepository .findByIdAndStatusWithMember (tempApplyId , Apply .Status .TEMP_SAVED ))
147+ .willReturn (Optional .of (tempSavedApply ));
148+
149+ // when
150+ adminTempApplyService .deleteTempApply (tempApplyId );
151+
152+ // then
153+ verify (applyRepository ).findByIdAndStatusWithMember (tempApplyId , Apply .Status .TEMP_SAVED );
154+ verify (applyRepository ).delete (tempSavedApply );
155+ }
110156}
You can’t perform that action at this time.
0 commit comments