-
Notifications
You must be signed in to change notification settings - Fork 3
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 #53 from dsc-sookmyung/feature/calendar-api
[#31] fix: add index properties in event entity
- Loading branch information
Showing
16 changed files
with
171 additions
and
65 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
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
39 changes: 22 additions & 17 deletions
39
spring/notinote/src/main/java/com/answer/notinote/Event/controller/EventController.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,45 +1,50 @@ | ||
package com.answer.notinote.Event.controller; | ||
|
||
import com.answer.notinote.Child.domain.Child; | ||
import com.answer.notinote.Child.service.ChildService; | ||
import com.answer.notinote.Event.domain.Event; | ||
import com.answer.notinote.Event.dto.EventRegisterDto; | ||
import com.answer.notinote.Event.dto.EventRequestDto; | ||
import com.answer.notinote.Event.dto.EventResponseDto; | ||
import com.answer.notinote.Event.service.EventService; | ||
import com.answer.notinote.Event.service.GoogleCalendarService; | ||
import io.swagger.models.Response; | ||
import com.answer.notinote.Notice.domain.entity.Notice; | ||
import com.answer.notinote.Notice.service.NoticeService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.io.IOException; | ||
import java.security.GeneralSecurityException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class EventController { | ||
|
||
private final EventService eventService; | ||
private final ChildService childService; | ||
private final GoogleCalendarService calendarService; | ||
private final NoticeService noticeService; | ||
|
||
@PostMapping("/event") | ||
public ResponseEntity<?> createEvent(@RequestParam(value = "id") Long id, @RequestBody EventRequestDto requestDto) { | ||
Child child = childService.findById(id); | ||
Notice notice = noticeService.findNoticeById(id); | ||
|
||
Event event = eventService.create(requestDto, child); | ||
Event event = eventService.create(requestDto, notice); | ||
|
||
return ResponseEntity.ok(new EventResponseDto(event)); | ||
} | ||
|
||
@PostMapping("/event/calendar") | ||
public ResponseEntity<?> createEventInCalendar(@RequestParam(value = "id") Long id) throws GeneralSecurityException, IOException { | ||
Event event = eventService.findEventById(id); | ||
calendarService.createEvent(event); | ||
@GetMapping("/event") | ||
public ResponseEntity<?> getEventList() { | ||
List<Event> eventList = eventService.findAll(); | ||
List<EventResponseDto> response = new ArrayList<>(); | ||
for (Event event : eventList) | ||
response.add(new EventResponseDto(event)); | ||
|
||
return ResponseEntity.ok(new EventResponseDto(event)); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@PutMapping("/event/register") | ||
public ResponseEntity<?> registerEvent(@RequestParam(value = "id") Long id, @RequestBody EventRegisterDto registerDto) throws GeneralSecurityException, IOException { | ||
return ResponseEntity.ok(eventService.registerEvent(id, registerDto)); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
spring/notinote/src/main/java/com/answer/notinote/Event/dto/EventRegisterDto.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,17 @@ | ||
package com.answer.notinote.Event.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Getter @Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class EventRegisterDto { | ||
Long cid; | ||
String title; | ||
LocalDate date; | ||
} |
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
13 changes: 13 additions & 0 deletions
13
spring/notinote/src/main/java/com/answer/notinote/Event/dto/urlResponseDto.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,13 @@ | ||
package com.answer.notinote.Event.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter @Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class urlResponseDto { | ||
String url; | ||
} |
36 changes: 30 additions & 6 deletions
36
spring/notinote/src/main/java/com/answer/notinote/Event/service/EventService.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,35 +1,59 @@ | ||
package com.answer.notinote.Event.service; | ||
|
||
import com.answer.notinote.Child.domain.Child; | ||
import com.answer.notinote.Child.service.ChildService; | ||
import com.answer.notinote.Event.domain.Event; | ||
import com.answer.notinote.Event.domain.repository.EventRepository; | ||
import com.answer.notinote.Event.dto.EventRegisterDto; | ||
import com.answer.notinote.Event.dto.EventRequestDto; | ||
import com.answer.notinote.Event.dto.urlResponseDto; | ||
import com.answer.notinote.Exception.CustomException; | ||
import com.answer.notinote.Exception.ErrorCode; | ||
import com.answer.notinote.Notice.domain.entity.Notice; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.io.IOException; | ||
import java.security.GeneralSecurityException; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class EventService { | ||
|
||
private final EventRepository eventRepository; | ||
private final ChildService childService; | ||
private final GoogleCalendarService calendarService; | ||
|
||
public Event create(EventRequestDto eventDto, Child child) { | ||
Event event = new Event(eventDto); | ||
event.setChild(child); | ||
public Event create(EventRequestDto requestDto, Notice notice) { | ||
Event event = new Event(requestDto); | ||
event.setNotice(notice); | ||
eventRepository.save(event); | ||
|
||
return eventRepository.save(event); | ||
return event; | ||
} | ||
|
||
public void registerEvent(Long id) { | ||
@Transactional | ||
public urlResponseDto registerEvent(Long id, EventRegisterDto requestDto) throws GeneralSecurityException, IOException { | ||
Event event = findEventById(id); | ||
event.register(); | ||
Child child = childService.findChildById(requestDto.getCid()); | ||
|
||
event.register(requestDto); | ||
event.setChild(child); | ||
eventRepository.save(event); | ||
|
||
String url = calendarService.createEvent(event); | ||
return new urlResponseDto(url); | ||
} | ||
|
||
public Event findEventById(Long id) { | ||
return eventRepository.findById(id).orElseThrow( | ||
() -> new CustomException(ErrorCode.NOT_FOUND) | ||
); | ||
} | ||
|
||
public List<Event> findAll() { | ||
return eventRepository.findAll(); | ||
} | ||
} |
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
Oops, something went wrong.