Skip to content

Commit

Permalink
feat: 에디터 추천 내 카테고리 추가 API 구현 (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaeeerish authored Sep 27, 2024
1 parent 51ddbc7 commit db8b0f5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/main/java/Skeep/backend/global/constant/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public class Constants {
"/api/auth/apple/login",
"/api/auth/jwt/reissue",
"/api/auth/apple/revoke",
"/api/ping/login",
"/api/ping/login/test",
"/api/ping",
"/api/picks",
"/swagger-ui/index.html",
"/swagger-ui/swagger-ui-standalone-preset.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import Skeep.backend.global.dto.JwtDto;
import Skeep.backend.global.exception.BaseException;
import Skeep.backend.global.exception.GlobalErrorCode;
import Skeep.backend.location.location.domain.LocationRepository;
import Skeep.backend.location.location.service.LocationRetriever;
import Skeep.backend.user.domain.User;
import Skeep.backend.user.service.UserFindService;
import Skeep.backend.weather.domain.locationGrid.LocationGrid;
Expand All @@ -28,6 +30,7 @@ public class PingController {
private final AppleService appleService;
private final LocationGridRepository locationGridRepository;
private final WeatherSchedulerService weatherSchedulerService;
private final LocationRepository locationRepository;

@PostMapping("/login")
public ResponseEntity<JwtDto> login(@RequestBody @Valid String serialId) {
Expand Down Expand Up @@ -55,4 +58,9 @@ public ResponseEntity<?> getWeather() {
weatherSchedulerService.updateWeather();
return ResponseEntity.ok().build();
}

@GetMapping("/location-list")
public ResponseEntity<?> getLocationList() {
return ResponseEntity.ok(locationRepository.findAll());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Skeep.backend.location.picks.controller;

import Skeep.backend.global.annotation.UserId;
import Skeep.backend.location.picks.dto.request.PicksRequest;
import Skeep.backend.location.picks.dto.response.PicksDtoList;
import Skeep.backend.location.picks.service.PicksService;
Expand All @@ -8,6 +9,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.net.URI;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/picks")
Expand All @@ -30,4 +33,13 @@ public ResponseEntity<Void> deleteAll() {
picksService.deleteAll();
return ResponseEntity.ok().build();
}

@PostMapping("/user-category")
public ResponseEntity<Void> addUserCategory(
@UserId Long userId,
@RequestParam("userCategoryId") Long userCategoryId,
@RequestParam("title") String title) {
Long userLocationId = picksService.addUserCategory(userId, userCategoryId, title);
return ResponseEntity.created(URI.create("/api/user-location/" + userLocationId)).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface PicksRepository extends JpaRepository<Picks, Long> {
Optional<Picks> findByPlaceName(String placeName);
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package Skeep.backend.location.picks.service;

import Skeep.backend.category.domain.ECategory;
import Skeep.backend.category.domain.UserCategory;
import Skeep.backend.category.service.UserCategoryRetriever;
import Skeep.backend.global.exception.BaseException;
import Skeep.backend.kakaoMap.dto.response.KakaoResponseResult;
import Skeep.backend.kakaoMap.service.KakaoMapService;
import Skeep.backend.location.location.domain.Location;
import Skeep.backend.location.location.service.LocationRetriever;
import Skeep.backend.location.picks.domain.Picks;
import Skeep.backend.location.picks.domain.PicksRepository;
import Skeep.backend.location.picks.dto.request.PicksRequest;
import Skeep.backend.location.picks.dto.response.PicksDto;
import Skeep.backend.location.picks.dto.response.PicksDtoList;
import Skeep.backend.location.tour.exception.TourErrorCode;
import Skeep.backend.location.userLocation.domain.UserLocation;
import Skeep.backend.location.userLocation.service.UserLocationSaver;
import Skeep.backend.s3.service.S3Service;
import Skeep.backend.user.domain.User;
import Skeep.backend.user.service.UserFindService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@Transactional(readOnly = true)
Expand All @@ -24,6 +33,10 @@ public class PicksService {
private final PicksRepository picksRepository;
private final KakaoMapService kakaoMapService;
private final S3Service s3Service;
private final LocationRetriever locationRetriever;
private final UserFindService userFindService;
private final UserCategoryRetriever userCategoryRetriever;
private final UserLocationSaver userLocationSaver;

@Transactional
public void save(PicksRequest request) {
Expand Down Expand Up @@ -65,4 +78,14 @@ public PicksDtoList findAll() {
public void deleteAll() {
picksRepository.deleteAll();;
}

@Transactional
public Long addUserCategory(Long userId, Long userCategoryId, String title) {
Picks picks = picksRepository.findByPlaceName(title).get();
Location location = locationRetriever.findByKakaoMapId(picks.getKakaoMapId());
User user = userFindService.findById(userId);
UserCategory userCategory = userCategoryRetriever.findById(userCategoryId);

return userLocationSaver.createUserLocation(UserLocation.createUserLocation(picks.getFileName(), location, user, userCategory)).getId();
}
}

0 comments on commit db8b0f5

Please sign in to comment.