Skip to content

Commit

Permalink
Merge pull request #211 from swm-nodriversomabus/BUS-212-accommodatio…
Browse files Browse the repository at this point in the history
…n-API

Bus 212 accommodation api
  • Loading branch information
namhyo01 authored Nov 15, 2023
2 parents c7e03d6 + 3d25ab6 commit b3226b2
Show file tree
Hide file tree
Showing 20 changed files with 457 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum ErrorCodeEnum {
MATCHING_NOT_FOUND(HttpStatus.BAD_REQUEST, "매칭 정보가 없습니다"),
PREFERENCE_NOT_FOUND(HttpStatus.BAD_REQUEST, "선호도 정보가 없습니다"),
APPLICATION_NOT_FOUND(HttpStatus.BAD_REQUEST, "신청 정보가 없습니다"),
ACCOMMODATION_NOT_FOUND(HttpStatus.BAD_REQUEST, "숙소 정보가 없습니다"),
IMAGE_NOT_FOUND(HttpStatus.BAD_REQUEST, "사진이 없습니다"),
FILE_NOT_FOUND(HttpStatus.BAD_REQUEST, "파일이 없습니다"),
INVALID_DATATYPE(HttpStatus.BAD_REQUEST, "유효하지 않은 데이터입니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import com.example.api.common.type.ApplicationStateEnum;
import com.example.api.common.type.ErrorCodeEnum;
import com.example.api.common.utils.AuthenticationUtils;
import com.example.api.matching.adapter.out.persistence.MatchingMapperInterface;
import com.example.api.matching.application.port.in.*;
import com.example.api.matching.domain.MatchingApplication;
import com.example.api.matching.dto.*;
import com.example.api.member.application.port.in.AddMemberChatRoomUsecase;
import com.example.api.matching.type.MatchingTypeEnum;
import com.example.api.user.application.port.in.FindUserUsecase;
import com.example.api.user.dto.FindUserInfoDto;
import com.example.api.user.dto.UserAuthorityCheckDto;
Expand Down Expand Up @@ -40,9 +41,9 @@ public class MatchingController {
private final FindMatchingUsecase findMatchingUsecase;
private final DeleteMatchingUsecase deleteMatchingUsecase;
private final MatchingApplicationUsecase matchingApplicationUsecase;
private final AccommodationUsecase accommodationUsecase;
private final LikeUsecase likeUsecase;
private final CreateChatRoomUsecase createChatRoomUsecase;
private final AddMemberChatRoomUsecase addMemberChatRoomUsecase;
private final MatchingMapperInterface matchingMapper;

/**
* 새 매칭 생성
Expand All @@ -51,12 +52,13 @@ public class MatchingController {
*/
@Operation(summary = "Create matching", description = "새로운 매칭을 생성한다.")
@PostMapping("/matching")
public FindMatchingDto createMatching(@Valid @RequestBody SaveMatchingDto saveMatchingDto) {
public FindMatchingDto createMatching(@Valid @RequestBody SaveMatchingDto saveMatchingDto, @Valid @RequestBody AccommodationDto accommodationDto) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("MatchingController::createMatching: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
FindMatchingDto findMatchingDto = saveMatchingUsecase.createMatching(securityUser.getUserId(), saveMatchingDto);

// 매칭 전용 채팅방 생성
CreateChatRoomDto createChatRoomDto = CreateChatRoomDto.builder()
Expand All @@ -81,6 +83,13 @@ public FindMatchingDto createMatching(@Valid @RequestBody SaveMatchingDto saveMa
.build();
matchingApplicationUsecase.createMatchingApplicationData(securityUser.getUserId(), saveMatchingApplicationDto);

if (saveMatchingDto.getType().equals(MatchingTypeEnum.Accommodation)) {
if (accommodationDto == null) {
log.error("MatchingController::createMatching: Accommodation data not found");
throw new CustomException(ErrorCodeEnum.ACCOMMODATION_NOT_FOUND);
}
accommodationUsecase.createAccommodation(findMatchingDto.getMatchingId(), accommodationDto);
}
return findMatchingDto;
}

Expand Down Expand Up @@ -126,20 +135,53 @@ public List<FindMatchingDto> getAll() {
return findMatchingUsecase.getAll();
}

@Operation(summary = "Get all dining matching", description = "모든 식사 매칭 목록을 조회한다.")
@GetMapping("/diningmatching")
public List<FindMatchingDto> getDiningMatchingList() {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("MatchingController::getDiningMatchingList: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
return findMatchingUsecase.getDiningMatchingList();
}

/**
* 숙소 매칭 목록 조회
* @return accommodation matching list
*/
@Operation(summary = "Get all accommodation matching", description = "모든 숙소 매칭 목록을 조회한다.")
@GetMapping("/accommodationmatching")
public List<AccommodationMatchingDto> getAccommodationMatchingList() {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("MatchingController::getAccommodationMatchingList: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
return accommodationUsecase.getAccommodationMatchingList();
}

/**
* ID가 matchingId인 매칭 조회
* ID가 matchingId인 매칭 조회 (유형 범용)
* @param matchingId (데이터)
* @return matching data
*/
@Operation(summary = "Get matching", description = "ID가 matchingId인 매칭을 조회한다.")
@GetMapping("/matching/{matchingId}")
public FindMatchingDto getMatchingById(@PathVariable Long matchingId) {
public AccommodationMatchingDto getMatchingById(@PathVariable Long matchingId) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("MatchingController::getMatchingById: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
return findMatchingUsecase.getMatchingById(matchingId);
AccommodationMatchingDto matchingDto = matchingMapper.toDto(findMatchingUsecase.getMatchingById(matchingId));
if (matchingDto.getType().equals(MatchingTypeEnum.Accommodation)) {
AccommodationDto accommodationDto = accommodationUsecase.getAccommodation(matchingId);
matchingDto.setPrice(accommodationDto.getPrice());
matchingDto.setPricePerOne(accommodationDto.getPrice() / Math.max(matchingDto.getCurrentMember(), 1));
matchingDto.setRoom(accommodationDto.getRoom());
}
return matchingDto;
}

/**
Expand Down Expand Up @@ -206,6 +248,17 @@ public int getLikeCount(@PathVariable Long matchingId) {
}
return likeUsecase.getLikeCount(matchingId);
}

@Operation(summary = "Get recommended accommodation list", description = "추천 숙소 리스트를 반환한다.")
@GetMapping("/accommodation/recommended")
public List<AccommodationDto> getRecommendedAccommodationList() {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("MatchingController::getRecommendedAccommodationList: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
return accommodationUsecase.getRecommendedAccommodationList(securityUser.getUserId());
}

/**
* ID가 matchingId인 매칭 정보 수정
Expand All @@ -223,6 +276,17 @@ public FindMatchingDto updateMatching(@PathVariable Long matchingId, @RequestBod
}
return saveMatchingUsecase.updateMatching(matchingId, matchingDto);
}

@Operation(summary = "Update accommodation", description = "숙소 정보를 수정한다.")
@PutMapping("/matching/{matchingId}/accommodation")
public void updateAccommodation(@PathVariable Long matchingId, @RequestBody AccommodationDto accommodationDto) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("MatchingController::updateAccommodation: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
accommodationUsecase.updateAccommodation(matchingId, accommodationDto);
}

/**
* 매칭의 좋아요 토글
Expand Down Expand Up @@ -296,4 +360,20 @@ public void deleteMatching(@PathVariable Long matchingId) {
}
deleteMatchingUsecase.deleteMatching(matchingId);
}

@Operation(summary = "Reset accommodation", description = "숙소 정보를 초기화한다.")
@DeleteMapping("/matching/{matchingId}/accommodation")
public void deleteAccommodation(@PathVariable Long matchingId) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("MatchingController::deleteAccommodation: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
FindMatchingDto matchingDto = findMatchingUsecase.getMatchingById(matchingId);
if (matchingDto == null) {
log.error("MatchingController::deleteMatching: No such matching");
throw new CustomException(ErrorCodeEnum.MATCHING_NOT_FOUND);
}
accommodationUsecase.deleteAccommodation(matchingId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Table(name="accommodationMatching")
public class AccommodationMatchingEntity {
@Table(name="accommodation")
public class AccommodationEntity {
@Id
private Long matchingId;

@Column
private Integer price;

@Column
private Integer pricePerOne;

@Column(length = 3000)
private String room;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.example.api.matching.adapter.out.persistence;

import com.example.api.matching.application.port.out.AccommodationPort;
import com.example.api.matching.domain.Accommodation;
import com.example.api.matching.repository.AccommodationRepository;
import com.example.api.matching.repository.MatchingRepository;
import com.example.api.matching.type.MatchingTypeEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@RequiredArgsConstructor
@Slf4j
@ComponentScan
public class AccommodationPersistenceAdapter implements AccommodationPort {
private final MatchingRepository matchingRepository;
private final AccommodationRepository accommodationRepository;
private final MatchingMapperInterface matchingMapper;

@Override
public void createAccommodation(Accommodation accommodation) {
accommodationRepository.save(matchingMapper.toEntity(accommodation));
}

@Override
public List<MatchingEntity> getAccommodationMatchingList() {
return matchingRepository.getByType(MatchingTypeEnum.Accommodation);
}

@Override
public List<AccommodationEntity> getAccommodationList() {
return accommodationRepository.getAllBy();
}

@Override
public Accommodation getAccommodation(Long matchingId) {
return matchingMapper.toDomain(accommodationRepository.getByMatchingId(matchingId).
orElse(AccommodationEntity.builder()
.matchingId(matchingId)
.price(0)
.pricePerOne(0)
.room("")
.build()
));
}

@Override
public void updateAccommodation(Accommodation accommodation) {
accommodationRepository.save(matchingMapper.toEntity(accommodation));
}

@Override
public void deleteAccommodation(Accommodation accommodation) {
accommodationRepository.save(matchingMapper.toEntity(accommodation));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.api.matching.adapter.out.persistence;

import com.example.api.matching.domain.Accommodation;
import com.example.api.matching.domain.AccommodationMatching;
import com.example.api.matching.domain.Matching;
import com.example.api.matching.domain.MatchingApplication;
import com.example.api.matching.dto.*;
Expand All @@ -13,14 +15,20 @@
public interface MatchingMapperInterface {
Matching toDomain(SaveMatchingDto matchingDto);
MatchingApplication toDomain(SaveMatchingApplicationDto matchingApplicationDto);
Accommodation toDomain(AccommodationDto accommodationDto);
MatchingEntity toEntity(Matching matching);
MatchingApplicationEntity toEntity(MatchingApplication matchingApplication);
AccommodationEntity toEntity(Accommodation accommodation);
LikeEntity toEntity(LikeDto likeDto);
Matching toDomain(MatchingEntity matchingEntity);
AccommodationMatching toAccommodationDomain(MatchingEntity matchingEntity);
MatchingApplication toDomain(MatchingApplicationEntity matchingApplicationEntity);
Accommodation toDomain(AccommodationEntity accommodationEntity);
FindMatchingDto toDto(Matching matching);
FindMatchingApplicationDto toDto(MatchingApplication matchingApplication);
FindMatchingDto toDto(MatchingEntity matchingEntity);
AccommodationMatchingDto toDto(AccommodationMatchingEntity accommodationMatchingEntity);
AccommodationDto toDto(Accommodation accommodation);
AccommodationMatchingDto toDto(AccommodationMatching accommodationMatching);
AccommodationMatchingDto toDto(FindMatchingDto matchingDto);
LikeDto toDto(LikeEntity likeEntity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.api.matching.domain.Matching;
import com.example.api.matching.repository.LikeRepository;
import com.example.api.matching.repository.MatchingRepository;
import com.example.api.matching.type.MatchingTypeEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -31,6 +32,11 @@ public List<MatchingEntity> getAllBy() {
return matchingRepository.getAllBy();
}

@Override
public List<MatchingEntity> getDiningMatchingList() {
return matchingRepository.getByType(MatchingTypeEnum.Dining);
}

@Override
public Optional<MatchingEntity> getByMatchingId(Long matchingId) {
return matchingRepository.getByMatchingId(matchingId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.api.matching.application.port.in;

import com.example.api.matching.dto.AccommodationDto;
import com.example.api.matching.dto.AccommodationMatchingDto;

import java.util.List;
import java.util.UUID;

public interface AccommodationUsecase {
void createAccommodation(Long matchingId, AccommodationDto accommodationDto);
List<AccommodationMatchingDto> getAccommodationMatchingList();
AccommodationDto getAccommodation(Long matchingId);
List<AccommodationDto> getRecommendedAccommodationList(UUID userId);
void updateAccommodation(Long matchingId, AccommodationDto accommodationDto);
void deleteAccommodation(Long matchingId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

public interface FindMatchingUsecase {
List<FindMatchingDto> getAll();
List<FindMatchingDto> getDiningMatchingList();
FindMatchingDto getMatchingById(Long matchingId);
List<FindMatchingDto> getMatchingByWriterId(UUID userId);
List<FindMatchingDto> getMatchingByIsActive(Boolean isActive);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.api.matching.application.port.out;

import com.example.api.matching.adapter.out.persistence.AccommodationEntity;
import com.example.api.matching.adapter.out.persistence.MatchingEntity;
import com.example.api.matching.domain.Accommodation;

import java.util.List;

public interface AccommodationPort {
void createAccommodation(Accommodation accommodation);
List<MatchingEntity> getAccommodationMatchingList();
List<AccommodationEntity> getAccommodationList();
Accommodation getAccommodation(Long matchingId);
void updateAccommodation(Accommodation accommodation);
void deleteAccommodation(Accommodation accommodation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public interface FindMatchingPort {
List<MatchingEntity> getAllBy();
List<MatchingEntity> getDiningMatchingList();
Optional<MatchingEntity> getByMatchingId(Long matchingId);
List<MatchingEntity> getByWriterId(UUID userId);
List<MatchingEntity> getByIsActive(Boolean isActive);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/example/api/matching/domain/Accommodation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.api.matching.domain;

import lombok.*;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Accommodation {
private Long matchingId;
private Integer price;
private Integer pricePerOne;
private String room;
}
Loading

0 comments on commit b3226b2

Please sign in to comment.