Skip to content

Commit

Permalink
Merge pull request #101 from H-Hive/feature/notification
Browse files Browse the repository at this point in the history
Feature/notification
  • Loading branch information
mixedtape authored Jan 26, 2024
2 parents 9e932b7 + 24bd7d9 commit 01f6cfe
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ public String getTitle() {
public static MajorCategory findByStringName(String categoryName) {
return Arrays.stream(MajorCategory.values()).filter(majorCategory -> majorCategory.name().equals(categoryName)).findFirst().orElse(null);
}
public static MajorCategory findByTitle(String title) {
return Arrays.stream(MajorCategory.values())
.filter(majorCategory -> majorCategory.title.equals(title))
.findFirst()
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ public String getTitle() {
public static SubCategory findByStringName(String categoryName) {
return Arrays.stream(SubCategory.values()).filter(subCategory -> subCategory.name().equals(categoryName)).findFirst().orElse(null);
}
public static SubCategory findByTitle(String title) {
return Arrays.stream(SubCategory.values())
.filter(subCategory -> subCategory.title.equals(title))
.findFirst()
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class HiveController {
public ResponseEntity<CommonResponse<HiveResponseDTO>> createHive(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestBody @Valid CreateHiveRequestDTO createHiveRequestDTO) {

SubCategory.findByStringName(createHiveRequestDTO.getSubCategoryName());
HiveResponseDTO response = hiveService.createHive(userDetails.getUser(),
createHiveRequestDTO);
return ResponseEntity.ok()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class CreateHiveRequestDTO {
@NotBlank
private String title;

private MajorCategory majorCategory;
private String majorCategoryName;

private SubCategory subCategory;
private String subCategoryName;

public Hive toEntity(User createdBy) {
public Hive toEntity(User createdBy,MajorCategory majorCategory,SubCategory subCategory) {
return Hive.builder()
.title(title)
.majorCategory(majorCategory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static HiveResponseDTO of(Hive hive) {
.majorCategory(majorName)
.subCategory(subName)
.introduction(hive.getIntroduction())
.hostId(hive.getId())
.hostName(hive.getUser().getEmail())
.hostId(hive.getCreatorId())
.hostName(hive.getUser().getUsername())
.createdAt(hive.getCreatedAt())
.modifiedAt(hive.getModifiedAt())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public HiveResponseDTO createHive(User user, CreateHiveRequestDTO createHiveRequ
if (hiveRepository.findByTitle(createHiveRequestDTO.getTitle()).isPresent()) {
throw new AlreadyExistHiveException();
}
Hive saveHive = hiveRepository.save(createHiveRequestDTO.toEntity(createBy));
Hive saveHive = hiveRepository.save(createHiveRequestDTO.toEntity(createBy
,MajorCategory.findByTitle(createHiveRequestDTO.getMajorCategoryName())
,SubCategory.findByTitle(createHiveRequestDTO.getSubCategoryName())));
hiveUserService.saveHiveUser(saveHive, createBy);

return HiveResponseDTO.of(saveHive);
Expand All @@ -51,6 +53,9 @@ public HiveResponseDTO createHive(User user, CreateHiveRequestDTO createHiveRequ
public HiveResponseDTO updateHive(User user, Long hiveId,
@Valid UpdateHiveRequestDTO updateHiveRequest) {
Hive hive = getHiveAndCheckAuth(user, hiveId);
if (hiveRepository.findByTitle(updateHiveRequest.getTitle()).isPresent()) {
throw new AlreadyExistHiveException();
}

hive.update(updateHiveRequest);
return HiveResponseDTO.of(hive);
Expand Down

0 comments on commit 01f6cfe

Please sign in to comment.