Skip to content

Commit

Permalink
Hotfix/program (#39)
Browse files Browse the repository at this point in the history
* hot fix : 이미지 변경사항이 있는지 공고등록 model에 추가

* hot fix : 공고 등록할때 마감일이 현재시간보다 전이면 마감상태로 저장

* hotfix : 진행중인 공고 마감일 오타 수정
  • Loading branch information
MyunghyunNero authored Nov 23, 2023
1 parent 885a308 commit eb8b1bf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public class ProgramManagerRes {
private LocalDate recruitStartDate;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
private LocalDate recuritEndDate;
private LocalDate recruitEndDate;
}
27 changes: 24 additions & 3 deletions src/main/java/kusitms/gallae/service/admin/ManagerServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -97,6 +98,8 @@ public ProgramPostReq getTempProgram(String username) {
}
@Override
public Long postProgram(ProgramPostReq programPostReq ,String username) {
LocalDateTime localDateTime = LocalDateTime.now().plusHours(9);
LocalDate localdate = localDateTime.toLocalDate();
User user = userRepository.findById(Long.valueOf(username)).get();
Program tempProgram = programRespository.findByUserIdAndStatus(user.getId(), //나중에 유저 생기면 수정 필요
Program.ProgramStatus.TEMP);
Expand All @@ -106,25 +109,35 @@ public Long postProgram(ProgramPostReq programPostReq ,String username) {
Program saveProgram = this.getProgramEntity(program,programPostReq);
saveProgram.setUser(user);
saveProgram.setStatus(Program.ProgramStatus.SAVE);
if(saveProgram.getRecruitEndDate().isBefore(localdate)){
saveProgram.setStatus(Program.ProgramStatus.FINISH);
}
Program programId = programRespository.save(saveProgram);
return programId.getId();
}else { //임시 저장이 있으면
Program saveProgram = this.getProgramEntity(tempProgram, programPostReq);
saveProgram.setStatus(Program.ProgramStatus.SAVE);
if(saveProgram.getRecruitEndDate().isBefore(localdate)){
saveProgram.setStatus(Program.ProgramStatus.FINISH);
}
return tempProgram.getId();
}
}

@Override
public Long editProgram(ProgramPostReq programPostReq ,String username) {

LocalDateTime localDateTime = LocalDateTime.now().plusHours(9);
LocalDate localdate = localDateTime.toLocalDate();
User user = userRepository.findById(Long.valueOf(username)).get();
Program tempProgram = programRespository.findById(programPostReq.getProgramId()).orElse(null);
if(user.getId() != tempProgram.getUser().getId()) {
throw new BaseException(BaseResponseStatus.NOT_WRITER);
}

Program saveProgram = this.getProgramEntity(tempProgram,programPostReq);
if(saveProgram.getRecruitEndDate().isBefore(localdate)){
saveProgram.setStatus(Program.ProgramStatus.FINISH);
}
saveProgram.setStatus(Program.ProgramStatus.SAVE);
Program programId = programRespository.save(saveProgram);
return programId.getId();
Expand All @@ -135,17 +148,24 @@ public Long postTempProgram(ProgramPostReq programPostReq , String username) {
User user = userRepository.findById(Long.valueOf(username)).get();
Program tempProgram = programRespository.findByUserIdAndStatus(user.getId(), //나중에 유저 생기면 수정 필요
Program.ProgramStatus.TEMP);

LocalDateTime localDateTime = LocalDateTime.now().plusHours(9);
LocalDate localdate = localDateTime.toLocalDate();
if(tempProgram == null) { //임시 저장이 없으면
Program program = new Program();
Program saveProgram = this.getProgramEntity(program,programPostReq);
saveProgram.setUser(user);
saveProgram.setStatus(Program.ProgramStatus.TEMP);
if(saveProgram.getRecruitEndDate().isBefore(localdate)){
saveProgram.setStatus(Program.ProgramStatus.FINISH);
}
Program programId = programRespository.save(saveProgram);
return programId.getId();
}else { //임시 저장이 있으면
Program saveProgram = this.getProgramEntity(tempProgram, programPostReq);
saveProgram.setStatus(Program.ProgramStatus.TEMP);
if(saveProgram.getRecruitEndDate().isBefore(localdate)){
saveProgram.setStatus(Program.ProgramStatus.FINISH);
}
return saveProgram.getId();
}
}
Expand Down Expand Up @@ -192,7 +212,7 @@ private List<ProgramManagerRes> getProgramManagerRes(List<Program> programs){
programManagerRes.setLike(program.getProgramLike());
programManagerRes.setViewCount(program.getViewCount());
programManagerRes.setRecruitStartDate(program.getRecruitStartDate());
programManagerRes.setRecuritEndDate(program.getRecruitEndDate());
programManagerRes.setRecruitEndDate(program.getRecruitEndDate());
return programManagerRes;
}).collect(Collectors.toList());
}
Expand All @@ -219,6 +239,7 @@ private Program getProgramEntity(Program program ,ProgramPostReq programPostReq)
program.setDescription(programPostReq.getBody());
program.setProgramLike(0L);
program.setViewCount(0L);

return program;
}
}

0 comments on commit eb8b1bf

Please sign in to comment.