-
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 DO-SOPT-APP3-Airbnb/feature/2
[FEAT] 지역 이미지 조회 기능 구현
- Loading branch information
Showing
9 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/com/app3/server/region/controller/RegionController.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,30 @@ | ||
package com.app3.server.region.controller; | ||
|
||
import com.app3.server.common.dto.ApiResponse; | ||
import com.app3.server.common.exception.enums.SuccessType; | ||
import com.app3.server.region.controller.dto.response.RegionGetResponse; | ||
import com.app3.server.region.domain.Region; | ||
import com.app3.server.region.service.RegionService; | ||
|
||
import jakarta.persistence.EntityNotFoundException; | ||
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 | ||
@RequestMapping("/api/region") | ||
@RequiredArgsConstructor | ||
|
||
public class RegionController { | ||
|
||
private final RegionService regionService; | ||
@GetMapping | ||
public ApiResponse<List<RegionGetResponse>> getMembersProfile() { | ||
return ApiResponse.success(SuccessType.REGION_SEARCH_SUCCESS, regionService.getRegions()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/app3/server/region/controller/dto/response/RegionGetResponse.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,15 @@ | ||
package com.app3.server.region.controller.dto.response; | ||
|
||
import com.app3.server.region.domain.Region; | ||
|
||
public record RegionGetResponse ( | ||
String regionName, | ||
String imageUrl | ||
) { | ||
public static RegionGetResponse of(Region region) { | ||
return new RegionGetResponse( | ||
region.getRegionName(), | ||
region.getImageUrl() | ||
); | ||
} | ||
} |
Empty file.
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,31 @@ | ||
package com.app3.server.region.domain; | ||
|
||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Region { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
private String regionName; | ||
private String imageUrl; | ||
|
||
|
||
@Builder | ||
public Region(String regionName,String imageUrl) { | ||
this.regionName = regionName; | ||
this.imageUrl = imageUrl; | ||
} | ||
} |
Empty file.
10 changes: 10 additions & 0 deletions
10
src/main/java/com/app3/server/region/repository/RegionJpaRepository.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,10 @@ | ||
package com.app3.server.region.repository; | ||
|
||
import com.app3.server.region.domain.Region; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface RegionJpaRepository extends JpaRepository<Region, Long>{ | ||
} |
Empty file.
24 changes: 24 additions & 0 deletions
24
src/main/java/com/app3/server/region/service/RegionService.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,24 @@ | ||
package com.app3.server.region.service; | ||
|
||
import com.app3.server.region.controller.dto.response.RegionGetResponse; | ||
import com.app3.server.region.repository.RegionJpaRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Transactional | ||
@Service | ||
@RequiredArgsConstructor | ||
public class RegionService { | ||
private final RegionJpaRepository regionJpaRepository; | ||
|
||
public List<RegionGetResponse> getRegions() { | ||
return regionJpaRepository.findAll() | ||
.stream() | ||
.map(RegionGetResponse::of) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
Empty file.