-
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 branch 'main' of https://github.com/beyond-sw-camp/be07-2nd-wan…
- Loading branch information
Showing
15 changed files
with
316 additions
and
42 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
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
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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/example/want/api/location/controller/LocationController.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,39 @@ | ||
package com.example.want.api.location.controller; | ||
|
||
import com.example.want.api.location.domain.Location; | ||
import com.example.want.api.location.dto.LocationResDto; | ||
import com.example.want.api.location.repository.LocationRepository; | ||
import com.example.want.api.location.service.LocationService; | ||
import com.example.want.common.CommonResDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
public class LocationController { | ||
|
||
private final LocationService locationService; | ||
private final LocationRepository locationRepository; | ||
|
||
// 추천 블럭 리스트에 사용할 코드 | ||
@GetMapping("/city/{stateId}") | ||
public ResponseEntity<CommonResDto> getPopularLocations(@PathVariable Long stateId) { | ||
List<LocationResDto> popularLocations = locationService.getPopularLocations(stateId); | ||
CommonResDto commonResDto = new CommonResDto(HttpStatus.OK, "조회 완료", popularLocations); | ||
return new ResponseEntity<>(commonResDto, HttpStatus.OK); | ||
} | ||
|
||
@GetMapping("/pop") | ||
public ResponseEntity<CommonResDto> getPopularCountFromCache() { | ||
locationService.getPopularCountFromCache(); | ||
List<Location> popularLocations = locationRepository.findAll(); | ||
CommonResDto commonResDto = new CommonResDto(HttpStatus.OK, "조회 완료", popularLocations); | ||
return new ResponseEntity<>(commonResDto, HttpStatus.OK); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/example/want/api/location/domain/Location.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,46 @@ | ||
package com.example.want.api.location.domain; | ||
|
||
import com.example.want.api.location.dto.LocationResDto; | ||
import com.example.want.api.state.domain.State; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import javax.persistence.*; | ||
import javax.validation.constraints.NotNull; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class Location { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private Double latitude; | ||
private Double longitude; | ||
|
||
private Long popularCount; | ||
private String placeName; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@NotNull | ||
@JoinColumn(name = "state_id") | ||
private State state; | ||
|
||
public void updatePopularCount(Long popularCount) { | ||
this.popularCount += popularCount; | ||
} | ||
|
||
public LocationResDto fromEntity(Location location) { | ||
LocationResDto dto = LocationResDto.builder() | ||
.latitude(location.getLatitude()) | ||
.longitude(location.getLongitude()) | ||
.popularCount(location.getPopularCount()) | ||
.placeName(location.getPlaceName()) | ||
.build(); | ||
return dto; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/example/want/api/location/dto/LocationReqDto.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,29 @@ | ||
package com.example.want.api.location.dto; | ||
|
||
|
||
import com.example.want.api.location.domain.Location; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class LocationReqDto { | ||
private Double latitude; | ||
private Double longitude; | ||
|
||
public static LocationReqDto toEntity(Location location) { | ||
LocationReqDto dto = LocationReqDto.builder() | ||
.latitude(location.getLatitude()) | ||
.longitude(location.getLongitude()) | ||
.build(); | ||
return dto; | ||
} | ||
|
||
|
||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/example/want/api/location/dto/LocationResDto.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,17 @@ | ||
package com.example.want.api.location.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class LocationResDto { | ||
private Double latitude; | ||
private Double longitude; | ||
private Long popularCount; | ||
private String placeName; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/example/want/api/location/repository/LocationRepository.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,14 @@ | ||
package com.example.want.api.location.repository; | ||
|
||
import com.example.want.api.location.domain.Location; | ||
import com.example.want.api.location.dto.LocationResDto; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface LocationRepository extends JpaRepository<Location, Long> { | ||
Location findByLatitudeAndLongitude(Double latitude, Double longitude); | ||
List<Location> findAllByStateIdOrderByPopularCountDesc(Long stateId); | ||
} |
Oops, something went wrong.