Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 어드민 복덕방 조회,수정,삭제취소 #631

Merged
merged 13 commits into from
Jun 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
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.RequestParam;

import in.koreatech.koin.admin.land.dto.AdminLandsRequest;
import in.koreatech.koin.admin.land.dto.AdminLandResponse;
import in.koreatech.koin.admin.land.dto.AdminLandRequest;
import in.koreatech.koin.admin.land.dto.AdminLandsResponse;

import in.koreatech.koin.global.auth.Auth;
Expand Down Expand Up @@ -55,7 +57,7 @@ ResponseEntity<AdminLandsResponse> getLands(
@SecurityRequirement(name = "Jwt Authentication")
@PostMapping("/admin/lands")
ResponseEntity<AdminLandsResponse> postLands(
@RequestBody @Valid AdminLandsRequest adminLandsRequest,
@RequestBody @Valid AdminLandRequest adminLandRequest,
@Auth(permit = {ADMIN}) Integer adminId
);

Expand All @@ -75,4 +77,52 @@ ResponseEntity<Void> deleteLand(
@Auth(permit = {ADMIN}) Integer adminId
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true))),
}
)
@Operation(summary = "복덕방 조회")
@SecurityRequirement(name = "Jwt Authentication")
@GetMapping("/admin/lands/{id}")
ResponseEntity<AdminLandResponse> getLand(
@PathVariable("id") Integer id,
@Auth(permit = {ADMIN}) Integer adminId
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true))),
}
)
@Operation(summary = "복덕방 수정")
@SecurityRequirement(name = "Jwt Authentication")
@PutMapping("/admin/lands/{id}")
ResponseEntity<Void> updateLand(
@PathVariable("id") Integer id,
@RequestBody @Valid AdminLandRequest request,
@Auth(permit = {ADMIN}) Integer adminId
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true))),
}
)
@Operation(summary = "복덕방 삭제 취소")
@SecurityRequirement(name = "Jwt Authentication")
@PostMapping("/admin/lands/{id}/undelete")
ResponseEntity<Void> undeleteLand(
@PathVariable("id") Integer id,
@Auth(permit = {ADMIN}) Integer adminId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import in.koreatech.koin.admin.land.dto.AdminLandsRequest;
import in.koreatech.koin.admin.land.dto.AdminLandResponse;
import in.koreatech.koin.admin.land.dto.AdminLandRequest;
import in.koreatech.koin.admin.land.dto.AdminLandsResponse;
import in.koreatech.koin.admin.land.service.AdminLandService;
import in.koreatech.koin.global.auth.Auth;
Expand All @@ -37,10 +39,10 @@ public ResponseEntity<AdminLandsResponse> getLands(

@PostMapping("/admin/lands")
public ResponseEntity<AdminLandsResponse> postLands(
@RequestBody @Valid AdminLandsRequest adminLandsRequest,
@RequestBody @Valid AdminLandRequest adminLandRequest,
@Auth(permit = {ADMIN}) Integer adminId
) {
adminLandService.createLands(adminLandsRequest);
adminLandService.createLands(adminLandRequest);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

Expand All @@ -53,4 +55,31 @@ public ResponseEntity<Void> deleteLand(
return null;
}

@GetMapping("/admin/lands/{id}")
public ResponseEntity<AdminLandResponse> getLand(
@PathVariable("id") Integer id,
@Auth(permit = {ADMIN}) Integer adminId
) {
return ResponseEntity.ok().body(adminLandService.getLand(id));
}

@PutMapping("/admin/lands/{id}")
public ResponseEntity<Void> updateLand(
@PathVariable("id") Integer id,
@RequestBody @Valid AdminLandRequest request,
@Auth(permit = {ADMIN}) Integer adminId
) {
adminLandService.updateLand(id, request);
return ResponseEntity.ok().build();
}

@PostMapping("/admin/lands/{id}/undelete")
public ResponseEntity<Void> undeleteLand(
@PathVariable("id") Integer id,
@Auth(permit = {ADMIN}) Integer adminId
) {
adminLandService.undeleteLand(id);
return ResponseEntity.ok().build();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package in.koreatech.koin.admin.land.dto;


import java.util.List;

import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
Expand All @@ -17,7 +16,7 @@
import jakarta.validation.constraints.Size;

@JsonNaming(SnakeCaseStrategy.class)
public record AdminLandsRequest(
public record AdminLandRequest(
@Schema(description = "이름 - not null - 최대 255자", example = "금실타운", requiredMode = REQUIRED)
@NotNull(message = "방이름은 필수입니다.")
@Size(max = 255, message = "방이름의 최대 길이는 255자입니다.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C

@NotBlank가 필요해보입니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵~ 고치겠습니다

Expand All @@ -29,17 +28,17 @@ public record AdminLandsRequest(
String internalName,

@Schema(description = "크기", example = "9.0")
String size,
double size,

@Schema(description = "종류 - 최대 20자", example = "원룸")
@Size(max = 20, message = "방종류의 최대 길이는 20자입니다.")
String roomType,

@Schema(description = "위도", example = "36.766205")
String latitude,
double latitude,

@Schema(description = "경도", example = "127.284638")
String longitude,
double longitude,

@Schema(description = "전화번호 - 정규식 `^[0-9]{3}-[0-9]{3,4}-[0-9]{4}$` 을 만족해야함", example = "041-111-1111")
@Pattern(regexp = "^[0-9]{3}-[0-9]{3,4}-[0-9]{4}$", message = "전화번호의 형식이 올바르지 않습니다.")
Expand Down Expand Up @@ -101,16 +100,37 @@ public record AdminLandsRequest(
boolean optAirConditioner,

@Schema(description = "샤워기 보유 여부 - null일경우 false로 요청됨", example = "true")
boolean optWasher
boolean optWasher,

@Schema(description = "침대 보유 여부", example = "false")
boolean optBed,

@Schema(description = "책상 보유 여부", example = "true")
boolean optDesk,

@Schema(description = "신발장 보유 여부", example = "true")
boolean optShoeCloset,

@Schema(description = "전자 도어락 보유 여부", example = "true")
boolean optElectronicDoorLocks,

@Schema(description = "비데 보유 여부", example = "false")
boolean optBidet,

@Schema(description = "베란다 보유 여부", example = "false")
boolean optVeranda,

@Schema(description = "엘리베이터 보유 여부", example = "true")
boolean optElevator
) {
public Land toLand() {
return Land.builder()
.name(name)
.internalName(internalName)
.size(size)
.size(String.valueOf(size))
.roomType(roomType)
.latitude(latitude)
.longitude(longitude)
.latitude(String.valueOf(latitude))
.longitude(String.valueOf(longitude))
.phone(phone)
.imageUrls(imageUrls)
.address(address)
Expand All @@ -129,6 +149,13 @@ public Land toLand() {
.optWaterPurifier(optWaterPurifier)
.optAirConditioner(optAirConditioner)
.optWasher(optWasher)
.optBed(optBed)
.optDesk(optDesk)
.optShoeCloset(optShoeCloset)
.optElectronicDoorLocks(optElectronicDoorLocks)
.optBidet(optBidet)
.optVeranda(optVeranda)
.optElevator(optElevator)
.build();
}
}
Expand Down
124 changes: 120 additions & 4 deletions src/main/java/in/koreatech/koin/admin/land/dto/AdminLandResponse.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package in.koreatech.koin.admin.land.dto;

import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

import java.util.List;

import com.fasterxml.jackson.databind.annotation.JsonNaming;

Expand All @@ -10,32 +11,147 @@

@JsonNaming(value = SnakeCaseStrategy.class)
public record AdminLandResponse(
@Schema(description = "고유 id", example = "1", requiredMode = REQUIRED)
@Schema(description = "고유 id", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
Integer id,

@Schema(description = "이름", example = "금실타운", requiredMode = REQUIRED)
@Schema(description = "이름", example = "금실타운", requiredMode = Schema.RequiredMode.REQUIRED)
String name,

@Schema(description = "내부 이름", example = "금실타운", requiredMode = Schema.RequiredMode.REQUIRED)
String internalName,

@Schema(description = "크기", example = "9.0")
double size,

@Schema(description = "종류", example = "원룸")
String roomType,

@Schema(description = "위도", example = "36.766205")
double latitude,

@Schema(description = "경도", example = "127.284638")
double longitude,

@Schema(description = "전화번호", example = "041-111-1111")
String phone,

@Schema(description = "이미지 URL 리스트")
List<String> imageUrls,

@Schema(description = "주소", example = "충청남도 천안시 동남구 병천면")
String address,

@Schema(description = "설명", example = "1년 계약시 20만원 할인")
String description,

@Schema(description = "층수", example = "4")
Integer floor,

@Schema(description = "보증금", example = "30")
String deposit,

@Schema(description = "월세", example = "200만원 (6개월)")
String monthlyFee,

@Schema(description = "전세", example = "3500")
String charterFee,

@Schema(description = "삭제(soft delete) 여부", example = "false", requiredMode = REQUIRED)
@Schema(description = "관리비", example = "21(1인 기준)")
String managementFee,

@Schema(description = "냉장고 보유 여부", example = "true")
boolean optRefrigerator,

@Schema(description = "옷장 보유 여부", example = "true")
boolean optCloset,

@Schema(description = "TV 보유 여부", example = "true")
boolean optTv,

@Schema(description = "전자레인지 보유 여부", example = "true")
boolean optMicrowave,

@Schema(description = "가스레인지 보유 여부", example = "false")
boolean optGasRange,

@Schema(description = "인덕션 보유 여부", example = "true")
boolean optInduction,

@Schema(description = "정수기 보유 여부", example = "true")
boolean optWaterPurifier,

@Schema(description = "에어컨 보유 여부", example = "true")
boolean optAirConditioner,

@Schema(description = "세탁기 보유 여부", example = "true")
boolean optWasher,

@Schema(description = "침대 보유 여부", example = "false")
boolean optBed,

@Schema(description = "책상 보유 여부", example = "true")
boolean optDesk,

@Schema(description = "신발장 보유 여부", example = "true")
boolean optShoeCloset,

@Schema(description = "전자 도어락 보유 여부", example = "true")
boolean optElectronicDoorLocks,

@Schema(description = "비데 보유 여부", example = "false")
boolean optBidet,

@Schema(description = "베란다 보유 여부", example = "false")
boolean optVeranda,

@Schema(description = "엘리베이터 보유 여부", example = "true")
boolean optElevator,

@Schema(description = "삭제(soft delete) 여부", example = "false", requiredMode = Schema.RequiredMode.REQUIRED)
Boolean isDeleted
) {
public static AdminLandResponse from(Land land) {
return new AdminLandResponse(
land.getId(),
land.getName(),
land.getInternalName(),
land.getSize() == null ? null : land.getSize(),
land.getRoomType(),
land.getLatitude() == null ? null : land.getLatitude(),
land.getLongitude() == null ? null : land.getLongitude(),
land.getPhone(),
convertToList(land.getImageUrls()),
land.getAddress(),
land.getDescription(),
land.getFloor(),
land.getDeposit(),
land.getMonthlyFee(),
land.getCharterFee(),
land.getManagementFee(),
land.isOptRefrigerator(),
land.isOptCloset(),
land.isOptTv(),
land.isOptMicrowave(),
land.isOptGasRange(),
land.isOptInduction(),
land.isOptWaterPurifier(),
land.isOptAirConditioner(),
land.isOptWasher(),
land.isOptBed(),
land.isOptDesk(),
land.isOptShoeCloset(),
land.isOptElectronicDoorLocks(),
land.isOptBidet(),
land.isOptVeranda(),
land.isOptElevator(),
land.isDeleted()
);
}

private static List<String> convertToList(String imageUrls) {
if (imageUrls == null || imageUrls.isEmpty()) {
return List.of();
}
return List.of(imageUrls.replace("[", "").replace("]", "").replace("\"", "").split(","));
}
}
Loading
Loading