Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copilot feature rld #25

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.liatrio.dojo.devopsknowledgeshareapi;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AuthController {

@GetMapping("/authors")
public ResponseEntity<String> getAuthors() {
return ResponseEntity.ok("Authors endpoint");
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/liatrio/dojo/devopsknowledgeshareapi/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}

private String dateUpdated;

public void setDateUpdated(Date dateAsDate) {
DateFormat dateFormat = new SimpleDateFormat(dateFormat());
this.dateUpdated = dateFormat.format(dateAsDate);
}

public String getDateUpdated() {
return dateUpdated;
}

public boolean validatePostLink(String postLink) {
String pattern = "\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
return postLink.matches(pattern);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.liatrio.dojo.devopsknowledgeshareapi;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -31,6 +32,25 @@ public Post post(@RequestBody Post post, HttpServletResponse resp) {
return repository.save(post);
}

@PutMapping("/posts/{id}")
public Post updatePost(@PathVariable Long id, @RequestBody Post newPost) {
return repository.findById(id)
.map(post -> {
post.setTitle(newPost.getTitle());
post.setFirstName(newPost.getFirstName());
try {
post.setLink(newPost.getLink());
} catch (Exception e) {
e.printStackTrace();
}
return repository.save(post);
})
.orElseGet(() -> {
newPost.setId(id);
return repository.save(newPost);
});
}

@DeleteMapping("/posts/{id}")
public void deletePost(@PathVariable("id") String id) {
log.info("{}: recieved a DELETE request", deploymentType);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.liatrio.dojo.devopsknowledgeshareapi;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest
@AutoConfigureMockMvc
public class AuthControllerTest {

@Autowired
private MockMvc mockMvc;

@Test
public void testGetAuthors() throws Exception {
mockMvc.perform(get("/authors"))
.andExpect(status().isOk());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Date;

import static org.junit.jupiter.api.Assertions.assertNotEquals;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

@ExtendWith(SpringExtension.class)
public class PostTest {
Expand Down Expand Up @@ -106,4 +111,26 @@ public void getImageUrlTest() throws Exception {
String test = hc.getImageUrl();
assertEquals(imageUrl, test);
}

@Test
public void setDateUpdatedTest() throws Exception {
Post hc = new Post();
Date date = new Date();
hc.setDateUpdated(date);
DateFormat dateFormat = new SimpleDateFormat(hc.dateFormat());
String expected = dateFormat.format(date);
String actual = hc.getDateUpdated();
assertEquals(expected, actual);
}

@Test
public void getDateUpdatedTest() throws Exception {
Post hc = new Post();
Date date = new Date();
hc.setDateUpdated(date);
DateFormat dateFormat = new SimpleDateFormat(hc.dateFormat());
String expected = dateFormat.format(date);
String actual = hc.getDateUpdated();
assertEquals(expected, actual);
}
}
Loading