-
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 pull request #6 from f-lab-edu/review/3-ticket-api-serialization
feat: ShowtimeResponse 객체와 직렬화 Config 추가
- Loading branch information
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/main/java/com/safeticket/common/config/JacksonConfig.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.safeticket.common.config; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class JacksonConfig { | ||
@Bean | ||
public ObjectMapper objectMapper() { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
objectMapper.registerModule(new Hibernate5Module()); | ||
objectMapper.registerModule(new JavaTimeModule()); | ||
return objectMapper; | ||
} | ||
} |
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 com.safeticket.event; | ||
|
||
import com.safeticket.event.dto.EventResponse; | ||
import com.safeticket.event.entity.Event; | ||
import com.safeticket.event.service.EventService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/events") | ||
public class EventController { | ||
|
||
private final EventService eventService; | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<EventResponse> getEventById(@PathVariable Long id) { | ||
return ResponseEntity.ok(EventResponse.of(eventService.getEventById(id))); | ||
} | ||
|
||
@GetMapping("/{id}/showtimes") | ||
public ResponseEntity<EventResponse> getEventByIdWithShowtimes(@PathVariable Long id) { | ||
return ResponseEntity.ok(EventResponse.of(eventService.getEventByIdWithShowtimes(id))); | ||
} | ||
|
||
@GetMapping | ||
public List<Event> getAllEvents() { | ||
return eventService.getAllEvents(); | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
src/main/java/com/safeticket/showtime/dto/ShowtimeResponse.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,55 @@ | ||
package com.safeticket.showtime.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.safeticket.event.entity.Event; | ||
import com.safeticket.showtime.entity.Showtime; | ||
import com.safeticket.venue.entity.Venue; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class ShowtimeResponse { | ||
private Long id; | ||
private LocalDateTime startTime; | ||
private LocalDateTime endTime; | ||
private Event event; | ||
private Venue venue; | ||
|
||
private LocalDateTime createdAt; | ||
private LocalDateTime updatedAt; | ||
|
||
public static ShowtimeResponse of(Showtime showtime) { | ||
if (showtime == null) { | ||
return null; | ||
} | ||
return ShowtimeResponse.builder() | ||
.id(showtime.getId()) | ||
.startTime(showtime.getStartTime()) | ||
.endTime(showtime.getEndTime()) | ||
.event(showtime.getEvent()) | ||
.venue(showtime.getVenue()) | ||
.createdAt(showtime.getCreatedAt()) | ||
.updatedAt(showtime.getUpdatedAt()) | ||
.build(); | ||
} | ||
|
||
public static List<ShowtimeResponse> ofList(List<Showtime> showtimes) { | ||
return (showtimes == null) ? Collections.emptyList() | ||
: showtimes.stream().map(ShowtimeResponse::of).collect(Collectors.toList()); | ||
} | ||
|
||
|
||
} |