Skip to content

Commit

Permalink
#551 Implementation of size categorization for resources and needs.
Browse files Browse the repository at this point in the history
  • Loading branch information
alitpc25 committed Dec 12, 2023
1 parent 60d3dfe commit 61296cc
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public NeedDto convertToDto(Need need) {
needDto.setLatitude(need.getLatitude());
needDto.setLongitude(need.getLongitude());
needDto.setCreatedDate(need.getCreatedAt());
needDto.setSize(need.getSize());
Request request = need.getRequest();
if (request != null) {
needDto.setRequestId(request.getId());
Expand All @@ -51,6 +52,7 @@ public Need convertToEntity(NeedDto needDto) {
need.setLongitude(needDto.getLongitude());
need.setStatus(needDto.getStatus());
need.setCreatedAt(needDto.getCreatedDate());
need.setSize(needDto.getSize());
Request request = requestRepository.findById(needDto.getRequestId()).orElse(null);
need.setRequest(request);
return need;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.groupa1.resq.dto.ResourceDto;
import com.groupa1.resq.entity.Resource;
import com.groupa1.resq.entity.enums.ESize;
import com.groupa1.resq.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -26,6 +27,7 @@ public ResourceDto convertToDto(Resource resource){
resourceDto.setLatitude(resource.getLatitude());
resourceDto.setLongitude(resource.getLongitude());
resourceDto.setCreatedDate(resource.getCreatedAt());
resourceDto.setSize(resource.getSize().toString());
return resourceDto;

}
Expand All @@ -47,6 +49,7 @@ public Resource convertToEntity(ResourceDto resourceDto){
resource.setLatitude(resourceDto.getLatitude());
resource.setLongitude(resourceDto.getLongitude());
resource.setCreatedAt(resourceDto.getCreatedDate());
resource.setSize(ESize.valueOf(resourceDto.getSize()));
return resource;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.groupa1.resq.dto;

import com.groupa1.resq.entity.enums.ENeedStatus;
import com.groupa1.resq.entity.enums.ESize;
import lombok.Data;

import java.math.BigDecimal;
Expand All @@ -18,4 +19,5 @@ public class NeedDto {
private Long requestId;
private ENeedStatus status;
private LocalDateTime createdDate;
private ESize size;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class ResourceDto {
private BigDecimal latitude;
private BigDecimal longitude;
private LocalDateTime createdDate;
private String size;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.groupa1.resq.entity;

import com.groupa1.resq.entity.enums.EGender;
import com.groupa1.resq.entity.enums.ENeedStatus;
import com.groupa1.resq.entity.enums.ESize;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
Expand Down Expand Up @@ -34,6 +36,13 @@ public class Need extends BaseEntity{
private BigDecimal latitude;
private BigDecimal longitude;

@Enumerated(EnumType.STRING)
private EGender gender;

// These field only for clothing
@Enumerated(EnumType.STRING)
private ESize size;

@ManyToOne
@JoinColumn(name = "request_id")
private Request request;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.groupa1.resq.entity;

import com.groupa1.resq.entity.enums.EGender;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import com.groupa1.resq.entity.enums.ESize;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -32,6 +30,10 @@ public class Resource extends BaseEntity {

private EGender gender;

// These field only for clothing
@Enumerated(EnumType.STRING)
private ESize size;

private Integer quantity;

private BigDecimal latitude;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.groupa1.resq.entity.enums;

public enum EGender {
MALE,
FEMALE
MAN,
WOMAN,
CHILDREN_BOY, CHILDREN_GIRL,
BABY
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.groupa1.resq.entity.enums;

public enum ESize {
XL, L, M, S, XS, // For Gender: MAN, WOMAN
AGE_0_2, AGE_2_4, // For Gender: BABY
AGE_4_8, AGE_8_12, AGE_12_18, // For Gender: CHILDREN_BOY, CHILDREN_GIRL
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class CreateNeedRequest {
private BigDecimal longitude;
private String categoryTreeId;
private Integer quantity;
private String size;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public class CreateResourceRequest {
private BigDecimal latitude;
private BigDecimal longitude;
private EGender gender;

private String size;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class UpdateNeedRequest {
private BigDecimal longitude;
private String categoryTreeId;
private Integer quantity;
private String size;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.groupa1.resq.entity.Need;
import com.groupa1.resq.entity.User;
import com.groupa1.resq.entity.enums.ENeedStatus;
import com.groupa1.resq.entity.enums.ESize;
import com.groupa1.resq.exception.EntityNotFoundException;
import com.groupa1.resq.exception.NotOwnerException;
import com.groupa1.resq.repository.NeedRepository;
Expand Down Expand Up @@ -55,6 +56,7 @@ public Long save(Long userId, CreateNeedRequest createNeedRequest) {
need.setLatitude(createNeedRequest.getLatitude());
need.setQuantity(createNeedRequest.getQuantity());
need.setCategoryTreeId(createNeedRequest.getCategoryTreeId());
need.setSize(ESize.valueOf(createNeedRequest.getSize()));
need.setStatus(ENeedStatus.NOT_INVOLVED);
return needRepository.save(need).getId();

Expand Down Expand Up @@ -102,6 +104,7 @@ public ResponseEntity<String> update (UpdateNeedRequest updateNeedRequest, Long
need.setLatitude(updateNeedRequest.getLatitude());
need.setQuantity(updateNeedRequest.getQuantity());
need.setCategoryTreeId(updateNeedRequest.getCategoryTreeId());
need.setSize(ESize.valueOf(updateNeedRequest.getSize()));
needRepository.save(need);
return ResponseEntity.ok("Need updated successfully");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.groupa1.resq.dto.ResourceDto;
import com.groupa1.resq.entity.Resource;
import com.groupa1.resq.entity.User;
import com.groupa1.resq.entity.enums.ESize;
import com.groupa1.resq.exception.EntityNotFoundException;
import com.groupa1.resq.repository.ResourceRepository;
import com.groupa1.resq.request.CreateResourceRequest;
Expand Down Expand Up @@ -54,6 +55,7 @@ public ResponseEntity<Object> createResource(CreateResourceRequest createResourc
resource.setLatitude(createResourceRequest.getLatitude());
resource.setQuantity(createResourceRequest.getQuantity());
resource.setCategoryTreeId(createResourceRequest.getCategoryTreeId());
resource.setSize(ESize.valueOf(createResourceRequest.getSize()));
Long resourceId = resourceRepository.save(resource).getId();
return ResponseEntity.ok(resourceId);
}
Expand All @@ -64,6 +66,7 @@ public ResponseEntity<String> updateResource(CreateResourceRequest createResourc
resource.setLatitude(createResourceRequest.getLatitude());
resource.setLongitude(createResourceRequest.getLongitude());
resource.setCategoryTreeId(createResourceRequest.getCategoryTreeId());
resource.setSize(ESize.valueOf(createResourceRequest.getSize()));
resourceRepository.save(resource);
return ResponseEntity.ok("Resource updated successfully");
}
Expand Down

0 comments on commit 61296cc

Please sign in to comment.