Skip to content

Commit

Permalink
Merge pull request #25 from hanium-haemil/feature/new_schedule
Browse files Browse the repository at this point in the history
[REFACTOR] schedule api
  • Loading branch information
devyubin authored Sep 14, 2023
2 parents 4c076d3 + e1e6515 commit 24705cf
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public enum ResponseStatus {
INVALID_TOKEN(false, 473, "Authorization header에 잘못된 토큰을 입력하였습니다."),
INVALID_AUTH(false, 474, "잘못된 Authorization 입니다."),

=======
MISSING_REQUIRED_FIELD(400, HttpStatus.Series.CLIENT_ERROR, "Required field(s) are missing"),
>>>>>>> 3911116 ([FEAT] add schedule api)
// --- 5xx Server Error ---
INTERNAL_SERVER_ERROR(500,HttpStatus.Series.SERVER_ERROR, "Internal Server Error"),
BAD_GATEWAY(502,HttpStatus.Series.SERVER_ERROR, "Bad Gateway"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.haemil.backend.map.service.MapService;
import com.haemil.backend.schedule.dto.ScheduleRequestDto;
import com.haemil.backend.schedule.dto.ScheduleResponseDto;
>>>>>>> 3911116 ([FEAT] add schedule api)
import com.haemil.backend.schedule.entity.Schedule;
import com.haemil.backend.schedule.service.ScheduleService;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -32,20 +31,6 @@ public ScheduleController(ScheduleService scheduleService, MapService mapService
this.mapService = mapService;
}

<<<<<<< HEAD
//클라이언트의 요청을 처리하는 컨트롤러 메서드
@PostMapping //@PostMapping 애너테이션을 통해 HTTP POST 요청을 수신
public Schedule saveSchedule(@RequestBody Schedule schedule){
//@RequestBody 애너테이션을 사용하여 요청 본문에 있는 데이터를 Schedule 객체로 변환함
return scheduleService.saveSchedule(schedule);
//scheduleService.saveSchedule(schedule)을 호출하여 일정을 저장하고,
//업데이트된 schedule 객체를 반환
}




=======
//일정 추가 API
@PostMapping("/schedule")
public ResponseEntity<BaseResponse> createSchedule(@RequestBody ScheduleRequestDto scheduleRequestDto) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.haemil.backend.schedule.dto;

import com.haemil.backend.schedule.entity.RepeatType;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalTime;

//schedule에 데이터를 넣을 때의 입력 요청 값을 받음
@NoArgsConstructor
@Getter
public class ScheduleRequestDto {

private Long id;

private LocalDate localDate;

private DayOfWeek dayOfWeek;

private LocalTime time;

private String content;

private Boolean done;

private String place;

private String medicine;

private RepeatType repeatType;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.haemil.backend.schedule.dto;

import com.haemil.backend.schedule.entity.RepeatType;
import com.haemil.backend.schedule.entity.Schedule;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalTime;

//schedule에서 값을 가져올 때 직접적인 entity 대신 앞에 써줌
//클라이언트에게 응답할 때 필요한 속성들 추가
@NoArgsConstructor
@Getter
@Setter
public class ScheduleResponseDto {

private String mapUrl;

private Long id;

private LocalDate localDate;

private DayOfWeek dayOfWeek;

private LocalTime time;

private String content;

private String place;

private Boolean done;

private String medicine;

private RepeatType repeatType;


public ScheduleResponseDto(Schedule schedule){
this.mapUrl = schedule.getMapUrl();

this.id = schedule.getId();

this.localDate = schedule.getLocalDate();

this.dayOfWeek = schedule.getDayOfWeek();

this.time = schedule.getTime();

this.content = schedule.getContent();

this.place = schedule.getPlace();

this.done = schedule.getDone();

this.medicine = schedule.getMedicine();

this.repeatType = schedule.getRepeatType();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.haemil.backend.schedule.entity;


public enum RepeatType {
DAILY,
WEEKLY,
MONTHLY,
NONE
}
31 changes: 11 additions & 20 deletions src/main/java/com/haemil/backend/schedule/entity/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,11 @@
@Getter
@NoArgsConstructor
public class Schedule {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

//일정 생성(year, month, day)
@Column(name = "creationDate", nullable = false)
private LocalDate creationDate;

//일정 수정(year, month, day)
@Column(name = "modificationDate", nullable = false)
private LocalDate modificationDate;

//일정의 실제 날짜 정보(year, month, day)
@Column(nullable = false)
private LocalDate localDate;
Expand All @@ -43,24 +36,22 @@ public class Schedule {
@Column(nullable = false, length = 100)
private String content;

//일정 완료 여부
@Column(nullable = false)
private Boolean done;

//장소
@Column(nullable = true, length = 50)
private String place;

//중요 일정
@Column(nullable = false)
private Boolean important_schedule;
//
@Column(nullable = true, length = 50)
private String medicine;

//고정 일정
//반복 routine
@Enumerated(value = EnumType.STRING)
@Column(nullable = false)
private Boolean fixed_schedule;

public Boolean isImportant(){
return important_schedule;
}
public Boolean isFixed(){
return fixed_schedule;
}
private RepeatType repeatType;

private String mapUrl;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.haemil.backend.schedule.repository;

import com.haemil.backend.schedule.entity.Schedule;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Example;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand All @@ -13,10 +14,11 @@
import java.util.List;
import java.util.Optional;

@Primary
//JpaRepository를 상속받아서 데이터베이스와 상호작용하는 메서드들 제공
public interface ScheduleRepository extends JpaRepository<Schedule,Long> {

//주어진 년, 월, 일에 해당하는 일정을 조회하는 메서드
//일정을 조회
List<Schedule> findByLocalDate(LocalDate localDate);


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.haemil.backend.schedule.service;

<<<<<<< HEAD
=======
import com.haemil.backend.global.exception.BaseException;
import com.haemil.backend.global.exception.MissingRequiredFieldException;
import com.haemil.backend.schedule.dto.ScheduleRequestDto;
import com.haemil.backend.schedule.dto.ScheduleResponseDto;
import com.haemil.backend.schedule.entity.RepeatType;
>>>>>>> 3911116 ([FEAT] add schedule api)
import com.haemil.backend.schedule.entity.Schedule;
import com.haemil.backend.schedule.repository.ScheduleRepository;
//import com.haemil.backend.schedule.repository.SpringDataJpaScheduleRepository;
Expand All @@ -31,31 +28,14 @@

//Schedule 객체를 저장하고 조회하는 기능을 구현
//ScheduleRepository를 사용하여 데이터베이스와 상호작용
<<<<<<< HEAD

=======
@Slf4j
@Transactional
>>>>>>> 3911116 ([FEAT] add schedule api)
public class ScheduleService {
private final ScheduleRepository scheduleRepository;

public ScheduleService(ScheduleRepository scheduleRepository){
public ScheduleService(ScheduleRepository scheduleRepository) {
this.scheduleRepository = scheduleRepository;
}
//일정 생성
<<<<<<< HEAD
public Schedule createSchedule(LocalDate createdDate, DayOfWeek dayOfWeek,
String content, boolean important_schedule,
boolean fixed_schedule, LocalTime time, String place) {
Schedule schedule = new Schedule();
schedule.setCreationDate(createdDate);
schedule.setDayOfWeek(dayOfWeek);
schedule.setContent(content);
schedule.setImportant_schedule(important_schedule);
schedule.setFixed_schedule(fixed_schedule);
schedule.setTime(time);
schedule.setPlace(place);

//일정 생성
public ScheduleResponseDto createSchedule(ScheduleRequestDto scheduleRequestDto) throws BaseException {
Expand Down Expand Up @@ -143,7 +123,6 @@ public List<Schedule> getTodaySchedules() throws BaseException {
}
}

>>>>>>> 3911116 ([FEAT] add schedule api)
//일정 삭제
@Transactional
public Long deleteSchedule(Long scheduleId) throws BaseException {
Expand All @@ -161,13 +140,6 @@ public Long deleteSchedule(Long scheduleId) throws BaseException {
}
}

//오늘에 해당하는 일정 조회
public List<Schedule> getTodaySchedules(){
LocalDate today = LocalDate.now();
DayOfWeek dayOfWeek = today.getDayOfWeek();
return scheduleRepository.findByLocalDate(today);
}

//일정 수정
@Transactional
public Schedule updateSchedule(Long id, ScheduleRequestDto requestDto) {
Expand Down

0 comments on commit 24705cf

Please sign in to comment.