Skip to content

Commit

Permalink
Merge pull request #63 from lab-cherry/haeri
Browse files Browse the repository at this point in the history
Haeri
  • Loading branch information
taking authored Nov 7, 2023
2 parents 14ba2da + c9cbc46 commit 9710bbc
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 121 deletions.
87 changes: 59 additions & 28 deletions nw/src/main/java/lab/cherry/nw/controller/ScheduleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lab.cherry.nw.error.ErrorResponse;
import lab.cherry.nw.model.FinalTemplEntity;
import lab.cherry.nw.model.ScheduleEntity;
import lab.cherry.nw.service.ScheduleService;
import lab.cherry.nw.util.Common;
Expand Down Expand Up @@ -120,38 +121,68 @@ public ResponseEntity<?> fianlToSchedule(@Valid @RequestBody(required = false) S
}


/**
* [ScheduleController] 스케줄표 날짜 기준 조회
*
* @param 날짜 기준으로 스케줄표를 조회합니다.
* @return
* <pre>
* true : 성공(200)을 반환합니다.
* false : 에러(400)를 반환합니다.
* </pre>
*
* Author : hhhaeri(yhoo0020@gmail.com)
*/
@PostMapping("/date/{start}/{end}")
@Operation(summary = "스케줄표 날짜 조회", description = "최종확인서에 있는 날짜 기준 조회")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "날짜 기준으로 조회를 완료되었습니다.", content = @Content(schema = @Schema(implementation = ResponseEntity.class))),
@ApiResponse(responseCode = "400", description = "입력 값이 잘못되었습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
public ResponseEntity<?> fianlToDateSchedule(@Valid @PathVariable("start") String start, @PathVariable("end") String end) {
/**
* [ScheduleController] 스케줄표 생성 함수
*
* @param ScheduleCreateDto 생성에 필요한 스케줄표 정보를 담고 있는 객체입니다.
* @return
* <pre>
* true : 성공(200)을 반환합니다.
* false : 에러(400)를 반환합니다.
* </pre>
*
* Author : hhhaeri(yhoo0020@gmail.com)
*/
@PostMapping("")
@Operation(summary = "스케줄표 생성", description = "스케줄표를 생성합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "스케줄표 생성이 완료되었습니다.", content = @Content(schema = @Schema(implementation = ResponseEntity.class))),
@ApiResponse(responseCode = "400", description = "입력 값이 잘못되었습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
public ResponseEntity<?> createFinalTemplate(@Valid @RequestBody(required = false) ScheduleEntity.ScheduleCreateDto scheduleCreateDto) {

log.info("[ScheduleController] fianlToDateSchedule...!");
log.info("[ScheduleController] createSchedule...!");

LocalDate localStartDate = LocalDate.parse(start);
LocalDate localEndDate = LocalDate.parse(end);
ScheduleEntity scheduleEntity = scheduleService.createSchedule(scheduleCreateDto);

// LocalDate를 Instant로 변환 (00:00:00 시간으로 설정)
Instant startDate = localStartDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
Instant endDate = localEndDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
return new ResponseEntity<>(scheduleEntity, new HttpHeaders(), HttpStatus.OK);
}

ScheduleEntity scheduleEntity = scheduleService.scheduleByDate(startDate,endDate);

return new ResponseEntity<>(scheduleEntity, new HttpHeaders(), HttpStatus.OK);
}


// /**
// * [ScheduleController] 스케줄표 날짜 기준 조회
// *
// * @param 날짜 기준으로 스케줄표를 조회합니다.
// * @return
// * <pre>
// * true : 성공(200)을 반환합니다.
// * false : 에러(400)를 반환합니다.
// * </pre>
// *
// * Author : hhhaeri(yhoo0020@gmail.com)
// */
// @PostMapping("/date/{start}/{end}")
// @Operation(summary = "스케줄표 날짜 조회", description = "최종확인서에 있는 날짜 기준 조회")
// @ApiResponses(value = {
// @ApiResponse(responseCode = "200", description = "날짜 기준으로 조회를 완료되었습니다.", content = @Content(schema = @Schema(implementation = ResponseEntity.class))),
// @ApiResponse(responseCode = "400", description = "입력 값이 잘못되었습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
// })
// public ResponseEntity<?> fianlToDateSchedule(@Valid @PathVariable("start") String start, @PathVariable("end") String end) {

// log.info("[ScheduleController] fianlToDateSchedule...!");

// LocalDate localStartDate = LocalDate.parse(start);
// LocalDate localEndDate = LocalDate.parse(end);

// // LocalDate를 Instant로 변환 (00:00:00 시간으로 설정)
// Instant startDate = localStartDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
// Instant endDate = localEndDate.atStartOfDay(ZoneId.systemDefault()).toInstant();

// ScheduleEntity scheduleEntity = scheduleService.scheduleByDate(startDate,endDate);

// return new ResponseEntity<>(scheduleEntity, new HttpHeaders(), HttpStatus.OK);
// }

}
40 changes: 23 additions & 17 deletions nw/src/main/java/lab/cherry/nw/model/FinalTemplEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@Builder
@NoArgsConstructor @AllArgsConstructor
@Document(collection = "finaltempl")
@JsonPropertyOrder({ "id", "finaltemplName","content","user","org","updated_at", "created_at"})
@JsonPropertyOrder({ "id", "finaltemplName", "content","user", "org", "usercard", "updated_at", "created_at"})
public class FinalTemplEntity implements Serializable {

@Id
Expand All @@ -51,16 +51,21 @@ public class FinalTemplEntity implements Serializable {
@Schema(title = "조직 정보", example = "64ed89aa9e813b5ab16da6de")
private OrgEntity org;


@NotNull
@JsonProperty("usercard")
@Schema(title = "고객카드 정보", example = "문서 내용")
private UserCardEntity usercard;

@NotNull
@JsonProperty("finaltemplName")
@Schema(title = "최종확인서 템플릿 이름", example = "예식장 최종 확인서 양식")
@Size(min = 4, max = 255, message = "Minimum name length: 4 characters")
private String name;

@NotNull
@JsonProperty("content")
@Schema(title = "최종확인서 템플릿 내용", example = "문서 내용")
private Map<String,String> content;
private Map<String,Object> content;


@JsonProperty("updated_at")
Expand All @@ -87,19 +92,20 @@ public static class FinalTemplCreateDto {
private String name;

@NotBlank
@JsonProperty("userid")
@Schema(title = "사용자 정보", example = "64ed89aa9e813b5ab16da6de")
private String user;
@Schema(title = "사용자 고유번호", example = "64ed89aa9e813b5ab16da6de")
private String userSeq;

@NotBlank
@JsonProperty("orgid")
@Schema(title = "조직 정보", example = "64ed89aa9e813b5ab16da6de")
private String org;
@Schema(title = "조직 고유번호", example = "64ed89aa9e813b5ab16da6de")
private String orgId;

@NotBlank
@Schema(title = "고객카드 고유 번호", example = "문서 내용")
private String usercardId;


@NotBlank
@JsonProperty("content")
@Schema(title = "최종확인서 템플릿 내용", example = "문서 내용")
private Map<String,String> content;
private Map<String,Object> content;


}
Expand All @@ -110,18 +116,18 @@ public static class FinalTemplCreateDto {
@NoArgsConstructor @AllArgsConstructor
public static class FinalTemplUpdateDto {

@Schema(title = "사용자 정보", example = "64ed89aa9e813b5ab16da6de")
private String user;
@Schema(title = "사용자 고유 번호", example = "64ed89aa9e813b5ab16da6de")
private String userSeq;

@Schema(title = "조직 정보", example = "64ed89aa9e813b5ab16da6de")
private String org;
@Schema(title = "조직 고유 번호", example = "64ed89aa9e813b5ab16da6de")
private String orgId;

@Schema(title = "최종확인서 템플릿 이름", example = "예식장 최종 확인서 양식")
@Size(min = 4, max = 255, message = "Minimum name length: 4 characters")
private String name;

@Schema(title = "최종확인서 템플릿 내용", example = "문서 내용")
private Map<String, String> content;
private Map<String, Object> content;


}
Expand Down
82 changes: 54 additions & 28 deletions nw/src/main/java/lab/cherry/nw/model/ScheduleEntity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package lab.cherry.nw.model;

import java.io.Serializable;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -30,7 +33,7 @@
@Builder
@NoArgsConstructor @AllArgsConstructor
@Document(collection = "schedule")
@JsonPropertyOrder({ "id", "scheduleSeq","user","org","finaltempl","scheduleName", "scheduleContent", "column"})
@JsonPropertyOrder({ "id", "scheduleSeq","user","org","finaltempl", "scheduleContent", "column", "created_at"})
public class ScheduleEntity implements Serializable {

@Id
Expand All @@ -48,49 +51,72 @@ public class ScheduleEntity implements Serializable {
@Schema(title = "조직 정보", example = "64ed89aa9e813b5ab16da6de")
private OrgEntity org;

@JsonProperty("finaltemplid")
@JsonProperty("finaltempl")
@Schema(title = "최종확인서 템플릿 정보", example = "64ed89aa9e813b5ab16da6de")
private FinalTemplEntity finaltempl;

@JsonProperty("scheduleName")
@Schema(title = "스케줄표 이름", example = "문서1")
@Size(min = 4, max = 255, message = "Minimum name length: 4 characters")
private String name;

@JsonProperty("scheduleContent")
@Schema(title = "스케줄표 내용", example = "[]")
private List<FinaldocsEntity> content;
private Map<String,Object> content;

@JsonProperty("column")
@Schema(title = "스케줄표 컬럼", example = "")
private Map<String, String> column;
private Map<String, Object> column;

@JsonProperty("created_at")
@JsonFormat(pattern="yyyy-MM-dd hh:mm:ss", locale = "ko_KR", timezone = "Asia/Seoul")
private Instant created_at;

//////////////////////////////////////////////////////////////////////////

@Getter
@Builder
@NoArgsConstructor @AllArgsConstructor
public static class ScheduleCreateDto {


@NotBlank
@Schema(title = "사용자 고유번호", example = "64ed89aa9e813b5ab16da6de")
private String userSeq;

@NotBlank
@Schema(title = "조직 고유번호", example = "64ed89aa9e813b5ab16da6de")
private String orgId;

@NotBlank
@Schema(title = "최종확인서 템플릿 고유번호", example = "문서 내용")
private String finaltemplId;


@Schema(title = "스케줄표 템플릿 내용", example = "문서 내용")
private Map<String,Object> content;


}

//////////////////////////////////////////////////////////////////////////

@Getter
@Setter
@Builder
@NoArgsConstructor @AllArgsConstructor
public static class transDto {
//////////////////////////////////////////////////////////////////////////

@Schema(title = "사용자 정보", example = "64ed89aa9e813b5ab16da6de")
private String user;
@Getter
@Setter
@Builder
@NoArgsConstructor @AllArgsConstructor
public static class transDto {

@Schema(title = "스케줄표 정보", example = "64ed89aa9e813b5ab16da6de")
private String finalTempl;
@Schema(title = "사용자 고유번호", example = "64ed89aa9e813b5ab16da6de")
private String userId;

@Schema(title = "조직 정보", example = "64ed89aa9e813b5ab16da6de")
private String org;
@Schema(title = "스케줄표 고유번호", example = "64ed89aa9e813b5ab16da6de")
private String finalTemplId;

@Schema(title = "스케줄표 이름", example = "문서1")
@Size(min = 4, max = 255, message = "Minimum name length: 4 characters")
private String name;
@Schema(title = "조직 고유번호", example = "64ed89aa9e813b5ab16da6de")
private String orgId;

@JsonProperty("scheduleContent")
@Schema(title = "스케줄표 내용", example = "[]")
private Map<String,String> content;
@JsonProperty("scheduleContent")
@Schema(title = "스케줄표 내용", example = "[]")
private Map<String,Object> content;

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public interface ScheduleRepository extends MongoRepository<ScheduleEntity, Stri

Page<ScheduleEntity> findAll(Pageable pageable);

Page<ScheduleEntity> findPageByName(String scheduleName, Pageable pageable);
// Page<ScheduleEntity> findPageByName(String scheduleName, Pageable pageable);

Page<ScheduleEntity> findPageById(String id, Pageable pageable);

Optional<ScheduleEntity> findById(String id);

Optional<ScheduleEntity> findByName(String scheduleName);
// Optional<ScheduleEntity> findByName(String scheduleName);

List<ScheduleEntity> findAllById(List<String> scheduleIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import lab.cherry.nw.error.exception.EntityNotFoundException;
import lab.cherry.nw.model.FinalTemplEntity;
import lab.cherry.nw.model.OrgEntity;
import lab.cherry.nw.model.UserCardEntity;
import lab.cherry.nw.model.UserEntity;
import lab.cherry.nw.repository.FinalTemplRepository;
import lab.cherry.nw.service.FinalTemplService;
import lab.cherry.nw.service.OrgService;
import lab.cherry.nw.service.UserCardService;
import lab.cherry.nw.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -36,6 +38,7 @@ public class FinalTemplServiceImpl implements FinalTemplService {
private final FinalTemplRepository finalTemplRepository;
private final UserService userService;
private final OrgService orgService;
private final UserCardService userCardService;

/**
* [FinalTemplServiceImpl] 최종확인서 템플릿 조회 함수
Expand Down Expand Up @@ -70,18 +73,20 @@ public FinalTemplEntity createFinalTemplate(FinalTemplEntity.FinalTemplCreateDto

Instant instant = Instant.now();

UserEntity userEntity = userService.findById(finalTemplCreateDto.getUser());
OrgEntity orgEntity = orgService.findById(finalTemplCreateDto.getOrg());
UserEntity userEntity = userService.findById(finalTemplCreateDto.getUserSeq());
OrgEntity orgEntity = orgService.findById(finalTemplCreateDto.getOrgId());
UserCardEntity usercard = userCardService.findById(finalTemplCreateDto.getUsercardId());

FinalTemplEntity finaldocsEntity = FinalTemplEntity.builder()
FinalTemplEntity finaltemplEntity = FinalTemplEntity.builder()
.name(finalTemplCreateDto.getName())
.content(finalTemplCreateDto.getContent())
.user(userEntity)
.usercard(usercard)
.org(orgEntity)
.created_at(instant)
.build();

return finalTemplRepository.save(finaldocsEntity);
return finalTemplRepository.save(finaltemplEntity);
}

/**
Expand All @@ -98,8 +103,8 @@ public FinalTemplEntity createFinalTemplate(FinalTemplEntity.FinalTemplCreateDto
public void updateById(String id, FinalTemplEntity.FinalTemplUpdateDto finalTempl) {

FinalTemplEntity finalTemplEntity = findById(id);
UserEntity userEntity = userService.findById(finalTempl.getUser());
OrgEntity orgEntity = orgService.findById(finalTempl.getOrg());
UserEntity userEntity = userService.findById(finalTempl.getUserSeq());
OrgEntity orgEntity = orgService.findById(finalTempl.getOrgId());
Instant instant = Instant.now();

if (finalTempl.getContent() != null) {
Expand Down
Loading

0 comments on commit 9710bbc

Please sign in to comment.