feat(internal/scoreboard/scoreboard.go): skeleton of scoreboard
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		
							parent
							
								
									5ac760814d
								
							
						
					
					
						commit
						625f123e18
					
				
							
								
								
									
										52
									
								
								internal/scoreboard/scoreboard.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								internal/scoreboard/scoreboard.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,52 @@ | |||
| package scoreboard | ||||
| 
 | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"os" | ||||
| ) | ||||
| 
 | ||||
| type Question struct { | ||||
| 	Name    string `json:"name"` | ||||
| 	Score   int    `json:"score"` | ||||
| 	Comment string `json:"comment"` | ||||
| } | ||||
| 
 | ||||
| type ScoreboardData struct { | ||||
| 	StudentName string     `json:"studentname"` | ||||
| 	StudentId   string     `json:"studentid"` | ||||
| 	Questions   []Question `json:"questions"` | ||||
| } | ||||
| 
 | ||||
| type Scoreboard struct { | ||||
| 	scoreboard ScoreboardData | ||||
| } | ||||
| 
 | ||||
| func (b *Scoreboard) Init(studentName string, studentId string) { | ||||
| 	b.scoreboard.StudentName = studentName | ||||
| 	b.scoreboard.StudentId = studentId | ||||
| 	b.scoreboard.Questions = make([]Question, 0) | ||||
| } | ||||
| 
 | ||||
| func (b *Scoreboard) AddScore(questionName string, score int) { | ||||
| 	flag := false | ||||
| 	for i, question := range b.scoreboard.Questions { | ||||
| 		if question.Name == questionName { | ||||
| 			b.scoreboard.Questions[i].Score = score | ||||
| 			flag = true | ||||
| 			break | ||||
| 		} | ||||
| 	} | ||||
| 	if flag { | ||||
| 		b.scoreboard.Questions = append(b.scoreboard.Questions, Question{Name: questionName, Score: score}) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (b *Scoreboard) SaveFile(filePath string) { | ||||
| 	json_file, _ := os.Create(filePath) | ||||
| 	defer json_file.Close() | ||||
| 
 | ||||
| 	encoder := json.NewEncoder(json_file) | ||||
| 	encoder.SetEscapeHTML(false) | ||||
| 	encoder.SetIndent("", "  ") | ||||
| 	_ = encoder.Encode(b.scoreboard) | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user