-
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.
Merge pull request #195 from Kim-s-Crew/dev
팀 생성 & 일정 생성
- Loading branch information
Showing
25 changed files
with
459 additions
and
47 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...ain/java/wercsmik/spaghetticodingclub/domain/schedule/controller/SchedulerController.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,34 @@ | ||
package wercsmik.spaghetticodingclub.domain.schedule.controller; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
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.RestController; | ||
import wercsmik.spaghetticodingclub.domain.schedule.dto.SchedulerCreationRequestDTO; | ||
import wercsmik.spaghetticodingclub.domain.schedule.dto.SchedulerCreationResponseDTO; | ||
import wercsmik.spaghetticodingclub.domain.schedule.service.SchedulerService; | ||
import wercsmik.spaghetticodingclub.global.common.CommonResponse; | ||
import wercsmik.spaghetticodingclub.global.security.UserDetailsImpl; | ||
|
||
@RestController | ||
@AllArgsConstructor | ||
@RequestMapping("/schedules") | ||
public class SchedulerController { | ||
|
||
private final SchedulerService schedulerService; | ||
|
||
@PostMapping | ||
public ResponseEntity<CommonResponse<SchedulerCreationResponseDTO>> createSchedule( | ||
@AuthenticationPrincipal UserDetailsImpl userDetails, | ||
@RequestBody SchedulerCreationRequestDTO requestDTO) { | ||
|
||
SchedulerCreationResponseDTO schedulerResponseDTO = schedulerService.createSchedule(userDetails, requestDTO); | ||
|
||
return ResponseEntity.status(HttpStatus.CREATED) | ||
.body(CommonResponse.of("일정 생성 성공", schedulerResponseDTO)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...in/java/wercsmik/spaghetticodingclub/domain/schedule/dto/SchedulerCreationRequestDTO.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,20 @@ | ||
package wercsmik.spaghetticodingclub.domain.schedule.dto; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class SchedulerCreationRequestDTO { | ||
|
||
private String title; | ||
|
||
private LocalDateTime startTime; | ||
|
||
private LocalDateTime endTime; | ||
} |
39 changes: 39 additions & 0 deletions
39
...n/java/wercsmik/spaghetticodingclub/domain/schedule/dto/SchedulerCreationResponseDTO.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,39 @@ | ||
package wercsmik.spaghetticodingclub.domain.schedule.dto; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import wercsmik.spaghetticodingclub.domain.schedule.entity.Scheduler; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
public class SchedulerCreationResponseDTO { | ||
|
||
private Long schedulerId; | ||
|
||
private Long userId; | ||
|
||
private String title; | ||
|
||
private LocalDateTime startTime; | ||
|
||
private LocalDateTime endTime; | ||
|
||
private LocalDateTime createdAt; | ||
|
||
private LocalDateTime modifiedAt; | ||
|
||
public static SchedulerCreationResponseDTO of(Scheduler scheduler) { | ||
return new SchedulerCreationResponseDTO( | ||
scheduler.getSchedulerId(), | ||
scheduler.getUserId().getUserId(), | ||
scheduler.getTitle(), | ||
scheduler.getStartTime(), | ||
scheduler.getEndTime(), | ||
scheduler.getCreatedAt(), | ||
scheduler.getModifiedAt() | ||
); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/wercsmik/spaghetticodingclub/domain/schedule/entity/Scheduler.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,42 @@ | ||
package wercsmik.spaghetticodingclub.domain.schedule.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import wercsmik.spaghetticodingclub.domain.user.entity.User; | ||
import wercsmik.spaghetticodingclub.global.auditing.BaseTimeEntity; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@RequiredArgsConstructor | ||
public class Scheduler extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long schedulerId; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id", nullable = false) | ||
private User userId; | ||
|
||
@Column | ||
private String title; | ||
|
||
@Column(nullable = false) | ||
private LocalDateTime startTime; | ||
|
||
@Column(nullable = false) | ||
private LocalDateTime endTime; | ||
} |
11 changes: 11 additions & 0 deletions
11
...ain/java/wercsmik/spaghetticodingclub/domain/schedule/repository/SchedulerRepository.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,11 @@ | ||
package wercsmik.spaghetticodingclub.domain.schedule.repository; | ||
|
||
import java.time.LocalDateTime; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import wercsmik.spaghetticodingclub.domain.schedule.entity.Scheduler; | ||
import wercsmik.spaghetticodingclub.domain.user.entity.User; | ||
|
||
public interface SchedulerRepository extends JpaRepository<Scheduler, Long> { | ||
|
||
boolean existsByUserIdAndStartTimeLessThanAndEndTimeGreaterThan(User user, LocalDateTime endTime, LocalDateTime startTime); | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/wercsmik/spaghetticodingclub/domain/schedule/service/SchedulerService.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,56 @@ | ||
package wercsmik.spaghetticodingclub.domain.schedule.service; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import wercsmik.spaghetticodingclub.domain.schedule.dto.SchedulerCreationRequestDTO; | ||
import wercsmik.spaghetticodingclub.domain.schedule.dto.SchedulerCreationResponseDTO; | ||
import wercsmik.spaghetticodingclub.domain.schedule.entity.Scheduler; | ||
import wercsmik.spaghetticodingclub.domain.schedule.repository.SchedulerRepository; | ||
import wercsmik.spaghetticodingclub.domain.user.entity.User; | ||
import wercsmik.spaghetticodingclub.global.exception.CustomException; | ||
import wercsmik.spaghetticodingclub.global.exception.ErrorCode; | ||
import wercsmik.spaghetticodingclub.global.security.UserDetailsImpl; | ||
|
||
@Service | ||
@AllArgsConstructor | ||
public class SchedulerService { | ||
|
||
private final SchedulerRepository schedulerRepository; | ||
|
||
@Transactional | ||
public SchedulerCreationResponseDTO createSchedule(UserDetailsImpl userDetails, SchedulerCreationRequestDTO requestDTO) { | ||
|
||
if (userDetails == null) { | ||
throw new CustomException(ErrorCode.USER_NOT_FOUND); | ||
} | ||
|
||
User user = userDetails.getUser(); | ||
|
||
LocalDateTime startTime = requestDTO.getStartTime(); | ||
LocalDateTime endTime = requestDTO.getEndTime(); | ||
|
||
// 종료 시간이 시작 시간보다 이전이면 예외 발생 | ||
if (endTime.isBefore(startTime)) { | ||
throw new CustomException(ErrorCode.INVALID_DATE_RANGE); | ||
} | ||
|
||
// 사용자가 이미 일정이 겹치는지 확인 | ||
boolean hasOverlap = schedulerRepository.existsByUserIdAndStartTimeLessThanAndEndTimeGreaterThan(user, endTime, startTime); | ||
if (hasOverlap) { | ||
throw new CustomException(ErrorCode.SCHEDULE_OVERLAP); | ||
} | ||
|
||
Scheduler scheduler = Scheduler.builder() | ||
.userId(user) | ||
.title(requestDTO.getTitle()) | ||
.startTime(requestDTO.getStartTime()) | ||
.endTime(requestDTO.getEndTime()) | ||
.build(); | ||
|
||
Scheduler savedSchedule = schedulerRepository.save(scheduler); | ||
|
||
return SchedulerCreationResponseDTO.of(savedSchedule); | ||
} | ||
} |
4 changes: 0 additions & 4 deletions
4
...in/java/wercsmik/spaghetticodingclub/domain/scheduler/controller/SchedulerController.java
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/main/java/wercsmik/spaghetticodingclub/domain/scheduler/dto/SchedulerRequestDTO.java
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/main/java/wercsmik/spaghetticodingclub/domain/scheduler/dto/SchedulerResponseDTO.java
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/main/java/wercsmik/spaghetticodingclub/domain/scheduler/entity/Scheduler.java
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
...in/java/wercsmik/spaghetticodingclub/domain/scheduler/repository/SchedulerRepository.java
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/main/java/wercsmik/spaghetticodingclub/domain/scheduler/service/SchedulerService.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
src/main/java/wercsmik/spaghetticodingclub/domain/team/controller/TeamController.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 |
---|---|---|
@@ -1,4 +1,33 @@ | ||
package wercsmik.spaghetticodingclub.domain.team.controller; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.*; | ||
import wercsmik.spaghetticodingclub.domain.team.dto.TeamCreationRequestDTO; | ||
import wercsmik.spaghetticodingclub.domain.team.dto.TeamCreationResponseDTO; | ||
import wercsmik.spaghetticodingclub.domain.team.service.TeamService; | ||
import wercsmik.spaghetticodingclub.global.common.CommonResponse; | ||
|
||
@RestController | ||
@RequestMapping("/tracks/{trackId}/trackWeeks/{trackWeekId}/teams") | ||
@AllArgsConstructor | ||
public class TeamController { | ||
|
||
private final TeamService teamService; | ||
|
||
@PostMapping | ||
@PreAuthorize("hasAuthority('ROLE_ADMIN')") | ||
public ResponseEntity<CommonResponse<TeamCreationResponseDTO>> createTeam( | ||
@PathVariable Long trackId, | ||
@PathVariable Long trackWeekId, | ||
@RequestBody TeamCreationRequestDTO requestDTO) { | ||
|
||
TeamCreationResponseDTO responseDTO = teamService.createTeam(trackId, trackWeekId, requestDTO); | ||
|
||
return ResponseEntity.status(HttpStatus.CREATED) | ||
.body(CommonResponse.of("팀 생성 성공", responseDTO)); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/wercsmik/spaghetticodingclub/domain/team/dto/TeamCreationRequestDTO.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 wercsmik.spaghetticodingclub.domain.team.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class TeamCreationRequestDTO { | ||
|
||
private String teamName; | ||
|
||
private List<Long> memberIds; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/wercsmik/spaghetticodingclub/domain/team/dto/TeamCreationResponseDTO.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 wercsmik.spaghetticodingclub.domain.team.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class TeamCreationResponseDTO { | ||
|
||
private Long teamId; | ||
|
||
private String teamName; | ||
|
||
private List<Map<String, Object>> members; | ||
} |
4 changes: 0 additions & 4 deletions
4
src/main/java/wercsmik/spaghetticodingclub/domain/team/dto/TeamRequestDTO.java
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/main/java/wercsmik/spaghetticodingclub/domain/team/dto/TeamResponseDTO.java
This file was deleted.
Oops, something went wrong.
46 changes: 45 additions & 1 deletion
46
src/main/java/wercsmik/spaghetticodingclub/domain/team/entity/Team.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 |
---|---|---|
@@ -1,4 +1,48 @@ | ||
package wercsmik.spaghetticodingclub.domain.team.entity; | ||
|
||
public class Team { | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import wercsmik.spaghetticodingclub.domain.track.entity.TrackWeek; | ||
import wercsmik.spaghetticodingclub.domain.user.entity.User; | ||
import wercsmik.spaghetticodingclub.global.auditing.BaseTimeEntity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class Team extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long teamId; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "trackWeekId", nullable = false) | ||
private TrackWeek trackWeek; | ||
|
||
@Column(length = 50, nullable = false) | ||
private String teamName; | ||
|
||
@OneToMany(mappedBy = "team", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<User> members = new ArrayList<>(); | ||
|
||
//TODO(은채): 팀리더 설정 | ||
|
||
public static class TeamBuilder { | ||
public TeamBuilder members(List<User> members) { | ||
if (this.members == null) { | ||
this.members = new ArrayList<>(); | ||
} | ||
this.members.addAll(members); | ||
return this; | ||
} | ||
} | ||
} |
Oops, something went wrong.