-
Notifications
You must be signed in to change notification settings - Fork 82
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 #1 from nak253/feature-GET-heroImage
Feat: 메인 히어로 이미지 기능 구현
- Loading branch information
Showing
7 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/main/java/kr/codesquad/airbnb/controller/MainController.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,22 @@ | ||
package kr.codesquad.airbnb.controller; | ||
|
||
import kr.codesquad.airbnb.dto.EventResponseDto; | ||
import kr.codesquad.airbnb.service.MainService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class MainController { | ||
|
||
private final MainService mainService; | ||
|
||
@GetMapping("/main/event") | ||
public EventResponseDto getEvent() { | ||
EventResponseDto event = mainService.getEvent(); | ||
System.out.println("event = " + event); | ||
return event; | ||
} | ||
|
||
} |
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,23 @@ | ||
package kr.codesquad.airbnb.domain; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import lombok.Getter; | ||
|
||
@Entity | ||
@Getter | ||
public class Event { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String title; | ||
private String description; | ||
private String buttonName; | ||
private String imageUrl; | ||
private boolean mainEvent; | ||
|
||
} |
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
33 changes: 33 additions & 0 deletions
33
src/main/java/kr/codesquad/airbnb/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,33 @@ | ||
package kr.codesquad.airbnb.dto; | ||
|
||
import kr.codesquad.airbnb.domain.Event; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class EventResponseDto { | ||
|
||
private Long id; | ||
private String title; | ||
private String description; | ||
private String buttonName; | ||
private String imageUrl; | ||
|
||
public EventResponseDto(Event event) { | ||
this.id = event.getId(); | ||
this.title = event.getTitle(); | ||
this.description = event.getDescription(); | ||
this.buttonName = event.getButtonName(); | ||
this.imageUrl = event.getImageUrl(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "EventResponseDto{" + | ||
"id=" + id + | ||
", title='" + title + '\'' + | ||
", description='" + description + '\'' + | ||
", buttonName='" + buttonName + '\'' + | ||
", imageUrl='" + imageUrl + '\'' + | ||
'}'; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/kr/codesquad/airbnb/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,11 @@ | ||
package kr.codesquad.airbnb.repository; | ||
|
||
import java.util.Optional; | ||
import kr.codesquad.airbnb.domain.Event; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface EventRepository extends JpaRepository<Event, Long> { | ||
|
||
Event findByMainEventIsTrue(); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/kr/codesquad/airbnb/service/MainService.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,23 @@ | ||
package kr.codesquad.airbnb.service; | ||
|
||
import kr.codesquad.airbnb.dto.EventResponseDto; | ||
import kr.codesquad.airbnb.repository.EventRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class MainService { | ||
|
||
private final EventRepository eventRepository; | ||
|
||
public EventResponseDto getEvent() { | ||
EventResponseDto eventResponseDto = new EventResponseDto( | ||
eventRepository.findByMainEventIsTrue()); | ||
System.out.println("eventResponseDto = " + eventResponseDto); | ||
|
||
return eventResponseDto; | ||
} | ||
} |
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,2 @@ | ||
INSERT INTO event (id,title,description,button_name,image_url,main_event) | ||
VALUE (1,'슬기로운 자연생활','에어비엔비가 엄선한 위시리스트를 만나보세요','여행 아이디어 얻기','어쩌구',true); |