-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#29 recruit crud api 개발
- Loading branch information
Showing
33 changed files
with
2,708 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.server.bbo_gak.domain.recruit.controller; | ||
|
||
import com.server.bbo_gak.domain.recruit.dto.request.RecruitCreateRequest; | ||
import com.server.bbo_gak.domain.recruit.dto.request.RecruitUpdateSeasonRequest; | ||
import com.server.bbo_gak.domain.recruit.dto.request.RecruitUpdateSiteUrlRequest; | ||
import com.server.bbo_gak.domain.recruit.dto.request.RecruitUpdateStatusRequest; | ||
import com.server.bbo_gak.domain.recruit.dto.request.RecruitUpdateTitleRequest; | ||
import com.server.bbo_gak.domain.recruit.dto.response.RecruitGetResponse; | ||
import com.server.bbo_gak.domain.recruit.service.RecruitService; | ||
import com.server.bbo_gak.domain.user.entity.User; | ||
import com.server.bbo_gak.global.annotation.AuthUser; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/recruits") | ||
@RequiredArgsConstructor | ||
public class RecruitController { | ||
|
||
private final RecruitService recruitService; | ||
|
||
@GetMapping("") | ||
public ResponseEntity<List<RecruitGetResponse>> getTotalRecruitList( | ||
@AuthUser User user | ||
) { | ||
return ResponseEntity.ok(recruitService.getTotalRecruitList(user)); | ||
} | ||
|
||
|
||
@GetMapping("/bySeason") | ||
public ResponseEntity<List<RecruitGetResponse>> getRecruitListBySeason( | ||
@AuthUser User user, | ||
@RequestParam("season") String season | ||
) { | ||
return ResponseEntity.ok(recruitService.getRecruitListBySeason(user, season)); | ||
} | ||
|
||
@GetMapping("/progressing") | ||
public ResponseEntity<List<RecruitGetResponse>> getProgressingRecruitList( | ||
@AuthUser User user | ||
) { | ||
return ResponseEntity.ok(recruitService.getProgressingRecruitList(user)); | ||
} | ||
|
||
@PostMapping("") | ||
public ResponseEntity<RecruitGetResponse> createRecruit( | ||
@AuthUser User user, | ||
@RequestBody RecruitCreateRequest request | ||
) { | ||
return ResponseEntity.ok(recruitService.createRecruit(user, request)); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteRecruit( | ||
@AuthUser User user, | ||
@PathVariable("id") Long id | ||
) { | ||
recruitService.deleteRecruit(user, id); | ||
return ResponseEntity.ok().body(null); | ||
} | ||
|
||
@PatchMapping("/{id}/title") | ||
public ResponseEntity<RecruitGetResponse> updateRecruitTitle( | ||
@AuthUser User user, | ||
@PathVariable("id") Long id, | ||
@RequestBody RecruitUpdateTitleRequest request) { | ||
RecruitGetResponse response = recruitService.updateRecruitTitle(user, id, request.title()); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@PatchMapping("/{id}/season") | ||
public ResponseEntity<RecruitGetResponse> updateRecruitSeason( | ||
@AuthUser User user, | ||
@PathVariable("id") Long id, | ||
@RequestBody RecruitUpdateSeasonRequest request) { | ||
RecruitGetResponse response = recruitService.updateRecruitSeason(user, id, request.season()); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@PatchMapping("/{id}/status") | ||
public ResponseEntity<RecruitGetResponse> updateRecruitStatus( | ||
@AuthUser User user, | ||
@PathVariable("id") Long id, | ||
@RequestBody RecruitUpdateStatusRequest request) { | ||
RecruitGetResponse response = recruitService.updateRecruitStatus(user, id, request.recruitStatus()); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@PatchMapping("/{id}/siteUrl") | ||
public ResponseEntity<RecruitGetResponse> updateRecruitSiteUrl( | ||
@AuthUser User user, | ||
@PathVariable("id") Long id, | ||
@RequestBody RecruitUpdateSiteUrlRequest request) { | ||
RecruitGetResponse response = recruitService.updateRecruitSiteUrl(user, id, request.siteUrl()); | ||
return ResponseEntity.ok(response); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/server/bbo_gak/domain/recruit/controller/SeasonController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.server.bbo_gak.domain.recruit.controller; | ||
|
||
import com.server.bbo_gak.domain.recruit.dto.response.SeasonGetResponse; | ||
import com.server.bbo_gak.domain.recruit.service.SeasonService; | ||
import com.server.bbo_gak.domain.user.entity.User; | ||
import com.server.bbo_gak.global.annotation.AuthUser; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/seasons") | ||
@RequiredArgsConstructor | ||
public class SeasonController { | ||
|
||
private final SeasonService seasonService; | ||
|
||
|
||
@GetMapping("") | ||
public ResponseEntity<List<SeasonGetResponse>> getRecruitSeasonList( | ||
@AuthUser User user | ||
) { | ||
return ResponseEntity.ok(seasonService.getSeasonListByUser(user)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/server/bbo_gak/domain/recruit/dao/RecruitRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.server.bbo_gak.domain.recruit.dao; | ||
|
||
import com.server.bbo_gak.domain.recruit.entity.Recruit; | ||
import com.server.bbo_gak.domain.recruit.entity.Season; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface RecruitRepository extends JpaRepository<Recruit, Long> { | ||
|
||
Optional<Recruit> findByUserIdAndId(Long userId, Long id); | ||
|
||
List<Recruit> findAllByUserId(Long userId); | ||
|
||
List<Recruit> findAllByUserIdAndSeason(Long userId, Season season); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/server/bbo_gak/domain/recruit/dao/SeasonRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.server.bbo_gak.domain.recruit.dao; | ||
|
||
import com.server.bbo_gak.domain.recruit.entity.Season; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface SeasonRepository extends JpaRepository<Season, Long> { | ||
|
||
List<Season> findAllByUserId(Long userId); | ||
|
||
boolean existsByUserIdAndName(Long userId, String name); | ||
|
||
Optional<Season> findByUserIdAndName(Long userId, String name); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.server.bbo_gak.domain.recruit.dto.request; | ||
|
||
import com.server.bbo_gak.domain.recruit.entity.Recruit; | ||
import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule; | ||
import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage; | ||
import com.server.bbo_gak.domain.recruit.entity.RecruitStatus; | ||
import com.server.bbo_gak.domain.recruit.entity.Season; | ||
import com.server.bbo_gak.domain.user.entity.User; | ||
|
||
public record RecruitCreateRequest( | ||
String season, | ||
String title, | ||
String siteUrl, | ||
RecruitScheduleStage recruitScheduleStage, | ||
String deadline | ||
) { | ||
|
||
public Recruit toEntity(User user, Season season, RecruitSchedule schedule) { | ||
return Recruit.builder() | ||
.season(season) | ||
.title(title) | ||
.siteUrl(siteUrl) | ||
.recruitStatus(RecruitStatus.APPLICATION_COMPLETED) | ||
.user(user) | ||
.build() | ||
.addSchedule(schedule); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.server.bbo_gak.domain.recruit.dto.request; | ||
|
||
import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule; | ||
import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage; | ||
import java.time.LocalDate; | ||
|
||
public record RecruitScheduleCreateRequest( | ||
RecruitScheduleStage recruitScheduleStage, | ||
String deadline | ||
) { | ||
|
||
public static RecruitSchedule of(RecruitScheduleStage recruitScheduleStage, String deadline) { | ||
return RecruitSchedule.builder() | ||
.recruitScheduleStage(recruitScheduleStage) | ||
.deadLine(LocalDate.parse(deadline)) | ||
.build(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitUpdateSeasonRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.server.bbo_gak.domain.recruit.dto.request; | ||
|
||
public record RecruitUpdateSeasonRequest(String season) { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitUpdateSiteUrlRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.server.bbo_gak.domain.recruit.dto.request; | ||
|
||
public record RecruitUpdateSiteUrlRequest(String siteUrl) { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitUpdateStatusRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.server.bbo_gak.domain.recruit.dto.request; | ||
|
||
import com.server.bbo_gak.domain.recruit.entity.RecruitStatus; | ||
|
||
public record RecruitUpdateStatusRequest(RecruitStatus recruitStatus) { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitUpdateTitleRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.server.bbo_gak.domain.recruit.dto.request; | ||
|
||
public record RecruitUpdateTitleRequest(String title) { | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/server/bbo_gak/domain/recruit/dto/response/RecruitGetResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.server.bbo_gak.domain.recruit.dto.response; | ||
|
||
import com.server.bbo_gak.domain.recruit.entity.Recruit; | ||
import com.server.bbo_gak.global.utils.BaseDateTimeFormatter; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record RecruitGetResponse( | ||
Long id, | ||
String title, | ||
String season, | ||
String siteUrl, | ||
String recruitStatus, | ||
String createdDate | ||
) { | ||
|
||
public static RecruitGetResponse from(Recruit recruit) { | ||
|
||
return RecruitGetResponse.builder() | ||
.id(recruit.getId()) | ||
.title(recruit.getTitle()) | ||
.season(recruit.getSeason().getName()) | ||
.siteUrl(recruit.getSiteUrl()) | ||
.recruitStatus(recruit.getRecruitStatus().getValue()) | ||
.createdDate(recruit.getCreatedDate().format(BaseDateTimeFormatter.getLocalDateTimeFormatter())) | ||
.build(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/server/bbo_gak/domain/recruit/dto/response/RecruitScheduleGetResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.server.bbo_gak.domain.recruit.dto.response; | ||
|
||
import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule; | ||
import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage; | ||
import com.server.bbo_gak.global.utils.BaseDateTimeFormatter; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record RecruitScheduleGetResponse( | ||
Long id, | ||
RecruitScheduleStage recruitScheduleStage, | ||
String deadLine | ||
) { | ||
|
||
public static RecruitScheduleGetResponse from(RecruitSchedule schedule) { | ||
return RecruitScheduleGetResponse.builder() | ||
.id(schedule.getId()) | ||
.recruitScheduleStage(schedule.getRecruitScheduleStage()) | ||
.deadLine(schedule.getDeadLine().format(BaseDateTimeFormatter.getLocalDateFormatter())) | ||
.build(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/server/bbo_gak/domain/recruit/dto/response/SeasonGetResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.server.bbo_gak.domain.recruit.dto.response; | ||
|
||
import com.server.bbo_gak.domain.recruit.entity.Season; | ||
|
||
public record SeasonGetResponse( | ||
String name | ||
) { | ||
|
||
public static SeasonGetResponse from(Season season) { | ||
return new SeasonGetResponse(season.getName()); | ||
} | ||
} |
Oops, something went wrong.