-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat : 최신프로그램 조회, hot fix : 유저 테이블 생성 오류 수정
- Loading branch information
Showing
9 changed files
with
246 additions
and
8 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/kusitms/gallae/controller/ProgramController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package kusitms.gallae.controller; | ||
|
||
import kusitms.gallae.config.BaseResponse; | ||
import kusitms.gallae.dto.program.ProgramMainRes; | ||
import kusitms.gallae.service.ProgramService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/program") | ||
public class ProgramController { | ||
|
||
private final ProgramService programService; | ||
|
||
@GetMapping("/recent") | ||
public ResponseEntity<BaseResponse<List<ProgramMainRes>>> findRecentProgram(){ | ||
return ResponseEntity.ok(new BaseResponse<>(this.programService.getRecentPrograms())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package kusitms.gallae.domain; | ||
|
||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.hibernate.annotations.CreationTimestamp; | ||
import org.hibernate.annotations.UpdateTimestamp; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Table(name = "program") | ||
@Setter | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PUBLIC) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Builder | ||
@ToString | ||
public class Program { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY, optional = false) | ||
@JoinColumn(name = "user_Id", nullable = false) | ||
@ToString.Exclude | ||
private User user; | ||
|
||
private String programName; | ||
|
||
private String location; | ||
|
||
private LocalDateTime recruitStartDate; | ||
|
||
private LocalDateTime recruitEndDate; | ||
|
||
private LocalDateTime tripStartDate; | ||
|
||
private LocalDateTime tripEndDate; | ||
|
||
private LocalDateTime activeStartDate; | ||
|
||
private LocalDateTime activeEndDate; | ||
|
||
private String contact; | ||
|
||
private String contactNumber; | ||
|
||
private String programLink; | ||
|
||
private String programType; | ||
|
||
private String detailType; | ||
|
||
private String photoUrl; | ||
|
||
private Long programLike; | ||
|
||
@Column | ||
@CreationTimestamp | ||
private LocalDateTime createdAt; | ||
|
||
@Column | ||
@UpdateTimestamp | ||
private LocalDateTime updatedAt; | ||
|
||
@Column(nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
private ProgramStatus status; | ||
|
||
public enum ProgramStatus { | ||
ACTIVE, | ||
SAVE, // 임시 저장 | ||
FINISH, //마감 | ||
DELETED | ||
} | ||
|
||
public void delete() { | ||
this.status = ProgramStatus.DELETED; | ||
} | ||
|
||
public void finish(){ | ||
this.status = ProgramStatus.FINISH; | ||
} | ||
|
||
public void save(){ | ||
this.status = ProgramStatus.SAVE; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/kusitms/gallae/dto/program/ProgramMainRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package kusitms.gallae.dto.program; | ||
|
||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class ProgramMainRes { | ||
|
||
private String photoUrl; | ||
|
||
private String programName; | ||
|
||
private Long Like; | ||
|
||
private String remainDay; | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/kusitms/gallae/global/DurationCalcurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package kusitms.gallae.global; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
public class DurationCalcurator { | ||
public static String getDuration(LocalDateTime endDate){ | ||
LocalDateTime today = LocalDate.now().atStartOfDay(); | ||
LocalDateTime dateTime = LocalDate.of(endDate.getYear(), endDate.getMonth() , endDate.getDayOfMonth()) | ||
.atStartOfDay(); | ||
Long remainDay = Duration.between(today,dateTime).toDays(); | ||
if(remainDay > 0) { | ||
return String.valueOf(remainDay); | ||
}else{ | ||
return "마감"; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/kusitms/gallae/repository/ProgramRespository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package kusitms.gallae.repository; | ||
|
||
import kusitms.gallae.domain.Program; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface ProgramRespository extends JpaRepository<Program, Long> { | ||
@Override | ||
Optional<Program> findById(Long programId); | ||
|
||
List<Program> findByProgramType(String programType); | ||
|
||
List<Program> findTop4ByOrderByCreatedAtDesc(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package kusitms.gallae.service; | ||
|
||
import kusitms.gallae.dto.program.ProgramMainRes; | ||
|
||
import java.util.List; | ||
|
||
public interface ProgramService { | ||
|
||
List<ProgramMainRes> getRecentPrograms(); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/kusitms/gallae/service/ProgramServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package kusitms.gallae.service; | ||
|
||
|
||
import jakarta.transaction.Transactional; | ||
import kusitms.gallae.global.DurationCalcurator; | ||
import kusitms.gallae.domain.Program; | ||
import kusitms.gallae.dto.program.ProgramMainRes; | ||
import kusitms.gallae.repository.ProgramRespository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional | ||
@Service | ||
public class ProgramServiceImpl implements ProgramService { | ||
private final ProgramRespository programRespository; | ||
|
||
@Override | ||
public List<ProgramMainRes> getRecentPrograms(){ | ||
List<Program> programs = programRespository.findTop4ByOrderByCreatedAtDesc(); | ||
|
||
return programs.stream().map(program -> { | ||
ProgramMainRes programMainRes = new ProgramMainRes(); | ||
programMainRes.setProgramName(program.getProgramName()); | ||
programMainRes.setLike(program.getProgramLike()); | ||
programMainRes.setPhotoUrl(program.getPhotoUrl()); | ||
String strRemainDay = DurationCalcurator.getDuration(program.getRecruitEndDate()); | ||
programMainRes.setRemainDay(strRemainDay); | ||
return programMainRes; | ||
}).collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters