This repository has been archived by the owner on Apr 27, 2024. It is now read-only.
-
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.
Merge pull request #43 from WisdomWorks/WW-93
WW-93
- Loading branch information
Showing
10 changed files
with
174 additions
and
17 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
46 changes: 46 additions & 0 deletions
46
src/main/java/com/example/codeE/controller/GroupController.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,46 @@ | ||
package com.example.codeE.controller; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import com.example.codeE.model.group.Group; | ||
import com.example.codeE.service.group.GroupService; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/group") | ||
@Validated | ||
public class GroupController { | ||
@Autowired | ||
private GroupService groupService; | ||
|
||
@GetMapping | ||
@RequestMapping(value = "",method = RequestMethod.GET) | ||
public ResponseEntity<?> getAllGroups() { | ||
return new ResponseEntity<>(groupService.getAll(), HttpStatus.OK); | ||
} | ||
|
||
@GetMapping | ||
@RequestMapping(value = "{groupId}",method = RequestMethod.GET) | ||
public ResponseEntity<?> getGroupById(@PathVariable String groupId) { | ||
return new ResponseEntity<>(groupService.getById(groupId), HttpStatus.OK); | ||
} | ||
|
||
@PostMapping | ||
@RequestMapping(value = "", method = RequestMethod.POST) | ||
public ResponseEntity<?> createGroup(@RequestBody Group group) { | ||
return new ResponseEntity<>(groupService.createOne(group), HttpStatus.CREATED); | ||
} | ||
|
||
// @PutMapping("/{groupId}") | ||
// public ResponseEntity<?> updateGroup(String groupId, @RequestBody Group group) { | ||
// return new ResponseEntity<>(groupService.updateGroupById(groupId, group), HttpStatus.OK); | ||
// } | ||
// @DeleteMapping("/{groupId}") | ||
// public ResponseEntity<?> deleteGroup(String groupId) { | ||
// groupService.deleteById(groupId); | ||
// return new ResponseEntity<>(HttpStatus.OK); | ||
// } | ||
} |
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 |
---|---|---|
@@ -1,27 +1,52 @@ | ||
package com.example.codeE.model.group; | ||
|
||
import java.sql.Date; | ||
import java.time.LocalDateTime; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.PrePersist; | ||
import jakarta.persistence.PreUpdate; | ||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.NonNull; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity(name = "group") | ||
public class Group { | ||
@NonNull | ||
@Id | ||
@NotBlank(message = "Group id is required") | ||
@Column(name = "group_id") | ||
private String groupId; | ||
@NonNull | ||
|
||
@NotBlank(message = "Course id is required") | ||
@Column(name = "course_id") | ||
private String courseId; | ||
@NonNull | ||
|
||
@NotBlank(message = "Group name is required") | ||
@Column(name = "group_name") | ||
private String groupName; | ||
@NonNull | ||
private Date dateCreate; | ||
@NonNull | ||
private String description; | ||
private int numberMember; | ||
|
||
@Column(name = "create_date", nullable = false, updatable = false, columnDefinition = "DATETIME DEFAULT CURRENT_TIMESTAMP") | ||
private LocalDateTime dateCreate; | ||
|
||
@Column(name = "update_date", nullable = false, columnDefinition = "DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") | ||
private LocalDateTime updateDate; | ||
|
||
@PrePersist | ||
protected void onCreate() { | ||
LocalDateTime now = LocalDateTime.now(); | ||
this.dateCreate = now; | ||
this.updateDate = now; | ||
} | ||
|
||
@PreUpdate | ||
protected void onUpdate() { | ||
updateDate = LocalDateTime.now(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/example/codeE/repository/GroupRepository.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,6 @@ | ||
package com.example.codeE.repository; | ||
|
||
import com.example.codeE.model.group.Group; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
public interface GroupRepository extends JpaRepository<Group, String>{ | ||
} |
5 changes: 2 additions & 3 deletions
5
src/main/java/com/example/codeE/service/common/CommonService.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
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
68 changes: 68 additions & 0 deletions
68
src/main/java/com/example/codeE/service/group/GroupImpl.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,68 @@ | ||
package com.example.codeE.service.group; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import com.example.codeE.model.group.Group; | ||
import com.example.codeE.model.user.User; | ||
import com.example.codeE.repository.GroupRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class GroupImpl implements GroupService{ | ||
|
||
@Autowired | ||
private GroupRepository groupRepository; | ||
|
||
@Override | ||
public Group createOne(Group group) { | ||
group.setGroupId(UUID.randomUUID().toString()); | ||
return this.groupRepository.save(group); | ||
} | ||
|
||
@Override | ||
public Group getById(String GroupId) { | ||
Optional<Group> groupOptional = this.groupRepository.findById(GroupId); | ||
return groupOptional.orElse(null); | ||
} | ||
|
||
@Override | ||
public List<Group> getAll() { | ||
var result = this.groupRepository.findAll(); | ||
if(result.size() > 0) { | ||
return result; | ||
}else | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean deleteById(String id) { | ||
if (!groupRepository.existsById(id)) { | ||
return false; | ||
} | ||
this.groupRepository.deleteById(id); | ||
return true; | ||
} | ||
|
||
@Override | ||
public List<Group> getGroupsByCourseId(String courseId) { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'getGroupsByCourseId'"); | ||
} | ||
|
||
@Override | ||
public List<User> getUsersInGroup(String groupId) { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'getUsersInGroup'"); | ||
} | ||
|
||
@Override | ||
public Boolean updateGroupById(String groupId, Group updatedGroup) { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'updateGroupById'"); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/example/codeE/service/group/GroupService.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,13 @@ | ||
package com.example.codeE.service.group; | ||
|
||
import java.util.List; | ||
|
||
import com.example.codeE.model.group.Group; | ||
import com.example.codeE.model.user.User; | ||
import com.example.codeE.service.common.CommonService; | ||
|
||
public interface GroupService extends CommonService<Group> { | ||
Boolean updateGroupById(String groupId, Group updatedGroup); | ||
List<Group> getGroupsByCourseId(String courseId); | ||
List<User> getUsersInGroup(String groupId); | ||
} |
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