Skip to content

Commit

Permalink
dto, form, html整理
Browse files Browse the repository at this point in the history
  • Loading branch information
tttol committed Jan 8, 2023
1 parent 4587a47 commit 0cdf09f
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class MrListController {

@GetMapping
public String list(Model model) {
model.addAttribute("mergeRequestInfoFormList", mergeRequestService.get());
model.addAttribute("mrInfoFormList", mergeRequestService.get());
return "list";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@NoArgsConstructor
@AllArgsConstructor
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class MergeRequestInfoDto {
public class GitLabMergeRequestApiResponseDto {
int id;

int iid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.tttol.mrls.external;

import io.github.tttol.mrls.dto.MergeRequestInfoDto;
import io.github.tttol.mrls.dto.GitLabMergeRequestApiResponseDto;
import io.github.tttol.mrls.exception.GitLabApiException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -26,7 +26,7 @@ public class GitLabApiExecutor {
@Value("${app.gitlab.project.accessToken}")
private String projectAccessToken;

public List<MergeRequestInfoDto> getMergeRequests() {
public List<GitLabMergeRequestApiResponseDto> getMergeRequests() {
// TODO 例外処理
try {
var requestEntity = RequestEntity
Expand All @@ -35,7 +35,7 @@ public List<MergeRequestInfoDto> getMergeRequests() {
.header("Authorization", "Bearer %s".formatted(projectAccessToken))
.build();
log.info("api url -> {}", requestEntity.getUrl());
var responseEntity = restTemplate.exchange(requestEntity, MergeRequestInfoDto[].class);
var responseEntity = restTemplate.exchange(requestEntity, GitLabMergeRequestApiResponseDto[].class);
log.debug("status code -> {}", responseEntity.getStatusCode());
var body = responseEntity.getBody();
return Objects.isNull(body) ? List.of() : Arrays.asList(body);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/io/github/tttol/mrls/form/LinkForm.java

This file was deleted.

This file was deleted.

7 changes: 7 additions & 0 deletions src/main/java/io/github/tttol/mrls/form/MrDetailForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.tttol.mrls.form;

import java.time.LocalDateTime;

public record MrDetailForm(String title, String webUrl, UserForm author, LocalDateTime createdAt,
LocalDateTime updatedAt) {
}
6 changes: 6 additions & 0 deletions src/main/java/io/github/tttol/mrls/form/MrInfoForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.tttol.mrls.form;

import java.util.List;

public record MrInfoForm(UserForm assignee, List<MrDetailForm> mrDetailForms, int assignedMrCount) {
}
3 changes: 3 additions & 0 deletions src/main/java/io/github/tttol/mrls/form/UserForm.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package io.github.tttol.mrls.form;

public record UserForm(int id, String username, String name, String state, String avatarUrl, String webUrl) {
public static UserForm empty() {
return new UserForm(0, null, null, null, null, null);
}
}
53 changes: 37 additions & 16 deletions src/main/java/io/github/tttol/mrls/service/MergeRequestService.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package io.github.tttol.mrls.service;

import io.github.tttol.mrls.dto.MergeRequestInfoDto;
import io.github.tttol.mrls.dto.GitLabMergeRequestApiResponseDto;
import io.github.tttol.mrls.external.GitLabApiExecutor;
import io.github.tttol.mrls.form.LinkForm;
import io.github.tttol.mrls.form.MergeRequestInfoForm;
import io.github.tttol.mrls.form.MrDetailForm;
import io.github.tttol.mrls.form.MrInfoForm;
import io.github.tttol.mrls.form.UserForm;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class MergeRequestService {
private final GitLabApiExecutor gitLabApiExecutor;

public List<MergeRequestInfoForm> get() {
public List<MrInfoForm> get() {
var mergeRequestInfoDtos = executeGitLabApi();
return mergeRequestInfoDtos.stream()
.collect(Collectors.groupingBy(
Expand All @@ -28,20 +29,40 @@ public List<MergeRequestInfoForm> get() {
.values().stream().map(this::generateForm).toList();
}

private List<MergeRequestInfoDto> executeGitLabApi() {
private List<GitLabMergeRequestApiResponseDto> executeGitLabApi() {
return gitLabApiExecutor.getMergeRequests();
}

private MergeRequestInfoForm generateForm(List<MergeRequestInfoDto> dtos) {
var userDto = dtos.stream().findAny()
.map(MergeRequestInfoDto::getAssignee).orElseThrow();
var userForm = new UserForm(userDto.getId(),
userDto.getUsername(),
userDto.getName(),
userDto.getState(),
userDto.getAvatarUrl(),
userDto.getWebUrl());
var linkForms = dtos.stream().map(e -> new LinkForm(e.getTitle(), e.getWebUrl())).toList();
return new MergeRequestInfoForm(userForm, linkForms, linkForms.size());
private MrInfoForm generateForm(List<GitLabMergeRequestApiResponseDto> responseDtos) {
var responseDto = responseDtos.stream().findAny().orElseThrow();
var assigneeForm = Optional.ofNullable(responseDto.getAssignee())
.map(assignee -> new UserForm(
assignee.getId(),
assignee.getUsername(),
assignee.getName(),
assignee.getState(),
assignee.getAvatarUrl(),
assignee.getWebUrl()
)
).orElse(UserForm.empty());
var linkForms = responseDtos.stream().map(e ->
new MrDetailForm(
e.getTitle(),
e.getWebUrl(),
Optional.ofNullable(e.getAuthor())
.map(assignee -> new UserForm(
assignee.getId(),
assignee.getUsername(),
assignee.getName(),
assignee.getState(),
assignee.getAvatarUrl(),
assignee.getWebUrl()
)
)
.orElse(UserForm.empty()),
e.getCreatedAt(),
e.getUpdatedAt()
)).toList();
return new MrInfoForm(assigneeForm, linkForms, linkForms.size());
}
}
36 changes: 34 additions & 2 deletions src/main/resources/static/css/list.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ body {
}

main {
margin: 15px 200px;
margin: 1% 5%;
}

a:-webkit-any-link {
Expand All @@ -20,6 +20,10 @@ table {
border-collapse:collapse;
}

.mrTable {
width: 100%;
}

.headerBox {
background-color: #292961;
height: 30px;
Expand All @@ -28,14 +32,22 @@ table {
text-align: center;
}

.avatarImg {
.assigneeAvatarImg {
width: 50px;
height: 50px;
border: solid;
border-width: 0.5px;
border-radius: 50%;
}

.authorAvatarImg {
width: 25px;
height: 25px;
border: solid;
border-width: 0.5px;
border-radius: 50%;
}

.avatar {
position: relative;
padding: 1rem;
Expand Down Expand Up @@ -66,6 +78,7 @@ table {

.mrList {
margin: 0;
padding: 0;
}

.mrList li:not(:last-child) {
Expand All @@ -76,6 +89,11 @@ table {

.mrBox {
padding: 5px;
display: flex;
}

.mrLinkBox {
margin-bottom: 5px;
}

.mrLink {
Expand All @@ -87,6 +105,20 @@ table {
opacity: 0.7;
}

.titleBox {
padding-right: 20px;
}

.at {
color: darkgray;
font-size: 13px;
padding-right: 10px;
}

.authorBox {
margin-left: auto;
}

footer .appVer {
color: darkgray;
font-size: 10pt;
Expand Down
30 changes: 23 additions & 7 deletions src/main/resources/templates/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,36 @@
<body>
<div th:replace="fragment/header::header"></div>
<main>
<table>
<tr class="assigneeBox" th:each="form : ${mergeRequestInfoFormList}">
<table class="mrTable">
<tr class="assigneeBox" th:each="infoForm : ${mrInfoFormList}">
<td>
<div class="avatar">
<img class="avatarImg" th:src="${form.assignee.avatarUrl}"/>
<span class="badge" th:text="${form.assignedMrCount}">1</span>
<img class="assigneeAvatarImg" th:src="${infoForm.assignee.avatarUrl}"/>
<span class="badge" th:text="${infoForm.assignedMrCount}">1</span>
</div>
</td>
<td>
<ul class="mrList">
<li th:each="link : ${form.linkForms}">
<li th:each="detailForm : ${infoForm.mrDetailForms}">
<div class="mrBox">
<a class="mrLink" th:href="${link.webUrl}" th:text="${link.title}"
target="_blank">MRタイトル</a>
<div class="titleBox">
<div class="mrLinkBox">
<a class="mrLink" th:href="${detailForm.webUrl}"
th:text="${detailForm.title}"
target="_blank">MRタイトル</a>
</div>
<span class="at">
created at:[[${#temporals.format(detailForm.createdAt, 'yyyy/MM/dd
HH:mm:ss')}]]
</span>
<span class="at">
updated at:[[${#temporals.format(detailForm.updatedAt, 'yyyy/MM/dd
HH:mm:ss')}]]
</span>
</div>
<div class="authorBox">
<img class="authorAvatarImg" th:src="${detailForm.author.avatarUrl}"/>
</div>
</div>
</li>
</ul>
Expand Down
Loading

0 comments on commit 0cdf09f

Please sign in to comment.