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

베이스 기타 수정 API 구현 #124

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.ajou.hertz.domain.instrument.bass_guitar.dto.request;

import com.ajou.hertz.common.dto.request.AddressRequest;
import com.ajou.hertz.domain.instrument.bass_guitar.constant.BassGuitarBrand;
import com.ajou.hertz.domain.instrument.bass_guitar.constant.BassGuitarPickUp;
import com.ajou.hertz.domain.instrument.bass_guitar.constant.BassGuitarPreAmplifier;
import com.ajou.hertz.domain.instrument.constant.GuitarColor;
import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus;
import com.ajou.hertz.domain.instrument.dto.request.InstrumentUpdateRequest;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.lang.Nullable;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Setter
@Getter
public class BassGuitarUpdateRequest extends InstrumentUpdateRequest {

@Nullable
private BassGuitarBrand brand;

@Nullable
private BassGuitarPickUp pickUp;

@Nullable
private BassGuitarPreAmplifier preAmplifier;

@Nullable
private GuitarColor color;

public BassGuitarUpdateRequest(
@Nullable String title,
@Nullable InstrumentProgressStatus progressStatus,
@Nullable AddressRequest tradeAddress,
@Nullable Short qualityStatus,
@Nullable Integer price,
@Nullable Boolean hasAnomaly,
@Nullable String description,
@Nullable List<Long> deletedImageIds,
@Nullable List<MultipartFile> newImages,
@Nullable List<Long> deletedHashtagIds,
@Nullable List<String> newHashtags,
@Nullable BassGuitarBrand brand,
@Nullable BassGuitarPickUp pickUp,
@Nullable BassGuitarPreAmplifier preAmplifier,
@Nullable GuitarColor color
) {
super(title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, deletedImageIds, newImages, deletedHashtagIds, newHashtags);
this.brand = brand;
this.pickUp = pickUp;
this.preAmplifier = preAmplifier;
this.color = color;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.ajou.hertz.domain.instrument.bass_guitar.entity;

import com.ajou.hertz.common.entity.Address;
import com.ajou.hertz.domain.instrument.amplifier.dto.request.AmplifierUpdateRequest;
import com.ajou.hertz.domain.instrument.bass_guitar.constant.BassGuitarBrand;
import com.ajou.hertz.domain.instrument.bass_guitar.constant.BassGuitarPickUp;
import com.ajou.hertz.domain.instrument.bass_guitar.constant.BassGuitarPreAmplifier;
import com.ajou.hertz.domain.instrument.bass_guitar.dto.request.BassGuitarUpdateRequest;
import com.ajou.hertz.domain.instrument.constant.GuitarColor;
import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus;
import com.ajou.hertz.domain.instrument.dto.request.InstrumentUpdateRequest;
import com.ajou.hertz.domain.instrument.entity.Instrument;
import com.ajou.hertz.domain.user.entity.User;

Expand Down Expand Up @@ -81,4 +84,13 @@ public static BassGuitar create(
price, hasAnomaly, description, brand, pickUp, preAmplifier, color
);
}

public void update(InstrumentUpdateRequest updateRequest) {
BassGuitarUpdateRequest bassGuitarUpdateRequest = (BassGuitarUpdateRequest)updateRequest;
super.update(updateRequest);
this.brand = bassGuitarUpdateRequest.getBrand();
this.pickUp = bassGuitarUpdateRequest.getPickUp();
this.preAmplifier = bassGuitarUpdateRequest.getPreAmplifier();
this.color = bassGuitarUpdateRequest.getColor();
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
package com.ajou.hertz.domain.instrument.controller;

import static com.ajou.hertz.common.constant.GlobalConstants.*;

import java.net.URI;

import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ajou.hertz.common.auth.UserPrincipal;
import com.ajou.hertz.domain.instrument.acoustic_and_classic_guitar.dto.AcousticAndClassicGuitarDto;
import com.ajou.hertz.domain.instrument.acoustic_and_classic_guitar.dto.request.AcousticAndClassicGuitarFilterConditions;
Expand All @@ -36,6 +17,7 @@
import com.ajou.hertz.domain.instrument.audio_equipment.dto.response.AudioEquipmentResponse;
import com.ajou.hertz.domain.instrument.bass_guitar.dto.BassGuitarDto;
import com.ajou.hertz.domain.instrument.bass_guitar.dto.request.BassGuitarFilterConditions;
import com.ajou.hertz.domain.instrument.bass_guitar.dto.request.BassGuitarUpdateRequest;
import com.ajou.hertz.domain.instrument.bass_guitar.dto.request.CreateNewBassGuitarRequest;
import com.ajou.hertz.domain.instrument.bass_guitar.dto.response.BassGuitarResponse;
import com.ajou.hertz.domain.instrument.constant.InstrumentSortOption;
Expand All @@ -55,7 +37,6 @@
import com.ajou.hertz.domain.instrument.mapper.InstrumentMapper;
import com.ajou.hertz.domain.instrument.service.InstrumentCommandService;
import com.ajou.hertz.domain.instrument.service.InstrumentQueryService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -65,6 +46,16 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.net.URI;

import static com.ajou.hertz.common.constant.GlobalConstants.API_VERSION_HEADER_NAME;

@Tag(name = "중고 악기 관련 API")
@RequiredArgsConstructor
Expand Down Expand Up @@ -472,6 +463,29 @@ public ElectricGuitarResponse updateElectricGuitarV1(
return InstrumentMapper.toElectricGuitarResponse(electricGuitarDto);
}

@Operation(
summary = "베이스 기타 매물 수정",
description = """
<p>베이스 기타 매물 정보를 수정합니다.
<p>요청 시 <strong>multipart/form-data</strong> content-type으로 요쳥해야 합니다.
<p>변경하고자 하는 매물 정보만 request body에 담아 요청하면 됩니다. 요청 시 보내지 않은 필드는 수정하지 않습니다.
""",
security = @SecurityRequirement(name = "access-token")
)
@PatchMapping("/bass-guitars/{bassGuitarId}")
public BassGuitarResponse updateBassGuitarV1(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@Parameter(description = "수정하고자 하는 악기 매물의 id", example = "2") @PathVariable Long bassGuitarId,
@ParameterObject @ModelAttribute @Valid BassGuitarUpdateRequest updateRequest
) {
BassGuitarDto bassGuitarDto = instrumentCommandService.updateBassGuitar(
userPrincipal.getUserId(),
bassGuitarId,
updateRequest
);
return InstrumentMapper.toBassGuitarResponse(bassGuitarDto);
}

@Operation(
summary = "어쿠스틱 기타 매물 수정",
description = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.ajou.hertz.domain.instrument.audio_equipment.entity.AudioEquipment;
import com.ajou.hertz.domain.instrument.audio_equipment.strategy.AudioEquipmentCreationStrategy;
import com.ajou.hertz.domain.instrument.bass_guitar.dto.BassGuitarDto;
import com.ajou.hertz.domain.instrument.bass_guitar.dto.request.BassGuitarUpdateRequest;
import com.ajou.hertz.domain.instrument.bass_guitar.dto.request.CreateNewBassGuitarRequest;
import com.ajou.hertz.domain.instrument.bass_guitar.entity.BassGuitar;
import com.ajou.hertz.domain.instrument.bass_guitar.strategy.BassGuitarCreationStrategy;
Expand Down Expand Up @@ -233,6 +234,22 @@ public ElectricGuitarDto updateElectricGuitar(
return (ElectricGuitarDto)updateInstrument(userId, electricGuitarId, updateRequest);
}

/**
* 베이스 기타 매물 정보를 수정한다.
*
* @param userId 수정하고자 하는 유저의 id. 악기 판매자와 동일해야 한다.
* @param bassGuitarId 수정할 베이스 기타의 id
* @param updateRequest 수정하고자 하는 정보
* @return 수정된 베이스 기타 매물 정보
*/
public BassGuitarDto updateBassGuitar(
Long userId,
Long bassGuitarId,
BassGuitarUpdateRequest updateRequest
) {
return (BassGuitarDto) updateInstrument(userId, bassGuitarId, updateRequest);
}

/**
* 어쿠스틱 & 클래식 기타 매물 정보를 수정한다.
*
Expand Down
Loading