-
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
…hedule [feat] : 유저는 마이페이지에서 고정 스케줄을 등록할 수 있다
- Loading branch information
Showing
16 changed files
with
349 additions
and
7 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/side/onetime/controller/FixedEventController.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 side.onetime.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import side.onetime.dto.fixedEvent.request.CreateFixedEventRequest; | ||
import side.onetime.global.common.ApiResponse; | ||
import side.onetime.global.common.status.SuccessStatus; | ||
import side.onetime.service.FixedEventService; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/fixed-events") | ||
@RequiredArgsConstructor | ||
public class FixedEventController { | ||
private final FixedEventService fixedEventService; | ||
|
||
// 고정 이벤트 생성 및 고정 스케줄 등록 API | ||
@PostMapping | ||
public ResponseEntity<ApiResponse<Object>> createFixedEvent( | ||
@RequestHeader("Authorization") String authorizationHeader, | ||
@Valid @RequestBody CreateFixedEventRequest createFixedEventRequest) { | ||
|
||
fixedEventService.createFixedEvent(authorizationHeader, createFixedEventRequest); | ||
|
||
return ApiResponse.onSuccess(SuccessStatus._CREATED_FIXED_SCHEDULE); | ||
} | ||
} |
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,45 @@ | ||
package side.onetime.domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import side.onetime.global.common.dao.BaseEntity; | ||
|
||
import java.util.List; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@Table(name = "fixed_events") | ||
public class FixedEvent extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "fixed_events_id") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "users_id", foreignKey = @ForeignKey(name = "fixed_events_fk_users_id")) | ||
private User user; | ||
|
||
@Column(name = "title", nullable = false, length = 30) | ||
private String title; | ||
|
||
@Column(name = "start_time", nullable = false) | ||
private String startTime; | ||
|
||
@Column(name = "end_time", nullable = false) | ||
private String endTime; | ||
|
||
@OneToMany(mappedBy = "fixedEvent",cascade = CascadeType.ALL, fetch = FetchType.LAZY) | ||
private List<FixedSelection> fixedSelections; | ||
|
||
@Builder | ||
public FixedEvent(User user, String title, String startTime, String endTime) { | ||
this.user = user; | ||
this.title = title; | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
} | ||
} |
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,36 @@ | ||
package side.onetime.domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import side.onetime.global.common.dao.BaseEntity; | ||
|
||
import java.util.List; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@Table(name = "fixed_schedules") | ||
public class FixedSchedule extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "fixed_schedules_id") | ||
private Long id; | ||
|
||
@Column(name = "day", length = 10) | ||
private String day; | ||
|
||
@Column(name = "time", nullable = false) | ||
private String time; | ||
|
||
@OneToMany(mappedBy = "fixedSchedule",cascade = CascadeType.ALL, fetch = FetchType.LAZY) | ||
private List<FixedSelection> fixedSelections; | ||
|
||
@Builder | ||
public FixedSchedule(String day, String time) { | ||
this.day = day; | ||
this.time = time; | ||
} | ||
} |
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,33 @@ | ||
package side.onetime.domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import side.onetime.global.common.dao.BaseEntity; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@Table(name = "fixed_selections") | ||
public class FixedSelection extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "fixed_selections_id") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "fixed_events_id", foreignKey = @ForeignKey(name = "fixed_selections_fk_fixed_events_id")) | ||
private FixedEvent fixedEvent; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "fixed_schedules_id", foreignKey = @ForeignKey(name = "fixed_selections_fk_fixed_schedules_id")) | ||
private FixedSchedule fixedSchedule; | ||
|
||
@Builder | ||
public FixedSelection(FixedEvent fixedEvent, FixedSchedule fixedSchedule) { | ||
this.fixedEvent = fixedEvent; | ||
this.fixedSchedule = fixedSchedule; | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
src/main/java/side/onetime/dto/fixedEvent/request/CreateFixedEventRequest.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,30 @@ | ||
package side.onetime.dto.fixedEvent.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import side.onetime.domain.FixedEvent; | ||
import side.onetime.domain.User; | ||
import side.onetime.dto.fixedEvent.response.FixedScheduleResponse; | ||
|
||
import java.util.List; | ||
|
||
import static side.onetime.util.DateUtil.addThirtyMinutes; | ||
|
||
@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public record CreateFixedEventRequest( | ||
@NotBlank(message = "제목은 필수 값입니다.") String title, | ||
@NotNull(message = "스케줄 목록은 필수 값입니다.") List<FixedScheduleResponse> schedules | ||
) { | ||
public FixedEvent toEntity(User user, String startTime, String endTime) { | ||
return FixedEvent.builder() | ||
.user(user) | ||
.title(title) | ||
.startTime(startTime) | ||
.endTime(addThirtyMinutes(endTime)) | ||
.build(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/side/onetime/dto/fixedEvent/response/FixedScheduleResponse.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,14 @@ | ||
package side.onetime.dto.fixedEvent.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
import java.util.List; | ||
|
||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public record FixedScheduleResponse( | ||
String timePoint, | ||
List<String> times | ||
) {} |
37 changes: 37 additions & 0 deletions
37
src/main/java/side/onetime/exception/status/FixedScheduleErrorStatus.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,37 @@ | ||
package side.onetime.exception.status; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import side.onetime.global.common.code.BaseErrorCode; | ||
import side.onetime.global.common.dto.ErrorReasonDto; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum FixedScheduleErrorStatus implements BaseErrorCode { | ||
_NOT_FOUND_FIXED_SCHEDULES(HttpStatus.NOT_FOUND, "FIXED-SCHEDULE-001", "스케줄을 가져오는 데 실패했습니다."), | ||
; | ||
|
||
private final HttpStatus httpStatus; | ||
private final String code; | ||
private final String message; | ||
|
||
@Override | ||
public ErrorReasonDto getReason() { | ||
return ErrorReasonDto.builder() | ||
.isSuccess(false) | ||
.code(code) | ||
.message(message) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public ErrorReasonDto getReasonHttpStatus() { | ||
return ErrorReasonDto.builder() | ||
.isSuccess(false) | ||
.httpStatus(httpStatus) | ||
.code(code) | ||
.message(message) | ||
.build(); | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/java/side/onetime/repository/FixedEventRepository.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 side.onetime.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import side.onetime.domain.FixedEvent; | ||
|
||
public interface FixedEventRepository extends JpaRepository<FixedEvent, Long> { | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/side/onetime/repository/FixedScheduleRepository.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 side.onetime.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import side.onetime.domain.FixedSchedule; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface FixedScheduleRepository extends JpaRepository<FixedSchedule, Long> { | ||
Optional<List<FixedSchedule>> findAllByDay(String day); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/side/onetime/repository/FixedSelectionRepository.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 side.onetime.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import side.onetime.domain.FixedSelection; | ||
|
||
public interface FixedSelectionRepository extends JpaRepository<FixedSelection, Long> { | ||
} |
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,33 @@ | ||
package side.onetime.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import side.onetime.domain.FixedEvent; | ||
import side.onetime.domain.User; | ||
import side.onetime.dto.fixedEvent.request.CreateFixedEventRequest; | ||
import side.onetime.repository.FixedEventRepository; | ||
import side.onetime.util.JwtUtil; | ||
|
||
import java.util.List; | ||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FixedEventService { | ||
private final FixedScheduleService fixedScheduleService; | ||
private final FixedEventRepository fixedEventRepository; | ||
private final JwtUtil jwtUtil; | ||
|
||
// 고정 이벤트 생성 메서드 | ||
@Transactional | ||
public void createFixedEvent(String authorizationHeader, CreateFixedEventRequest createFixedEventRequest) { | ||
User user = jwtUtil.getUserFromHeader(authorizationHeader); | ||
List<String> times = createFixedEventRequest.schedules().get(0).times(); | ||
String startTime = times.get(0); | ||
String endTime = times.get(times.size() - 1); | ||
FixedEvent fixedEvent = createFixedEventRequest.toEntity(user, startTime, endTime); | ||
fixedEventRepository.save(fixedEvent); | ||
fixedScheduleService.createFixedSchedules(createFixedEventRequest, fixedEvent); | ||
} | ||
} |
Oops, something went wrong.