Skip to content

Commit

Permalink
Merge pull request #6 from DO-SOPT-APP3-Airbnb/feature/2
Browse files Browse the repository at this point in the history
[FEAT] 지역 이미지 조회 기능 구현
  • Loading branch information
csb9427 authored Nov 24, 2023
2 parents 3efab3c + 898854e commit 49cc8bb
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 0 deletions.
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());
}
}
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.
31 changes: 31 additions & 0 deletions src/main/java/com/app3/server/region/domain/Region.java
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.
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 src/main/java/com/app3/server/region/service/RegionService.java
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.

0 comments on commit 49cc8bb

Please sign in to comment.