-
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 #51 from dsc-sookmyung/feature/calendar-api
[#31] google calendar api & event entity
- Loading branch information
Showing
19 changed files
with
423 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
|
||
import org.springframework.stereotype.Controller; | ||
|
||
|
||
@Controller | ||
public class ChildController { | ||
|
||
|
||
} |
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
19 changes: 19 additions & 0 deletions
19
spring/notinote/src/main/java/com/answer/notinote/Child/dto/ChildrenResponseDto.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.answer.notinote.Child.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
public class ChildrenResponseDto { | ||
int event_num = 0; | ||
List<ChildDto> children = new ArrayList<>(); | ||
|
||
public void addChild(ChildDto childDto) { | ||
children.add(childDto); | ||
event_num += childDto.getEvents().size(); | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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.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 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 java.io.IOException; | ||
import java.security.GeneralSecurityException; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class EventController { | ||
|
||
private final EventService eventService; | ||
private final ChildService childService; | ||
private final GoogleCalendarService calendarService; | ||
|
||
@PostMapping("/event") | ||
public ResponseEntity<?> createEvent(@RequestParam(value = "id") Long id, @RequestBody EventRequestDto requestDto) { | ||
Child child = childService.findById(id); | ||
|
||
Event event = eventService.create(requestDto, child); | ||
|
||
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); | ||
|
||
return ResponseEntity.ok(new EventResponseDto(event)); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
spring/notinote/src/main/java/com/answer/notinote/Event/domain/Event.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,58 @@ | ||
package com.answer.notinote.Event.domain; | ||
|
||
import com.answer.notinote.Child.domain.Child; | ||
import com.answer.notinote.Event.dto.EventRequestDto; | ||
import com.answer.notinote.Event.util.BooleanToYNConverter; | ||
import com.answer.notinote.User.domain.entity.Timestamped; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDate; | ||
|
||
@Entity | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Event extends Timestamped { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column | ||
private Long eid; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "cid") | ||
private Child child; | ||
|
||
@Column(length = 1000) | ||
private String content; | ||
|
||
@Column | ||
private LocalDate date; | ||
|
||
@Convert(converter = BooleanToYNConverter.class) | ||
@Column(length = 1) | ||
private boolean registered; | ||
|
||
@Convert(converter = BooleanToYNConverter.class) | ||
@Column(length = 1) | ||
private boolean highlight; | ||
|
||
public Event(EventRequestDto eventDto) { | ||
this.content = eventDto.getContent(); | ||
this.date = eventDto.getDate(); | ||
this.registered = eventDto.getRegistered(); | ||
this.highlight = eventDto.getHighlight(); | ||
} | ||
|
||
public void setChild(Child child) { | ||
this.child = child; | ||
child.setEvents(this); | ||
} | ||
|
||
public void register() { | ||
this.registered = true; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...g/notinote/src/main/java/com/answer/notinote/Event/domain/repository/EventRepository.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,9 @@ | ||
package com.answer.notinote.Event.domain.repository; | ||
|
||
import com.answer.notinote.Event.domain.Event; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface EventRepository extends JpaRepository<Event, Long> { | ||
} |
18 changes: 18 additions & 0 deletions
18
spring/notinote/src/main/java/com/answer/notinote/Event/dto/EventRequestDto.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 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 EventRequestDto { | ||
private String content; | ||
private LocalDate date; | ||
private Boolean highlight; | ||
private Boolean registered; | ||
} |
21 changes: 21 additions & 0 deletions
21
spring/notinote/src/main/java/com/answer/notinote/Event/dto/EventResponseDto.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,21 @@ | ||
package com.answer.notinote.Event.dto; | ||
|
||
import com.answer.notinote.Event.domain.Event; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Getter | ||
@Setter | ||
public class EventResponseDto { | ||
private Long eid; | ||
private String content; | ||
private LocalDate date; | ||
|
||
public EventResponseDto(Event event) { | ||
this.eid = event.getEid(); | ||
this.content = event.getContent(); | ||
this.date = event.getDate(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.answer.notinote.Event.service; | ||
|
||
import com.answer.notinote.Child.domain.Child; | ||
import com.answer.notinote.Event.domain.Event; | ||
import com.answer.notinote.Event.domain.repository.EventRepository; | ||
import com.answer.notinote.Event.dto.EventRequestDto; | ||
import com.answer.notinote.Exception.CustomException; | ||
import com.answer.notinote.Exception.ErrorCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class EventService { | ||
|
||
private final EventRepository eventRepository; | ||
|
||
public Event create(EventRequestDto eventDto, Child child) { | ||
Event event = new Event(eventDto); | ||
event.setChild(child); | ||
|
||
return eventRepository.save(event); | ||
} | ||
|
||
public void registerEvent(Long id) { | ||
Event event = findEventById(id); | ||
event.register(); | ||
} | ||
|
||
public Event findEventById(Long id) { | ||
return eventRepository.findById(id).orElseThrow( | ||
() -> new CustomException(ErrorCode.NOT_FOUND) | ||
); | ||
} | ||
} |
Oops, something went wrong.