-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from aws-cloud-clubs/feature/issue-20
Feature/issue 20
- Loading branch information
Showing
14 changed files
with
284 additions
and
8 deletions.
There are no files selected for viewing
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
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,55 @@ | ||
package acc.hotsix.file_share.domain; | ||
|
||
import static com.querydsl.core.types.PathMetadataFactory.*; | ||
|
||
import com.querydsl.core.types.dsl.*; | ||
|
||
import com.querydsl.core.types.PathMetadata; | ||
import javax.annotation.processing.Generated; | ||
import com.querydsl.core.types.Path; | ||
import com.querydsl.core.types.dsl.PathInits; | ||
|
||
|
||
/** | ||
* QLog is a Querydsl query type for Log | ||
*/ | ||
@Generated("com.querydsl.codegen.DefaultEntitySerializer") | ||
public class QLog extends EntityPathBase<Log> { | ||
|
||
private static final long serialVersionUID = -26769568L; | ||
|
||
private static final PathInits INITS = PathInits.DIRECT2; | ||
|
||
public static final QLog log = new QLog("log"); | ||
|
||
public final DateTimePath<java.time.LocalDateTime> createdAt = createDateTime("createdAt", java.time.LocalDateTime.class); | ||
|
||
public final QFile file; | ||
|
||
public final NumberPath<Long> logId = createNumber("logId", Long.class); | ||
|
||
public final EnumPath<Log.Type> type = createEnum("type", Log.Type.class); | ||
|
||
public QLog(String variable) { | ||
this(Log.class, forVariable(variable), INITS); | ||
} | ||
|
||
public QLog(Path<? extends Log> path) { | ||
this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); | ||
} | ||
|
||
public QLog(PathMetadata metadata) { | ||
this(metadata, PathInits.getFor(metadata, INITS)); | ||
} | ||
|
||
public QLog(PathMetadata metadata, PathInits inits) { | ||
this(Log.class, metadata, inits); | ||
} | ||
|
||
public QLog(Class<? extends Log> type, PathMetadata metadata, PathInits inits) { | ||
super(type, metadata, inits); | ||
this.file = inits.isInitialized("file") ? new QFile(forProperty("file")) : null; | ||
} | ||
|
||
} | ||
|
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
40 changes: 40 additions & 0 deletions
40
src/main/java/acc/hotsix/file_share/api/LogController.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,40 @@ | ||
package acc.hotsix.file_share.api; | ||
|
||
import acc.hotsix.file_share.application.LogService; | ||
import acc.hotsix.file_share.dto.LogResponseDto; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
@RestController | ||
@AllArgsConstructor | ||
@RequestMapping("/files") | ||
public class LogController { | ||
|
||
private final LogService logService; | ||
|
||
// @GetMapping("/{file-id}/logs") | ||
// public ResponseEntity<List<LogResponseDto>> getFileLogs(@PathVariable("file-id") Long fileId, | ||
// @RequestParam(defaultValue = "0") int page, | ||
// @RequestParam(defaultValue = "10") int size) { | ||
// | ||
// return ResponseEntity.ok().body(logService.findLogsByFileId(fileId, page, size)); | ||
// } | ||
|
||
@GetMapping("/{file-id}/logs") | ||
public ResponseEntity<List<LogResponseDto>> getFileLogsByType(@PathVariable("file-id") Long fileId, | ||
@RequestParam(required = false,defaultValue = "none") String type, | ||
@RequestParam(defaultValue = "0") int page, | ||
@RequestParam(defaultValue = "10") int size) { | ||
|
||
return ResponseEntity.ok().body(logService.findLogsByFileIdAndType(fileId, type, page, size)); | ||
} | ||
} | ||
|
||
// 로그 파일id로 조회, | ||
// 로그 타입으로 조회, 로그 생성 시각으로 조회 |
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
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
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
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
43 changes: 43 additions & 0 deletions
43
src/main/java/acc/hotsix/file_share/application/LogService.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,43 @@ | ||
package acc.hotsix.file_share.application; | ||
|
||
import acc.hotsix.file_share.dao.LogRepository; | ||
import acc.hotsix.file_share.domain.Log; | ||
import acc.hotsix.file_share.dto.LogResponseDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class LogService { | ||
private final LogRepository logRepository; | ||
|
||
// public List<LogResponseDto> findLogsByFileId(Long fileId, int page, int size) { | ||
// Pageable pageable = PageRequest.of(page, size); | ||
// List<Log> content = logRepository.findByFileFileId(fileId, pageable).getContent(); | ||
// | ||
// return content.stream() | ||
// .map(log -> LogResponseDto.toLogResponseDto(log)) | ||
// .collect(Collectors.toList()); | ||
// } | ||
|
||
public List<LogResponseDto> findLogsByFileIdAndType(Long fileId, String type, int page, int size) { | ||
Pageable pageable = PageRequest.of(page, size); | ||
List<Log> content; | ||
|
||
if(type.equals("none")) | ||
content = logRepository.findByFileFileId(fileId, pageable).getContent(); | ||
else | ||
content = logRepository.findByFileFileIdAndType(fileId, Log.Type.valueOf(type), pageable).getContent(); | ||
|
||
return content.stream() | ||
.map(log -> LogResponseDto.toLogResponseDto(log)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/acc/hotsix/file_share/dao/LogRepository.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,14 @@ | ||
package acc.hotsix.file_share.dao; | ||
|
||
import acc.hotsix.file_share.domain.Log; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface LogRepository extends JpaRepository<Log, Long> { | ||
Page<Log> findByFileFileId(Long fileId, Pageable pageable); | ||
|
||
Page<Log> findByFileFileIdAndType(Long fileId, Log.Type type, Pageable pageable); | ||
} |
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
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,41 @@ | ||
package acc.hotsix.file_share.domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class Log { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long logId; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private Type type; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name="file_id") | ||
private File file; | ||
|
||
@CreatedDate | ||
private LocalDateTime createdAt; | ||
|
||
public enum Type { | ||
CREATE, READ, UPDATE, DOWNLOAD | ||
} | ||
|
||
@Builder | ||
private Log(Type type, File file) { | ||
this.type = type; | ||
this.file = file; | ||
} | ||
} |
Oops, something went wrong.