forked from codesquad-members-2024/be-airdnb
-
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.
- Loading branch information
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
BE/airdnb/src/main/java/com/team01/airdnb/accommadation/AccommodationController.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,51 @@ | ||
package com.team01.airdnb.accommadation; | ||
|
||
|
||
import com.team01.airdnb.accommadation.dto.AccommodationRegisterRequest; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
public class AccommodationController { | ||
@Autowired | ||
private AccommodationService accommodationService; | ||
// @GetMapping("/accommodations") | ||
// public ResponseEntity<Accommodation> | ||
|
||
//숙소 생성 | ||
@PostMapping("/accommodations") | ||
public void registerAccommodation(@RequestBody AccommodationRegisterRequest accommodationRegisterRequest){ | ||
accommodationService.register(accommodationRegisterRequest); | ||
} | ||
|
||
//숙소 검색 | ||
@PostMapping("/accommodations/search") | ||
public void searchAccommodations() { | ||
|
||
} | ||
|
||
//숙소 상세보기 | ||
@GetMapping("/accommodations/{id}") | ||
public void showAccommodation(@PathVariable Long id) { | ||
} | ||
|
||
//숙소 수정 | ||
@PutMapping("/accommodations/{id}") | ||
public void updateAccommodation(@PathVariable Long id) { | ||
|
||
} | ||
|
||
//숙소 삭제 | ||
@DeleteMapping("accommodations/{id}") | ||
public void deleteAccommodation(@PathVariable Long id) { | ||
|
||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
BE/airdnb/src/main/java/com/team01/airdnb/accommadation/AccommodationService.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,60 @@ | ||
package com.team01.airdnb.accommadation; | ||
|
||
import com.team01.airdnb.accommadation.dto.AccommodationRegisterRequest; | ||
import com.team01.airdnb.amenity.Amenity; | ||
import com.team01.airdnb.image.Image; | ||
import com.team01.airdnb.user.User; | ||
import com.team01.airdnb.user.UserService; | ||
import java.util.List; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class AccommodationService { | ||
AccommodationRepository accommodationRepository; | ||
UserService userService; | ||
|
||
public AccommodationService(AccommodationRepository accommodationRepository, UserService userService){ | ||
this.accommodationRepository = accommodationRepository; | ||
this.userService = userService; | ||
} | ||
|
||
|
||
/** | ||
* 숙소를 등록합니다 | ||
*/ | ||
public void register(AccommodationRegisterRequest accommodationRegisterRequest) { | ||
User user = userService.FindUserById(accommodationRegisterRequest.userId()); | ||
|
||
Accommodation accommodation = accommodationRegisterRequest.toAccommodationEntity(); | ||
Amenity amenity = accommodationRegisterRequest.toAmenityEntity(); | ||
List<Image> image = accommodationRegisterRequest.toImageEntity(); | ||
|
||
accommodation.setUser(user); | ||
accommodation.setAmenityMapping(amenity); | ||
accommodation.setImageMapping(image); | ||
|
||
accommodationRepository.save(accommodation); | ||
} | ||
|
||
/** | ||
* 숙소의 상세 내용을 확인합니다. | ||
*/ | ||
|
||
/** | ||
* 숙소를 수정합니다. | ||
*/ | ||
public void updateAccommodation() { | ||
} | ||
|
||
/** | ||
* 숙소를 삭제합니다. | ||
*/ | ||
public void deleteAccommodation(Long id) { | ||
accommodationRepository.deleteById(id); | ||
} | ||
|
||
/** | ||
* 숙소를 검색합니다. | ||
*/ | ||
|
||
} |