-
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 branch 'develop' into feat/FU-346-daily-schedule-api
- Loading branch information
Showing
13 changed files
with
537 additions
and
0 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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/foru/freebe/member/entity/ScheduleUnit.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 com.foru.freebe.member.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public enum ScheduleUnit { | ||
|
||
@JsonProperty("THIRTY_MINUTES") | ||
THIRTY_MINUTES, | ||
@JsonProperty("SIXTY_MINUTES") | ||
SIXTY_MINUTES | ||
} |
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
95 changes: 95 additions & 0 deletions
95
src/main/java/com/foru/freebe/schedule/controller/BaseScheduleController.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,95 @@ | ||
package com.foru.freebe.schedule.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.foru.freebe.auth.model.MemberAdapter; | ||
import com.foru.freebe.schedule.dto.BaseScheduleDto; | ||
import com.foru.freebe.schedule.dto.ScheduleUnitDto; | ||
import com.foru.freebe.schedule.service.BaseScheduleService; | ||
import com.foru.freebe.common.dto.ResponseBody; | ||
import com.foru.freebe.member.entity.Member; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/photographer") | ||
public class BaseScheduleController { | ||
|
||
private final BaseScheduleService baseScheduleService; | ||
|
||
@GetMapping("/schedule/base") | ||
public ResponseEntity<ResponseBody<List<BaseScheduleDto>>> getBaseSchedules( | ||
@AuthenticationPrincipal MemberAdapter memberAdapter) { | ||
Member photographer = memberAdapter.getMember(); | ||
List<BaseScheduleDto> responseData = baseScheduleService.getBaseSchedules(photographer.getId()); | ||
|
||
ResponseBody<List<BaseScheduleDto>> responseBody = ResponseBody | ||
.<List<BaseScheduleDto>>builder() | ||
.message("Successfully retrieve basic schedules.") | ||
.data(responseData) | ||
.build(); | ||
|
||
return ResponseEntity.status(HttpStatus.OK.value()) | ||
.body(responseBody); | ||
} | ||
|
||
@PutMapping("/schedule/base") | ||
public ResponseEntity<ResponseBody<Void>> updateBaseSchedule(@AuthenticationPrincipal MemberAdapter memberAdapter, | ||
@Valid @RequestBody List<BaseScheduleDto> request) { | ||
|
||
Member photographer = memberAdapter.getMember(); | ||
baseScheduleService.updateBaseSchedule(request, photographer.getId()); | ||
|
||
ResponseBody<Void> responseBody = ResponseBody.<Void>builder() | ||
.message("Basic schedule successfully changed") | ||
.data(null) | ||
.build(); | ||
|
||
return ResponseEntity.status(HttpStatus.OK.value()) | ||
.body(responseBody); | ||
} | ||
|
||
@GetMapping("/schedule/unit") | ||
public ResponseEntity<ResponseBody<ScheduleUnitDto>> getScheduleUnit( | ||
@AuthenticationPrincipal MemberAdapter memberAdapter) { | ||
|
||
Member photographer = memberAdapter.getMember(); | ||
ScheduleUnitDto responseData = baseScheduleService.getScheduleUnit(photographer.getId()); | ||
|
||
ResponseBody<ScheduleUnitDto> responseBody = ResponseBody | ||
.<ScheduleUnitDto>builder() | ||
.message("Successfully retrieve schedule unit.") | ||
.data(responseData) | ||
.build(); | ||
|
||
return ResponseEntity.status(HttpStatus.OK.value()) | ||
.body(responseBody); | ||
} | ||
|
||
|
||
@PutMapping("/schedule/unit") | ||
public ResponseEntity<ResponseBody<Void>> updateScheduleUnit(@Valid @RequestBody ScheduleUnitDto request, @AuthenticationPrincipal MemberAdapter memberAdapter) { | ||
|
||
Member photographer = memberAdapter.getMember(); | ||
baseScheduleService.updateScheduleUnit(photographer.getId(), request); | ||
|
||
ResponseBody<Void> responseBody = ResponseBody.<Void>builder() | ||
.message("Schedule Unit successfully changed") | ||
.data(null) | ||
.build(); | ||
|
||
return ResponseEntity.status(HttpStatus.OK.value()) | ||
.body(responseBody); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/foru/freebe/schedule/dto/BaseScheduleDto.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 com.foru.freebe.schedule.dto; | ||
|
||
import java.time.LocalTime; | ||
|
||
import com.foru.freebe.schedule.entity.DayOfWeek; | ||
import com.foru.freebe.schedule.entity.OperationStatus; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class BaseScheduleDto { | ||
|
||
@NotNull | ||
private DayOfWeek dayOfWeek; | ||
|
||
@NotNull | ||
private LocalTime startTime; | ||
|
||
@NotNull | ||
private LocalTime endTime; | ||
|
||
@NotNull | ||
private OperationStatus operationStatus; | ||
|
||
@Builder | ||
public BaseScheduleDto(DayOfWeek dayOfWeek, LocalTime startTime, LocalTime endTime, | ||
OperationStatus operationStatus) { | ||
this.dayOfWeek = dayOfWeek; | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
this.operationStatus = operationStatus; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/foru/freebe/schedule/dto/ScheduleUnitDto.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,19 @@ | ||
package com.foru.freebe.schedule.dto; | ||
|
||
import com.foru.freebe.member.entity.ScheduleUnit; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class ScheduleUnitDto { | ||
|
||
@NotNull | ||
ScheduleUnit scheduleUnit; | ||
|
||
public ScheduleUnitDto(ScheduleUnit scheduleUnit) { | ||
this.scheduleUnit = scheduleUnit; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/com/foru/freebe/schedule/entity/BaseSchedule.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,79 @@ | ||
package com.foru.freebe.schedule.entity; | ||
|
||
|
||
import java.time.LocalTime; | ||
|
||
import com.foru.freebe.common.entity.BaseEntity; | ||
import com.foru.freebe.member.entity.Member; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
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 jakarta.validation.constraints.NotNull; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
public class BaseSchedule extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "base_schedule_id") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "photographer_id") | ||
@NotNull(message = "Photographer must not be null") | ||
private Member photographer; | ||
|
||
@NotNull(message = "DayOfWeek must not be null") | ||
@Enumerated(EnumType.STRING) | ||
private DayOfWeek dayOfWeek; | ||
|
||
@NotNull(message = "Start time must not be null") | ||
private LocalTime startTime; | ||
|
||
@NotNull(message = "End time must not be null") | ||
private LocalTime endTime; | ||
|
||
@NotNull(message = "Operation status must not be null") | ||
@Enumerated(EnumType.STRING) | ||
private OperationStatus operationStatus; | ||
|
||
public void updateScheduleTime(LocalTime startTime, LocalTime endTime, OperationStatus operationStatus) { | ||
if (operationStatus == OperationStatus.INACTIVE) { | ||
this.startTime = LocalTime.of(9,0,0); | ||
this.endTime = LocalTime.of(18,0,0); | ||
} else { | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
} | ||
this.operationStatus = operationStatus; | ||
} | ||
|
||
public void initializeSchedule() { | ||
this.startTime = LocalTime.of(9,0,0); | ||
this.endTime = LocalTime.of(18,0,0); | ||
this.operationStatus = OperationStatus.ACTIVE; | ||
} | ||
|
||
@Builder | ||
public BaseSchedule(Member photographer, DayOfWeek dayOfWeek, LocalTime startTime, LocalTime endTime, | ||
OperationStatus operationStatus) { | ||
this.photographer = photographer; | ||
this.dayOfWeek = dayOfWeek; | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
this.operationStatus = operationStatus; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/foru/freebe/schedule/entity/DayOfWeek.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.foru.freebe.schedule.entity; | ||
|
||
public enum DayOfWeek { | ||
|
||
MONDAY, | ||
TUESDAY, | ||
WEDNESDAY, | ||
THURSDAY, | ||
FRIDAY, | ||
SATURDAY, | ||
SUNDAY; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/foru/freebe/schedule/entity/OperationStatus.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 com.foru.freebe.schedule.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public enum OperationStatus { | ||
|
||
@JsonProperty("ACTIVE") | ||
ACTIVE, | ||
@JsonProperty("INACTIVE") | ||
INACTIVE | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/foru/freebe/schedule/repository/BaseScheduleRepository.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 com.foru.freebe.schedule.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.foru.freebe.schedule.entity.BaseSchedule; | ||
import com.foru.freebe.schedule.entity.DayOfWeek; | ||
|
||
public interface BaseScheduleRepository extends JpaRepository<BaseSchedule, Long> { | ||
List<BaseSchedule> findByPhotographerId(Long photographerId); | ||
|
||
BaseSchedule findByDayOfWeekAndPhotographerId(DayOfWeek dayOfWeek, Long photographerId); | ||
} |
Oops, something went wrong.