Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SYAHDAN PUTRA ADRIATAMA
Advanced Programming Tutorial 2022
Commits
5f931e01
Commit
5f931e01
authored
Feb 13, 2022
by
SYAHDAN PUTRA ADRIATAMA
Browse files
Merge branch 'task-implementation-course' into 'master'
Implement course page See merge request
!3
parents
ef740150
c26519ed
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/main/java/id/ac/ui/cs/advprog/tutorial0/controller/CourseController.java
0 → 100644
View file @
5f931e01
package
id.ac.ui.cs.advprog.tutorial0.controller
;
import
id.ac.ui.cs.advprog.tutorial0.model.Course
;
import
id.ac.ui.cs.advprog.tutorial0.service.CourseService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@Controller
@RequestMapping
(
"/course"
)
public
class
CourseController
{
@Autowired
private
CourseService
service
;
@GetMapping
(
"/list"
)
public
String
courseListPage
(
Model
model
)
{
List
<
Course
>
allCourses
=
service
.
findAll
();
model
.
addAttribute
(
"courses"
,
allCourses
);
return
"courseList"
;
}
@GetMapping
(
"/create"
)
public
String
createCoursePage
(
Model
model
)
{
Course
course
=
new
Course
();
model
.
addAttribute
(
"course"
,
course
);
return
"createCourse"
;
}
@PostMapping
(
"/create"
)
public
String
createCoursePost
(
@ModelAttribute
Course
course
,
Model
model
)
{
service
.
create
(
course
);
return
"redirect:list"
;
}
}
src/main/java/id/ac/ui/cs/advprog/tutorial0/model/Course.java
0 → 100644
View file @
5f931e01
package
id.ac.ui.cs.advprog.tutorial0.model
;
import
lombok.Getter
;
import
lombok.Setter
;
@Getter
@Setter
public
class
Course
{
private
String
courseId
;
private
String
name
;
private
Boolean
status
=
true
;
}
src/main/java/id/ac/ui/cs/advprog/tutorial0/repository/CourseRepository.java
0 → 100644
View file @
5f931e01
package
id.ac.ui.cs.advprog.tutorial0.repository
;
import
id.ac.ui.cs.advprog.tutorial0.model.Course
;
import
org.springframework.stereotype.Repository
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
@Repository
public
class
CourseRepository
{
private
List
<
Course
>
coursesInMemory
=
new
ArrayList
<>();
public
Course
create
(
Course
course
)
{
coursesInMemory
.
add
(
course
);
return
course
;
}
public
Iterator
<
Course
>
findAll
()
{
return
coursesInMemory
.
iterator
();
}
}
src/main/java/id/ac/ui/cs/advprog/tutorial0/service/CourseService.java
0 → 100644
View file @
5f931e01
package
id.ac.ui.cs.advprog.tutorial0.service
;
import
id.ac.ui.cs.advprog.tutorial0.model.Course
;
import
java.util.List
;
public
interface
CourseService
{
public
Course
create
(
Course
course
);
public
List
<
Course
>
findAll
();
}
src/main/java/id/ac/ui/cs/advprog/tutorial0/service/CourseServiceImpl.java
0 → 100644
View file @
5f931e01
package
id.ac.ui.cs.advprog.tutorial0.service
;
import
id.ac.ui.cs.advprog.tutorial0.model.Course
;
import
id.ac.ui.cs.advprog.tutorial0.repository.CourseRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
@Service
public
class
CourseServiceImpl
implements
CourseService
{
@Autowired
private
CourseRepository
courseRepository
;
@Override
public
Course
create
(
Course
course
)
{
generateId
(
course
);
courseRepository
.
create
(
course
);
return
course
;
}
private
void
generateId
(
Course
course
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
char
letter:
course
.
getName
().
toCharArray
())
{
stringBuilder
.
append
(
String
.
valueOf
((
int
)
letter
));
}
String
id
=
stringBuilder
.
toString
();
course
.
setCourseId
(
id
);
}
@Override
public
List
<
Course
>
findAll
()
{
Iterator
<
Course
>
courseIterator
=
courseRepository
.
findAll
();
List
<
Course
>
allCourse
=
new
ArrayList
<>();
courseIterator
.
forEachRemaining
(
allCourse:
:
add
);
return
allCourse
;
}
}
src/main/resources/templates/courseList.html
0 → 100644
View file @
5f931e01
<!DOCTYPE html>
<html
lang=
"en"
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
Course List
</title>
<link
href=
"https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel=
"stylesheet"
integrity=
"sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin=
"anonymous"
>
</head>
<body>
<h2>
Course' List
</h2>
<a
th:href=
"@{/course/create}"
class=
"btn btn-primary btn-sm mb-3"
>
Create course
</a>
<table
class=
"table"
>
<thead>
<tr>
<th
scope=
"col"
>
Name
</th>
<th
scope=
"col"
>
Course Id
</th>
<th
scope=
"col"
>
Vacancy Status
</th>
</tr>
</thead>
<tbody
th:each=
"course: ${courses}"
>
<tr>
<td
th:text=
"${course.name}"
></td>
<td
th:text=
"${course.courseId}"
></td>
<td
th:text=
"${course.status}"
></td>
</tr>
</tbody>
</table>
<script
src=
"https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity=
"sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin=
"anonymous"
></script>
</body>
</html>
\ No newline at end of file
src/main/resources/templates/createCourse.html
0 → 100644
View file @
5f931e01
<!DOCTYPE html>
<html
lang=
"en"
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
Create new Course
</title>
<link
href=
"https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel=
"stylesheet"
integrity=
"sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin=
"anonymous"
>
</head>
<body>
<h3>
Create new Course
</h3>
<form
th:action=
"@{/course/create}"
th:object=
"${course}"
method=
"post"
>
<div
class=
"form-group"
>
<label
for=
"nameInput"
>
Course Name
</label>
<input
th:field=
"*{name}"
type=
"text"
class=
"form-control"
id=
"nameInput"
aria-describedby=
"nameHelp"
placeholder=
"Enter course's name"
required
>
</div>
<button
type=
"submit"
class=
"btn btn-primary"
>
Submit
</button>
</form>
<script
src=
"https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity=
"sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin=
"anonymous"
></script>
</body>
</html>
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment