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

update : 하이브 수정 기능을 타이틀수정, 내용수정 으로 나누어서 기능구현 #102

Merged
merged 1 commit into from
Jan 26, 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
Expand Up @@ -4,7 +4,8 @@
import com.HHive.hhive.domain.category.data.SubCategory;
import com.HHive.hhive.domain.hive.dto.CreateHiveRequestDTO;
import com.HHive.hhive.domain.hive.dto.HiveResponseDTO;
import com.HHive.hhive.domain.hive.dto.UpdateHiveRequestDTO;
import com.HHive.hhive.domain.hive.dto.UpdateHiveInfoRequestDTO;
import com.HHive.hhive.domain.hive.dto.UpdateHiveTitleRequestDTO;
import com.HHive.hhive.domain.hive.service.HiveService;
import com.HHive.hhive.domain.relationship.hiveuser.dto.HiveUserInviteRequestDTO;
import com.HHive.hhive.domain.user.UserDetailsImpl;
Expand Down Expand Up @@ -47,12 +48,22 @@ public ResponseEntity<CommonResponse<HiveResponseDTO>> createHive(
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브가 작성되었습니다.", response));
}

@PatchMapping("{hive_id}/update")
public ResponseEntity<CommonResponse<HiveResponseDTO>> updateHive(
@PatchMapping("{hive_id}/title")
public ResponseEntity<CommonResponse<HiveResponseDTO>> updateHiveTitle(
@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable Long hive_id,
@RequestBody @Valid UpdateHiveRequestDTO updateRequest) {
HiveResponseDTO response = hiveService.updateHive(userDetails.getUser(), hive_id,
updateRequest);
@RequestBody @Valid UpdateHiveTitleRequestDTO updateHiveTitleRequest) {
HiveResponseDTO response = hiveService.updateHiveTitle(userDetails.getUser(), hive_id,
updateHiveTitleRequest);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브가 수정되었습니다.", response));
}

@PatchMapping("{hive_id}/info")
public ResponseEntity<CommonResponse<HiveResponseDTO>> updateHiveInfo(
@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable Long hive_id,
@RequestBody @Valid UpdateHiveInfoRequestDTO updateHiveInfoRequest) {
HiveResponseDTO response = hiveService.updateHiveInfo(userDetails.getUser(), hive_id,
updateHiveInfoRequest);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브가 수정되었습니다.", response));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UpdateHiveRequestDTO {

private String title;
public class UpdateHiveInfoRequestDTO {

private String introduction;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.HHive.hhive.domain.hive.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UpdateHiveTitleRequestDTO {

private String title;
}
15 changes: 9 additions & 6 deletions src/main/java/com/HHive/hhive/domain/hive/entity/Hive.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import com.HHive.hhive.domain.category.data.MajorCategory;
import com.HHive.hhive.domain.category.data.SubCategory;
import com.HHive.hhive.domain.hive.dto.UpdateHiveRequestDTO;
import com.HHive.hhive.domain.hive.dto.UpdateHiveInfoRequestDTO;
import com.HHive.hhive.domain.hive.dto.UpdateHiveTitleRequestDTO;
import com.HHive.hhive.domain.user.entity.User;
import com.HHive.hhive.global.auditing.BaseTimeEntity;
import jakarta.persistence.Column;
Expand Down Expand Up @@ -63,13 +64,15 @@ public class Hive extends BaseTimeEntity {
// private Category category;
Copy link
Member

Choose a reason for hiding this comment

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

주석을 남겨두신 이유가 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

아니 없어요

Copy link
Contributor

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ 웃다가 토쏠렸어요..



public void update(UpdateHiveRequestDTO updateHiveRequestDTO) {
if (updateHiveRequestDTO.getTitle() != null) {
this.title = updateHiveRequestDTO.getTitle();
public void updateHiveTitle(UpdateHiveTitleRequestDTO updateHiveTitleRequestDTO) {
if (updateHiveTitleRequestDTO.getTitle() != null) {
this.title = updateHiveTitleRequestDTO.getTitle();
}
}

if (updateHiveRequestDTO.getIntroduction() != null) {
this.introduction = updateHiveRequestDTO.getIntroduction();
public void updateHiveInfo(UpdateHiveInfoRequestDTO updateHiveInfoRequest) {
if (updateHiveInfoRequest.getIntroduction() != null) {
this.introduction = updateHiveInfoRequest.getIntroduction();
}
}

Expand Down
18 changes: 12 additions & 6 deletions src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import com.HHive.hhive.domain.category.data.SubCategory;
import com.HHive.hhive.domain.hive.dto.CreateHiveRequestDTO;
import com.HHive.hhive.domain.hive.dto.HiveResponseDTO;
import com.HHive.hhive.domain.hive.dto.UpdateHiveRequestDTO;
import com.HHive.hhive.domain.hive.dto.UpdateHiveInfoRequestDTO;
import com.HHive.hhive.domain.hive.dto.UpdateHiveTitleRequestDTO;
import com.HHive.hhive.domain.hive.entity.Hive;
import com.HHive.hhive.domain.hive.repository.HiveRepository;
import com.HHive.hhive.domain.relationship.hiveuser.dto.HiveUserInviteRequestDTO;
Expand Down Expand Up @@ -50,14 +51,20 @@ public HiveResponseDTO createHive(User user, CreateHiveRequestDTO createHiveRequ
}

@Transactional
public HiveResponseDTO updateHive(User user, Long hiveId,
@Valid UpdateHiveRequestDTO updateHiveRequest) {
public HiveResponseDTO updateHiveTitle(User user, Long hiveId,
@Valid UpdateHiveTitleRequestDTO updateHiveTitleRequest) {
Hive hive = getHiveAndCheckAuth(user, hiveId);
if (hiveRepository.findByTitle(updateHiveRequest.getTitle()).isPresent()) {
if (hiveRepository.findByTitle(updateHiveTitleRequest.getTitle()).isPresent()) {
throw new AlreadyExistHiveException();
}

hive.update(updateHiveRequest);
hive.updateHiveTitle(updateHiveTitleRequest);
return HiveResponseDTO.of(hive);
}

public HiveResponseDTO updateHiveInfo(User user, Long hiveId, UpdateHiveInfoRequestDTO updateHiveInfoRequest) {
Hive hive = getHiveAndCheckAuth(user, hiveId);
hive.updateHiveInfo(updateHiveInfoRequest);
return HiveResponseDTO.of(hive);
}

Expand Down Expand Up @@ -139,5 +146,4 @@ public Hive findHiveById(Long hiveId) {
NotFoundHiveException::new);
}


}
Loading