Skip to content

Commit

Permalink
Test: #107 합주실 매물 생성 api test 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
tinon1004 committed May 1, 2024
1 parent c0bb80d commit a0c1e72
Show file tree
Hide file tree
Showing 12 changed files with 991 additions and 41 deletions.
31 changes: 16 additions & 15 deletions src/main/java/com/ajou/hertz/common/entity/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
package com.ajou.hertz.common.entity;

import java.time.LocalDateTime;

import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.LastModifiedBy;

import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.LastModifiedBy;

import java.time.LocalDateTime;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@MappedSuperclass
public abstract class BaseEntity extends TimeTrackedBaseEntity {

@CreatedBy
@Column(nullable = false, updatable = false)
protected Long createdBy;
@CreatedBy
@Column(nullable = false, updatable = false)
protected Long createdBy;

@LastModifiedBy
@Column(nullable = false)
protected Long updatedBy;
@LastModifiedBy
@Column(nullable = false)
protected Long updatedBy;

protected BaseEntity(LocalDateTime createdAt, LocalDateTime updatedAt, Long createdBy, Long updatedBy) {
super(createdAt, updatedAt);
this.createdBy = createdBy;
this.updatedBy = updatedBy;
}
protected BaseEntity(LocalDateTime createdAt, LocalDateTime updatedAt, Long createdBy, Long updatedBy) {
super(createdAt, updatedAt);
this.createdBy = createdBy;
this.updatedBy = updatedBy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Embeddable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@AllArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
public class PracticeRoomDto {
Expand All @@ -21,6 +21,7 @@ public class PracticeRoomDto {
private UserDto seller;
private String title;
private FullAddressDto tradeAddress;
private CoordinateDto coordinate;
private Boolean hasSoundEquipment;
private Boolean hasInstrument;
private Integer pricePerDay;
Expand All @@ -30,18 +31,16 @@ public class PracticeRoomDto {
private String size;
private Boolean hasParkingLot;
private String description;
private CoordinateDto coordinate;
private List<PracticeRoomImageDto> images;
private List<String> hashtags;

public PracticeRoomDto(PracticeRoom practiceRoom) {
this(practiceRoom.getId(), UserDto.from(practiceRoom.getSeller()), practiceRoom.getTitle(),
FullAddressDto.from(practiceRoom.getTradeAddress()), practiceRoom.getHasSoundEquipment(),
practiceRoom.getHasInstrument(), practiceRoom.getPricePerDay(), practiceRoom.getPricePerHour(),
practiceRoom.getPricePerMonth(), practiceRoom.getCapacity(), practiceRoom.getSize(),
practiceRoom.getHasParkingLot(), practiceRoom.getDescription().getDescription(),
CoordinateDto.from(practiceRoom.getCoordinate()), practiceRoom.getImages().toDtos(),
practiceRoom.getHashtags().toStrings());
FullAddressDto.from(practiceRoom.getTradeAddress()), CoordinateDto.from(practiceRoom.getCoordinate()),
practiceRoom.getHasSoundEquipment(), practiceRoom.getHasInstrument(), practiceRoom.getPricePerDay(),
practiceRoom.getPricePerHour(), practiceRoom.getPricePerMonth(), practiceRoom.getCapacity(),
practiceRoom.getSize(), practiceRoom.getHasParkingLot(), practiceRoom.getDescription().getDescription(),
practiceRoom.getImages().toDtos(), practiceRoom.getHashtags().toStrings());
}

public static PracticeRoomDto from(PracticeRoom practiceRoom) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,41 @@ public class CreateNewPracticeRoomRequest {
private List<@NotBlank @Length(max = 10) String> hashtags;

public PracticeRoom toEntity(User seller) {
return PracticeRoom.create(seller, getTitle(), getDescription(), getCapacity(), getSize(),
getHasSoundEquipment(), getHasInstrument(), getPricePerHour(), getPricePerDay(), getPricePerMonth(),
getHasParkingLot(), getTradeAddress().toEntity(), getCoordinate().toEntity());
return PracticeRoom.create(seller, getTitle(), getTradeAddress().toEntity(), getCoordinate().toEntity(),
getHasSoundEquipment(), getHasInstrument(), getPricePerDay(), getPricePerHour(), getPricePerMonth(),
getCapacity(), getSize(), getHasParkingLot(), getDescription());
}

public CreateNewPracticeRoomRequest(
String title,
FullAddressRequest tradeAddress,
CoordinateRequest coordinate,
Boolean hasSoundEquipment,
Boolean hasInstrument,
Integer pricePerDay,
Integer pricePerHour,
Integer pricePerMonth,
Short capacity,
String size,
Boolean hasParkingLot,
String description,
List<MultipartFile> images,
List<String> hashtags
) {
this.title = title;
this.tradeAddress = tradeAddress;
this.coordinate = coordinate;
this.hasSoundEquipment = hasSoundEquipment;
this.hasInstrument = hasInstrument;
this.pricePerDay = pricePerDay;
this.pricePerHour = pricePerHour;
this.pricePerMonth = pricePerMonth;
this.capacity = capacity;
this.size = size;
this.hasParkingLot = hasParkingLot;
this.description = description;
this.images = images;
this.hashtags = hashtags;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ protected PracticeRoom(
User seller,
String title,
FullAddress tradeAddress,
Coordinate coordinate,
Boolean hasSoundEquipment,
Boolean hasInstrument,
Integer pricePerDay,
Expand All @@ -90,14 +91,13 @@ protected PracticeRoom(
Short capacity,
String size,
Boolean hasParkingLot,
String description,
Coordinate coordinate

String description
) {
this.id = id;
this.seller = seller;
this.title = title;
this.tradeAddress = tradeAddress;
this.coordinate = coordinate;
this.hasSoundEquipment = hasSoundEquipment;
this.hasInstrument = hasInstrument;
this.pricePerDay = pricePerDay;
Expand All @@ -107,29 +107,31 @@ protected PracticeRoom(
this.size = size;
this.hasParkingLot = hasParkingLot;
this.description = new PracticeRoomDescription(description);
this.coordinate = coordinate;

}

public static PracticeRoom create(
User seller,
String title,
String description,
Short capacity,
String size,
FullAddress tradeAddress,
Coordinate coordinate,
Boolean hasSoundEquipment,
Boolean hasInstrument,
Integer pricePerHour,
Integer pricePerDay,
Integer pricePerMonth,
Short capacity,
String size,
Boolean hasParkingLot,
FullAddress tradeAddress,
Coordinate coordinate
String description

) {
return new PracticeRoom(
null,
seller,
title,
tradeAddress,
coordinate,
hasSoundEquipment,
hasInstrument,
pricePerDay,
Expand All @@ -138,8 +140,7 @@ public static PracticeRoom create(
capacity,
size,
hasParkingLot,
description,
coordinate
description
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public PracticeRoomDto createNewPracticeRoom(Long sellerId,
);
practiceRoom.getHashtags().addAll(savedPracticeRoomHashtags);

PracticeRoom updatedPracticeRoom = practiceRoomRepository.save(practiceRoom);

return new PracticeRoomDto(updatedPracticeRoom);
return new PracticeRoomDto(practiceRoom);
}
}
Loading

0 comments on commit a0c1e72

Please sign in to comment.